music: simplify disc number resolution
Introduce a resolveDisc extension function to share disc name resolution between detail/browser
This commit is contained in:
parent
c9664d75c0
commit
f4589616be
5 changed files with 19 additions and 20 deletions
|
@ -35,6 +35,7 @@ import org.oxycblt.auxio.list.adapter.SimpleDiffCallback
|
|||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.info.Disc
|
||||
import org.oxycblt.auxio.music.info.resolveNumber
|
||||
import org.oxycblt.auxio.playback.formatDurationMs
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.inflater
|
||||
|
@ -111,16 +112,10 @@ private class DiscHeaderViewHolder(private val binding: ItemDiscHeaderBinding) :
|
|||
*/
|
||||
fun bind(discHeader: DiscHeader) {
|
||||
val disc = discHeader.inner
|
||||
if (disc != null) {
|
||||
binding.discNumber.text = binding.context.getString(R.string.fmt_disc_no, disc.number)
|
||||
binding.discName.apply {
|
||||
text = disc.name
|
||||
isGone = disc.name == null
|
||||
}
|
||||
} else {
|
||||
logD("Disc is null, defaulting to no disc")
|
||||
binding.discNumber.text = binding.context.getString(R.string.def_disc)
|
||||
binding.discName.isGone = true
|
||||
binding.discNumber.text = disc.resolveNumber(binding.context)
|
||||
binding.discName.apply {
|
||||
text = disc?.name
|
||||
isGone = disc?.name == null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -136,11 +136,13 @@ private class HomeGeneratorImpl(
|
|||
invalidator.invalidateMusic(MusicType.PLAYLISTS, UpdateInstructions.Diff)
|
||||
}
|
||||
}
|
||||
|
||||
override fun release() {
|
||||
musicRepository.removeUpdateListener(this)
|
||||
listSettings.unregisterListener(this)
|
||||
homeSettings.unregisterListener(this)
|
||||
}
|
||||
|
||||
override fun songs() =
|
||||
musicRepository.deviceLibrary?.let { listSettings.songSort.songs(it.songs) } ?: emptyList()
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.oxycblt.auxio.music.info
|
||||
|
||||
import android.content.Context
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.list.Item
|
||||
|
||||
/**
|
||||
|
@ -34,3 +36,6 @@ class Disc(val number: Int, val name: String?) : Item, Comparable<Disc> {
|
|||
|
||||
override fun compareTo(other: Disc) = number.compareTo(other.number)
|
||||
}
|
||||
|
||||
|
||||
fun Disc?.resolveNumber(context: Context) = this?.run { context.getString(R.string.fmt_disc_no, number) } ?: context.getString(R.string.def_disc)
|
|
@ -34,6 +34,7 @@ import org.oxycblt.auxio.music.MusicRepository
|
|||
import org.oxycblt.auxio.music.MusicType
|
||||
import org.oxycblt.auxio.music.Playlist
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.info.resolveNumber
|
||||
import org.oxycblt.auxio.search.SearchEngine
|
||||
|
||||
class MusicBrowser
|
||||
|
@ -234,15 +235,9 @@ private constructor(
|
|||
is DetailSection.Artists ->
|
||||
section.items.map { it.toMediaItem(context, header(section.stringRes)) }
|
||||
is DetailSection.Discs ->
|
||||
section.discs.flatMap { entry ->
|
||||
val disc = entry.key
|
||||
val discString =
|
||||
if (disc != null) {
|
||||
context.getString(R.string.fmt_disc_no, disc.number)
|
||||
} else {
|
||||
context.getString(R.string.def_disc)
|
||||
}
|
||||
entry.value.map { it.toMediaItem(context, null, header(discString)) }
|
||||
section.discs.flatMap { (disc, songs) ->
|
||||
val discString = disc.resolveNumber(context)
|
||||
songs.map { it.toMediaItem(context, null, header(discString)) }
|
||||
}
|
||||
else -> error("Unknown section type: $section")
|
||||
}
|
||||
|
|
|
@ -44,7 +44,9 @@ import org.oxycblt.auxio.util.logD
|
|||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class ReplayGainAudioProcessor @Inject constructor(
|
||||
class ReplayGainAudioProcessor
|
||||
@Inject
|
||||
constructor(
|
||||
private val playbackManager: PlaybackStateManager,
|
||||
private val playbackSettings: PlaybackSettings
|
||||
) : BaseAudioProcessor(), PlaybackStateManager.Listener, PlaybackSettings.Listener {
|
||||
|
|
Loading…
Reference in a new issue