Move play & shuffle to dedicated buttons
Move the play and shuffle actions to dedicated buttons on the DetailFragments. Actually looks r e a l l y nice.
This commit is contained in:
@@ -44,7 +44,7 @@ class AlbumDetailFragment : DetailFragment() {
|
||||
}
|
||||
|
||||
val detailAdapter = AlbumDetailAdapter(
|
||||
detailModel, viewLifecycleOwner,
|
||||
detailModel, playbackModel, viewLifecycleOwner,
|
||||
doOnClick = { playbackModel.playSong(it, PlaybackMode.IN_ALBUM) },
|
||||
doOnLongClick = { data, view ->
|
||||
PopupMenu(requireContext(), view).setupAlbumSongActions(
|
||||
@@ -57,23 +57,8 @@ class AlbumDetailFragment : DetailFragment() {
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
|
||||
setupToolbar(R.menu.menu_album_actions) {
|
||||
setupToolbar(R.menu.menu_album_detail) {
|
||||
when (it) {
|
||||
R.id.action_shuffle -> {
|
||||
playbackModel.playAlbum(
|
||||
detailModel.currentAlbum.value!!, true
|
||||
)
|
||||
|
||||
true
|
||||
}
|
||||
R.id.action_play -> {
|
||||
playbackModel.playAlbum(
|
||||
detailModel.currentAlbum.value!!, false
|
||||
)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_queue_add -> {
|
||||
playbackModel.addToUserQueue(detailModel.currentAlbum.value!!)
|
||||
getString(R.string.label_queue_added).createToast(requireContext())
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.detail.adapters.ArtistDetailAdapter
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.Album
|
||||
@@ -43,7 +42,7 @@ class ArtistDetailFragment : DetailFragment() {
|
||||
}
|
||||
|
||||
val detailAdapter = ArtistDetailAdapter(
|
||||
detailModel, viewLifecycleOwner,
|
||||
detailModel, playbackModel, viewLifecycleOwner,
|
||||
doOnClick = {
|
||||
if (!detailModel.isNavigating) {
|
||||
detailModel.updateNavigationStatus(true)
|
||||
@@ -64,29 +63,7 @@ class ArtistDetailFragment : DetailFragment() {
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
|
||||
setupToolbar(R.menu.menu_artist_actions) {
|
||||
when (it) {
|
||||
R.id.action_shuffle -> {
|
||||
playbackModel.playArtist(
|
||||
detailModel.currentArtist.value!!,
|
||||
true
|
||||
)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_play_albums -> {
|
||||
playbackModel.playArtist(
|
||||
detailModel.currentArtist.value!!, false
|
||||
)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
setupToolbar()
|
||||
setupRecycler(detailAdapter)
|
||||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
@@ -47,16 +47,23 @@ abstract class DetailFragment : Fragment() {
|
||||
/**
|
||||
* Shortcut method for doing setup of the detail toolbar.
|
||||
*/
|
||||
protected fun setupToolbar(@MenuRes menu: Int, onMenuClick: (id: Int) -> Boolean) {
|
||||
protected fun setupToolbar(
|
||||
@MenuRes menu: Int = -1,
|
||||
onMenuClick: ((id: Int) -> Boolean)? = null
|
||||
) {
|
||||
binding.detailToolbar.apply {
|
||||
inflateMenu(menu)
|
||||
if (menu != -1) {
|
||||
inflateMenu(menu)
|
||||
}
|
||||
|
||||
setNavigationOnClickListener {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
onMenuClick(it.itemId)
|
||||
onMenuClick?.let {
|
||||
setOnMenuItemClickListener {
|
||||
it(it.itemId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.detail.adapters.GenreDetailAdapter
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.Album
|
||||
@@ -42,7 +41,7 @@ class GenreDetailFragment : DetailFragment() {
|
||||
}
|
||||
|
||||
val detailAdapter = GenreDetailAdapter(
|
||||
detailModel, viewLifecycleOwner,
|
||||
detailModel, playbackModel, viewLifecycleOwner,
|
||||
doOnClick = {
|
||||
playbackModel.playSong(it, PlaybackMode.IN_GENRE)
|
||||
},
|
||||
@@ -57,21 +56,7 @@ class GenreDetailFragment : DetailFragment() {
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
|
||||
setupToolbar(R.menu.menu_genre_actions) {
|
||||
when (it) {
|
||||
R.id.action_shuffle -> {
|
||||
playbackModel.playGenre(
|
||||
detailModel.currentGenre.value!!,
|
||||
true
|
||||
)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
setupToolbar()
|
||||
setupRecycler(detailAdapter)
|
||||
|
||||
// --- DETAILVIEWMODEL SETUP ---
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
package org.oxycblt.auxio.detail.adapters
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumHeaderBinding
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumSongBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.recycler.DiffCallback
|
||||
import org.oxycblt.auxio.recycler.viewholders.BaseViewHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.Highlightable
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.disable
|
||||
import org.oxycblt.auxio.ui.setTextColorResource
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
||||
/**
|
||||
* An adapter for displaying the details and [Song]s of an [Album]
|
||||
*/
|
||||
class AlbumDetailAdapter(
|
||||
private val detailModel: DetailViewModel,
|
||||
private val playbackModel: PlaybackViewModel,
|
||||
private val lifecycleOwner: LifecycleOwner,
|
||||
private val doOnClick: (data: Song) -> Unit,
|
||||
private val doOnLongClick: (data: Song, view: View) -> Unit
|
||||
@@ -109,8 +114,25 @@ class AlbumDetailAdapter(
|
||||
override fun onBind(data: Album) {
|
||||
binding.album = data
|
||||
binding.detailModel = detailModel
|
||||
binding.playbackModel = playbackModel
|
||||
binding.lifecycleOwner = lifecycleOwner
|
||||
|
||||
// Apply the accent programmatically since I don't want to deal the with the
|
||||
// nightmarish mess of switching out my styling to Material
|
||||
val accent = accent.first.toColor(binding.albumShuffleButton.context)
|
||||
val selection = ColorStateList.valueOf(
|
||||
R.color.selection_color.toColor(binding.albumShuffleButton.context)
|
||||
)
|
||||
|
||||
binding.albumShuffleButton.apply {
|
||||
backgroundTintList = ColorStateList.valueOf(accent)
|
||||
rippleColor = selection
|
||||
}
|
||||
binding.albumPlayButton.apply {
|
||||
setTextColor(accent)
|
||||
rippleColor = selection
|
||||
}
|
||||
|
||||
if (data.songs.size < 2) {
|
||||
binding.albumSortButton.disable()
|
||||
}
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
package org.oxycblt.auxio.detail.adapters
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.ItemArtistAlbumBinding
|
||||
import org.oxycblt.auxio.databinding.ItemArtistHeaderBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.recycler.DiffCallback
|
||||
import org.oxycblt.auxio.recycler.viewholders.BaseViewHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.Highlightable
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.disable
|
||||
import org.oxycblt.auxio.ui.setTextColorResource
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
||||
/**
|
||||
* An adapter for displaying the [Album]s of an artist.
|
||||
*/
|
||||
class ArtistDetailAdapter(
|
||||
private val detailModel: DetailViewModel,
|
||||
private val playbackModel: PlaybackViewModel,
|
||||
private val lifecycleOwner: LifecycleOwner,
|
||||
private val doOnClick: (data: Album) -> Unit,
|
||||
private val doOnLongClick: (data: Album, view: View) -> Unit,
|
||||
@@ -108,8 +113,26 @@ class ArtistDetailAdapter(
|
||||
override fun onBind(data: Artist) {
|
||||
binding.artist = data
|
||||
binding.detailModel = detailModel
|
||||
binding.playbackModel = playbackModel
|
||||
binding.lifecycleOwner = lifecycleOwner
|
||||
|
||||
// Apply the accent programmatically since I don't want to deal the with the
|
||||
// nightmarish mess of switching out my styling to Material
|
||||
val accent = accent.first.toColor(binding.artistShuffleButton.context)
|
||||
val selection = ColorStateList.valueOf(
|
||||
R.color.selection_color.toColor(binding.artistShuffleButton.context)
|
||||
)
|
||||
|
||||
binding.artistShuffleButton.apply {
|
||||
backgroundTintList = ColorStateList.valueOf(accent)
|
||||
rippleColor = selection
|
||||
}
|
||||
|
||||
binding.artistPlayButton.apply {
|
||||
setTextColor(accent)
|
||||
rippleColor = selection
|
||||
}
|
||||
|
||||
if (data.albums.size < 2) {
|
||||
binding.artistSortButton.disable()
|
||||
}
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
package org.oxycblt.auxio.detail.adapters
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.ItemGenreHeaderBinding
|
||||
import org.oxycblt.auxio.databinding.ItemGenreSongBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
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.recycler.DiffCallback
|
||||
import org.oxycblt.auxio.recycler.viewholders.BaseViewHolder
|
||||
import org.oxycblt.auxio.recycler.viewholders.Highlightable
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.disable
|
||||
import org.oxycblt.auxio.ui.setTextColorResource
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
||||
/**
|
||||
* An adapter for displaying the [Song]s of a genre.
|
||||
*/
|
||||
class GenreDetailAdapter(
|
||||
private val detailModel: DetailViewModel,
|
||||
private val playbackModel: PlaybackViewModel,
|
||||
private val lifecycleOwner: LifecycleOwner,
|
||||
private val doOnClick: (data: Song) -> Unit,
|
||||
private val doOnLongClick: (data: Song, view: View) -> Unit
|
||||
@@ -109,8 +114,26 @@ class GenreDetailAdapter(
|
||||
override fun onBind(data: Genre) {
|
||||
binding.genre = data
|
||||
binding.detailModel = detailModel
|
||||
binding.playbackModel = playbackModel
|
||||
binding.lifecycleOwner = lifecycleOwner
|
||||
|
||||
// Apply the accent programmatically since I don't want to deal the with the
|
||||
// nightmarish mess of switching out my styling to Material
|
||||
val accent = accent.first.toColor(binding.genreShuffleButton.context)
|
||||
val selection = ColorStateList.valueOf(
|
||||
R.color.selection_color.toColor(binding.genreShuffleButton.context)
|
||||
)
|
||||
|
||||
binding.genreShuffleButton.apply {
|
||||
backgroundTintList = ColorStateList.valueOf(accent)
|
||||
rippleColor = selection
|
||||
}
|
||||
|
||||
binding.genrePlayButton.apply {
|
||||
setTextColor(accent)
|
||||
rippleColor = selection
|
||||
}
|
||||
|
||||
if (data.songs.size < 2) {
|
||||
binding.genreSortButton.disable()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user