Add album list to ArtistDetailFragment
Add a list of the artists albums to ArtistDetailFragment.
This commit is contained in:
parent
0e6750b19c
commit
47aec7f18a
8 changed files with 223 additions and 69 deletions
|
@ -7,8 +7,11 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import org.oxycblt.auxio.ClickListener
|
||||||
import org.oxycblt.auxio.databinding.FragmentArtistDetailBinding
|
import org.oxycblt.auxio.databinding.FragmentArtistDetailBinding
|
||||||
|
import org.oxycblt.auxio.detail.adapters.DetailAlbumAdapter
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
|
import org.oxycblt.auxio.theme.applyDivider
|
||||||
|
|
||||||
class ArtistDetailFragment : Fragment() {
|
class ArtistDetailFragment : Fragment() {
|
||||||
|
|
||||||
|
@ -24,7 +27,19 @@ class ArtistDetailFragment : Fragment() {
|
||||||
val musicModel: MusicViewModel by activityViewModels()
|
val musicModel: MusicViewModel by activityViewModels()
|
||||||
val artistId = ArtistDetailFragmentArgs.fromBundle(requireArguments()).artistId
|
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.")
|
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(
|
class AlbumAdapter(
|
||||||
private val data: List<Album>,
|
private val data: List<Album>,
|
||||||
private val listener: ClickListener<Album>
|
private val listener: ClickListener<Album>,
|
||||||
|
private val isLarge: Boolean
|
||||||
) : RecyclerView.Adapter<AlbumAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<AlbumAdapter.ViewHolder>() {
|
||||||
|
|
||||||
override fun getItemCount(): Int = data.size
|
override fun getItemCount(): Int = data.size
|
||||||
|
|
|
@ -15,14 +15,9 @@ class ArtistAdapter(
|
||||||
override fun getItemCount(): Int = data.size
|
override fun getItemCount(): Int = data.size
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val binding = ItemArtistBinding.inflate(LayoutInflater.from(parent.context))
|
return ViewHolder(
|
||||||
|
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(binding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.oxycblt.auxio.music
|
package org.oxycblt.auxio.music
|
||||||
|
|
||||||
import android.content.ContentUris
|
import android.content.ContentUris
|
||||||
import android.content.Context
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
@ -66,7 +65,9 @@ fun Long.toAlbumArtURI(): Uri {
|
||||||
// Format the amount of songs in an album
|
// Format the amount of songs in an album
|
||||||
@BindingAdapter("songCount")
|
@BindingAdapter("songCount")
|
||||||
fun TextView.getAlbumSongs(album: Album) {
|
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")
|
@BindingAdapter("artistCounts")
|
||||||
|
|
|
@ -10,10 +10,9 @@
|
||||||
type="org.oxycblt.auxio.music.models.Artist" />
|
type="org.oxycblt.auxio.music.models.Artist" />
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:animateLayoutChanges="true"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
@ -27,6 +26,16 @@
|
||||||
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
|
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
|
||||||
tools:titleTextColor="@color/blue" />
|
tools:titleTextColor="@color/blue" />
|
||||||
|
|
||||||
|
<androidx.core.widget.NestedScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/artist_image"
|
android:id="@+id/artist_image"
|
||||||
android:layout_width="@dimen/cover_size_huge"
|
android:layout_width="@dimen/cover_size_huge"
|
||||||
|
@ -35,7 +44,7 @@
|
||||||
app:artistImage="@{artist}"
|
app:artistImage="@{artist}"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/toolbar"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:src="@drawable/ic_artist"
|
tools:src="@drawable/ic_artist"
|
||||||
tools:tint="@color/blue" />
|
tools:tint="@color/blue" />
|
||||||
|
|
||||||
|
@ -65,7 +74,6 @@
|
||||||
android:id="@+id/artist_genre"
|
android:id="@+id/artist_genre"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@{artist.genres.get(0).getName()}"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:layout_marginStart="@dimen/margin_medium"
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
|
@ -86,6 +94,22 @@
|
||||||
app:layout_constraintTop_toBottomOf="@+id/artist_genre"
|
app:layout_constraintTop_toBottomOf="@+id/artist_genre"
|
||||||
tools:text="2 Albums, 20 Songs" />
|
tools:text="2 Albums, 20 Songs" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/album_recycler"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
android:nestedScrollingEnabled="true"
|
||||||
|
android:overScrollMode="never"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/artist_counts"
|
||||||
|
tools:layout_editor_absoluteX="16dp"
|
||||||
|
tools:listitem="@layout/item_album" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
63
app/src/main/res/layout/item_album_big.xml
Normal file
63
app/src/main/res/layout/item_album_big.xml
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<variable
|
||||||
|
name="album"
|
||||||
|
type="org.oxycblt.auxio.music.models.Album" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/ripple"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:padding="@dimen/padding_medium">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/cover"
|
||||||
|
android:layout_width="@dimen/cover_size_large"
|
||||||
|
android:layout_height="@dimen/cover_size_large"
|
||||||
|
app:coverArt="@{album}"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:ignore="ContentDescription"
|
||||||
|
tools:src="@drawable/ic_album"
|
||||||
|
tools:tint="@color/blue" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/album_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
|
android:text="@{album.name}"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/song_count"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/cover"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
|
tools:text="Album Name" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/song_count"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/cover"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/album_name"
|
||||||
|
app:songCount="@{album}"
|
||||||
|
tools:text="10 Songs" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</layout>
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
<dimen name="cover_size_compact">44dp</dimen>
|
<dimen name="cover_size_compact">44dp</dimen>
|
||||||
<dimen name="cover_size_normal">56dp</dimen>
|
<dimen name="cover_size_normal">56dp</dimen>
|
||||||
|
<dimen name="cover_size_large">80dp</dimen>
|
||||||
<dimen name="cover_size_huge">230dp</dimen>
|
<dimen name="cover_size_huge">230dp</dimen>
|
||||||
|
|
||||||
<dimen name="detail_header_size_max">26sp</dimen>
|
<dimen name="detail_header_size_max">26sp</dimen>
|
||||||
|
|
Loading…
Reference in a new issue