Move detail controls to Toolbar
Move the play/shuffle buttons from the header of the DetailFragments to their Toolbar, it makes far more sense for them to be there honestly.
This commit is contained in:
@@ -55,16 +55,30 @@ class AlbumDetailFragment : Fragment() {
|
||||
binding.playbackModel = playbackModel
|
||||
binding.album = detailModel.currentAlbum.value!!
|
||||
|
||||
binding.albumToolbar.apply {
|
||||
setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_shuffle -> playbackModel.play(
|
||||
detailModel.currentAlbum.value!!,
|
||||
true
|
||||
)
|
||||
R.id.action_play -> playbackModel.play(detailModel.currentAlbum.value!!, false)
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
binding.albumSongRecycler.apply {
|
||||
adapter = songAdapter
|
||||
applyDivider()
|
||||
setHasFixedSize(true)
|
||||
}
|
||||
|
||||
binding.albumToolbar.setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
// Don't enable the sort button if there's only one song [or less]
|
||||
if (detailModel.currentAlbum.value!!.numSongs < 2) {
|
||||
binding.albumSortButton.disable(requireContext())
|
||||
@@ -84,16 +98,6 @@ class AlbumDetailFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
|
||||
// Observe playback model to update the play button
|
||||
// TODO: Make these icons animated
|
||||
playbackModel.currentMode.observe(viewLifecycleOwner) {
|
||||
updatePlayButton(it, binding)
|
||||
}
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
updatePlayButton(playbackModel.currentMode.value!!, binding)
|
||||
}
|
||||
|
||||
// If the album was shown directly from LibraryFragment, Then enable the ability to
|
||||
// navigate upwards to the parent artist
|
||||
if (args.enableParentNav) {
|
||||
@@ -118,34 +122,4 @@ class AlbumDetailFragment : Fragment() {
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
// Update the play button depending on the current playback status
|
||||
// If playing this album -> Make button show media controls
|
||||
// If not playing this album -> Make button update playback to the artist
|
||||
private fun updatePlayButton(
|
||||
mode: PlaybackMode,
|
||||
binding: FragmentAlbumDetailBinding
|
||||
) {
|
||||
playbackModel.currentParent.value?.let { parent ->
|
||||
if (mode == PlaybackMode.IN_ALBUM &&
|
||||
parent.id == detailModel.currentAlbum.value!!.id
|
||||
) {
|
||||
if (playbackModel.isPlaying.value!!) {
|
||||
binding.albumPlay.setImageResource(R.drawable.ic_pause)
|
||||
} else {
|
||||
binding.albumPlay.setImageResource(R.drawable.ic_play)
|
||||
}
|
||||
|
||||
binding.albumPlay.setOnClickListener {
|
||||
playbackModel.invertPlayingStatus()
|
||||
}
|
||||
} else {
|
||||
binding.albumPlay.setImageResource(R.drawable.ic_play)
|
||||
|
||||
binding.albumPlay.setOnClickListener {
|
||||
playbackModel.play(detailModel.currentAlbum.value!!, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,11 @@ import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentArtistDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.DetailAlbumAdapter
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackMode
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.theme.applyDivider
|
||||
import org.oxycblt.auxio.theme.disable
|
||||
|
||||
class ArtistDetailFragment : Fragment() {
|
||||
|
||||
private val args: ArtistDetailFragmentArgs by navArgs()
|
||||
private val detailModel: DetailViewModel by activityViewModels()
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
@@ -60,8 +58,22 @@ class ArtistDetailFragment : Fragment() {
|
||||
binding.playbackModel = playbackModel
|
||||
binding.artist = detailModel.currentArtist.value!!
|
||||
|
||||
binding.artistToolbar.setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
binding.artistToolbar.apply {
|
||||
setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_shuffle -> playbackModel.play(
|
||||
detailModel.currentArtist.value!!,
|
||||
true
|
||||
)
|
||||
R.id.action_play -> playbackModel.play(detailModel.currentArtist.value!!, false)
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
// Disable the sort button if there is only one album [Or less]
|
||||
@@ -89,49 +101,11 @@ class ArtistDetailFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
|
||||
playbackModel.currentMode.observe(viewLifecycleOwner) {
|
||||
updatePlayButton(it, binding)
|
||||
}
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
updatePlayButton(playbackModel.currentMode.value!!, binding)
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
// Update the play button depending on the current playback status
|
||||
// If playing this artist -> Make button show media controls
|
||||
// If not playing this artist -> Make button update playback to the artist
|
||||
private fun updatePlayButton(
|
||||
mode: PlaybackMode,
|
||||
binding: FragmentArtistDetailBinding
|
||||
) {
|
||||
playbackModel.currentParent.value?.let { parent ->
|
||||
if (mode == PlaybackMode.IN_ARTIST &&
|
||||
parent.id == detailModel.currentArtist.value!!.id
|
||||
) {
|
||||
if (playbackModel.isPlaying.value!!) {
|
||||
binding.artistPlay.setImageResource(R.drawable.ic_pause)
|
||||
} else {
|
||||
binding.artistPlay.setImageResource(R.drawable.ic_play)
|
||||
}
|
||||
|
||||
binding.artistPlay.setOnClickListener {
|
||||
playbackModel.invertPlayingStatus()
|
||||
}
|
||||
} else {
|
||||
binding.artistPlay.setImageResource(R.drawable.ic_play)
|
||||
|
||||
binding.artistPlay.setOnClickListener {
|
||||
playbackModel.play(detailModel.currentAlbum.value!!, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import org.oxycblt.auxio.recycler.SortMode
|
||||
|
||||
// ViewModel for the Detail Fragments.
|
||||
// TODO:
|
||||
// - Implement a system where the Toolbar will update with the info [And Media Controls] when
|
||||
// the main info of the detail fragment is removed.
|
||||
// - Implement a system where the Toolbar will update with some infowhen
|
||||
// the main detail header is obscured.
|
||||
class DetailViewModel : ViewModel() {
|
||||
private var mIsNavigating = false
|
||||
val isNavigating: Boolean get() = mIsNavigating
|
||||
|
||||
@@ -9,9 +9,11 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentGenreDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.DetailArtistAdapter
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.theme.applyDivider
|
||||
import org.oxycblt.auxio.theme.disable
|
||||
|
||||
@@ -19,6 +21,7 @@ class GenreDetailFragment : Fragment() {
|
||||
|
||||
private val args: GenreDetailFragmentArgs by navArgs()
|
||||
private val detailModel: DetailViewModel by activityViewModels()
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -55,8 +58,22 @@ class GenreDetailFragment : Fragment() {
|
||||
binding.detailModel = detailModel
|
||||
binding.genre = detailModel.currentGenre.value
|
||||
|
||||
binding.genreToolbar.setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
binding.genreToolbar.apply {
|
||||
setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_shuffle -> playbackModel.play(
|
||||
detailModel.currentGenre.value!!,
|
||||
true
|
||||
)
|
||||
R.id.action_play -> playbackModel.play(detailModel.currentGenre.value!!, false)
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
// Disable the sort button if there is only one artist [Or less]
|
||||
|
||||
@@ -21,7 +21,7 @@ class LibraryViewModel : ViewModel() {
|
||||
val searchHasFocus: Boolean get() = mSearchHasFocus
|
||||
|
||||
// TODO: Move these to prefs when they're added
|
||||
private val mShowMode = MutableLiveData(ShowMode.SHOW_ARTISTS)
|
||||
private val mShowMode = MutableLiveData(ShowMode.SHOW_GENRES)
|
||||
val showMode: LiveData<ShowMode> get() = mShowMode
|
||||
|
||||
private val mSortMode = MutableLiveData(SortMode.ALPHA_DOWN)
|
||||
|
||||
@@ -38,7 +38,7 @@ class CompactPlaybackFragment : Fragment() {
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
// Put a placeholder song in the binding & hide the playback fragment initially,
|
||||
// as for some reason the attach event doesn't register anymore w/LiveData
|
||||
// just in case.
|
||||
binding.song = MusicStore.getInstance().songs[0]
|
||||
binding.playbackModel = playbackModel
|
||||
|
||||
@@ -59,7 +59,6 @@ class CompactPlaybackFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Fix the thing where the icons will animate on startup
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
if (playbackModel.canAnimate) {
|
||||
if (it) {
|
||||
|
||||
@@ -46,7 +46,9 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
binding.playbackModel = playbackModel
|
||||
binding.song = playbackModel.currentSong.value!!
|
||||
|
||||
binding.playbackToolbar.setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
@@ -54,7 +56,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
// Make marquee scroll work
|
||||
binding.playbackSong.isSelected = true
|
||||
|
||||
binding.playbackSeekBar.setOnSeekBarChangeListener(this)
|
||||
|
||||
// --- VIEWMODEL SETUP --
|
||||
|
||||
@@ -5,5 +5,5 @@ package org.oxycblt.auxio.playback
|
||||
// IN_ARTIST -> Play from the songs of the artist
|
||||
// IN_ALBUM -> Play from the songs of the album
|
||||
enum class PlaybackMode {
|
||||
IN_ARTIST, IN_ALBUM, ALL_SONGS;
|
||||
IN_ARTIST, IN_GENRE, IN_ALBUM, ALL_SONGS;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.lifecycle.ViewModel
|
||||
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.MusicStore
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.toDuration
|
||||
@@ -63,6 +64,15 @@ class PlaybackViewModel : ViewModel() {
|
||||
|
||||
// Update the current song while changing the queue mode.
|
||||
fun update(song: Song, mode: PlaybackMode) {
|
||||
|
||||
// Auxio doesn't support playing songs while swapping the mode to GENRE, as genres
|
||||
// are bound to artists, not songs.
|
||||
if (mode == PlaybackMode.IN_GENRE) {
|
||||
Log.e(this::class.simpleName, "Auxio cant play songs with the mode of IN_GENRE.")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Updating song to ${song.name} and mode to $mode")
|
||||
|
||||
val musicStore = MusicStore.getInstance()
|
||||
@@ -75,12 +85,14 @@ class PlaybackViewModel : ViewModel() {
|
||||
PlaybackMode.ALL_SONGS -> musicStore.songs.toMutableList()
|
||||
PlaybackMode.IN_ARTIST -> song.album.artist.songs
|
||||
PlaybackMode.IN_ALBUM -> song.album.songs
|
||||
PlaybackMode.IN_GENRE -> error("what")
|
||||
}
|
||||
|
||||
mCurrentParent.value = when (mode) {
|
||||
PlaybackMode.ALL_SONGS -> null
|
||||
PlaybackMode.IN_ARTIST -> song.album.artist
|
||||
PlaybackMode.IN_ALBUM -> song.album
|
||||
PlaybackMode.IN_GENRE -> error("what")
|
||||
}
|
||||
|
||||
if (mIsShuffling.value!!) {
|
||||
@@ -92,6 +104,7 @@ class PlaybackViewModel : ViewModel() {
|
||||
mCurrentIndex.value = mQueue.value!!.indexOf(song)
|
||||
}
|
||||
|
||||
// Play some parent music model, whether that being albums/artists/genres.
|
||||
fun play(album: Album, isShuffled: Boolean) {
|
||||
Log.d(this::class.simpleName, "Playing album ${album.name}")
|
||||
|
||||
@@ -132,6 +145,26 @@ class PlaybackViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun play(genre: Genre, isShuffled: Boolean) {
|
||||
Log.d(this::class.simpleName, "Playing genre ${genre.name}")
|
||||
|
||||
val songs = orderSongsInGenre(genre)
|
||||
|
||||
updatePlayback(songs[0])
|
||||
|
||||
mQueue.value = songs
|
||||
mCurrentIndex.value = 0
|
||||
mCurrentParent.value = genre
|
||||
mIsShuffling.value = isShuffled
|
||||
mCurrentMode.value = PlaybackMode.IN_GENRE
|
||||
|
||||
if (mIsShuffling.value!!) {
|
||||
genShuffle(false)
|
||||
} else {
|
||||
resetShuffle()
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current duration using a SeekBar progress
|
||||
fun updateCurrentDurationWithProgress(progress: Int) {
|
||||
mCurrentDuration.value = progress.toLong()
|
||||
@@ -232,6 +265,7 @@ class PlaybackViewModel : ViewModel() {
|
||||
mQueue.value = when (mCurrentMode.value!!) {
|
||||
PlaybackMode.IN_ARTIST -> orderSongsInArtist(mCurrentParent.value as Artist)
|
||||
PlaybackMode.IN_ALBUM -> orderSongsInAlbum(mCurrentParent.value as Album)
|
||||
PlaybackMode.IN_GENRE -> orderSongsInGenre(mCurrentParent.value as Genre)
|
||||
PlaybackMode.ALL_SONGS -> MusicStore.getInstance().songs.toMutableList()
|
||||
}
|
||||
|
||||
@@ -246,8 +280,22 @@ class PlaybackViewModel : ViewModel() {
|
||||
private fun orderSongsInArtist(artist: Artist): MutableList<Song> {
|
||||
val final = mutableListOf<Song>()
|
||||
|
||||
artist.albums.sortedByDescending { it.year }.forEach {
|
||||
final.addAll(it.songs.sortedBy { it.track })
|
||||
artist.albums.sortedByDescending { it.year }.forEach { album ->
|
||||
final.addAll(album.songs.sortedBy { it.track })
|
||||
}
|
||||
|
||||
return final
|
||||
}
|
||||
|
||||
private fun orderSongsInGenre(genre: Genre): MutableList<Song> {
|
||||
val final = mutableListOf<Song>()
|
||||
|
||||
genre.artists.sortedWith(
|
||||
compareBy(String.CASE_INSENSITIVE_ORDER) { it.name }
|
||||
).forEach { artist ->
|
||||
artist.albums.sortedByDescending { it.year }.forEach { album ->
|
||||
final.addAll(album.songs.sortedBy { it.track })
|
||||
}
|
||||
}
|
||||
|
||||
return final
|
||||
|
||||
@@ -82,7 +82,7 @@ class AlbumViewHolder private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add indicators to song recycler items when they're being played.
|
||||
// TODO: Add indicators to song recycler items when they're being played?
|
||||
|
||||
class SongViewHolder private constructor(
|
||||
doOnClick: (Song) -> Unit,
|
||||
|
||||
Reference in New Issue
Block a user