playback: allow customization of detail playback
Add a new "Detail playback mode" option that allows one to configure what selecting a song will do in an album/artist/genre. This is mostly a clone of the prior setting, just in a new context. Resolves #164.
This commit is contained in:
@@ -38,12 +38,14 @@ import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.settings.Settings
|
||||
import org.oxycblt.auxio.ui.Header
|
||||
import org.oxycblt.auxio.ui.Item
|
||||
import org.oxycblt.auxio.ui.MenuFragment
|
||||
import org.oxycblt.auxio.util.applySpans
|
||||
import org.oxycblt.auxio.util.canScroll
|
||||
import org.oxycblt.auxio.util.collectWith
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.launch
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
@@ -62,6 +64,7 @@ class AlbumDetailFragment :
|
||||
|
||||
private val args: AlbumDetailFragmentArgs by navArgs()
|
||||
private val detailAdapter = AlbumDetailAdapter(this)
|
||||
private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) }
|
||||
|
||||
override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater)
|
||||
|
||||
@@ -118,7 +121,7 @@ class AlbumDetailFragment :
|
||||
|
||||
override fun onItemClick(item: Item) {
|
||||
if (item is Song) {
|
||||
playbackModel.play(item, PlaybackMode.IN_ALBUM)
|
||||
playbackModel.play(item, settings.detailPlaybackMode ?: PlaybackMode.IN_ALBUM)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,13 @@ import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.settings.Settings
|
||||
import org.oxycblt.auxio.ui.Header
|
||||
import org.oxycblt.auxio.ui.Item
|
||||
import org.oxycblt.auxio.ui.MenuFragment
|
||||
import org.oxycblt.auxio.util.applySpans
|
||||
import org.oxycblt.auxio.util.collectWith
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.launch
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
@@ -57,6 +59,7 @@ class ArtistDetailFragment :
|
||||
|
||||
private val args: ArtistDetailFragmentArgs by navArgs()
|
||||
private val detailAdapter = ArtistDetailAdapter(this)
|
||||
private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) }
|
||||
|
||||
override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater)
|
||||
|
||||
@@ -110,7 +113,8 @@ class ArtistDetailFragment :
|
||||
|
||||
override fun onItemClick(item: Item) {
|
||||
when (item) {
|
||||
is Song -> playbackModel.play(item, PlaybackMode.IN_ARTIST)
|
||||
is Song ->
|
||||
playbackModel.play(item, settings.detailPlaybackMode ?: PlaybackMode.IN_ARTIST)
|
||||
is Album -> navModel.exploreNavigateTo(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,13 @@ import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.settings.Settings
|
||||
import org.oxycblt.auxio.ui.Header
|
||||
import org.oxycblt.auxio.ui.Item
|
||||
import org.oxycblt.auxio.ui.MenuFragment
|
||||
import org.oxycblt.auxio.util.applySpans
|
||||
import org.oxycblt.auxio.util.collectWith
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.launch
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
@@ -58,6 +60,7 @@ class GenreDetailFragment :
|
||||
|
||||
private val args: GenreDetailFragmentArgs by navArgs()
|
||||
private val detailAdapter = GenreDetailAdapter(this)
|
||||
private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) }
|
||||
|
||||
override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater)
|
||||
|
||||
@@ -110,7 +113,8 @@ class GenreDetailFragment :
|
||||
|
||||
override fun onItemClick(item: Item) {
|
||||
when (item) {
|
||||
is Song -> playbackModel.play(item, PlaybackMode.IN_GENRE)
|
||||
is Song ->
|
||||
playbackModel.play(item, settings.detailPlaybackMode ?: PlaybackMode.IN_GENRE)
|
||||
is Album ->
|
||||
findNavController()
|
||||
.navigate(ArtistDetailFragmentDirections.actionShowAlbum(item.id))
|
||||
|
||||
@@ -147,7 +147,7 @@ class HomeViewModel(application: Application) :
|
||||
}
|
||||
|
||||
override fun onSettingChanged(key: String) {
|
||||
if (key == application.getString(R.string.set_lib_tabs)) {
|
||||
if (key == application.getString(R.string.set_key_lib_tabs)) {
|
||||
tabs = visibleTabs
|
||||
_shouldRecreateTabs.value = true
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class SongListFragment : HomeListFragment<Song>() {
|
||||
|
||||
override fun onItemClick(item: Item) {
|
||||
check(item is Song)
|
||||
playbackModel.play(item, settings.songPlaybackMode)
|
||||
playbackModel.play(item, settings.libPlaybackMode)
|
||||
}
|
||||
|
||||
override fun onOpenMenu(item: Item, anchor: View) {
|
||||
|
||||
@@ -29,10 +29,10 @@ import org.oxycblt.auxio.ui.MainNavigationAction
|
||||
import org.oxycblt.auxio.ui.NavigationViewModel
|
||||
import org.oxycblt.auxio.ui.ViewBindingFragment
|
||||
import org.oxycblt.auxio.util.androidActivityViewModels
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.getColorStateListSafe
|
||||
import org.oxycblt.auxio.util.getSystemBarInsetsCompat
|
||||
import org.oxycblt.auxio.util.getSystemGestureInsetsCompat
|
||||
import org.oxycblt.auxio.util.launch
|
||||
import org.oxycblt.auxio.util.textSafe
|
||||
|
||||
/**
|
||||
@@ -76,15 +76,17 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
binding.playbackProgressBar.trackColor =
|
||||
requireContext().getColorStateListSafe(R.color.sel_track).defaultColor
|
||||
|
||||
binding.playbackProgressBar.progress = 0
|
||||
|
||||
binding.playbackPlayPause.setOnClickListener { playbackModel.invertPlaying() }
|
||||
|
||||
binding.playbackSkipNext.setOnClickListener { playbackModel.next() }
|
||||
|
||||
// -- VIEWMODEL SETUP ---
|
||||
|
||||
launch { playbackModel.song.collect(::updateSong) }
|
||||
launch { playbackModel.isPlaying.collect(::updateIsPlaying) }
|
||||
launch { playbackModel.positionSecs.collect(::updatePosition) }
|
||||
collectImmediately(playbackModel.song, ::updateSong)
|
||||
collectImmediately(playbackModel.isPlaying, ::updateIsPlaying)
|
||||
collectImmediately(playbackModel.positionSecs, ::updatePosition)
|
||||
}
|
||||
|
||||
private fun updateSong(song: Song?) {
|
||||
|
||||
@@ -171,7 +171,7 @@ class PlaybackViewModel(application: Application) :
|
||||
is DelayedAction.ShuffleAll -> shuffleAll()
|
||||
is DelayedAction.Open -> {
|
||||
library.findSongForUri(application, action.uri)?.let { song ->
|
||||
play(song, settings.songPlaybackMode)
|
||||
play(song, settings.libPlaybackMode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ class SearchFragment :
|
||||
|
||||
override fun onItemClick(item: Item) {
|
||||
when (item) {
|
||||
is Song -> playbackModel.play(item, settings.songPlaybackMode)
|
||||
is Song -> playbackModel.play(item, settings.libPlaybackMode)
|
||||
is MusicParent -> navModel.exploreNavigateTo(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,13 +152,24 @@ class Settings(private val context: Context, private val callback: Callback? = n
|
||||
}
|
||||
}
|
||||
|
||||
/** What queue to create when a song is selected (ex. From All Songs or Search) */
|
||||
val songPlaybackMode: PlaybackMode
|
||||
/** What queue to create when a song is selected from the library or search */
|
||||
val libPlaybackMode: PlaybackMode
|
||||
get() =
|
||||
PlaybackMode.fromInt(
|
||||
inner.getInt(context.getString(R.string.set_key_song_play_mode), Int.MIN_VALUE))
|
||||
inner.getInt(
|
||||
context.getString(R.string.set_key_library_song_playback_mode), Int.MIN_VALUE))
|
||||
?: PlaybackMode.ALL_SONGS
|
||||
|
||||
/**
|
||||
* What queue t create when a song is selected from an album/artist/genre. Null means to default
|
||||
* to the currently shown item.
|
||||
*/
|
||||
val detailPlaybackMode: PlaybackMode?
|
||||
get() =
|
||||
PlaybackMode.fromInt(
|
||||
inner.getInt(
|
||||
context.getString(R.string.set_key_detail_song_playback_mode), Int.MIN_VALUE))
|
||||
|
||||
/** Whether shuffle should stay on when a new song is selected. */
|
||||
val keepShuffle: Boolean
|
||||
get() = inner.getBoolean(context.getString(R.string.set_key_keep_shuffle), true)
|
||||
|
||||
@@ -46,6 +46,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.launch
|
||||
import org.oxycblt.auxio.R
|
||||
@@ -157,6 +158,21 @@ val RecyclerView.canScroll: Boolean
|
||||
val @receiver:ColorRes Int.stateList
|
||||
get() = ColorStateList.valueOf(this)
|
||||
|
||||
/**
|
||||
* Collect a [stateFlow] into [block] a UI-safe way.
|
||||
*
|
||||
* This method automatically calls [block] when initially starting to ensure UI state consistency.
|
||||
* This does nominally mean that there are two initializing collections, but this is considered
|
||||
* okay. [block] should be a function pointer in order to ensure lifecycle consistency.
|
||||
*
|
||||
* Only use this if your code absolutely needs to have a good state for ~100ms of draw-time.
|
||||
* Otherwise, it's somewhat in-efficient.
|
||||
*/
|
||||
fun <T> Fragment.collectImmediately(stateFlow: StateFlow<T>, block: (T) -> Unit) {
|
||||
block(stateFlow.value)
|
||||
launch { stateFlow.collect(block) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches [block] in a lifecycle-aware coroutine once [state] is reached. This is primarily a
|
||||
* shortcut intended to correctly launch a co-routine on a fragment in a way that won't cause
|
||||
|
||||
Reference in New Issue
Block a user