diff --git a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt index c7d80dfdb..49423ad5a 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt @@ -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() @@ -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 { diff --git a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt index 0aaf190b9..615e6371f 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/SettingsManager.kt @@ -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" } diff --git a/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt b/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt index 93ca7240d..d913e4572 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt @@ -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 } diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml new file mode 100644 index 000000000..4916bfc3f --- /dev/null +++ b/app/src/main/res/values/integers.xml @@ -0,0 +1,6 @@ + + + 1 + 30 + 5 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 23cd136c1..2edf4601a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -71,6 +71,11 @@ Behavior When a song is selected + Rewind before skipping back + Rewind before skipping to the previous song + Rewind threshold + Progress at which a rewind should occur (seconds) + State saved diff --git a/app/src/main/res/xml-v27/prefs_main.xml b/app/src/main/res/xml-v27/prefs_main.xml index a15f8baa3..bfc9e4990 100644 --- a/app/src/main/res/xml-v27/prefs_main.xml +++ b/app/src/main/res/xml-v27/prefs_main.xml @@ -93,5 +93,23 @@ app:iconSpaceReserved="false" app:useSimpleSummaryProvider="true" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/prefs_main.xml b/app/src/main/res/xml/prefs_main.xml index eade6ffad..23ddd9b5d 100644 --- a/app/src/main/res/xml/prefs_main.xml +++ b/app/src/main/res/xml/prefs_main.xml @@ -84,5 +84,23 @@ app:iconSpaceReserved="false" app:useSimpleSummaryProvider="true" /> + + + + \ No newline at end of file