Add header to artist albums

Add a header to the album RecyclerView in ArtistDetailFragment.
This commit is contained in:
OxygenCobalt 2020-09-14 18:13:33 -06:00
parent 47aec7f18a
commit f3e47414b0
9 changed files with 61 additions and 89 deletions

View file

@ -4,7 +4,7 @@ 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.databinding.ItemAlbumBinding
import org.oxycblt.auxio.music.models.Album
class DetailAlbumAdapter(
@ -16,19 +16,17 @@ class DetailAlbumAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
ItemAlbumBigBinding.inflate(LayoutInflater.from(parent.context))
ItemAlbumBinding.inflate(LayoutInflater.from(parent.context))
)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val album = data[position]
holder.bind(album)
holder.bind(data[position])
}
// Generic ViewHolder for an album
inner class ViewHolder(
private val binding: ItemAlbumBigBinding
private val binding: ItemAlbumBinding
) : RecyclerView.ViewHolder(binding.root) {
init {

View file

@ -9,8 +9,7 @@ import org.oxycblt.auxio.music.models.Album
class AlbumAdapter(
private val data: List<Album>,
private val listener: ClickListener<Album>,
private val isLarge: Boolean
private val listener: ClickListener<Album>
) : RecyclerView.Adapter<AlbumAdapter.ViewHolder>() {
override fun getItemCount(): Int = data.size
@ -22,9 +21,7 @@ class AlbumAdapter(
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val album = data[position]
holder.bind(album)
holder.bind(data[position])
}
// Generic ViewHolder for an album

View file

@ -15,14 +15,9 @@ class SongAdapter(
override fun getItemCount(): Int = data.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = ItemSongBinding.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(
ItemSongBinding.inflate(LayoutInflater.from(parent.context))
)
return ViewHolder(binding)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?><!--
Divider used by recyclerview header items
https://stackoverflow.com/a/61157571/14143986
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-2dp"
android:right="-2dp">
<shape android:shape="rectangle">
<stroke
android:width="0.5dp"
android:color="@color/divider_color" />
</shape>
</item>
<item>
<ripple android:color="@color/selection_color">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/selection_color" />
</shape>
</item>
</ripple>
</item>
</layer-list>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/selection_color">
<!-- TODO: Find better color to override -->
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/selection_color" />

Binary file not shown.

View file

@ -21,14 +21,14 @@
android:layout_height="?android:attr/actionBarSize"
android:background="?android:attr/windowBackground"
android:elevation="@dimen/elevation_normal"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/title_library_fragment"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
app:title="@string/title_library_fragment"
tools:titleTextColor="@color/blue" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:overScrollMode="ifContentScrolls">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
@ -94,18 +94,39 @@
app:layout_constraintTop_toBottomOf="@+id/artist_genre"
tools:text="2 Albums, 20 Songs" />
<TextView
android:id="@+id/header_albums"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_albums"
android:textAppearance="@style/TextAppearance.MaterialComponents.Overline"
android:textSize="16sp"
android:fontFamily="@font/inter_bold"
android:clickable="true"
android:focusable="true"
android:layout_marginTop="@dimen/padding_medium"
android:paddingStart="@dimen/padding_medium"
android:paddingEnd="@dimen/padding_small"
android:paddingTop="@dimen/padding_small"
android:paddingBottom="@dimen/padding_small"
android:background="@drawable/header_dividers"
app:layout_constraintTop_toBottomOf="@+id/artist_counts"
tools:layout_editor_absoluteX="60dp" />
<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:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/artist_counts"
tools:layout_editor_absoluteX="16dp"
app:layout_constraintTop_toBottomOf="@+id/header_albums"
app:layout_constraintVertical_bias="0.0"
tools:itemCount="4"
tools:layout_editor_absoluteX="0dp"
tools:listitem="@layout/item_album" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,63 +0,0 @@
<?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>

View file

@ -11,6 +11,7 @@
<string name="label_retry">Retry</string>
<string name="label_grant">Grant</string>
<string name="label_albums">Albums</string>
<string name="placeholder_unknown_genre">Unknown Genre</string>
<string name="placeholder_unknown_artist">Unknown Artist</string>