Update loop behavior [Resolves #13]
Change the loop behavior to something that is actually sensible, with [ ] looping the whole playlist and [ 1 ] looping the song. This also removes the "Do on end" setting. A new stop option may be reintroduced, however. This resolves issue #13.
This commit is contained in:
@@ -106,16 +106,16 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
binding.playbackLoop.setImageResource(R.drawable.ic_loop)
|
||||
}
|
||||
|
||||
LoopMode.ONCE -> {
|
||||
binding.playbackLoop.imageTintList = accentColor
|
||||
binding.playbackLoop.setImageResource(R.drawable.ic_loop_one)
|
||||
}
|
||||
|
||||
LoopMode.INFINITE -> {
|
||||
LoopMode.ALL -> {
|
||||
binding.playbackLoop.imageTintList = accentColor
|
||||
binding.playbackLoop.setImageResource(R.drawable.ic_loop)
|
||||
}
|
||||
|
||||
LoopMode.TRACK -> {
|
||||
binding.playbackLoop.imageTintList = accentColor
|
||||
binding.playbackLoop.setImageResource(R.drawable.ic_loop_one)
|
||||
}
|
||||
|
||||
else -> return@observe
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ package org.oxycblt.auxio.playback.state
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
enum class LoopMode {
|
||||
NONE, ONCE, INFINITE;
|
||||
NONE, ALL, TRACK;
|
||||
|
||||
/**
|
||||
* Increment the LoopMode, e.g from [NONE] to [ONCE]
|
||||
* Increment the LoopMode, e.g from [NONE] to [ALL]
|
||||
*/
|
||||
fun increment(): LoopMode {
|
||||
return when (this) {
|
||||
NONE -> ONCE
|
||||
ONCE -> INFINITE
|
||||
INFINITE -> NONE
|
||||
NONE -> ALL
|
||||
ALL -> TRACK
|
||||
TRACK -> NONE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,25 +25,24 @@ enum class LoopMode {
|
||||
fun toInt(): Int {
|
||||
return when (this) {
|
||||
NONE -> CONST_NONE
|
||||
ONCE -> CONST_ONCE
|
||||
INFINITE -> CONST_INFINITE
|
||||
ALL -> CONST_ALL
|
||||
TRACK -> CONST_TRACK
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CONST_NONE = 0xA100
|
||||
const val CONST_ONCE = 0xA101
|
||||
const val CONST_INFINITE = 0xA102
|
||||
const val CONST_ALL = 0xA101
|
||||
const val CONST_TRACK = 0xA102
|
||||
|
||||
/**
|
||||
* Convert an int [constant] into a LoopMode
|
||||
* @return The corresponding LoopMode. Null if it corresponds to nothing.
|
||||
* Convert an int [constant] into a LoopMode, or null if it isnt valid.
|
||||
*/
|
||||
fun fromInt(constant: Int): LoopMode? {
|
||||
return when (constant) {
|
||||
CONST_NONE -> NONE
|
||||
CONST_ONCE -> ONCE
|
||||
CONST_INFINITE -> INFINITE
|
||||
CONST_ALL -> ALL
|
||||
CONST_TRACK -> TRACK
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -47,6 +47,5 @@ enum class PlaybackMode {
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,17 +235,13 @@ class PlaybackStateManager private constructor() {
|
||||
/**
|
||||
* Update the playback to a new [song], doing all the required logic.
|
||||
*/
|
||||
private fun updatePlayback(song: Song) {
|
||||
private fun updatePlayback(song: Song, shouldPlay: Boolean = true) {
|
||||
mIsInUserQueue = false
|
||||
|
||||
mSong = song
|
||||
mPosition = 0
|
||||
|
||||
if (!mIsPlaying) {
|
||||
setPlaying(true)
|
||||
}
|
||||
|
||||
clearLoopMode()
|
||||
setPlaying(shouldPlay)
|
||||
}
|
||||
|
||||
// --- QUEUE FUNCTIONS ---
|
||||
@@ -269,13 +265,14 @@ class PlaybackStateManager private constructor() {
|
||||
// If it cant be incremented anymore, end playback or loop depending on the setting.
|
||||
if (mIndex < mQueue.lastIndex) {
|
||||
mIndex = mIndex.inc()
|
||||
updatePlayback(mQueue[mIndex])
|
||||
} else {
|
||||
handlePlaylistEnd()
|
||||
mIndex = 0
|
||||
updatePlayback(mQueue[mIndex], shouldPlay = mLoopMode == LoopMode.ALL)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
updatePlayback(mQueue[mIndex])
|
||||
forceQueueUpdate()
|
||||
}
|
||||
}
|
||||
@@ -299,39 +296,6 @@ class PlaybackStateManager private constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle what to do at then end of a playlist.
|
||||
*/
|
||||
private fun handlePlaylistEnd() {
|
||||
when (settingsManager.doAtEnd) {
|
||||
SettingsManager.EntryValues.AT_END_LOOP_PAUSE -> {
|
||||
mIndex = 0
|
||||
mPosition = 0
|
||||
mIsInUserQueue = false
|
||||
mSong = mQueue[0]
|
||||
|
||||
clearLoopMode()
|
||||
setPlaying(false)
|
||||
forceQueueUpdate()
|
||||
}
|
||||
|
||||
SettingsManager.EntryValues.AT_END_LOOP -> {
|
||||
mIndex = 0
|
||||
|
||||
forceQueueUpdate()
|
||||
updatePlayback(mQueue[0])
|
||||
}
|
||||
|
||||
SettingsManager.EntryValues.AT_END_STOP -> {
|
||||
mQueue.clear()
|
||||
forceQueueUpdate()
|
||||
|
||||
mSong = null
|
||||
mParent = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- QUEUE EDITING FUNCTIONS ---
|
||||
|
||||
/**
|
||||
@@ -562,17 +526,6 @@ class PlaybackStateManager private constructor() {
|
||||
mLoopMode = mode
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the current [LoopMode] from [LoopMode.ONCE], if needed.
|
||||
* Use this instead of duplicating the code manually.
|
||||
*/
|
||||
fun clearLoopMode() {
|
||||
// Reset the loop mode from ONCE if needed.
|
||||
if (mLoopMode == LoopMode.ONCE) {
|
||||
mLoopMode = LoopMode.NONE
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark whether this instance has played or not
|
||||
*/
|
||||
|
||||
@@ -135,8 +135,8 @@ class PlaybackNotification private constructor(
|
||||
): NotificationCompat.Action {
|
||||
val drawableRes = when (loopMode) {
|
||||
LoopMode.NONE -> R.drawable.ic_loop_inactive
|
||||
LoopMode.ONCE -> R.drawable.ic_loop_one
|
||||
LoopMode.INFINITE -> R.drawable.ic_loop
|
||||
LoopMode.ALL -> R.drawable.ic_loop
|
||||
LoopMode.TRACK -> R.drawable.ic_loop_one
|
||||
}
|
||||
|
||||
return buildAction(context, ACTION_LOOP, drawableRes)
|
||||
|
||||
@@ -202,11 +202,6 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||
}
|
||||
|
||||
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
|
||||
// Reset the loop mode from LOOP_ONE (if it is LOOP_ONE) on each repeat
|
||||
if (reason == Player.MEDIA_ITEM_TRANSITION_REASON_REPEAT) {
|
||||
playbackManager.clearLoopMode()
|
||||
}
|
||||
|
||||
// We use the wakelock to ensure that the CPU is active while music is being loaded
|
||||
acquireWakeLock()
|
||||
}
|
||||
@@ -263,10 +258,10 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||
}
|
||||
|
||||
override fun onLoopUpdate(loopMode: LoopMode) {
|
||||
player.repeatMode = if (loopMode == LoopMode.NONE) {
|
||||
Player.REPEAT_MODE_OFF
|
||||
player.repeatMode = if (loopMode == LoopMode.TRACK) {
|
||||
Player.REPEAT_MODE_ONE
|
||||
} else {
|
||||
Player.REPEAT_MODE_ALL
|
||||
Player.REPEAT_MODE_OFF
|
||||
}
|
||||
|
||||
if (!settingsManager.useAltNotifAction) {
|
||||
|
||||
@@ -45,8 +45,7 @@ class AboutDialog : BottomSheetDialogFragment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Go through the process of opening a [link] in a browser. Only supports the links
|
||||
* in [AboutDialog.Companion.LINKS].
|
||||
* Go through the process of opening a [link] in a browser.
|
||||
*/
|
||||
private fun openLinkInBrowser(link: String) {
|
||||
try {
|
||||
|
||||
@@ -38,6 +38,7 @@ class SettingsManager private constructor(context: Context) :
|
||||
/** The current accent. */
|
||||
var accent: Accent
|
||||
get() = handleAccentCompat(sharedPrefs)
|
||||
|
||||
set(value) {
|
||||
val accentIndex = ACCENTS.indexOf(value)
|
||||
|
||||
@@ -87,11 +88,6 @@ class SettingsManager private constructor(context: Context) :
|
||||
val songPlaybackMode: PlaybackMode
|
||||
get() = handleSongPlayModeCompat(sharedPrefs)
|
||||
|
||||
/** What to do at the end of a playlist. */
|
||||
val doAtEnd: String
|
||||
get() = sharedPrefs.getString(KEY_AT_END, EntryValues.AT_END_LOOP_PAUSE)
|
||||
?: EntryValues.AT_END_LOOP_PAUSE
|
||||
|
||||
/** Whether shuffle should stay on when a new song is selected. */
|
||||
val keepShuffle: Boolean
|
||||
get() = sharedPrefs.getBoolean(KEY_KEEP_SHUFFLE, true)
|
||||
@@ -115,6 +111,7 @@ class SettingsManager private constructor(context: Context) :
|
||||
/** The current filter mode of the search tab */
|
||||
var searchFilterMode: DisplayMode
|
||||
get() = handleSearchModeCompat(sharedPrefs)
|
||||
|
||||
set(value) {
|
||||
sharedPrefs.edit {
|
||||
putInt(KEY_SEARCH_FILTER_MODE, value.toInt())
|
||||
@@ -159,19 +156,6 @@ class SettingsManager private constructor(context: Context) :
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Values for some settings entries that arent important enough to recieve an enum.
|
||||
*/
|
||||
object EntryValues {
|
||||
/** Pause and loop at the end. Similar to Spotify. */
|
||||
const val AT_END_LOOP_PAUSE = "LOOP_PAUSE"
|
||||
|
||||
/** Loop at the end. Similar to Music Player GO. */
|
||||
const val AT_END_LOOP = "LOOP"
|
||||
|
||||
/** Stop at the end. */
|
||||
const val AT_END_STOP = "STOP"
|
||||
}
|
||||
|
||||
/**
|
||||
* An interface for receiving some preference updates. Use/Extend this instead of
|
||||
@@ -200,7 +184,6 @@ class SettingsManager private constructor(context: Context) :
|
||||
const val KEY_PLUG_MANAGEMENT = "KEY_PLUG_MGT"
|
||||
|
||||
const val KEY_SONG_PLAYBACK_MODE = "KEY_SONG_PLAY_MODE2"
|
||||
const val KEY_AT_END = "KEY_AT_END"
|
||||
const val KEY_KEEP_SHUFFLE = "KEY_KEEP_SHUFFLE"
|
||||
const val KEY_PREV_REWIND = "KEY_PREV_REWIND"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user