Add playing indicator to album songs
Add an indicator to album songs that shows if theyre being currently played or not.
This commit is contained in:
parent
7e0ee3d04f
commit
e7e683c3a9
3 changed files with 49 additions and 6 deletions
|
@ -13,6 +13,7 @@ import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
||||||
import org.oxycblt.auxio.detail.adapters.AlbumSongAdapter
|
import org.oxycblt.auxio.detail.adapters.AlbumSongAdapter
|
||||||
import org.oxycblt.auxio.music.MusicStore
|
import org.oxycblt.auxio.music.MusicStore
|
||||||
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||||
import org.oxycblt.auxio.ui.disable
|
import org.oxycblt.auxio.ui.disable
|
||||||
|
@ -55,6 +56,8 @@ class AlbumDetailFragment : DetailFragment() {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var lastHolder: AlbumSongAdapter.ViewHolder? = null
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
@ -126,9 +129,36 @@ class AlbumDetailFragment : DetailFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playbackModel.song.observe(viewLifecycleOwner) { song ->
|
||||||
|
if (song != null) {
|
||||||
|
val pos = detailModel.albumSortMode.value!!.getSortedSongList(
|
||||||
|
detailModel.currentAlbum.value!!.songs
|
||||||
|
).indexOfFirst { it.id == song.id }
|
||||||
|
|
||||||
|
if (pos != -1) {
|
||||||
|
binding.albumSongRecycler.post {
|
||||||
|
lastHolder?.removePlaying()
|
||||||
|
|
||||||
|
lastHolder = (
|
||||||
|
binding.albumSongRecycler.getChildViewHolder(
|
||||||
|
binding.albumSongRecycler.getChildAt(pos)
|
||||||
|
) as AlbumSongAdapter.ViewHolder
|
||||||
|
)
|
||||||
|
|
||||||
|
lastHolder?.setPlaying(requireContext())
|
||||||
|
}
|
||||||
|
|
||||||
|
return@observe
|
||||||
|
} else {
|
||||||
|
lastHolder?.removePlaying()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastHolder?.removePlaying()
|
||||||
|
}
|
||||||
|
|
||||||
playbackModel.navToItem.observe(viewLifecycleOwner) {
|
playbackModel.navToItem.observe(viewLifecycleOwner) {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
/*
|
|
||||||
if (it is Song) {
|
if (it is Song) {
|
||||||
// Calculate where the item for the currently played song is, and navigate to there.
|
// Calculate where the item for the currently played song is, and navigate to there.
|
||||||
val pos = detailModel.albumSortMode.value!!.getSortedSongList(
|
val pos = detailModel.albumSortMode.value!!.getSortedSongList(
|
||||||
|
@ -147,8 +177,6 @@ class AlbumDetailFragment : DetailFragment() {
|
||||||
playbackModel.doneWithNavToItem()
|
playbackModel.doneWithNavToItem()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TODO: Re-add scroll if you find a way to implement the playing indicators on song items
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (detailModel.currentAlbum.value!!.id == playbackModel.song.value!!.album.id) {
|
if (detailModel.currentAlbum.value!!.id == playbackModel.song.value!!.album.id) {
|
||||||
playbackModel.doneWithNavToItem()
|
playbackModel.doneWithNavToItem()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.oxycblt.auxio.detail.adapters
|
package org.oxycblt.auxio.detail.adapters
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -8,6 +9,8 @@ import org.oxycblt.auxio.databinding.ItemAlbumSongBinding
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.recycler.DiffCallback
|
import org.oxycblt.auxio.recycler.DiffCallback
|
||||||
import org.oxycblt.auxio.recycler.viewholders.BaseViewHolder
|
import org.oxycblt.auxio.recycler.viewholders.BaseViewHolder
|
||||||
|
import org.oxycblt.auxio.ui.accent
|
||||||
|
import org.oxycblt.auxio.ui.toColor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An adapter for displaying the [Song]s of an album.
|
* An adapter for displaying the [Song]s of an album.
|
||||||
|
@ -30,11 +33,25 @@ class AlbumSongAdapter(
|
||||||
inner class ViewHolder(
|
inner class ViewHolder(
|
||||||
private val binding: ItemAlbumSongBinding,
|
private val binding: ItemAlbumSongBinding,
|
||||||
) : BaseViewHolder<Song>(binding, doOnClick, doOnLongClick) {
|
) : BaseViewHolder<Song>(binding, doOnClick, doOnLongClick) {
|
||||||
|
private val normalColor = binding.songName.currentTextColor
|
||||||
|
private val inactiveColor = binding.songTrack.currentTextColor
|
||||||
|
|
||||||
override fun onBind(data: Song) {
|
override fun onBind(data: Song) {
|
||||||
binding.song = data
|
binding.song = data
|
||||||
|
|
||||||
binding.songName.requestLayout()
|
binding.songName.requestLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setPlaying(context: Context) {
|
||||||
|
val accentColor = accent.first.toColor(context)
|
||||||
|
|
||||||
|
binding.songName.setTextColor(accentColor)
|
||||||
|
binding.songTrack.setTextColor(accentColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removePlaying() {
|
||||||
|
binding.songName.setTextColor(normalColor)
|
||||||
|
binding.songTrack.setTextColor(inactiveColor)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,8 +468,6 @@ class PlaybackStateManager private constructor() {
|
||||||
database.writeQueue(queueItems)
|
database.writeQueue(queueItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
getCommonGenre()
|
|
||||||
|
|
||||||
val time = System.currentTimeMillis() - start
|
val time = System.currentTimeMillis() - start
|
||||||
|
|
||||||
Log.d(this::class.simpleName, "Save finished in ${time}ms")
|
Log.d(this::class.simpleName, "Save finished in ${time}ms")
|
||||||
|
|
Loading…
Reference in a new issue