Redesign headers/menus
Redesign the header items so they look nicer, update the PopupMenus with some new things as well.
This commit is contained in:
@@ -13,6 +13,7 @@ import org.oxycblt.auxio.ui.accent
|
||||
// lead to nothing being displayed [Possibly Un-fixable]
|
||||
// FIXME: Compat issues with Versions 5/6 that cause recyclerview
|
||||
// dividers not to show and for progress bars to look wonky
|
||||
// FIXME: Navigation memory leak that is really confusing
|
||||
class MainActivity : AppCompatActivity(R.layout.activity_main) {
|
||||
|
||||
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
@@ -17,6 +18,7 @@ import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.ui.applyDivider
|
||||
import org.oxycblt.auxio.ui.disable
|
||||
import org.oxycblt.auxio.ui.setupAlbumSongActions
|
||||
|
||||
class AlbumDetailFragment : Fragment() {
|
||||
|
||||
@@ -36,7 +38,6 @@ class AlbumDetailFragment : Fragment() {
|
||||
if (detailModel.currentAlbum.value == null ||
|
||||
detailModel.currentAlbum.value?.id != args.albumId
|
||||
) {
|
||||
|
||||
detailModel.updateAlbum(
|
||||
MusicStore.getInstance().albums.find {
|
||||
it.id == args.albumId
|
||||
@@ -44,9 +45,16 @@ class AlbumDetailFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
|
||||
val songAdapter = DetailSongAdapter {
|
||||
playbackModel.playSong(it, PlaybackMode.IN_ALBUM)
|
||||
}
|
||||
val songAdapter = DetailSongAdapter(
|
||||
{
|
||||
playbackModel.playSong(it, PlaybackMode.IN_ALBUM)
|
||||
},
|
||||
{ data, view ->
|
||||
PopupMenu(requireContext(), view).setupAlbumSongActions(
|
||||
data, requireContext(), detailModel, playbackModel
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
@@ -100,24 +108,20 @@ class AlbumDetailFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
|
||||
// If the album was shown directly from LibraryFragment, Then enable the ability to
|
||||
// navigate upwards to the parent artist
|
||||
if (args.enableParentNav) {
|
||||
detailModel.doneWithNavToParent()
|
||||
detailModel.doneWithNavToParent()
|
||||
|
||||
detailModel.navToParent.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
detailModel.navToParent.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
if (!args.enableParentNav) {
|
||||
findNavController().navigateUp()
|
||||
} else {
|
||||
findNavController().navigate(
|
||||
AlbumDetailFragmentDirections.actionShowParentArtist(
|
||||
detailModel.currentAlbum.value!!.artist.id
|
||||
)
|
||||
)
|
||||
|
||||
detailModel.doneWithNavToParent()
|
||||
}
|
||||
}
|
||||
|
||||
binding.albumArtist.setBackgroundResource(R.drawable.ui_ripple)
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.oxycblt.auxio.detail.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumSongBinding
|
||||
@@ -9,7 +10,8 @@ import org.oxycblt.auxio.recycler.DiffCallback
|
||||
import org.oxycblt.auxio.recycler.viewholders.BaseViewHolder
|
||||
|
||||
class DetailSongAdapter(
|
||||
private val doOnClick: (data: Song) -> Unit
|
||||
private val doOnClick: (data: Song) -> Unit,
|
||||
private val doOnLongClick: (data: Song, view: View) -> Unit
|
||||
) : ListAdapter<Song, DetailSongAdapter.ViewHolder>(DiffCallback()) {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
@@ -24,7 +26,7 @@ class DetailSongAdapter(
|
||||
// Generic ViewHolder for a song
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemAlbumSongBinding,
|
||||
) : BaseViewHolder<Song>(binding, doOnClick, null) {
|
||||
) : BaseViewHolder<Song>(binding, doOnClick, doOnLongClick) {
|
||||
|
||||
override fun onBind(data: Song) {
|
||||
binding.song = data
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.forEach
|
||||
@@ -30,7 +31,7 @@ import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.ui.applyColor
|
||||
import org.oxycblt.auxio.ui.applyDivider
|
||||
import org.oxycblt.auxio.ui.resolveAttr
|
||||
import org.oxycblt.auxio.ui.showActionMenuForSong
|
||||
import org.oxycblt.auxio.ui.setupSongActions
|
||||
|
||||
// A Fragment to show all the music in the Library.
|
||||
class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
@@ -57,7 +58,9 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
||||
},
|
||||
{ data, view ->
|
||||
if (data is Song) {
|
||||
showActionMenuForSong(requireContext(), data, view, playbackModel)
|
||||
PopupMenu(requireContext(), view).setupSongActions(
|
||||
data, requireContext(), playbackModel
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -173,25 +173,27 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||
}
|
||||
|
||||
// Move queue OR user queue items, given QueueAdapter indices.
|
||||
// I have no idea what is going on in this function, but it works, so
|
||||
fun moveQueueItems(adapterFrom: Int, adapterTo: Int): Boolean {
|
||||
var from = adapterFrom.dec()
|
||||
var to = adapterTo.dec()
|
||||
|
||||
if (from < mUserQueue.value!!.size) {
|
||||
|
||||
// Ignore invalid movements to out of bounds, header, or queue positions
|
||||
if (to >= mUserQueue.value!!.size || to < 0) return false
|
||||
|
||||
playbackManager.moveUserQueueItems(from, to)
|
||||
} else {
|
||||
// Ignore invalid movements to out of bounds or header positions
|
||||
if (to < 0) return false
|
||||
|
||||
// Get the real queue positions from the nextInQueue positions
|
||||
val delta = mQueue.value!!.size - nextItemsInQueue.value!!.size
|
||||
|
||||
from += delta
|
||||
to += delta
|
||||
|
||||
if (userQueue.value!!.isNotEmpty()) {
|
||||
// Ignore user queue positions
|
||||
if (to <= mUserQueue.value!!.size.inc()) return false
|
||||
|
||||
from -= mUserQueue.value!!.size.inc()
|
||||
|
||||
@@ -44,6 +44,10 @@ class QueueFragment : Fragment() {
|
||||
}
|
||||
|
||||
playbackModel.userQueue.observe(viewLifecycleOwner) {
|
||||
if (it.isEmpty() && playbackModel.nextItemsInQueue.value!!.isEmpty()) {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
queueAdapter.submitList(createQueueDisplay()) {
|
||||
binding.queueRecycler.scrollToPosition(0)
|
||||
scrollRecyclerIfNeeded(binding)
|
||||
@@ -51,6 +55,10 @@ class QueueFragment : Fragment() {
|
||||
}
|
||||
|
||||
playbackModel.nextItemsInQueue.observe(viewLifecycleOwner) {
|
||||
if (it.isEmpty() && playbackModel.userQueue.value!!.isEmpty()) {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
queueAdapter.submitList(createQueueDisplay()) {
|
||||
scrollRecyclerIfNeeded(binding)
|
||||
}
|
||||
@@ -87,7 +95,7 @@ class QueueFragment : Fragment() {
|
||||
|
||||
private fun scrollRecyclerIfNeeded(binding: FragmentQueueBinding) {
|
||||
if ((binding.queueRecycler.layoutManager as LinearLayoutManager)
|
||||
.findFirstVisibleItemPosition() < 1
|
||||
.findFirstVisibleItemPosition() < 1
|
||||
) {
|
||||
binding.queueRecycler.scrollToPosition(0)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import org.oxycblt.auxio.R
|
||||
@@ -13,7 +14,7 @@ import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.ui.applyDivider
|
||||
import org.oxycblt.auxio.ui.showActionMenuForSong
|
||||
import org.oxycblt.auxio.ui.setupSongActions
|
||||
|
||||
class SongsFragment : Fragment() {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
@@ -46,7 +47,9 @@ class SongsFragment : Fragment() {
|
||||
playbackModel.playSong(it, PlaybackMode.ALL_SONGS)
|
||||
},
|
||||
{ data, view ->
|
||||
showActionMenuForSong(requireContext(), data, view, playbackModel)
|
||||
PopupMenu(requireContext(), view).setupSongActions(
|
||||
data, requireContext(), playbackModel
|
||||
)
|
||||
}
|
||||
)
|
||||
applyDivider()
|
||||
|
||||
@@ -6,61 +6,20 @@ import android.graphics.drawable.ColorDrawable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.ImageButton
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
|
||||
// Functions for managing UI elements [Not Colors]
|
||||
|
||||
fun showActionMenuForSong(
|
||||
context: Context,
|
||||
song: Song,
|
||||
view: View,
|
||||
playbackModel: PlaybackViewModel
|
||||
) {
|
||||
PopupMenu(context, view).apply {
|
||||
inflate(R.menu.menu_song_actions)
|
||||
setOnMenuItemClickListener {
|
||||
return@setOnMenuItemClickListener when (it.itemId) {
|
||||
R.id.action_queue_add -> {
|
||||
playbackModel.addToUserQueue(song)
|
||||
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.label_queue_added),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_play_artist -> {
|
||||
playbackModel.playSong(song, PlaybackMode.IN_ARTIST)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_play_album -> {
|
||||
playbackModel.playSong(song, PlaybackMode.IN_ALBUM)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
// Apply a color to a Menu Item
|
||||
fun MenuItem.applyColor(@ColorInt color: Int) {
|
||||
SpannableString(title).apply {
|
||||
@@ -95,3 +54,67 @@ fun RecyclerView.applyDivider() {
|
||||
|
||||
addItemDecoration(div)
|
||||
}
|
||||
|
||||
fun PopupMenu.setupSongActions(song: Song, context: Context, playbackModel: PlaybackViewModel) {
|
||||
inflate(R.menu.menu_song_actions)
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_queue_add -> {
|
||||
playbackModel.addToUserQueue(song)
|
||||
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.label_queue_added),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_play_artist -> {
|
||||
playbackModel.playSong(song, PlaybackMode.IN_ARTIST)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_play_album -> {
|
||||
playbackModel.playSong(song, PlaybackMode.IN_ALBUM)
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
show()
|
||||
}
|
||||
|
||||
fun PopupMenu.setupAlbumSongActions(
|
||||
song: Song,
|
||||
context: Context,
|
||||
detailViewModel: DetailViewModel,
|
||||
playbackModel: PlaybackViewModel
|
||||
) {
|
||||
inflate(R.menu.menu_album_song_actions)
|
||||
setOnMenuItemClickListener {
|
||||
when (it.itemId) {
|
||||
R.id.action_queue_add -> {
|
||||
playbackModel.addToUserQueue(song)
|
||||
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.label_queue_added),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_go_artist -> {
|
||||
detailViewModel.doNavToParent()
|
||||
true
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user