Minor music model changes
Move the size recalculations/child item sorting to a method called finalize() in artists, albums, and genres. Also remove the artist images for now, Ill figure out a good way to bring them back.
This commit is contained in:
parent
7a2c779fe2
commit
565d1efa96
9 changed files with 63 additions and 46 deletions
|
@ -65,25 +65,6 @@ fun Long.toAlbumArtURI(): Uri {
|
|||
)
|
||||
}
|
||||
|
||||
// Get the cover art
|
||||
@BindingAdapter("coverArt")
|
||||
fun ImageView.getCoverArt(any: Any) {
|
||||
val uri = when (any) {
|
||||
is Song -> any.album.coverUri
|
||||
is Album -> any.coverUri
|
||||
|
||||
// TODO: Artist images
|
||||
|
||||
else -> Uri.EMPTY
|
||||
}
|
||||
|
||||
load(uri) {
|
||||
crossfade(true)
|
||||
placeholder(android.R.color.transparent)
|
||||
error(R.drawable.ic_music)
|
||||
}
|
||||
}
|
||||
|
||||
fun Int.toSongCount(): Int {
|
||||
return if (this < 2) {
|
||||
R.string.label_single_song
|
||||
|
@ -113,3 +94,30 @@ fun TextView.getSongAlbumCount(artist: Artist) {
|
|||
|
||||
text = context.getString(R.string.format_combined_song_album, albums, songs)
|
||||
}
|
||||
|
||||
// Get the cover art
|
||||
@BindingAdapter("coverArt")
|
||||
fun ImageView.getCoverArt(any: Any) {
|
||||
val uri = when (any) {
|
||||
is Song -> any.album.coverUri
|
||||
is Album -> any.coverUri
|
||||
|
||||
else -> Uri.EMPTY
|
||||
}
|
||||
|
||||
load(uri) {
|
||||
crossfade(true)
|
||||
placeholder(android.R.color.transparent)
|
||||
error(R.drawable.ic_music)
|
||||
}
|
||||
}
|
||||
|
||||
// Get the artist image.
|
||||
@BindingAdapter("artistImage")
|
||||
fun ImageView.getArtistImage(artist: Artist) {
|
||||
load(artist.albums[0].coverUri) {
|
||||
crossfade(true)
|
||||
placeholder(android.R.color.transparent)
|
||||
error(R.drawable.ic_music)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,4 +14,8 @@ data class Album(
|
|||
lateinit var artist: Artist
|
||||
|
||||
val songs = mutableListOf<Song>()
|
||||
|
||||
fun finalize() {
|
||||
songs.sortBy { it.track }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,4 +9,13 @@ data class Artist(
|
|||
val albums = mutableListOf<Album>()
|
||||
var numAlbums = 0
|
||||
var numSongs = 0
|
||||
|
||||
fun finalize() {
|
||||
albums.sortByDescending { it.year }
|
||||
|
||||
numAlbums = albums.size
|
||||
albums.forEach { album ->
|
||||
numSongs += album.numSongs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,9 @@ data class Genre(
|
|||
) {
|
||||
val artists = mutableListOf<Artist>()
|
||||
var numArtists = 0
|
||||
|
||||
fun finalize() {
|
||||
artists.sortByDescending { it.name }
|
||||
numArtists = artists.size
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ class MusicSorter(
|
|||
}
|
||||
|
||||
unknownAlbum.numSongs = unknownAlbum.songs.size
|
||||
unknownAlbum.finalize()
|
||||
|
||||
albums.add(unknownAlbum)
|
||||
|
||||
|
@ -62,6 +63,8 @@ class MusicSorter(
|
|||
"${unknownSongs.size} songs were placed into an unknown album."
|
||||
)
|
||||
}
|
||||
|
||||
albums.sortByDescending { it.title }
|
||||
}
|
||||
|
||||
private fun sortAlbumsIntoArtists() {
|
||||
|
@ -79,10 +82,7 @@ class MusicSorter(
|
|||
artist.albums.add(album)
|
||||
}
|
||||
|
||||
artist.numAlbums = artist.albums.size
|
||||
artist.albums.forEach { album ->
|
||||
artist.numSongs += album.numSongs
|
||||
}
|
||||
artist.finalize()
|
||||
|
||||
unknownAlbums.removeAll(artistAlbums)
|
||||
}
|
||||
|
@ -98,10 +98,7 @@ class MusicSorter(
|
|||
unknownArtist.albums.add(album)
|
||||
}
|
||||
|
||||
unknownArtist.numAlbums = unknownArtist.albums.size
|
||||
unknownArtist.albums.forEach { album ->
|
||||
unknownArtist.numSongs += album.numSongs
|
||||
}
|
||||
unknownArtist.finalize()
|
||||
|
||||
artists.add(unknownArtist)
|
||||
|
||||
|
@ -110,6 +107,8 @@ class MusicSorter(
|
|||
"${unknownAlbums.size} albums were placed into an unknown artist."
|
||||
)
|
||||
}
|
||||
|
||||
artists.sortByDescending { it.name }
|
||||
}
|
||||
|
||||
private fun sortArtistsIntoGenres() {
|
||||
|
@ -150,6 +149,8 @@ class MusicSorter(
|
|||
"${unknownArtists.size} albums were placed into an unknown genre."
|
||||
)
|
||||
}
|
||||
|
||||
genres.sortByDescending { it.name }
|
||||
}
|
||||
|
||||
// Correct any empty names [""] with the proper placeholders [Unknown Album]
|
||||
|
|
|
@ -18,29 +18,20 @@
|
|||
android:focusable="true"
|
||||
android:padding="@dimen/padding_medium">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/artist_image"
|
||||
android:layout_width="@dimen/cover_size_normal"
|
||||
android:layout_height="@dimen/cover_size_normal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:src="@tools:sample/backgrounds/scenic"
|
||||
tools:ignore="ContentDescription" />
|
||||
<!-- TODO: Artist images -->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/artist_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/margin_medium"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@{artist.name}"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
app:layout_constraintBottom_toTopOf="@+id/album_song_count"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/artist_image"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_chainStyle="packed"
|
||||
tools:text="Artist Name" />
|
||||
|
@ -49,13 +40,13 @@
|
|||
android:id="@+id/album_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:albumSongCount="@{artist}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/artist_image"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/artist_name"
|
||||
tools:text="2 Albums, 20 Songs" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
|
@ -17,7 +17,7 @@
|
|||
android:elevation="@dimen/elevation_normal"
|
||||
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
|
||||
app:title="@string/title_library_fragment"
|
||||
tools:titleTextColor="@color/blue"/>
|
||||
tools:titleTextColor="@color/blue" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/library_recycler"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
app:titleTextAppearance="@style/TextAppearance.Toolbar.Bold"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:title="@string/title_all_songs"
|
||||
tools:titleTextColor="@color/blue"/>
|
||||
tools:titleTextColor="@color/blue" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/song_recycler"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<fade xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="@android:integer/config_longAnimTime">
|
||||
</fade>
|
||||
android:duration="@android:integer/config_longAnimTime"></fade>
|
Loading…
Reference in a new issue