Add album list to ArtistDetailFragment
Add a list of the artists albums to ArtistDetailFragment.
This commit is contained in:
@@ -7,8 +7,11 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import org.oxycblt.auxio.ClickListener
|
||||
import org.oxycblt.auxio.databinding.FragmentArtistDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.DetailAlbumAdapter
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.theme.applyDivider
|
||||
|
||||
class ArtistDetailFragment : Fragment() {
|
||||
|
||||
@@ -24,7 +27,19 @@ class ArtistDetailFragment : Fragment() {
|
||||
val musicModel: MusicViewModel by activityViewModels()
|
||||
val artistId = ArtistDetailFragmentArgs.fromBundle(requireArguments()).artistId
|
||||
|
||||
binding.artist = musicModel.artists.value?.find { it.id == artistId }
|
||||
val artist = musicModel.artists.value?.find { it.id == artistId }!!
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
binding.artist = artist
|
||||
|
||||
binding.albumRecycler.adapter = DetailAlbumAdapter(
|
||||
artist.albums,
|
||||
ClickListener {
|
||||
Log.d(this::class.simpleName, it.name)
|
||||
}
|
||||
)
|
||||
binding.albumRecycler.applyDivider()
|
||||
binding.albumRecycler.setHasFixedSize(true)
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.oxycblt.auxio.detail.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.ClickListener
|
||||
import org.oxycblt.auxio.databinding.ItemAlbumBigBinding
|
||||
import org.oxycblt.auxio.music.models.Album
|
||||
|
||||
class DetailAlbumAdapter(
|
||||
private val data: List<Album>,
|
||||
private val listener: ClickListener<Album>
|
||||
) : RecyclerView.Adapter<DetailAlbumAdapter.ViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemAlbumBigBinding.inflate(LayoutInflater.from(parent.context))
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val album = data[position]
|
||||
|
||||
holder.bind(album)
|
||||
}
|
||||
|
||||
// Generic ViewHolder for an album
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemAlbumBigBinding
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
init {
|
||||
// Force the viewholder to *actually* be the screen width so ellipsizing can work.
|
||||
binding.root.layoutParams = RecyclerView.LayoutParams(
|
||||
RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
}
|
||||
|
||||
// Bind the view w/new data
|
||||
fun bind(album: Album) {
|
||||
binding.album = album
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
listener.onClick(album)
|
||||
}
|
||||
|
||||
// Force-update the layout so ellipsizing works.
|
||||
binding.albumName.requestLayout()
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import org.oxycblt.auxio.music.models.Album
|
||||
|
||||
class AlbumAdapter(
|
||||
private val data: List<Album>,
|
||||
private val listener: ClickListener<Album>
|
||||
private val listener: ClickListener<Album>,
|
||||
private val isLarge: Boolean
|
||||
) : RecyclerView.Adapter<AlbumAdapter.ViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
||||
@@ -15,14 +15,9 @@ class ArtistAdapter(
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val binding = ItemArtistBinding.inflate(LayoutInflater.from(parent.context))
|
||||
|
||||
// Force the item to *actually* be the screen width so ellipsizing can work.
|
||||
binding.root.layoutParams = RecyclerView.LayoutParams(
|
||||
RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT
|
||||
return ViewHolder(
|
||||
ItemArtistBinding.inflate(LayoutInflater.from(parent.context))
|
||||
)
|
||||
|
||||
return ViewHolder(binding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.oxycblt.auxio.music
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import android.widget.TextView
|
||||
@@ -66,7 +65,9 @@ fun Long.toAlbumArtURI(): Uri {
|
||||
// Format the amount of songs in an album
|
||||
@BindingAdapter("songCount")
|
||||
fun TextView.getAlbumSongs(album: Album) {
|
||||
text = context.resources.getQuantityString(R.plurals.format_song_count, album.numSongs)
|
||||
text = context.resources.getQuantityString(
|
||||
R.plurals.format_song_count, album.numSongs, album.numSongs
|
||||
)
|
||||
}
|
||||
|
||||
@BindingAdapter("artistCounts")
|
||||
|
||||
Reference in New Issue
Block a user