all: reformat

This commit is contained in:
Alexander Capehart 2024-12-17 11:27:25 -05:00
parent 8bbb7497a6
commit f3913b148a
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 57 additions and 128 deletions

View file

@ -15,14 +15,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.oxycblt.auxio.detail package org.oxycblt.auxio.detail
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject import javax.inject.Inject
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -43,7 +42,6 @@ import org.oxycblt.auxio.music.MusicRepository
import org.oxycblt.auxio.music.MusicType import org.oxycblt.auxio.music.MusicType
import org.oxycblt.auxio.playback.PlaySong import org.oxycblt.auxio.playback.PlaySong
import org.oxycblt.auxio.playback.PlaybackSettings import org.oxycblt.auxio.playback.PlaybackSettings
import org.oxycblt.auxio.playback.formatDurationMs
import org.oxycblt.auxio.util.Event import org.oxycblt.auxio.util.Event
import org.oxycblt.auxio.util.MutableEvent import org.oxycblt.auxio.util.MutableEvent
import org.oxycblt.auxio.util.unlikelyToBeNull import org.oxycblt.auxio.util.unlikelyToBeNull
@ -225,23 +223,18 @@ constructor(
val album = detailGenerator.album(currentAlbum.value?.uid ?: return) val album = detailGenerator.album(currentAlbum.value?.uid ?: return)
refreshDetail(album, _currentAlbum, _albumSongList, _albumSongInstructions, replace) refreshDetail(album, _currentAlbum, _albumSongList, _albumSongInstructions, replace)
} }
MusicType.ARTISTS -> { MusicType.ARTISTS -> {
val artist = detailGenerator.artist(currentArtist.value?.uid ?: return) val artist = detailGenerator.artist(currentArtist.value?.uid ?: return)
refreshDetail( refreshDetail(
artist, _currentArtist, _artistSongList, _artistSongInstructions, replace artist, _currentArtist, _artistSongList, _artistSongInstructions, replace)
)
} }
MusicType.GENRES -> { MusicType.GENRES -> {
val genre = detailGenerator.genre(currentGenre.value?.uid ?: return) val genre = detailGenerator.genre(currentGenre.value?.uid ?: return)
refreshDetail(genre, _currentGenre, _genreSongList, _genreSongInstructions, replace) refreshDetail(genre, _currentGenre, _genreSongList, _genreSongInstructions, replace)
} }
MusicType.PLAYLISTS -> { MusicType.PLAYLISTS -> {
refreshPlaylist(currentPlaylist.value?.uid ?: return) refreshPlaylist(currentPlaylist.value?.uid ?: return)
} }
else -> error("Unexpected music type $type") else -> error("Unexpected music type $type")
} }
} }
@ -279,8 +272,7 @@ constructor(
Show.SongArtistDecision(song) Show.SongArtistDecision(song)
} else { } else {
Show.ArtistDetails(song.artists.first()) Show.ArtistDetails(song.artists.first())
} })
)
/** /**
* Navigate to the details of one of the [Artist]s of an [Album] using the corresponding choice * Navigate to the details of one of the [Artist]s of an [Album] using the corresponding choice
@ -294,8 +286,7 @@ constructor(
Show.AlbumArtistDecision(album) Show.AlbumArtistDecision(album)
} else { } else {
Show.ArtistDetails(album.artists.first()) Show.ArtistDetails(album.artists.first())
} })
)
/** /**
* Navigate to the details of an [Artist]. * Navigate to the details of an [Artist].
@ -527,103 +518,37 @@ constructor(
} else { } else {
L.d("Playlist will be empty after removal, removing header") L.d("Playlist will be empty after removal, removing header")
UpdateInstructions.Remove(at - 1, 3) UpdateInstructions.Remove(at - 1, 3)
} })
)
} }
private fun refreshAudioInfo(song: Song) { private fun refreshAudioInfo(song: Song) {
_currentSongProperties.value = _currentSongProperties.value = buildList {
buildList { add(SongProperty(R.string.lbl_name, SongProperty.Value.MusicName(song)))
add(SongProperty(R.string.lbl_name, SongProperty.Value.MusicName(song))) add(SongProperty(R.string.lbl_album, SongProperty.Value.MusicName(song.album)))
add(SongProperty(R.string.lbl_album, SongProperty.Value.MusicName(song.album))) add(SongProperty(R.string.lbl_artists, SongProperty.Value.MusicNames(song.artists)))
add( add(SongProperty(R.string.lbl_genres, SongProperty.Value.MusicNames(song.genres)))
SongProperty( song.date?.let { add(SongProperty(R.string.lbl_date, SongProperty.Value.ItemDate(it))) }
R.string.lbl_artists, song.track?.let {
SongProperty.Value.MusicNames(song.artists) add(SongProperty(R.string.lbl_track, SongProperty.Value.Number(it, null)))
)
)
add(
SongProperty(
R.string.lbl_genres,
SongProperty.Value.MusicNames(song.genres)
)
)
song.date?.let {
add(
SongProperty(
R.string.lbl_date,
SongProperty.Value.ItemDate(it)
)
)
}
song.track?.let {
add(
SongProperty(
R.string.lbl_track,
SongProperty.Value.Number(it, null)
)
)
}
song.disc?.let {
add(
SongProperty(
R.string.lbl_disc,
SongProperty.Value.Number(it.number, it.name)
)
)
}
add(
SongProperty(
R.string.lbl_path,
SongProperty.Value.ItemPath(song.path)
)
)
add(
SongProperty(
R.string.lbl_size, SongProperty.Value.Size(song.size)
)
)
add(
SongProperty(
R.string.lbl_duration,
SongProperty.Value.Duration(song.durationMs)
)
)
add(
SongProperty(
R.string.lbl_format,
SongProperty.Value.ItemFormat(song.format)
)
)
add(
SongProperty(
R.string.lbl_bitrate,
SongProperty.Value.Bitrate(song.bitrateKbps)
)
)
add(
SongProperty(
R.string.lbl_sample_rate,
SongProperty.Value.SampleRate(song.sampleRateHz)
)
)
song.replayGainAdjustment.track?.let {
add(
SongProperty(
R.string.lbl_replaygain_track,
SongProperty.Value.Decibels(it)
)
)
}
song.replayGainAdjustment.album?.let {
add(
SongProperty(
R.string.lbl_replaygain_album,
SongProperty.Value.Decibels(it)
)
)
}
} }
song.disc?.let {
add(SongProperty(R.string.lbl_disc, SongProperty.Value.Number(it.number, it.name)))
}
add(SongProperty(R.string.lbl_path, SongProperty.Value.ItemPath(song.path)))
add(SongProperty(R.string.lbl_size, SongProperty.Value.Size(song.size)))
add(SongProperty(R.string.lbl_duration, SongProperty.Value.Duration(song.durationMs)))
add(SongProperty(R.string.lbl_format, SongProperty.Value.ItemFormat(song.format)))
add(SongProperty(R.string.lbl_bitrate, SongProperty.Value.Bitrate(song.bitrateKbps)))
add(
SongProperty(
R.string.lbl_sample_rate, SongProperty.Value.SampleRate(song.sampleRateHz)))
song.replayGainAdjustment.track?.let {
add(SongProperty(R.string.lbl_replaygain_track, SongProperty.Value.Decibels(it)))
}
song.replayGainAdjustment.album?.let {
add(SongProperty(R.string.lbl_replaygain_album, SongProperty.Value.Decibels(it)))
}
}
} }
private inline fun <T : MusicParent> refreshDetail( private inline fun <T : MusicParent> refreshDetail(
@ -653,7 +578,6 @@ constructor(
newList.add(header) newList.add(header)
section.items section.items
} }
is DetailSection.Discs -> { is DetailSection.Discs -> {
val header = SortHeader(section.stringRes) val header = SortHeader(section.stringRes)
if (newList.isNotEmpty()) { if (newList.isNotEmpty()) {
@ -694,10 +618,9 @@ constructor(
if (edited == null) { if (edited == null) {
val playlist = detailGenerator.playlist(uid) val playlist = detailGenerator.playlist(uid)
refreshDetail( refreshDetail(
playlist, _currentPlaylist, _playlistSongList, _playlistSongInstructions, null playlist, _currentPlaylist, _playlistSongList, _playlistSongInstructions, null) {
) { EditHeader(it)
EditHeader(it) }
}
return return
} }
val list = mutableListOf<Item>() val list = mutableListOf<Item>()

View file

@ -18,7 +18,6 @@
package org.oxycblt.auxio.detail package org.oxycblt.auxio.detail
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
@ -31,13 +30,9 @@ import org.oxycblt.auxio.databinding.DialogSongDetailBinding
import org.oxycblt.auxio.detail.list.SongProperty import org.oxycblt.auxio.detail.list.SongProperty
import org.oxycblt.auxio.detail.list.SongPropertyAdapter import org.oxycblt.auxio.detail.list.SongPropertyAdapter
import org.oxycblt.auxio.list.adapter.UpdateInstructions import org.oxycblt.auxio.list.adapter.UpdateInstructions
import org.oxycblt.auxio.music.resolve
import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment import org.oxycblt.auxio.ui.ViewBindingMaterialDialogFragment
import org.oxycblt.auxio.util.collectImmediately import org.oxycblt.auxio.util.collectImmediately
import org.oxycblt.auxio.util.concatLocalized
import org.oxycblt.musikr.Music
import org.oxycblt.musikr.Song import org.oxycblt.musikr.Song
import org.oxycblt.musikr.tag.Name
import timber.log.Timber as L import timber.log.Timber as L
/** /**

View file

@ -18,7 +18,6 @@
package org.oxycblt.auxio.detail.list package org.oxycblt.auxio.detail.list
import android.text.Editable
import android.text.format.Formatter import android.text.format.Formatter
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -39,7 +38,6 @@ import org.oxycblt.musikr.Music
import org.oxycblt.musikr.fs.Format import org.oxycblt.musikr.fs.Format
import org.oxycblt.musikr.fs.Path import org.oxycblt.musikr.fs.Path
import org.oxycblt.musikr.tag.Date import org.oxycblt.musikr.tag.Date
import org.oxycblt.musikr.tag.Name
/** /**
* An adapter for [SongProperty] instances. * An adapter for [SongProperty] instances.
@ -67,15 +65,25 @@ class SongPropertyAdapter :
data class SongProperty(@StringRes val name: Int, val value: Value) { data class SongProperty(@StringRes val name: Int, val value: Value) {
sealed interface Value { sealed interface Value {
data class MusicName(val music: Music) : Value data class MusicName(val music: Music) : Value
data class MusicNames(val name: List<Music>) : Value data class MusicNames(val name: List<Music>) : Value
data class Number(val value: Int, val subtitle: String?) : Value data class Number(val value: Int, val subtitle: String?) : Value
data class ItemDate(val date: Date) : Value data class ItemDate(val date: Date) : Value
data class ItemPath(val path: Path) : Value data class ItemPath(val path: Path) : Value
data class Size(val sizeBytes: Long) : Value data class Size(val sizeBytes: Long) : Value
data class Duration(val durationMs: Long) : Value data class Duration(val durationMs: Long) : Value
data class ItemFormat(val format: Format) : Value data class ItemFormat(val format: Format) : Value
data class Bitrate(val kbps: Int) : Value data class Bitrate(val kbps: Int) : Value
data class SampleRate(val hz: Int) : Value data class SampleRate(val hz: Int) : Value
data class Decibels(val value: Float) : Value data class Decibels(val value: Float) : Value
} }
} }
@ -102,11 +110,12 @@ class SongPropertyViewHolder private constructor(private val binding: ItemSongPr
is SongProperty.Value.Number -> { is SongProperty.Value.Number -> {
val value = context.getString(R.string.fmt_number, property.value.value) val value = context.getString(R.string.fmt_number, property.value.value)
val subtitle = property.value.subtitle val subtitle = property.value.subtitle
binding.propertyValue.setText(if (subtitle != null) { binding.propertyValue.setText(
context.getString(R.string.fmt_zipped_names, value, subtitle) if (subtitle != null) {
} else { context.getString(R.string.fmt_zipped_names, value, subtitle)
value } else {
}) value
})
} }
is SongProperty.Value.ItemDate -> { is SongProperty.Value.ItemDate -> {
val date = property.value.date val date = property.value.date

View file

@ -157,15 +157,17 @@ fun ReleaseType.resolve(context: Context) =
fun Format.resolve(context: Context): String = fun Format.resolve(context: Context): String =
when (this) { when (this) {
is Format.MPEG3 -> context.getString(R.string.cdc_mp3) is Format.MPEG3 -> context.getString(R.string.cdc_mp3)
is Format.MPEG4 -> containing?.let { context.getString(R.string.cnt_mp4, it.resolve(context)) } is Format.MPEG4 ->
?: context.getString(R.string.cdc_mp4) containing?.let { context.getString(R.string.cnt_mp4, it.resolve(context)) }
?: context.getString(R.string.cdc_mp4)
is Format.AAC -> context.getString(R.string.cdc_aac) is Format.AAC -> context.getString(R.string.cdc_aac)
is Format.ALAC -> context.getString(R.string.cdc_alac) is Format.ALAC -> context.getString(R.string.cdc_alac)
is Format.Ogg -> containing?.let { context.getString(R.string.cnt_ogg, it.resolve(context)) } is Format.Ogg ->
?: context.getString(R.string.cdc_ogg) containing?.let { context.getString(R.string.cnt_ogg, it.resolve(context)) }
?: context.getString(R.string.cdc_ogg)
is Format.Opus -> context.getString(R.string.cdc_opus) is Format.Opus -> context.getString(R.string.cdc_opus)
is Format.Vorbis -> context.getString(R.string.cdc_vorbis) is Format.Vorbis -> context.getString(R.string.cdc_vorbis)
is Format.FLAC -> context.getString(R.string.cdc_flac) is Format.FLAC -> context.getString(R.string.cdc_flac)
is Format.Wav -> context.getString(R.string.cdc_wav) is Format.Wav -> context.getString(R.string.cdc_wav)
is Format.Unknown -> extension ?: context.getString(R.string.cdc_unknown) is Format.Unknown -> extension ?: context.getString(R.string.cdc_unknown)
} }