Skip to content

Commit

Permalink
I think it is final
Browse files Browse the repository at this point in the history
  • Loading branch information
Deliner committed Sep 6, 2020
1 parent 793f7db commit b76bb72
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
package com.deliner.mosfauna.activity

import android.content.Intent
import android.media.MediaPlayer
import android.os.Bundle
import android.view.MenuItem
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import com.deliner.mosfauna.R
import com.deliner.mosfauna.utils.LoginManager
import com.google.android.material.floatingactionbutton.FloatingActionButton

class BirdInfoActivity : UserActivity() {

private var photoId = -1


private lateinit var birdName: String


private lateinit var birdImageView: ImageView
private lateinit var birdNameView: TextView
private lateinit var birdEnglishNameView: TextView
private lateinit var birdInfoView: TextView
private lateinit var actionButton: FloatingActionButton
private lateinit var playSongButton: ImageView

private val audioPlayer = MediaPlayer()
private var infoPlayer: MediaPlayer? = null
private var songPlayer: MediaPlayer? = null

private var songIsPlaying = false
private var infoIsPlaying = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -51,6 +49,67 @@ class BirdInfoActivity : UserActivity() {
birdEnglishNameView.text = getEnglishName(birdName)
birdImageView.setImageResource(photoId)
birdInfoView.text = getBirdInfo(birdName)


playSongButton.setOnClickListener {
if (songIsPlaying) {
songPlayer!!.stop()
songIsPlaying = false
songPlayer = null
playSongButton.setImageResource(R.drawable.ic_baseline_play)
} else {
playSongButton.setImageResource(R.drawable.ic_pause)
songPlayer = MediaPlayer.create(applicationContext, getSongRaw(birdName))
songPlayer!!.setOnCompletionListener {
songPlayer!!.stop()
songIsPlaying = false
songPlayer = null
playSongButton.setImageResource(R.drawable.ic_baseline_play)
}
songPlayer!!.start()
songIsPlaying = true
}
}

actionButton.setOnClickListener {
if (infoIsPlaying) {
infoPlayer!!.stop()
infoIsPlaying = false
infoPlayer = null
actionButton.setImageResource(R.drawable.ic_play)
} else {
actionButton.setImageResource(R.drawable.ic_pause_action)
infoPlayer = MediaPlayer.create(applicationContext, getInfoRaw(birdName))
infoPlayer!!.setOnCompletionListener {
infoPlayer!!.stop()
infoIsPlaying = false
infoPlayer = null
playSongButton.setImageResource(R.drawable.ic_play)
}
infoPlayer!!.start()
infoIsPlaying = true
}
}
}

private fun getSongRaw(name: String): Int {
return when (name) {
"Обыкновенный гоголь" -> R.raw.gogol
"Ястреб-перепелятник" -> R.raw.perepel
"Ястреб-тетеревятник" -> R.raw.teterev
"Серая неясыть" -> R.raw.neyasyt
else -> R.raw.gogol
}
}

private fun getInfoRaw(name: String): Int {
return when (name) {
"Обыкновенный гоголь" -> R.raw.info_gogol
"Ястреб-перепелятник" -> R.raw.info_perepel
"Ястреб-тетеревятник" -> R.raw.info_teterev
"Серая неясыть" -> R.raw.info_neyas
else -> R.raw.info_gogol
}
}

private fun getEnglishName(name: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class GuideFragment : CommonFragment(), OnMapReadyCallback,

override fun onClusterItemClick(item: Bird): Boolean {
currentBirb = item
Toast.makeText(context, "Поставьте маркер, где вы видели животное", Toast.LENGTH_LONG).show()
return false
}

Expand Down
10 changes: 10 additions & 0 deletions amc/app/src/main/res/drawable/ic_pause.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM11,16L9,16L9,8h2v8zM15,16h-2L13,8h2v8z" />
</vector>
5 changes: 5 additions & 0 deletions amc/app/src/main/res/drawable/ic_pause_action.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="32dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z"/>
</vector>
2 changes: 1 addition & 1 deletion amc/app/src/main/res/drawable/ic_play.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:tint="?attr/colorControlNormal"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
Expand Down
27 changes: 16 additions & 11 deletions amc/app/src/main/res/layout/activity_bird_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
layout="@layout/toolbar" />

<RelativeLayout
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">

android:layout_height="wrap_content"
android:padding="8dp">

<ImageView
android:id="@+id/activity_bird_info_image"
Expand All @@ -34,16 +33,16 @@
android:orientation="vertical">

<TextView
android:textSize="24sp"
android:id="@+id/activity_bird_info_bird_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:textSize="24sp" />

<TextView
android:textSize="18sp"
android:id="@+id/activity_bird_info_bird_name_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:textSize="18sp" />


<RelativeLayout
Expand All @@ -55,7 +54,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Услышать пение птицы " />
android:text="Пение птицы " />

<ImageView
android:id="@+id/activity_bird_info_play_song_button"
Expand All @@ -71,10 +70,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/activity_bird_info_text"

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">

<TextView
android:id="@+id/activity_bird_info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</ScrollView>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/activity_bird_info_action_button"
Expand Down
Binary file added amc/app/src/main/res/raw/gogol.mp3
Binary file not shown.
Binary file added amc/app/src/main/res/raw/info_gogol.m4a
Binary file not shown.
Binary file added amc/app/src/main/res/raw/info_neyas.m4a
Binary file not shown.
Binary file added amc/app/src/main/res/raw/info_perepel.m4a
Binary file not shown.
Binary file added amc/app/src/main/res/raw/info_teterev.m4a
Binary file not shown.
Binary file added amc/app/src/main/res/raw/neyasyt.mp3
Binary file not shown.
Binary file added amc/app/src/main/res/raw/perepel.mp3
Binary file not shown.
Binary file added amc/app/src/main/res/raw/teterev.mp3
Binary file not shown.
Loading

0 comments on commit b76bb72

Please sign in to comment.