Add more details to ArtistDetailFragment

Add the Artist Name/Genre/Counts to ArtistDetailFragment.
This commit is contained in:
OxygenCobalt 2020-09-14 15:06:10 -06:00
parent 26b53bd502
commit 0e6750b19c
7 changed files with 83 additions and 11 deletions

View file

@ -1,6 +1,7 @@
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
@ -69,8 +70,7 @@ fun TextView.getAlbumSongs(album: Album) {
}
@BindingAdapter("artistCounts")
fun TextView.getArtistCounts(artist: Artist) {
// Get the quantity string for both albums & artists, and then stitch them together.
fun TextView.bindArtistCounts(artist: Artist) {
val albums = context.resources.getQuantityString(
R.plurals.format_albums, artist.numAlbums, artist.numAlbums
)
@ -80,3 +80,18 @@ fun TextView.getArtistCounts(artist: Artist) {
text = context.getString(R.string.format_double_counts, albums, songs)
}
@BindingAdapter("artistGenre")
fun TextView.getArtistGenre(artist: Artist) {
// If the artist has more than one genre, pick the most used one.
// TODO: Add an option to display all genres.
val genre: String = if (artist.genres.size > 1) {
val genres = artist.genres.groupBy { it.name }
genres.keys.sortedByDescending { genres[it]?.size }[0]
} else {
artist.genres[0].name
}
text = genre
}

View file

@ -81,8 +81,7 @@ class MusicLoader(private val resolver: ContentResolver) {
var name = cursor.getString(nameIndex) ?: ""
// If a genre is still in an old int-based format [Android formats it as "(INT)"],
// convert that to the corresponding ID3 genre. Really hope anyone doesn't have
// a genre that contains parentheses.
// convert that to the corresponding ID3 genre.
if (name.contains(Regex("[0123456789)]"))) {
name = name.toNamedGenre()
}

View file

@ -13,8 +13,8 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:animateLayoutChanges="true">
android:animateLayoutChanges="true"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
@ -31,13 +31,61 @@
android:id="@+id/artist_image"
android:layout_width="@dimen/cover_size_huge"
android:layout_height="@dimen/cover_size_huge"
android:layout_margin="@dimen/margin_medium"
android:layout_marginTop="@dimen/margin_medium"
app:artistImage="@{artist}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
tools:ignore="ContentDescription"
tools:src="@drawable/ic_artist"
tools:tint="@color/blue" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/artist_name"
style="@style/DetailHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_medium"
android:layout_marginEnd="@dimen/margin_medium"
android:layout_marginStart="@dimen/margin_medium"
android:fontFamily="@font/inter_black"
android:text="@{artist.name}"
android:textSize="@dimen/detail_header_size_max"
app:autoSizeMaxTextSize="@dimen/detail_header_size_max"
app:autoSizeMinTextSize="@dimen/detail_header_size_min"
app:autoSizeStepGranularity="@dimen/detail_header_size_increment"
app:autoSizeTextType="uniform"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/artist_image"
tools:text="Artist Name"
tools:textColor="@color/blue" />
<TextView
android:id="@+id/artist_genre"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@{artist.genres.get(0).getName()}"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="?android:attr/textColorSecondary"
android:layout_marginStart="@dimen/margin_medium"
app:artistGenre="@{artist}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/artist_name"
tools:text="Genre Name" />
<TextView
android:id="@+id/artist_counts"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="?android:attr/textColorSecondary"
android:layout_marginStart="@dimen/margin_medium"
app:artistCounts="@{artist}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/artist_genre"
tools:text="2 Albums, 20 Songs" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -58,7 +58,7 @@
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary"
android:text="@{@string/format_song_info(song.album.artist.name, song.album.name)}"
android:text="@{@string/format_info(song.album.artist.name, song.album.name)}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/duration"
app:layout_constraintStart_toEndOf="@+id/cover"

View file

@ -13,7 +13,11 @@
<dimen name="cover_size_compact">44dp</dimen>
<dimen name="cover_size_normal">56dp</dimen>
<dimen name="cover_size_huge">168dp</dimen>
<dimen name="cover_size_huge">230dp</dimen>
<dimen name="detail_header_size_max">26sp</dimen>
<dimen name="detail_header_size_min">10sp</dimen>'
<dimen name="detail_header_size_increment">2sp</dimen>
<dimen name="elevation_normal">4dp</dimen>
</resources>

View file

@ -16,7 +16,7 @@
<string name="placeholder_unknown_artist">Unknown Artist</string>
<string name="placeholder_unknown_album">Unknown Album</string>
<string name="format_song_info">%1$s / %2$s</string>
<string name="format_info">%1$s / %2$s</string>
<string name="format_double_counts">%1$s, %2$s</string>
<plurals name="format_song_count">

View file

@ -11,4 +11,10 @@
<item name="android:fontFamily">@font/inter_black</item>
<item name="android:textColor">?android:attr/colorPrimary</item>
</style>
<style name="DetailHeader">
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:textColor">?android:attr/colorPrimary</item>
<item name="android:fontFamily">@font/inter_black</item>
</style>
</resources>