adding some sleep timer related things
This commit is contained in:
parent
5fc31a38e6
commit
268d183b6f
3 changed files with 38 additions and 9 deletions
|
@ -10,6 +10,7 @@ import android.graphics.drawable.LayerDrawable
|
|||
import android.media.AudioManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.CountDownTimer
|
||||
import android.os.Environment
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
|
@ -54,6 +55,7 @@ class MainActivity : SimpleActivity(), SongListListener {
|
|||
private var isThirdPartyIntent = false
|
||||
private var songs = ArrayList<Song>()
|
||||
private var searchMenuItem: MenuItem? = null
|
||||
private var sleepTimer: CountDownTimer? = null
|
||||
private var isSearchOpen = false
|
||||
private var wasInitialPlaylistSet = false
|
||||
private var lastFilePickerPath = ""
|
||||
|
@ -97,7 +99,7 @@ class MainActivity : SimpleActivity(), SongListListener {
|
|||
repeat_btn.setOnClickListener { toggleSongRepetition() }
|
||||
song_progress_current.setOnClickListener { sendIntent(SKIP_BACKWARD) }
|
||||
song_progress_max.setOnClickListener { sendIntent(SKIP_FORWARD) }
|
||||
sleep_timer_stop.setOnClickListener { }
|
||||
sleep_timer_stop.setOnClickListener { stopSleepTimer() }
|
||||
|
||||
songs_playlist_empty_add_folder.setOnClickListener { addFolderToPlaylist() }
|
||||
volumeControlStream = AudioManager.STREAM_MUSIC
|
||||
|
@ -174,6 +176,7 @@ class MainActivity : SimpleActivity(), SongListListener {
|
|||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bus.unregister(this)
|
||||
sleepTimer?.cancel()
|
||||
|
||||
if (isThirdPartyIntent && !isChangingConfigurations) {
|
||||
sendIntent(FINISH)
|
||||
|
@ -353,15 +356,36 @@ class MainActivity : SimpleActivity(), SongListListener {
|
|||
RadioItem(30 * 60, "30 $minutes"),
|
||||
RadioItem(60 * 60, hour))
|
||||
|
||||
RadioGroupDialog(this, items, config.lastSleepTimerMinutes) {
|
||||
RadioGroupDialog(this, items, config.lastSleepTimerSeconds) {
|
||||
if (it as Int > 0) {
|
||||
config.lastSleepTimerMinutes = it
|
||||
sleep_timer_holder.beVisible()
|
||||
sleep_timer_value.text = it.getFormattedDuration()
|
||||
config.lastSleepTimerSeconds = it
|
||||
config.sleepInTS = System.currentTimeMillis() + it * 1000
|
||||
startSleepTimer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startSleepTimer() {
|
||||
sleep_timer_holder.beVisible()
|
||||
|
||||
sleepTimer = object : CountDownTimer((config.lastSleepTimerSeconds + 1) * 1000L, 1000) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
val seconds = (millisUntilFinished / 1000).toInt()
|
||||
sleep_timer_value.text = seconds.getFormattedDuration()
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
}
|
||||
}
|
||||
sleepTimer?.start()
|
||||
}
|
||||
|
||||
private fun stopSleepTimer() {
|
||||
config.sleepInTS = 0
|
||||
sleepTimer?.cancel()
|
||||
sleep_timer_holder.beGone()
|
||||
}
|
||||
|
||||
private fun removePlaylist() {
|
||||
if (config.currentPlaylist == ALL_SONGS_PLAYLIST_ID) {
|
||||
toast(R.string.all_songs_cannot_be_deleted)
|
||||
|
|
|
@ -51,7 +51,11 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = prefs.getBoolean(SWAP_PREV_NEXT, false)
|
||||
set(swapPrevNext) = prefs.edit().putBoolean(SWAP_PREV_NEXT, swapPrevNext).apply()
|
||||
|
||||
var lastSleepTimerMinutes: Int
|
||||
get() = prefs.getInt(LAST_SLEEP_TIMER_MINUTES, 30 * 60)
|
||||
set(lastSleepTimerMinutes) = prefs.edit().putInt(LAST_SLEEP_TIMER_MINUTES, lastSleepTimerMinutes).apply()
|
||||
var lastSleepTimerSeconds: Int
|
||||
get() = prefs.getInt(LAST_SLEEP_TIMER_SECONDS, 30 * 60)
|
||||
set(lastSleepTimerSeconds) = prefs.edit().putInt(LAST_SLEEP_TIMER_SECONDS, lastSleepTimerSeconds).apply()
|
||||
|
||||
var sleepInTS: Long
|
||||
get() = prefs.getLong(SLEEP_IN_TS, 0)
|
||||
set(sleepInTS) = prefs.edit().putLong(SLEEP_IN_TS, sleepInTS).apply()
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ const val CURRENT_PLAYLIST = "current_playlist"
|
|||
const val SHOW_FILENAME = "show_filename"
|
||||
const val SHOW_ALBUM_COVER = "show_album_cover"
|
||||
const val SWAP_PREV_NEXT = "swap_prev_next"
|
||||
const val LAST_SLEEP_TIMER_MINUTES = "last_sleep_timer_minutes"
|
||||
const val LAST_SLEEP_TIMER_SECONDS = "last_sleep_timer_seconds"
|
||||
const val SLEEP_IN_TS = "sleep_in_ts"
|
||||
|
||||
const val LIST_HEADERS_COUNT = 2
|
||||
const val LOWER_ALPHA = 0.5f
|
||||
|
|
Loading…
Reference in a new issue