Add option to rewind before skipping back

Add an option to rewind before skipping to prevous song, depending on the user-defined threshhold.
This commit is contained in:
OxygenCobalt
2020-12-12 15:45:51 -07:00
parent aaa1ad1a3d
commit 6882722201
7 changed files with 75 additions and 14 deletions
@@ -14,6 +14,7 @@ import org.oxycblt.auxio.music.Genre
import org.oxycblt.auxio.music.Header
import org.oxycblt.auxio.music.MusicStore
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.settings.SettingsManager
import kotlin.random.Random
/**
@@ -100,6 +101,8 @@ class PlaybackStateManager private constructor() {
val isRestored: Boolean get() = mIsRestored
val hasPlayed: Boolean get() = mHasPlayed
private val settingsManager = SettingsManager.getInstance()
// --- CALLBACKS ---
private val callbacks = mutableListOf<Callback>()
@@ -252,7 +255,7 @@ class PlaybackStateManager private constructor() {
forceUserQueueUpdate()
} else {
// If not in the user queue, then increment the current index
// Increment the index.
// If it cant be incremented anymore, end playback or loop depending on the setting.
if (mIndex < mQueue.lastIndex) {
mIndex = mIndex.inc()
@@ -271,18 +274,24 @@ class PlaybackStateManager private constructor() {
/**
* Go to the previous song, doing any checks that are needed.
* TODO: Implement option to rewind before skipping back
*/
fun prev() {
if (mIndex > 0 && !mIsInUserQueue) {
mIndex = mIndex.dec()
// If enabled, rewind before skipping back if the position is past the threshold set.
if (settingsManager.rewindWithPrev && mPosition >= settingsManager.rewindThreshold) {
seekTo(0)
} else {
// Only decrement the index if there's a song to move back to AND if we are not exiting
// the user queue.
if (mIndex > 0 && !mIsInUserQueue) {
mIndex = mIndex.dec()
}
resetLoopMode()
updatePlayback(mQueue[mIndex])
forceQueueUpdate()
}
resetLoopMode()
updatePlayback(mQueue[mIndex])
forceQueueUpdate()
}
fun removeQueueItem(index: Int): Boolean {
@@ -73,6 +73,12 @@ class SettingsManager private constructor(context: Context) :
)
)
val rewindWithPrev: Boolean
get() = sharedPrefs.getBoolean(Keys.KEY_PREV_REWIND, true)
val rewindThreshold: Long
get() = (sharedPrefs.getInt(Keys.KEY_REWIND_THRESHOLD, 5) * 1000).toLong()
var librarySortMode: SortMode
get() {
return SortMode.fromInt(
@@ -145,7 +151,7 @@ class SettingsManager private constructor(context: Context) :
*/
fun getInstance(): SettingsManager {
check(::INSTANCE.isInitialized) {
"PrefsManager must be initialized with init() before getting its instance."
"SettingsManager must be initialized with init() before getting its instance."
}
return INSTANCE
}
@@ -161,6 +167,8 @@ class SettingsManager private constructor(context: Context) :
const val KEY_AUDIO_FOCUS = "KEY_AUDIO_FOCUS"
const val KEY_PLUG_MANAGEMENT = "KEY_PLUG_MGT"
const val KEY_SONG_PLAYBACK_MODE = "KEY_SONG_PLAY_MODE"
const val KEY_PREV_REWIND = "KEY_PREV_REWIND"
const val KEY_REWIND_THRESHOLD = "KEY_REWIND_THRESHOLD"
const val KEY_LIBRARY_SORT_MODE = "KEY_LIBRARY_SORT_MODE"
}
@@ -8,7 +8,6 @@ import android.os.Build
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.util.Log
import android.view.MenuItem
import android.view.View
import android.view.Window
@@ -150,8 +149,6 @@ fun PopupMenu.setupSongActions(song: Song, context: Context, playbackModel: Play
else -> -1
}
Log.d(this::class.simpleName, (idToRemove == R.id.action_play_album).toString())
menu.findItem(idToRemove)?.isVisible = false
}