Add song playback mode option
Add an option to customize whether a song should play from its artist, its album, or all songs when selected.
This commit is contained in:
@@ -25,7 +25,7 @@ import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.ui.applyColor
|
||||
import org.oxycblt.auxio.ui.resolveAttr
|
||||
import org.oxycblt.auxio.ui.setupAlbumActions
|
||||
@@ -197,7 +197,9 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
// If the item is a song [That was selected through search], then update the playback
|
||||
// to that song instead of doing any navigation
|
||||
if (baseModel is Song) {
|
||||
playbackModel.playSong(baseModel, PlaybackMode.ALL_SONGS)
|
||||
val settingsManager = SettingsManager.getInstance()
|
||||
|
||||
playbackModel.playSong(baseModel, settingsManager.songPlaybackMode)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
package org.oxycblt.auxio.library.adapters
|
||||
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.AsyncListDiffer
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.recycler.DiffCallback
|
||||
import org.oxycblt.auxio.recycler.viewholders.AlbumViewHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.ArtistViewHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.GenreViewHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.HeaderViewHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.SongViewHolder
|
||||
|
||||
/**
|
||||
* A near-identical adapter as [SearchAdapter] but this one isn't a [ListAdapter]
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.oxycblt.auxio.library.adapters
|
||||
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.AsyncListDiffer
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.music.Album
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.content.Context
|
||||
@@ -45,7 +43,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
val userQueue: LiveData<MutableList<Song>> get() = mUserQueue
|
||||
|
||||
private val mIndex = MutableLiveData(0)
|
||||
val index: LiveData<Int> get() = mIndex
|
||||
// val index: LiveData<Int> get() = mIndex
|
||||
|
||||
private val mMode = MutableLiveData(PlaybackMode.ALL_SONGS)
|
||||
val mode: LiveData<PlaybackMode> get() = mMode
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.oxycblt.auxio.playback.state
|
||||
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
// Enum for instruction how the queue should function.
|
||||
// ALL SONGS -> Play from all songs
|
||||
// IN_ARTIST -> Play from the songs of the artist
|
||||
@@ -32,5 +34,17 @@ enum class PlaybackMode {
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun valueOfOrFallback(value: String?): PlaybackMode {
|
||||
if (value == null) {
|
||||
return ALL_SONGS
|
||||
}
|
||||
|
||||
return try {
|
||||
valueOf(value)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
ALL_SONGS
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package org.oxycblt.auxio.settings
|
||||
|
||||
import android.os.Bundle
|
||||
@@ -21,6 +19,7 @@ import org.oxycblt.auxio.ui.ACCENTS
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.getDetailedAccentSummary
|
||||
|
||||
@Suppress("UNUSED")
|
||||
class SettingsListFragment : PreferenceFragmentCompat() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.oxycblt.auxio.settings
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.preference.PreferenceManager
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.recycler.DisplayMode
|
||||
import org.oxycblt.auxio.recycler.SortMode
|
||||
import org.oxycblt.auxio.ui.ACCENTS
|
||||
@@ -51,14 +52,12 @@ class SettingsManager private constructor(context: Context) :
|
||||
get() = sharedPrefs.getBoolean(Keys.KEY_USE_ALT_NOTIFICATION_ACTION, false)
|
||||
|
||||
val libraryDisplayMode: DisplayMode
|
||||
get() {
|
||||
return DisplayMode.valueOfOrFallback(
|
||||
sharedPrefs.getString(
|
||||
Keys.KEY_LIBRARY_DISPLAY_MODE,
|
||||
DisplayMode.SHOW_ARTISTS.toString()
|
||||
)
|
||||
get() = DisplayMode.valueOfOrFallback(
|
||||
sharedPrefs.getString(
|
||||
Keys.KEY_LIBRARY_DISPLAY_MODE,
|
||||
DisplayMode.SHOW_ARTISTS.toString()
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
val doAudioFocus: Boolean
|
||||
get() = sharedPrefs.getBoolean(Keys.KEY_AUDIO_FOCUS, true)
|
||||
@@ -66,6 +65,14 @@ class SettingsManager private constructor(context: Context) :
|
||||
val doPlugMgt: Boolean
|
||||
get() = sharedPrefs.getBoolean(Keys.KEY_PLUG_MANAGEMENT, true)
|
||||
|
||||
val songPlaybackMode: PlaybackMode
|
||||
get() = PlaybackMode.valueOfOrFallback(
|
||||
sharedPrefs.getString(
|
||||
Keys.KEY_SONG_PLAYBACK_MODE,
|
||||
PlaybackMode.ALL_SONGS.toString()
|
||||
)
|
||||
)
|
||||
|
||||
var librarySortMode: SortMode
|
||||
get() {
|
||||
return SortMode.fromInt(
|
||||
@@ -153,6 +160,7 @@ class SettingsManager private constructor(context: Context) :
|
||||
const val KEY_LIBRARY_DISPLAY_MODE = "KEY_LIBRARY_DISPLAY_MODE"
|
||||
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_LIBRARY_SORT_MODE = "KEY_LIBRARY_SORT_MODE"
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentSongsBinding
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.ui.setupSongActions
|
||||
import kotlin.math.ceil
|
||||
|
||||
@@ -42,10 +42,11 @@ class SongsFragment : Fragment() {
|
||||
val binding = FragmentSongsBinding.inflate(inflater)
|
||||
|
||||
val musicStore = MusicStore.getInstance()
|
||||
val settingsManager = SettingsManager.getInstance()
|
||||
|
||||
val songAdapter = SongsAdapter(
|
||||
musicStore.songs,
|
||||
doOnClick = { playbackModel.playSong(it, PlaybackMode.ALL_SONGS) },
|
||||
doOnClick = { playbackModel.playSong(it, settingsManager.songPlaybackMode) },
|
||||
doOnLongClick = { data, view ->
|
||||
PopupMenu(requireContext(), view).setupSongActions(
|
||||
data, requireContext(), playbackModel
|
||||
|
||||
@@ -8,6 +8,7 @@ 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
|
||||
@@ -26,6 +27,7 @@ import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
|
||||
// Functions for managing UI elements [Not Colors]
|
||||
|
||||
@@ -108,6 +110,8 @@ fun Window.handleTransparentSystemBars(config: Configuration) {
|
||||
* Show actions for a song item, such as the ones found in [org.oxycblt.auxio.songs.SongsFragment]
|
||||
*/
|
||||
fun PopupMenu.setupSongActions(song: Song, context: Context, playbackModel: PlaybackViewModel) {
|
||||
inflateAndShow(R.menu.menu_song_actions)
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_queue_add -> {
|
||||
@@ -126,14 +130,34 @@ fun PopupMenu.setupSongActions(song: Song, context: Context, playbackModel: Play
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_play_all_songs -> {
|
||||
playbackModel.playSong(song, PlaybackMode.ALL_SONGS)
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
inflateAndShow(R.menu.menu_song_actions)
|
||||
|
||||
val settingsManager = SettingsManager.getInstance()
|
||||
|
||||
// Find the action that is redundant from the menu and hide it.
|
||||
val idToRemove = when (settingsManager.songPlaybackMode) {
|
||||
PlaybackMode.ALL_SONGS -> R.id.action_play_all_songs
|
||||
PlaybackMode.IN_ARTIST -> R.id.action_play_artist
|
||||
PlaybackMode.IN_ALBUM -> R.id.action_play_album
|
||||
|
||||
else -> -1
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, (idToRemove == R.id.action_play_album).toString())
|
||||
|
||||
menu.findItem(idToRemove)?.isVisible = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Show actions for a song item, such as the ones found in [org.oxycblt.auxio.songs.SongsFragment]
|
||||
* Show actions for a album song item, such as the ones found in
|
||||
* [org.oxycblt.auxio.detail.AlbumDetailFragment]
|
||||
*/
|
||||
fun PopupMenu.setupAlbumSongActions(
|
||||
song: Song,
|
||||
|
||||
Reference in New Issue
Block a user