diff --git a/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt b/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt
index 2519538..e7cfb14 100644
--- a/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt
+++ b/app/src/main/java/eu/zderadicka/audioserve/MainActivity.kt
@@ -21,7 +21,6 @@ import android.view.View
import android.widget.TextView
import android.widget.Toast
import eu.zderadicka.audioserve.fragments.*
-import eu.zderadicka.audioserve.utils.ifStoppedOrDead
import kotlinx.android.synthetic.main.content_main.*
import java.io.File
import android.app.SearchManager
@@ -35,9 +34,7 @@ import eu.zderadicka.audioserve.data.*
import eu.zderadicka.audioserve.net.DOWNLOAD_ACTION
import eu.zderadicka.audioserve.net.DownloadService
import eu.zderadicka.audioserve.ui.ExpandableFrameLayout
-import eu.zderadicka.audioserve.utils.SleepService
-import eu.zderadicka.audioserve.utils.cancelSleepTimer
-import eu.zderadicka.audioserve.utils.extendSleepTimer
+import eu.zderadicka.audioserve.utils.*
import kotlinx.android.synthetic.main.sleep_overlay.*
@@ -87,16 +84,25 @@ class MainActivity : AppCompatActivity(),
}
+
+ private var playerControlsVisible = false
+ set(value) {
+ if (field!= value) {
+ field = value
+ invalidateOptionsMenu()
+ }
+ }
private val mCallback = object : MediaControllerCompat.Callback() {
override fun onPlaybackStateChanged(state: PlaybackStateCompat?) {
- if (state == null) return
super.onPlaybackStateChanged(state)
ifStoppedOrDead(state,
{
playerControlsContainer.visibility = View.GONE
+ playerControlsVisible = false
},
{
playerControlsContainer.visibility = View.VISIBLE
+ playerControlsVisible = true
//playerControlsContainer.layoutParams.height = resources.getDimension(R.dimen.control_view_height_max).toInt();
})
@@ -392,8 +398,16 @@ class MainActivity : AppCompatActivity(),
mCallback.onPlaybackStateChanged(mediaController?.playbackState)
}
-
+ private var timerOn = false
+ set(value) {
+ if (field!= value) {
+ invalidateOptionsMenu()
+ field = value
+ }
+ }
private fun onTimerChange(isRunning:Boolean, remains_mins: Int) {
+
+ timerOn = isRunning
val menu = nav_view.menu
val startTimer = menu.findItem(R.id.nav_sleep)
val stopTimer = menu.findItem(R.id.nav_cancel_sleep)
@@ -452,7 +466,7 @@ class MainActivity : AppCompatActivity(),
super.onBackPressed()
} else {
backDoublePressed = true
- Toast.makeText(this, "Press Back again to exit", Toast.LENGTH_SHORT).show()
+ Toast.makeText(this, getString(R.string.press_back_toast), Toast.LENGTH_SHORT).show()
Handler().postDelayed({ backDoublePressed = false }, 2000)
}
@@ -466,6 +480,8 @@ class MainActivity : AppCompatActivity(),
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
+ val timerItem = menu.findItem(R.id.action_sleep)
+ timerItem.isVisible = ! timerOn && playerControlsVisible
val searchItem = menu.findItem(R.id.action_search)
searchItem.isVisible = searchPrefix != null
val infoItem = menu.findItem(R.id.action_info)
@@ -483,10 +499,10 @@ class MainActivity : AppCompatActivity(),
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
Log.d(LOG_TAG, "Clicked menu item id ${item.itemId} which is resource ${resources.getResourceName(item.itemId)}")
- when (item.itemId) {
+ return when (item.itemId) {
R.id.action_reload -> {
folderFragment?.reload()
- return true
+ true
}
R.id.action_info -> {
@@ -495,7 +511,12 @@ class MainActivity : AppCompatActivity(),
intent.putExtra(ARG_FOLDER_NAME, folderFragment?.folderName)
intent.putExtra(ARG_FOLDER_DETAILS, folderDetails)
startActivity(intent)
- return true
+ true
+ }
+
+ R.id.action_sleep -> {
+ startSleepTimer(this)
+ true
}
diff --git a/app/src/main/java/eu/zderadicka/audioserve/fragments/SleepDialogFragment.kt b/app/src/main/java/eu/zderadicka/audioserve/fragments/SleepDialogFragment.kt
index 040833b..04cd466 100644
--- a/app/src/main/java/eu/zderadicka/audioserve/fragments/SleepDialogFragment.kt
+++ b/app/src/main/java/eu/zderadicka/audioserve/fragments/SleepDialogFragment.kt
@@ -12,6 +12,7 @@ import android.widget.Switch
import eu.zderadicka.audioserve.R
import eu.zderadicka.audioserve.utils.SLEEP_START_ACTION
import eu.zderadicka.audioserve.utils.SleepService
+import eu.zderadicka.audioserve.utils.startSleepTimer
// All four must be dividable by 5
@@ -78,11 +79,7 @@ class SleepDialogFragment : DialogFragment() {
.setIcon(R.drawable.ic_timer)
.setView(view)
.setPositiveButton("Start", { _, _ ->
-
- val intent = Intent(context, SleepService::class.java)
- intent.action = SLEEP_START_ACTION
- activity?.startService(intent)
-
+ activity?.let { startSleepTimer(it) }
})
.setNegativeButton("Cancel", { _, _ ->
diff --git a/app/src/main/java/eu/zderadicka/audioserve/utils/SleepService.kt b/app/src/main/java/eu/zderadicka/audioserve/utils/SleepService.kt
index 222b445..879249f 100644
--- a/app/src/main/java/eu/zderadicka/audioserve/utils/SleepService.kt
+++ b/app/src/main/java/eu/zderadicka/audioserve/utils/SleepService.kt
@@ -46,6 +46,12 @@ fun cancelSleepTimer(context: Context) {
context.startService(intent)
}
+fun startSleepTimer(context: Context) {
+ val intent = Intent(context, SleepService::class.java)
+ intent.action = SLEEP_START_ACTION
+ context.startService(intent)
+}
+
fun extendSleepTimer(context: Context) {
val intent = Intent(context, SleepService::class.java)
intent.action = SLEEP_EXTEND_ACTION
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index 4436aa1..bf6ab49 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -6,7 +6,15 @@
android:icon="@drawable/ic_search"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView" />
+
+
+
- TRANSCODING
When dowloading folder %1$s files will download in parallell.
Assure you have enough transcoding slots on the server
- Sleep Timer
+ Sleep Timer Details
Minutes
Extend By
Pause After
@@ -112,4 +112,6 @@
Pitch:
Recently Modified
Recently Modified Folders
+ Start Sleep Timer
+ Press Back again to exit