Add song list to AlbumDetailFragment
Add a list of the albums songs to AlbumDetailFragment.
This commit is contained in:
@@ -8,8 +8,11 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import org.oxycblt.auxio.ClickListener
|
||||
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.DetailSongAdapter
|
||||
import org.oxycblt.auxio.music.MusicViewModel
|
||||
import org.oxycblt.auxio.theme.applyDivider
|
||||
|
||||
class AlbumDetailFragment : Fragment() {
|
||||
|
||||
@@ -30,6 +33,15 @@ class AlbumDetailFragment : Fragment() {
|
||||
binding.lifecycleOwner = this
|
||||
binding.album = album
|
||||
|
||||
binding.songRecycler.adapter = DetailSongAdapter(
|
||||
album.songs,
|
||||
ClickListener {
|
||||
Log.d(this::class.simpleName, it.name)
|
||||
}
|
||||
)
|
||||
binding.songRecycler.applyDivider()
|
||||
binding.songRecycler.setHasFixedSize(true)
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
|
||||
return binding.root
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
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.ItemAlbumSongBinding
|
||||
import org.oxycblt.auxio.music.models.Song
|
||||
|
||||
class DetailSongAdapter(
|
||||
private val data: List<Song>,
|
||||
private val listener: ClickListener<Song>
|
||||
) : RecyclerView.Adapter<DetailSongAdapter.ViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemAlbumSongBinding.inflate(LayoutInflater.from(parent.context))
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(data[position])
|
||||
}
|
||||
|
||||
// Generic ViewHolder for an album
|
||||
inner class ViewHolder(
|
||||
private val binding: ItemAlbumSongBinding
|
||||
) : 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(song: Song) {
|
||||
binding.song = song
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
listener.onClick(song)
|
||||
}
|
||||
|
||||
// Force-update the layout so ellipsizing works.
|
||||
binding.songName.requestLayout()
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ data class Album(
|
||||
var name: String = "",
|
||||
val artistName: String = "", // only used for sorting. Use artist.name instead.
|
||||
val coverUri: Uri = Uri.EMPTY,
|
||||
val year: String = ""
|
||||
val year: Int = 0
|
||||
) {
|
||||
lateinit var artist: Artist
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ class MusicLoader(private val resolver: ContentResolver) {
|
||||
albums.add(
|
||||
Album(
|
||||
id, name, artist,
|
||||
coverUri, year.toString()
|
||||
coverUri, year
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ class MusicSorter(
|
||||
album.songs.add(song)
|
||||
}
|
||||
|
||||
album.finalize()
|
||||
|
||||
unknownSongs.removeAll(albumSongs)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user