all: break off musikr
This commit is contained in:
@@ -54,7 +54,6 @@ import org.oxycblt.musikr.Music
|
||||
import org.oxycblt.musikr.MusicParent
|
||||
import org.oxycblt.musikr.Playlist
|
||||
import org.oxycblt.musikr.Song
|
||||
import org.oxycblt.musikr.metadata.AudioProperties
|
||||
import timber.log.Timber as L
|
||||
|
||||
/**
|
||||
@@ -69,7 +68,6 @@ class DetailViewModel
|
||||
constructor(
|
||||
private val listSettings: ListSettings,
|
||||
private val musicRepository: MusicRepository,
|
||||
private val audioPropertiesFactory: AudioProperties.Factory,
|
||||
private val playbackSettings: PlaybackSettings,
|
||||
detailGeneratorFactory: DetailGenerator.Factory
|
||||
) : ViewModel(), DetailGenerator.Invalidator {
|
||||
@@ -89,10 +87,6 @@ constructor(
|
||||
val currentSong: StateFlow<Song?>
|
||||
get() = _currentSong
|
||||
|
||||
private val _songAudioProperties = MutableStateFlow<AudioProperties?>(null)
|
||||
/** The [AudioProperties] of the currently shown [Song]. Null if not loaded yet. */
|
||||
val songAudioProperties: StateFlow<AudioProperties?> = _songAudioProperties
|
||||
|
||||
// --- ALBUM ---
|
||||
|
||||
private val _currentAlbum = MutableStateFlow<Album?>(null)
|
||||
@@ -308,7 +302,7 @@ constructor(
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new [currentSong] from it's [Music.UID]. [currentSong] and [songAudioProperties] will
|
||||
* Set a new [currentSong] from it's [Music.UID]. [currentSong] will
|
||||
* be updated to align with the new [Song].
|
||||
*
|
||||
* @param uid The UID of the [Song] to load. Must be valid.
|
||||
@@ -511,17 +505,7 @@ constructor(
|
||||
}
|
||||
|
||||
private fun refreshAudioInfo(song: Song) {
|
||||
L.d("Refreshing audio info")
|
||||
// Clear any previous job in order to avoid stale data from appearing in the UI.
|
||||
currentSongJob?.cancel()
|
||||
_songAudioProperties.value = null
|
||||
currentSongJob =
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val info = audioPropertiesFactory.extract(song)
|
||||
yield()
|
||||
L.d("Updating audio info to $info")
|
||||
_songAudioProperties.value = info
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private inline fun <T : MusicParent> refreshDetail(
|
||||
|
||||
@@ -41,7 +41,6 @@ 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.metadata.AudioProperties
|
||||
import org.oxycblt.musikr.tag.Name
|
||||
import timber.log.Timber as L
|
||||
|
||||
@@ -72,63 +71,63 @@ class SongDetailDialog : ViewBindingMaterialDialogFragment<DialogSongDetailBindi
|
||||
// DetailViewModel handles most initialization from the navigation argument.
|
||||
detailModel.setSong(args.songUid)
|
||||
detailModel.toShow.consume()
|
||||
collectImmediately(detailModel.currentSong, detailModel.songAudioProperties, ::updateSong)
|
||||
collectImmediately(detailModel.currentSong, ::updateSong)
|
||||
}
|
||||
|
||||
private fun updateSong(song: Song?, info: AudioProperties?) {
|
||||
if (song == null) {
|
||||
private fun updateSong(song: Song?) {
|
||||
// if (song == null) {
|
||||
L.d("No song to show, navigating away")
|
||||
findNavController().navigateUp()
|
||||
return
|
||||
}
|
||||
|
||||
if (info != null) {
|
||||
val context = requireContext()
|
||||
detailAdapter.update(
|
||||
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.resolve(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, formattedNumber, it.name)
|
||||
} else {
|
||||
formattedNumber
|
||||
}
|
||||
add(SongProperty(R.string.lbl_disc, zipped))
|
||||
}
|
||||
add(SongProperty(R.string.lbl_path, song.path.resolve(context)))
|
||||
// info.format.resolveName(context)?.let {
|
||||
// add(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)))
|
||||
}
|
||||
song.replayGainAdjustment.track?.let {
|
||||
add(SongProperty(R.string.lbl_replaygain_track, it.formatDb(context)))
|
||||
}
|
||||
song.replayGainAdjustment.album?.let {
|
||||
add(SongProperty(R.string.lbl_replaygain_album, it.formatDb(context)))
|
||||
}
|
||||
},
|
||||
UpdateInstructions.Replace(0))
|
||||
}
|
||||
// }
|
||||
//
|
||||
// if (info != null) {
|
||||
// val context = requireContext()
|
||||
// detailAdapter.update(
|
||||
// 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.resolve(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, formattedNumber, it.name)
|
||||
// } else {
|
||||
// formattedNumber
|
||||
// }
|
||||
// add(SongProperty(R.string.lbl_disc, zipped))
|
||||
// }
|
||||
// add(SongProperty(R.string.lbl_path, song.path.resolve(context)))
|
||||
// // info.format.resolveName(context)?.let {
|
||||
// // add(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)))
|
||||
// }
|
||||
// song.replayGainAdjustment.track?.let {
|
||||
// add(SongProperty(R.string.lbl_replaygain_track, it.formatDb(context)))
|
||||
// }
|
||||
// song.replayGainAdjustment.album?.let {
|
||||
// add(SongProperty(R.string.lbl_replaygain_album, it.formatDb(context)))
|
||||
// }
|
||||
// },
|
||||
// UpdateInstructions.Replace(0))
|
||||
// }
|
||||
}
|
||||
|
||||
private fun <T : Music> T.zipName(context: Context): String {
|
||||
|
||||
Reference in New Issue
Block a user