music: implement album types in UI
Implement album type displays in the album detail, artist detail, and album item views. Resolves #158.
This commit is contained in:
@@ -241,8 +241,20 @@ class DetailViewModel(application: Application) :
|
||||
private fun refreshArtistData(artist: Artist) {
|
||||
logD("Refreshing artist data")
|
||||
val data = mutableListOf<Item>(artist)
|
||||
data.add(Header(-2, R.string.lbl_albums))
|
||||
data.addAll(Sort(Sort.Mode.ByYear, false).albums(artist.albums))
|
||||
val albums = Sort(Sort.Mode.ByYear, false).albums(artist.albums)
|
||||
val byType = albums.groupBy { it.type ?: Album.Type.Album }
|
||||
byType.keys.sorted().forEachIndexed { index, type ->
|
||||
val typeString =
|
||||
when (type) {
|
||||
Album.Type.Album -> R.string.lbl_albums
|
||||
Album.Type.EP -> R.string.lbl_eps
|
||||
Album.Type.Single -> R.string.lbl_singles
|
||||
}
|
||||
|
||||
data.add(Header(-2L - index, typeString))
|
||||
data.addAll(unlikelyToBeNull(byType[type]))
|
||||
}
|
||||
|
||||
data.add(SortHeader(-3, R.string.lbl_songs))
|
||||
data.addAll(artistSort.songs(artist.songs))
|
||||
_artistData.value = data.toList()
|
||||
|
||||
@@ -123,13 +123,25 @@ private class AlbumDetailViewHolder private constructor(private val binding: Ite
|
||||
}
|
||||
|
||||
binding.detailInfo.apply {
|
||||
val date =
|
||||
item.date?.let { context.getString(R.string.fmt_number, it.year) }
|
||||
?: context.getString(R.string.def_date)
|
||||
|
||||
val songCount = context.getPluralSafe(R.plurals.fmt_song_count, item.songs.size)
|
||||
|
||||
val duration = item.durationSecs.formatDuration(false)
|
||||
|
||||
text =
|
||||
context.getString(
|
||||
R.string.fmt_three,
|
||||
item.date?.let { context.getString(R.string.fmt_number, it.year) }
|
||||
?: context.getString(R.string.def_date),
|
||||
context.getPluralSafe(R.plurals.fmt_song_count, item.songs.size),
|
||||
item.durationSecs.formatDuration(false))
|
||||
if (item.type != null) {
|
||||
context.getString(
|
||||
R.string.fmt_four,
|
||||
context.getString(item.type.string),
|
||||
date,
|
||||
songCount,
|
||||
duration)
|
||||
} else {
|
||||
context.getString(R.string.fmt_three, date, songCount, duration)
|
||||
}
|
||||
}
|
||||
|
||||
binding.detailPlayButton.setOnClickListener { listener.onPlayParent() }
|
||||
@@ -153,7 +165,8 @@ private class AlbumDetailViewHolder private constructor(private val binding: Ite
|
||||
oldItem.artist.rawName == newItem.artist.rawName &&
|
||||
oldItem.date == newItem.date &&
|
||||
oldItem.songs.size == newItem.songs.size &&
|
||||
oldItem.durationSecs == newItem.durationSecs
|
||||
oldItem.durationSecs == newItem.durationSecs &&
|
||||
oldItem.type == newItem.type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +258,15 @@ data class Album(
|
||||
enum class Type {
|
||||
Album,
|
||||
EP,
|
||||
Single
|
||||
Single;
|
||||
|
||||
val string: Int
|
||||
get() =
|
||||
when (this) {
|
||||
Album -> R.string.lbl_album
|
||||
EP -> R.string.lbl_ep
|
||||
Single -> R.string.lbl_single
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ fun <R> ContentResolver.useQuery(
|
||||
): R? = queryCursor(uri, projection, selector, args)?.use(block)
|
||||
|
||||
/**
|
||||
* For some reason the album cover URI namespace does not have a member in [MediaStore], but it still
|
||||
* works since at least API 21.
|
||||
* For some reason the album cover URI namespace does not have a member in [MediaStore], but it
|
||||
* still works since at least API 21.
|
||||
*/
|
||||
private val EXTERNAL_ALBUM_ART_URI = Uri.parse("content://media/external/audio/albumart")
|
||||
|
||||
@@ -100,6 +100,7 @@ fun String.parseSortName() =
|
||||
else -> this
|
||||
}
|
||||
|
||||
/** Parse a release type from this string into an [Album.Type]. Handles MusicBrainz separators. */
|
||||
fun String.parseReleaseType() =
|
||||
parseReleaseTypeImpl() ?: split("+", limit = 2)[0].trim().parseReleaseTypeImpl()
|
||||
|
||||
|
||||
@@ -82,7 +82,15 @@ private constructor(
|
||||
override fun bind(item: Album, listener: MenuItemListener) {
|
||||
binding.parentImage.bind(item)
|
||||
binding.parentName.textSafe = item.resolveName(binding.context)
|
||||
binding.parentInfo.textSafe = item.artist.resolveName(binding.context)
|
||||
|
||||
val artistName = item.artist.resolveName(binding.context)
|
||||
binding.parentInfo.textSafe =
|
||||
if (item.type != null) {
|
||||
binding.context.getString(
|
||||
R.string.fmt_two, binding.context.getString(item.type.string), artistName)
|
||||
} else {
|
||||
artistName
|
||||
}
|
||||
binding.root.apply {
|
||||
setOnClickListener { listener.onItemClick(item) }
|
||||
setOnLongClickListener { view ->
|
||||
@@ -106,7 +114,8 @@ private constructor(
|
||||
object : SimpleItemCallback<Album>() {
|
||||
override fun areItemsTheSame(oldItem: Album, newItem: Album) =
|
||||
oldItem.rawName == newItem.rawName &&
|
||||
oldItem.artist.rawName == newItem.artist.rawName
|
||||
oldItem.artist.rawName == newItem.artist.rawName &&
|
||||
oldItem.type == newItem.type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user