Add queue behavior options

Add options for whether to remember the shuffle toggle & what to do when a playlist ends.
This commit is contained in:
OxygenCobalt
2020-12-13 12:18:43 -07:00
parent 6882722201
commit c7549d6bfa
8 changed files with 127 additions and 41 deletions
@@ -23,7 +23,6 @@ import org.oxycblt.auxio.music.processing.MusicLoaderResponse
* @author OxygenCobalt
*/
class LoadingFragment : Fragment(R.layout.fragment_loading) {
private val loadingModel: LoadingViewModel by activityViewModels {
LoadingViewModel.Factory(requireActivity().application)
}
@@ -8,7 +8,6 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.support.v4.media.session.MediaSessionCompat
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.media.app.NotificationCompat.MediaStyle
import org.oxycblt.auxio.MainActivity
@@ -172,8 +171,6 @@ private fun newAction(action: String, context: Context): NotificationCompat.Acti
}
NotificationUtils.ACTION_SHUFFLE -> {
Log.d("A function", "Jesus christ does this even call???")
if (playbackManager.isShuffling) {
R.drawable.ic_shuffle
} else {
@@ -155,10 +155,14 @@ class PlaybackStateManager private constructor() {
resetLoopMode()
updatePlayback(song)
if (mIsShuffling) {
genShuffle(true)
if (settingsManager.keepShuffle) {
if (mIsShuffling) {
genShuffle(true)
} else {
resetShuffle()
}
} else {
resetShuffle()
setShuffleStatus(false)
}
mIndex = mQueue.indexOf(song)
@@ -210,11 +214,11 @@ class PlaybackStateManager private constructor() {
}
}
private fun updatePlayback(song: Song) {
private fun updatePlayback(song: Song, dontPlay: Boolean = false) {
mSong = song
mPosition = 0
if (!mIsPlaying) {
if (!mIsPlaying && !dontPlay) {
setPlayingStatus(true)
}
@@ -260,9 +264,7 @@ class PlaybackStateManager private constructor() {
if (mIndex < mQueue.lastIndex) {
mIndex = mIndex.inc()
} else {
// TODO: Implement option to make the playlist loop instead of stop
mQueue = mutableListOf()
mSong = null
handlePlaylistEnd()
return
}
@@ -294,6 +296,37 @@ class PlaybackStateManager private constructor() {
}
}
/**
* Handle what to do at then end of a playlist.
*/
private fun handlePlaylistEnd() {
when (settingsManager.doAtEnd) {
SettingsManager.EntryNames.AT_END_LOOP_PAUSE -> {
mIndex = 0
forceQueueUpdate()
updatePlayback(mQueue[0], dontPlay = true)
setPlayingStatus(false)
}
SettingsManager.EntryNames.AT_END_LOOP -> {
mIndex = 0
forceQueueUpdate()
updatePlayback(mQueue[0])
}
SettingsManager.EntryNames.AT_END_STOP -> {
mQueue.clear()
forceQueueUpdate()
mSong = null
}
}
}
// --- QUEUE EDITING FUNCTIONS ---
fun removeQueueItem(index: Int): Boolean {
Log.d(this::class.simpleName, "Removing item ${mQueue[index].name}.")
@@ -73,6 +73,13 @@ class SettingsManager private constructor(context: Context) :
)
)
val doAtEnd: String
get() = sharedPrefs.getString(Keys.KEY_AT_END, EntryNames.AT_END_LOOP_PAUSE)
?: EntryNames.AT_END_LOOP_PAUSE
val keepShuffle: Boolean
get() = sharedPrefs.getBoolean(Keys.KEY_KEEP_SHUFFLE, false)
val rewindWithPrev: Boolean
get() = sharedPrefs.getBoolean(Keys.KEY_PREV_REWIND, true)
@@ -80,14 +87,13 @@ class SettingsManager private constructor(context: Context) :
get() = (sharedPrefs.getInt(Keys.KEY_REWIND_THRESHOLD, 5) * 1000).toLong()
var librarySortMode: SortMode
get() {
return SortMode.fromInt(
sharedPrefs.getInt(
Keys.KEY_LIBRARY_SORT_MODE,
SortMode.CONSTANT_ALPHA_DOWN
)
) ?: SortMode.ALPHA_DOWN
}
get() = SortMode.fromInt(
sharedPrefs.getInt(
Keys.KEY_LIBRARY_SORT_MODE,
SortMode.CONSTANT_ALPHA_DOWN
)
) ?: SortMode.ALPHA_DOWN
set(value) {
sharedPrefs.edit()
.putInt(Keys.KEY_LIBRARY_SORT_MODE, value.toInt())
@@ -167,6 +173,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_AT_END = "KEY_AT_END"
const val KEY_KEEP_SHUFFLE = "KEY_KEEP_SHUFFLE"
const val KEY_PREV_REWIND = "KEY_PREV_REWIND"
const val KEY_REWIND_THRESHOLD = "KEY_REWIND_THRESHOLD"
@@ -177,6 +185,10 @@ class SettingsManager private constructor(context: Context) :
const val THEME_AUTO = "AUTO"
const val THEME_LIGHT = "LIGHT"
const val THEME_DARK = "DARK"
const val AT_END_LOOP_PAUSE = "LOOP_PAUSE"
const val AT_END_LOOP = "LOOP"
const val AT_END_STOP = "STOP"
}
/**