detail: add metadata to song detail view
Add metadata items to the song detail view. Should provide a useful view into how Auxio is interpreting song metadata. Resolves #330.
This commit is contained in:
@@ -17,22 +17,28 @@
|
||||
|
||||
package org.oxycblt.auxio.detail
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.format.Formatter
|
||||
import android.view.LayoutInflater
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.DialogSongDetailBinding
|
||||
import org.oxycblt.auxio.detail.recycler.SongPropertyAdapter
|
||||
import org.oxycblt.auxio.detail.recycler.SongProperty
|
||||
import org.oxycblt.auxio.list.adapter.BasicListInstructions
|
||||
import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.metadata.AudioInfo
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.formatDurationMs
|
||||
import org.oxycblt.auxio.ui.ViewBindingDialogFragment
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.concatLocalized
|
||||
|
||||
/**
|
||||
* A [ViewBindingDialogFragment] that shows information about a Song.
|
||||
@@ -44,6 +50,7 @@ class SongDetailDialog : ViewBindingDialogFragment<DialogSongDetailBinding>() {
|
||||
// Information about what song to display is initially within the navigation arguments
|
||||
// as a UID, as that is the only safe way to parcel an song.
|
||||
private val args: SongDetailDialogArgs by navArgs()
|
||||
private val detailAdapter = SongPropertyAdapter()
|
||||
|
||||
override fun onCreateBinding(inflater: LayoutInflater) =
|
||||
DialogSongDetailBinding.inflate(inflater)
|
||||
@@ -55,6 +62,7 @@ class SongDetailDialog : ViewBindingDialogFragment<DialogSongDetailBinding>() {
|
||||
|
||||
override fun onBindingCreated(binding: DialogSongDetailBinding, savedInstanceState: Bundle?) {
|
||||
super.onBindingCreated(binding, savedInstanceState)
|
||||
binding.detailProperties.adapter = detailAdapter
|
||||
// DetailViewModel handles most initialization from the navigation argument.
|
||||
detailModel.setSongUid(args.itemUid)
|
||||
collectImmediately(detailModel.currentSong, detailModel.songAudioInfo, ::updateSong)
|
||||
@@ -67,35 +75,59 @@ class SongDetailDialog : ViewBindingDialogFragment<DialogSongDetailBinding>() {
|
||||
return
|
||||
}
|
||||
|
||||
val binding = requireBinding()
|
||||
if (info != null) {
|
||||
// Finished loading song audio info, populate and show the list of Song information.
|
||||
binding.detailLoading.isInvisible = true
|
||||
binding.detailContainer.isInvisible = false
|
||||
|
||||
val context = requireContext()
|
||||
binding.detailFileName.setText(song.path.name)
|
||||
binding.detailRelativeDir.setText(song.path.parent.resolveName(context))
|
||||
binding.detailFormat.setText(info.resolvedMimeType.resolveName(context))
|
||||
binding.detailSize.setText(Formatter.formatFileSize(context, song.size))
|
||||
binding.detailDuration.setText(song.durationMs.formatDurationMs(true))
|
||||
|
||||
if (info.bitrateKbps != null) {
|
||||
binding.detailBitrate.setText(getString(R.string.fmt_bitrate, info.bitrateKbps))
|
||||
} else {
|
||||
binding.detailBitrate.setText(R.string.def_bitrate)
|
||||
}
|
||||
|
||||
if (info.sampleRateHz != null) {
|
||||
binding.detailSampleRate.setText(
|
||||
getString(R.string.fmt_sample_rate, info.sampleRateHz))
|
||||
} else {
|
||||
binding.detailSampleRate.setText(R.string.def_sample_rate)
|
||||
}
|
||||
} else {
|
||||
// Loading is still on-going, don't show anything yet.
|
||||
binding.detailLoading.isInvisible = false
|
||||
binding.detailContainer.isInvisible = true
|
||||
detailAdapter.submitList(
|
||||
buildList {
|
||||
add(SongProperty(R.string.lbl_name, song.zipName(context)))
|
||||
add(SongProperty(R.string.lbl_album, song.album.zipName(context)))
|
||||
add(SongProperty(R.string.lbl_artists, song.artists.zipNames(context)))
|
||||
add(SongProperty(R.string.lbl_genres, song.genres.resolveNames(context)))
|
||||
song.date?.let { add(SongProperty(R.string.lbl_date, it.resolveDate(context))) }
|
||||
song.track?.let {
|
||||
add(SongProperty(R.string.lbl_track, getString(R.string.fmt_number, it)))
|
||||
}
|
||||
song.disc?.let {
|
||||
val formattedNumber = getString(R.string.fmt_number, it.number)
|
||||
val zipped =
|
||||
if (it.name != null) {
|
||||
getString(R.string.fmt_zipped_names, it.name, formattedNumber)
|
||||
} else {
|
||||
formattedNumber
|
||||
}
|
||||
add(SongProperty(R.string.lbl_disc, zipped))
|
||||
}
|
||||
add(SongProperty(R.string.lbl_file_name, song.path.name))
|
||||
add(
|
||||
SongProperty(
|
||||
R.string.lbl_relative_path, song.path.parent.resolveName(context)))
|
||||
info.resolvedMimeType.resolveName(context)?.let {
|
||||
SongProperty(R.string.lbl_format, it)
|
||||
}
|
||||
add(
|
||||
SongProperty(
|
||||
R.string.lbl_size, Formatter.formatFileSize(context, song.size)))
|
||||
add(SongProperty(R.string.lbl_duration, song.durationMs.formatDurationMs(true)))
|
||||
info.bitrateKbps?.let {
|
||||
add(SongProperty(R.string.lbl_bitrate, getString(R.string.fmt_bitrate, it)))
|
||||
}
|
||||
info.sampleRateHz?.let {
|
||||
add(
|
||||
SongProperty(
|
||||
R.string.lbl_sample_rate, getString(R.string.fmt_sample_rate, it)))
|
||||
}
|
||||
},
|
||||
BasicListInstructions.REPLACE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Music> T.zipName(context: Context) =
|
||||
if (rawSortName != null) {
|
||||
getString(R.string.fmt_zipped_names, resolveName(context), rawSortName)
|
||||
} else {
|
||||
resolveName(context)
|
||||
}
|
||||
|
||||
private fun <T : Music> List<T>.zipNames(context: Context) =
|
||||
concatLocalized(context) { it.zipName(context) }
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ import org.oxycblt.auxio.list.adapter.SelectionIndicatorAdapter
|
||||
import org.oxycblt.auxio.list.adapter.SimpleDiffCallback
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.areRawNamesTheSame
|
||||
import org.oxycblt.auxio.music.metadata.Disc
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.formatDurationMs
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.getPlural
|
||||
@@ -136,7 +138,7 @@ private class AlbumDetailViewHolder private constructor(private val binding: Ite
|
||||
|
||||
// Artist name maps to the subhead text
|
||||
binding.detailSubhead.apply {
|
||||
text = album.resolveArtistContents(context)
|
||||
text = album.artists.resolveNames(context)
|
||||
|
||||
// Add a QoL behavior where navigation to the artist will occur if the artist
|
||||
// name is pressed.
|
||||
@@ -173,7 +175,7 @@ private class AlbumDetailViewHolder private constructor(private val binding: Ite
|
||||
object : SimpleDiffCallback<Album>() {
|
||||
override fun areContentsTheSame(oldItem: Album, newItem: Album) =
|
||||
oldItem.rawName == newItem.rawName &&
|
||||
oldItem.areArtistContentsTheSame(newItem) &&
|
||||
oldItem.artists.areRawNamesTheSame(newItem.artists) &&
|
||||
oldItem.dates == newItem.dates &&
|
||||
oldItem.songs.size == newItem.songs.size &&
|
||||
oldItem.durationMs == newItem.durationMs &&
|
||||
|
||||
@@ -30,10 +30,7 @@ import org.oxycblt.auxio.list.Item
|
||||
import org.oxycblt.auxio.list.SelectableListListener
|
||||
import org.oxycblt.auxio.list.adapter.SelectionIndicatorAdapter
|
||||
import org.oxycblt.auxio.list.adapter.SimpleDiffCallback
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.Music
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.*
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.getPlural
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
@@ -122,7 +119,7 @@ private class ArtistDetailViewHolder private constructor(private val binding: It
|
||||
// Information about the artist's genre(s) map to the sub-head text
|
||||
binding.detailSubhead.apply {
|
||||
isVisible = true
|
||||
text = artist.resolveGenreContents(binding.context)
|
||||
text = artist.genres.resolveNames(context)
|
||||
}
|
||||
|
||||
// Song and album counts map to the info
|
||||
@@ -168,7 +165,7 @@ private class ArtistDetailViewHolder private constructor(private val binding: It
|
||||
object : SimpleDiffCallback<Artist>() {
|
||||
override fun areContentsTheSame(oldItem: Artist, newItem: Artist) =
|
||||
oldItem.rawName == newItem.rawName &&
|
||||
oldItem.areGenreContentsTheSame(newItem) &&
|
||||
oldItem.genres.areRawNamesTheSame(newItem.genres) &&
|
||||
oldItem.albums.size == newItem.albums.size &&
|
||||
oldItem.songs.size == newItem.songs.size
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.detail.recycler
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.oxycblt.auxio.databinding.ItemSongPropertyBinding
|
||||
import org.oxycblt.auxio.list.Item
|
||||
import org.oxycblt.auxio.list.adapter.BasicListInstructions
|
||||
import org.oxycblt.auxio.list.adapter.DiffAdapter
|
||||
import org.oxycblt.auxio.list.adapter.ListDiffer
|
||||
import org.oxycblt.auxio.list.adapter.SimpleDiffCallback
|
||||
import org.oxycblt.auxio.list.recycler.DialogRecyclerView
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
|
||||
/**
|
||||
* An adapter for [SongProperty] instances.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class SongPropertyAdapter :
|
||||
DiffAdapter<SongProperty, BasicListInstructions, SongPropertyViewHolder>(
|
||||
ListDiffer.Blocking(SongPropertyViewHolder.DIFF_CALLBACK)) {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||
SongPropertyViewHolder.from(parent)
|
||||
|
||||
override fun onBindViewHolder(holder: SongPropertyViewHolder, position: Int) {
|
||||
holder.bind(getItem(position))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A property entry for use in [SongPropertyAdapter].
|
||||
* @param name The contextual title to use for the property.
|
||||
* @param value The value of the property.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
data class SongProperty(@StringRes val name: Int, val value: String) : Item
|
||||
|
||||
/**
|
||||
* A [RecyclerView.ViewHolder] that displays a [SongProperty]. Use [from] to create an instance.
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class SongPropertyViewHolder private constructor(private val binding: ItemSongPropertyBinding) :
|
||||
DialogRecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(property: SongProperty) {
|
||||
val context = binding.context
|
||||
binding.propertyName.hint = context.getString(property.name)
|
||||
binding.propertyValue.setText(property.value)
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param parent The parent to inflate this instance from.
|
||||
* @return A new instance.
|
||||
*/
|
||||
fun from(parent: View) =
|
||||
SongPropertyViewHolder(ItemSongPropertyBinding.inflate(parent.context.inflater))
|
||||
|
||||
/** A comparator that can be used with DiffUtil. */
|
||||
val DIFF_CALLBACK =
|
||||
object : SimpleDiffCallback<SongProperty>() {
|
||||
override fun areContentsTheSame(oldItem: SongProperty, newItem: SongProperty) =
|
||||
oldItem.name == newItem.name && oldItem.value == newItem.value
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class SongViewHolder private constructor(private val binding: ItemSongBinding) :
|
||||
listener.bind(song, this, menuButton = binding.songMenu)
|
||||
binding.songAlbumCover.bind(song)
|
||||
binding.songName.text = song.resolveName(binding.context)
|
||||
binding.songInfo.text = song.resolveArtistContents(binding.context)
|
||||
binding.songInfo.text = song.artists.resolveNames(binding.context)
|
||||
}
|
||||
|
||||
override fun updatePlayingIndicator(isActive: Boolean, isPlaying: Boolean) {
|
||||
@@ -76,7 +76,8 @@ class SongViewHolder private constructor(private val binding: ItemSongBinding) :
|
||||
val DIFF_CALLBACK =
|
||||
object : SimpleDiffCallback<Song>() {
|
||||
override fun areContentsTheSame(oldItem: Song, newItem: Song) =
|
||||
oldItem.rawName == newItem.rawName && oldItem.areArtistContentsTheSame(newItem)
|
||||
oldItem.rawName == newItem.rawName &&
|
||||
oldItem.artists.areRawNamesTheSame(newItem.artists)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +97,7 @@ class AlbumViewHolder private constructor(private val binding: ItemParentBinding
|
||||
listener.bind(album, this, menuButton = binding.parentMenu)
|
||||
binding.parentImage.bind(album)
|
||||
binding.parentName.text = album.resolveName(binding.context)
|
||||
binding.parentInfo.text = album.resolveArtistContents(binding.context)
|
||||
binding.parentInfo.text = album.artists.resolveNames(binding.context)
|
||||
}
|
||||
|
||||
override fun updatePlayingIndicator(isActive: Boolean, isPlaying: Boolean) {
|
||||
@@ -124,7 +125,7 @@ class AlbumViewHolder private constructor(private val binding: ItemParentBinding
|
||||
object : SimpleDiffCallback<Album>() {
|
||||
override fun areContentsTheSame(oldItem: Album, newItem: Album) =
|
||||
oldItem.rawName == newItem.rawName &&
|
||||
oldItem.areArtistContentsTheSame(newItem) &&
|
||||
oldItem.artists.areRawNamesTheSame(newItem.artists) &&
|
||||
oldItem.releaseType == newItem.releaseType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.os.Parcelable
|
||||
import java.security.MessageDigest
|
||||
import java.text.CollationKey
|
||||
import java.util.UUID
|
||||
import kotlin.math.max
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.oxycblt.auxio.list.Item
|
||||
@@ -31,6 +32,7 @@ import org.oxycblt.auxio.music.metadata.Disc
|
||||
import org.oxycblt.auxio.music.metadata.ReleaseType
|
||||
import org.oxycblt.auxio.music.storage.MimeType
|
||||
import org.oxycblt.auxio.music.storage.Path
|
||||
import org.oxycblt.auxio.util.concatLocalized
|
||||
import org.oxycblt.auxio.util.toUuidOrNull
|
||||
|
||||
/**
|
||||
@@ -269,28 +271,11 @@ interface Song : Music {
|
||||
* this field.
|
||||
*/
|
||||
val artists: List<Artist>
|
||||
/**
|
||||
* Resolves one or more [Artist]s into a single piece of human-readable names.
|
||||
* @param context [Context] required for [resolveName]. formatter.
|
||||
*/
|
||||
fun resolveArtistContents(context: Context): String
|
||||
/**
|
||||
* Checks if the [Artist] *display* of this [Song] and another [Song] are equal. This will only
|
||||
* compare surface-level names, and not [Music.UID]s.
|
||||
* @param other The [Song] to compare to.
|
||||
* @return True if the [Artist] displays are equal, false otherwise
|
||||
*/
|
||||
fun areArtistContentsTheSame(other: Song): Boolean
|
||||
/**
|
||||
* The parent [Genre]s of this [Song]. Is often one, but there can be multiple if more than one
|
||||
* [Genre] name was specified in the metadata.
|
||||
*/
|
||||
val genres: List<Genre>
|
||||
/**
|
||||
* Resolves one or more [Genre]s into a single piece human-readable names.
|
||||
* @param context [Context] required for [resolveName].
|
||||
*/
|
||||
fun resolveGenreContents(context: Context): String
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,18 +306,6 @@ interface Album : MusicParent {
|
||||
* are prioritized for this field.
|
||||
*/
|
||||
val artists: List<Artist>
|
||||
/**
|
||||
* Resolves one or more [Artist]s into a single piece of human-readable names.
|
||||
* @param context [Context] required for [resolveName].
|
||||
*/
|
||||
fun resolveArtistContents(context: Context): String
|
||||
/**
|
||||
* Checks if the [Artist] *display* of this [Album] and another [Album] are equal. This will
|
||||
* only compare surface-level names, and not [Music.UID]s.
|
||||
* @param other The [Album] to compare to.
|
||||
* @return True if the [Artist] displays are equal, false otherwise
|
||||
*/
|
||||
fun areArtistContentsTheSame(other: Album): Boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,18 +332,6 @@ interface Artist : MusicParent {
|
||||
val isCollaborator: Boolean
|
||||
/** The [Genre]s of this artist. */
|
||||
val genres: List<Genre>
|
||||
/**
|
||||
* Resolves one or more [Genre]s into a single piece of human-readable names.
|
||||
* @param context [Context] required for [resolveName].
|
||||
*/
|
||||
fun resolveGenreContents(context: Context): String
|
||||
/**
|
||||
* Checks if the [Genre] *display* of this [Artist] and another [Artist] are equal. This will
|
||||
* only compare surface-level names, and not [Music.UID]s.
|
||||
* @param other The [Artist] to compare to.
|
||||
* @return True if the [Genre] displays are equal, false otherwise
|
||||
*/
|
||||
fun areGenreContentsTheSame(other: Artist): Boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,3 +346,18 @@ interface Genre : MusicParent {
|
||||
/** The total duration of the songs in this genre, in milliseconds. */
|
||||
val durationMs: Long
|
||||
}
|
||||
|
||||
fun <T : Music> List<T>.resolveNames(context: Context) =
|
||||
concatLocalized(context) { it.resolveName(context) }
|
||||
|
||||
fun <T : Music> List<T>.areRawNamesTheSame(other: List<T>): Boolean {
|
||||
for (i in 0 until max(size, other.size)) {
|
||||
val a = getOrNull(i) ?: return false
|
||||
val b = other.getOrNull(i) ?: return false
|
||||
if (a.rawName != b.rawName) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import androidx.annotation.VisibleForTesting
|
||||
import java.security.MessageDigest
|
||||
import java.text.CollationKey
|
||||
import java.text.Collator
|
||||
import kotlin.math.max
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.list.Sort
|
||||
import org.oxycblt.auxio.music.Album
|
||||
@@ -124,23 +123,10 @@ class SongImpl(rawSong: RawSong, musicSettings: MusicSettings) : Song {
|
||||
private val _artists = mutableListOf<ArtistImpl>()
|
||||
override val artists: List<Artist>
|
||||
get() = _artists
|
||||
override fun resolveArtistContents(context: Context) = resolveNames(context, artists)
|
||||
override fun areArtistContentsTheSame(other: Song): Boolean {
|
||||
for (i in 0 until max(artists.size, other.artists.size)) {
|
||||
val a = artists.getOrNull(i) ?: return false
|
||||
val b = other.artists.getOrNull(i) ?: return false
|
||||
if (a.rawName != b.rawName) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private val _genres = mutableListOf<GenreImpl>()
|
||||
override val genres: List<Genre>
|
||||
get() = _genres
|
||||
override fun resolveGenreContents(context: Context) = resolveNames(context, genres)
|
||||
|
||||
/**
|
||||
* The [RawAlbum] instances collated by the [Song]. This can be used to group [Song]s into an
|
||||
@@ -268,18 +254,7 @@ class AlbumImpl(val rawAlbum: RawAlbum, override val songs: List<SongImpl>) : Al
|
||||
private val _artists = mutableListOf<ArtistImpl>()
|
||||
override val artists: List<Artist>
|
||||
get() = _artists
|
||||
override fun resolveArtistContents(context: Context) = resolveNames(context, artists)
|
||||
override fun areArtistContentsTheSame(other: Album): Boolean {
|
||||
for (i in 0 until max(artists.size, other.artists.size)) {
|
||||
val a = artists.getOrNull(i) ?: return false
|
||||
val b = other.artists.getOrNull(i) ?: return false
|
||||
if (a.rawName != b.rawName) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
init {
|
||||
var totalDuration: Long = 0
|
||||
var earliestDateAdded: Long = Long.MAX_VALUE
|
||||
@@ -361,18 +336,6 @@ class ArtistImpl(private val rawArtist: RawArtist, songAlbums: List<Music>) : Ar
|
||||
other is ArtistImpl && uid == other.uid && songs == other.songs
|
||||
|
||||
override lateinit var genres: List<Genre>
|
||||
override fun resolveGenreContents(context: Context) = resolveNames(context, genres)
|
||||
override fun areGenreContentsTheSame(other: Artist): Boolean {
|
||||
for (i in 0 until max(genres.size, other.genres.size)) {
|
||||
val a = genres.getOrNull(i) ?: return false
|
||||
val b = other.genres.getOrNull(i) ?: return false
|
||||
if (a.rawName != b.rawName) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
init {
|
||||
val distinctSongs = mutableSetOf<Song>()
|
||||
@@ -534,27 +497,6 @@ fun MessageDigest.update(n: Int?) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a list of [Music]'s resolved names into a string in a localized manner, using
|
||||
* [R.string.fmt_list].
|
||||
* @param context [Context] required to obtain localized formatting.
|
||||
* @param values The list of [Music] to format.
|
||||
* @return A single string consisting of the values delimited by a localized separator.
|
||||
*/
|
||||
private fun resolveNames(context: Context, values: List<Music>): String {
|
||||
if (values.isEmpty()) {
|
||||
// Nothing to do.
|
||||
return ""
|
||||
}
|
||||
|
||||
var joined = values.first().resolveName(context)
|
||||
for (i in 1..values.lastIndex) {
|
||||
// Chain all previous values with the next value in the list with another delimiter.
|
||||
joined = context.getString(R.string.fmt_list, joined, values[i].resolveName(context))
|
||||
}
|
||||
return joined
|
||||
}
|
||||
|
||||
/** Cached collator instance re-used with [makeCollationKey]. */
|
||||
private val COLLATOR: Collator = Collator.getInstance().apply { strength = Collator.PRIMARY }
|
||||
|
||||
|
||||
@@ -142,10 +142,9 @@ data class MimeType(val fromExtension: String, val fromFormat: String?) {
|
||||
* Resolve the mime type into a human-readable format name, such as "Ogg Vorbis".
|
||||
* @param context [Context] required to obtain human-readable strings.
|
||||
* @return A human-readable name for this mime type. Will first try [fromFormat], then falling
|
||||
* back to [fromExtension], then falling back to the extension name, and then finally a
|
||||
* placeholder "No Format" string.
|
||||
* back to [fromExtension], and then null if that fails.
|
||||
*/
|
||||
fun resolveName(context: Context): String {
|
||||
fun resolveName(context: Context): String? {
|
||||
// We try our best to produce a more readable name for the common audio formats.
|
||||
val formatName =
|
||||
when (fromFormat) {
|
||||
@@ -201,8 +200,6 @@ data class MimeType(val fromExtension: String, val fromFormat: String?) {
|
||||
} else {
|
||||
// Fall back to the extension if we can't find a special name for this format.
|
||||
MimeTypeMap.getSingleton().getExtensionFromMimeType(fromExtension)?.uppercase()
|
||||
// Fall back to a placeholder if even that fails.
|
||||
?: context.getString(R.string.def_codec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentPlaybackBarBinding
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.state.RepeatMode
|
||||
import org.oxycblt.auxio.ui.MainNavigationAction
|
||||
import org.oxycblt.auxio.ui.NavigationViewModel
|
||||
@@ -122,7 +123,7 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
val binding = requireBinding()
|
||||
binding.playbackCover.bind(song)
|
||||
binding.playbackSong.text = song.resolveName(context)
|
||||
binding.playbackInfo.text = song.resolveArtistContents(context)
|
||||
binding.playbackInfo.text = song.artists.resolveNames(context)
|
||||
binding.playbackProgressBar.max = song.durationMs.msToDs().toInt()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentPlaybackPanelBinding
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.state.RepeatMode
|
||||
import org.oxycblt.auxio.playback.ui.StyledSeekBar
|
||||
import org.oxycblt.auxio.ui.MainNavigationAction
|
||||
@@ -184,7 +185,7 @@ class PlaybackPanelFragment :
|
||||
val context = requireContext()
|
||||
binding.playbackCover.bind(song)
|
||||
binding.playbackSong.text = song.resolveName(context)
|
||||
binding.playbackArtist.text = song.resolveArtistContents(context)
|
||||
binding.playbackArtist.text = song.artists.resolveNames(context)
|
||||
binding.playbackAlbum.text = song.album.resolveName(context)
|
||||
binding.playbackSeekBar.durationDs = song.durationMs.msToDs()
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.oxycblt.auxio.list.adapter.ListDiffer
|
||||
import org.oxycblt.auxio.list.adapter.PlayingIndicatorAdapter
|
||||
import org.oxycblt.auxio.list.recycler.SongViewHolder
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.util.*
|
||||
|
||||
/**
|
||||
@@ -149,7 +150,7 @@ class QueueSongViewHolder private constructor(private val binding: ItemQueueSong
|
||||
listener.bind(song, this, bodyView, binding.songDragHandle)
|
||||
binding.songAlbumCover.bind(song)
|
||||
binding.songName.text = song.resolveName(binding.context)
|
||||
binding.songInfo.text = song.resolveArtistContents(binding.context)
|
||||
binding.songInfo.text = song.artists.resolveNames(binding.context)
|
||||
// Not swiping this ViewHolder if it's being re-bound, ensure that the background is
|
||||
// not visible. See QueueDragCallback for why this is done.
|
||||
binding.background.isInvisible = true
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.oxycblt.auxio.image.BitmapProvider
|
||||
import org.oxycblt.auxio.image.ImageSettings
|
||||
import org.oxycblt.auxio.music.MusicParent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.ActionMode
|
||||
import org.oxycblt.auxio.playback.PlaybackSettings
|
||||
import org.oxycblt.auxio.playback.queue.Queue
|
||||
@@ -285,7 +286,7 @@ constructor(
|
||||
// Populate MediaMetadataCompat. For efficiency, cache some fields that are re-used
|
||||
// several times.
|
||||
val title = song.resolveName(context)
|
||||
val artist = song.resolveArtistContents(context)
|
||||
val artist = song.artists.resolveNames(context)
|
||||
val builder =
|
||||
MediaMetadataCompat.Builder()
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_TITLE, title)
|
||||
@@ -295,14 +296,14 @@ constructor(
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
|
||||
.putText(
|
||||
MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST,
|
||||
song.album.resolveArtistContents(context))
|
||||
song.album.artists.resolveNames(context))
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_AUTHOR, artist)
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_COMPOSER, artist)
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_WRITER, artist)
|
||||
.putText(
|
||||
METADATA_KEY_PARENT,
|
||||
parent?.resolveName(context) ?: context.getString(R.string.lbl_all_songs))
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_GENRE, song.resolveGenreContents(context))
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_GENRE, song.genres.resolveNames(context))
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, title)
|
||||
.putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, artist)
|
||||
.putText(
|
||||
@@ -348,7 +349,7 @@ constructor(
|
||||
// as it's used to request a song to be played from the queue.
|
||||
.setMediaId(song.uid.toString())
|
||||
.setTitle(song.resolveName(context))
|
||||
.setSubtitle(song.resolveArtistContents(context))
|
||||
.setSubtitle(song.artists.resolveNames(context))
|
||||
// Since we usually have to load many songs into the queue, use the
|
||||
// MediaStore URI instead of loading a bitmap.
|
||||
.setIconUri(song.album.coverUri)
|
||||
|
||||
@@ -39,6 +39,7 @@ import androidx.core.content.ContextCompat
|
||||
import kotlin.reflect.KClass
|
||||
import org.oxycblt.auxio.IntegerTable
|
||||
import org.oxycblt.auxio.MainActivity
|
||||
import org.oxycblt.auxio.R
|
||||
|
||||
/**
|
||||
* Get a [LayoutInflater] instance from this [Context].
|
||||
@@ -57,6 +58,25 @@ val Context.isNight
|
||||
val Context.isLandscape
|
||||
get() = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
|
||||
/**
|
||||
* Concatenate values in a list together in a localized manner.
|
||||
* @param context [Context] require.d
|
||||
* @param map Function to map the [T] values to a string value to be concatenated.
|
||||
*/
|
||||
inline fun <T> List<T>.concatLocalized(context: Context, map: (T) -> String): String {
|
||||
if (isEmpty()) {
|
||||
// Nothing to do.
|
||||
return ""
|
||||
}
|
||||
|
||||
var joined = map(first())
|
||||
for (i in 1..lastIndex) {
|
||||
// Chain all previous values with the next value in the list with another delimiter.
|
||||
joined = context.getString(R.string.fmt_list, joined, map(get(i)))
|
||||
}
|
||||
return joined
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a plural resource.
|
||||
* @param pluralRes A plural resource ID.
|
||||
|
||||
@@ -31,6 +31,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
import org.oxycblt.auxio.BuildConfig
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.music.resolveNames
|
||||
import org.oxycblt.auxio.playback.state.RepeatMode
|
||||
import org.oxycblt.auxio.playback.system.PlaybackService
|
||||
import org.oxycblt.auxio.ui.UISettings
|
||||
@@ -265,7 +266,7 @@ class WidgetProvider : AppWidgetProvider() {
|
||||
): RemoteViews {
|
||||
setupCover(context, state)
|
||||
setTextViewText(R.id.widget_song, state.song.resolveName(context))
|
||||
setTextViewText(R.id.widget_artist, state.song.resolveArtistContents(context))
|
||||
setTextViewText(R.id.widget_artist, state.song.artists.resolveNames(context))
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user