all: reformat

This commit is contained in:
Alexander Capehart
2026-08-29 15:29:20 -06:00
parent d19cd9dc34
commit bf6c70192b
18 changed files with 220 additions and 216 deletions
@@ -239,8 +239,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
val playbackIndicator = (playbackIndicator ?: return).view val playbackIndicator = (playbackIndicator ?: return).view
val iconSize = iconSize ?: (measuredWidth / 2) val iconSize = iconSize ?: (measuredWidth / 2)
playbackIndicator.apply { playbackIndicator.apply {
imageMatrix = imageMatrix = indicatorMatrix.apply {
indicatorMatrix.apply {
reset() reset()
drawable?.let { drawable -> drawable?.let { drawable ->
// First scale the icon up to the desired size. // First scale the icon up to the desired size.
@@ -88,8 +88,7 @@ private constructor(context: Context, private val data: GalleryCoverCollection,
val positions = listOf(p0, p1, p2, p3) val positions = listOf(p0, p1, p2, p3)
// first we actually have to aggregate the geometry here so that // first we actually have to aggregate the geometry here so that
// our overlaps will actually work // our overlaps will actually work
val tiles = val tiles = positions.mapIndexed { index, baseRect ->
positions.mapIndexed { index, baseRect ->
// generate path-tiles for each cover // generate path-tiles for each cover
val isTop = index < 2 val isTop = index < 2
val isLeft = index % 2 == 0 val isLeft = index % 2 == 0
@@ -135,8 +135,9 @@ private constructor(
// Cancel the previous music loading job. // Cancel the previous music loading job.
currentIndexJob?.cancel() currentIndexJob?.cancel()
// Start a new music loading job on a co-routine. // Start a new music loading job on a co-routine.
currentIndexJob = currentIndexJob = indexScope.launch {
indexScope.launch { musicRepository.index(this@IndexingHolder, withCache) } musicRepository.index(this@IndexingHolder, withCache)
}
} }
override fun onIndexingStateChanged() { override fun onIndexingStateChanged() {
@@ -102,14 +102,18 @@ constructor(
fun getRoot() = BrowserRoot(MediaSessionUID.Tab(TabNode.Root).toString(), Bundle()) fun getRoot() = BrowserRoot(MediaSessionUID.Tab(TabNode.Root).toString(), Bundle())
fun getItem(mediaId: String, result: Result<MediaItem>) = fun getItem(mediaId: String, result: Result<MediaItem>) = result.dispatch {
result.dispatch { musicBrowser.getItem(mediaId) } musicBrowser.getItem(mediaId)
}
fun getChildren(mediaId: String, maxTabs: Int, result: Result<MutableList<MediaItem>>) = fun getChildren(mediaId: String, maxTabs: Int, result: Result<MutableList<MediaItem>>) =
result.dispatch { musicBrowser.getChildren(mediaId, maxTabs)?.toMutableList() } result.dispatch {
musicBrowser.getChildren(mediaId, maxTabs)?.toMutableList()
}
fun search(query: String, result: Result<MutableList<MediaItem>>) = fun search(query: String, result: Result<MutableList<MediaItem>>) = result.dispatchAsync {
result.dispatchAsync { musicBrowser.search(query) } musicBrowser.search(query)
}
private fun <T> Result<T>.dispatch(body: () -> T?) { private fun <T> Result<T>.dispatch(body: () -> T?) {
try { try {
@@ -194,8 +194,7 @@ constructor(
// Replace the previous position co-routine with a new one that uses the new // Replace the previous position co-routine with a new one that uses the new
// state information. // state information.
lastPositionJob?.cancel() lastPositionJob?.cancel()
lastPositionJob = lastPositionJob = viewModelScope.launch {
viewModelScope.launch {
while (true) { while (true) {
_positionDs.value = progression.calculateElapsedPositionMs().msToDs() _positionDs.value = progression.calculateElapsedPositionMs().msToDs()
// Wait a deci-second for the next position tick. // Wait a deci-second for the next position tick.
@@ -310,8 +310,7 @@ private constructor(
* @param queue The current queue to upload. * @param queue The current queue to upload.
*/ */
private fun updateQueue(queue: List<Song>) { private fun updateQueue(queue: List<Song>) {
val queueItems = val queueItems = queue.mapIndexed { i, song ->
queue.mapIndexed { i, song ->
val description = val description =
song.toMediaDescription( song.toMediaDescription(
context, context,
@@ -89,12 +89,9 @@ private constructor(
private fun scheduleAutoStop() { private fun scheduleAutoStop() {
autoStopJob?.cancel() autoStopJob?.cancel()
autoStopJob = autoStopJob = scope.launch {
scope.launch {
delay(AUTO_STOP_DELAY_MS) delay(AUTO_STOP_DELAY_MS)
L.d( L.d("Auto-stop timer expired after ${AUTO_STOP_DELAY_MS / 60000} minutes of inactivity")
"Auto-stop timer expired after ${AUTO_STOP_DELAY_MS / 60000} minutes of inactivity"
)
playbackManager.endSession() playbackManager.endSession()
} }
} }
@@ -123,8 +123,7 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
val one = alphaSpring.alpha(binding.icon1, cyclicAlpha[row]) val one = alphaSpring.alpha(binding.icon1, cyclicAlpha[row])
val two = alphaSpring.alpha(binding.icon2, cyclicAlpha[row + 1]) val two = alphaSpring.alpha(binding.icon2, cyclicAlpha[row + 1])
val three = alphaSpring.alpha(binding.icon3, cyclicAlpha[row + 2]) val three = alphaSpring.alpha(binding.icon3, cyclicAlpha[row + 2])
val endListener = val endListener = DynamicAnimation.OnAnimationEndListener { _, cancelled, _, _ ->
DynamicAnimation.OnAnimationEndListener { _, cancelled, _, _ ->
if (!cancelled) { if (!cancelled) {
cycle((at + 1) % 5) cycle((at + 1) % 5)
} }
@@ -102,8 +102,7 @@ constructor(
// Searching is time-consuming, so do it in the background. // Searching is time-consuming, so do it in the background.
L.d("Searching music library for $query") L.d("Searching music library for $query")
currentSearchJob = currentSearchJob = viewModelScope.launch {
viewModelScope.launch {
_searchResults.value = searchImpl(library, query).also { yield() } _searchResults.value = searchImpl(library, query).also { yield() }
} }
} }
@@ -51,8 +51,7 @@ class MusicPreferenceFragment : BasePreferenceFragment(R.xml.preferences_music)
override fun onSetupPreference(preference: Preference) { override fun onSetupPreference(preference: Preference) {
if (preference.key == getString(R.string.set_key_cover_mode)) { if (preference.key == getString(R.string.set_key_cover_mode)) {
L.d("Configuring cover mode setting") L.d("Configuring cover mode setting")
preference.onPreferenceChangeListener = preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
Preference.OnPreferenceChangeListener { _, _ ->
L.d("Cover mode changed, reloading music") L.d("Cover mode changed, reloading music")
musicModel.refresh() musicModel.refresh()
true true
@@ -60,8 +59,7 @@ class MusicPreferenceFragment : BasePreferenceFragment(R.xml.preferences_music)
} }
if (preference.key == getString(R.string.set_key_square_covers)) { if (preference.key == getString(R.string.set_key_square_covers)) {
L.d("Configuring square cover setting") L.d("Configuring square cover setting")
preference.onPreferenceChangeListener = preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
Preference.OnPreferenceChangeListener { _, _ ->
L.d("Cover mode changed, resetting image memory cache") L.d("Cover mode changed, resetting image memory cache")
imageLoader.memoryCache?.clear() imageLoader.memoryCache?.clear()
true true
@@ -69,8 +67,7 @@ class MusicPreferenceFragment : BasePreferenceFragment(R.xml.preferences_music)
} }
if (preference.key == getString(R.string.set_key_with_hidden)) { if (preference.key == getString(R.string.set_key_with_hidden)) {
L.d("Configuring ignore hidden files setting") L.d("Configuring ignore hidden files setting")
preference.onPreferenceChangeListener = preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
Preference.OnPreferenceChangeListener { _, _ ->
L.d("Ignore hidden files setting changed, reloading music") L.d("Ignore hidden files setting changed, reloading music")
musicModel.refresh() musicModel.refresh()
true true
@@ -51,8 +51,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
private var scrollingChild: View? = null private var scrollingChild: View? = null
private val tConsumed = IntArray(2) private val tConsumed = IntArray(2)
private val onPreDraw = private val onPreDraw = ViewTreeObserver.OnPreDrawListener {
ViewTreeObserver.OnPreDrawListener {
val child = findScrollingChild() val child = findScrollingChild()
if (child != null) { if (child != null) {
@@ -309,7 +309,10 @@ class WidgetProvider : AppWidgetProvider() {
setImageViewBitmap(R.id.widget_cover, state.cover) setImageViewBitmap(R.id.widget_cover, state.cover)
setContentDescription( setContentDescription(
R.id.widget_cover, R.id.widget_cover,
context.getString(R.string.desc_album_cover, state.song.album.name.resolve(context)), context.getString(
R.string.desc_album_cover,
state.song.album.name.resolve(context),
),
) )
} else { } else {
discardCover(context) discardCover(context)
@@ -41,8 +41,7 @@ class DBCache private constructor(private val readDao: CacheReadDao) : Cache {
private val mappingLock = Mutex() private val mappingLock = Mutex()
override suspend fun read(file: File): CacheResult { override suspend fun read(file: File): CacheResult {
val currentMapping = val currentMapping = mappingLock.withLock {
mappingLock.withLock {
mapping ?: readDao.selectAllSongs().associateBy { it.uri }.also { mapping = it } mapping ?: readDao.selectAllSongs().associateBy { it.uri }.also { mapping = it }
} }
val dbSong = currentMapping[file.uri] ?: return CacheResult.Miss(file) val dbSong = currentMapping[file.uri] ?: return CacheResult.Miss(file)
@@ -148,8 +147,7 @@ private constructor(private val inner: DBCache, private val writeDao: CacheWrite
return MutableDBCache(DBCache.from(db), db.writeDao()) return MutableDBCache(DBCache.from(db), db.writeDao())
} }
internal fun from(inner: DBCache, writeDao: CacheWriteDao) = internal fun from(inner: DBCache, writeDao: CacheWriteDao) = MutableDBCache(inner, writeDao)
MutableDBCache(inner, writeDao)
private const val BATCH_SIZE = 500 private const val BATCH_SIZE = 500
} }
@@ -381,8 +381,7 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
return return
} }
// No full MBID coverage, discard the MBIDs from the graph. // No full MBID coverage, discard the MBIDs from the graph.
val strippedCluster = val strippedCluster = cluster.map {
cluster.map {
val noMbidPreArtist = it.preArtist.copy(musicBrainzId = null) val noMbidPreArtist = it.preArtist.copy(musicBrainzId = null)
val simpleMbidVertex = val simpleMbidVertex =
artistVertices.getOrPut(noMbidPreArtist) { ArtistVertex(noMbidPreArtist) } artistVertices.getOrPut(noMbidPreArtist) { ArtistVertex(noMbidPreArtist) }
@@ -457,8 +456,7 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
return return
} }
// No full MBID coverage, discard the MBIDs from the graph. // No full MBID coverage, discard the MBIDs from the graph.
val strippedMbidCluster = val strippedMbidCluster = cluster.map {
cluster.map {
val noMbidPreAlbum = it.preAlbum.copy(musicBrainzId = null) val noMbidPreAlbum = it.preAlbum.copy(musicBrainzId = null)
val simpleMbidVertex = val simpleMbidVertex =
albumVertices.getOrPut(noMbidPreAlbum) { albumVertices.getOrPut(noMbidPreAlbum) {
@@ -467,20 +465,21 @@ private class MusicGraphBuilderImpl : MusicGraph.Builder {
meldAlbumVertices(it, simpleMbidVertex) meldAlbumVertices(it, simpleMbidVertex)
simpleMbidVertex simpleMbidVertex
} }
val fullAlbumArtistCoverage = val fullAlbumArtistCoverage = strippedMbidCluster.all {
strippedMbidCluster.all { it.preAlbum.preArtists is PreArtistsFrom.Album } it.preAlbum.preArtists is PreArtistsFrom.Album
}
if (fullAlbumArtistCoverage) { if (fullAlbumArtistCoverage) {
// All albums have album artists, we can reasonably cluster around artists // All albums have album artists, we can reasonably cluster around artists
// rather than just name. // rather than just name.
val albumArtistClusters = val albumArtistClusters = strippedMbidCluster.groupBy {
strippedMbidCluster.groupBy { it.preAlbum.preArtists.preArtists } it.preAlbum.preArtists.preArtists
}
for (albumArtistCluster in albumArtistClusters.values) { for (albumArtistCluster in albumArtistClusters.values) {
simplifyAlbumClusterImpl(albumArtistCluster) simplifyAlbumClusterImpl(albumArtistCluster)
} }
return return
} }
val strippedAlbumArtistCluster = val strippedAlbumArtistCluster = strippedMbidCluster.map {
strippedMbidCluster.map {
val noAlbumArtistPreAlbum = val noAlbumArtistPreAlbum =
it.preAlbum.copy( it.preAlbum.copy(
preArtists = PreArtistsFrom.Individual(it.preAlbum.preArtists.preArtists) preArtists = PreArtistsFrom.Individual(it.preAlbum.preArtists.preArtists)
@@ -32,7 +32,6 @@ import androidx.room.RoomDatabase
import androidx.room.Transaction import androidx.room.Transaction
import androidx.room.TypeConverters import androidx.room.TypeConverters
import androidx.room.migration.Migration import androidx.room.migration.Migration
import androidx.sqlite.SQLiteConnection
import androidx.sqlite.db.SupportSQLiteDatabase import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteQueryBuilder import androidx.sqlite.db.SupportSQLiteQueryBuilder
import org.oxycblt.musikr.Music import org.oxycblt.musikr.Music
@@ -60,19 +59,32 @@ internal abstract class PlaylistDatabase : RoomDatabase() {
) )
.addMigrations( .addMigrations(
object : Migration(30, 75) { object : Migration(30, 75) {
private fun washUids(db: SupportSQLiteDatabase, table: String, column: String) { private fun washUids(
val playlistUidMigration = db.query( db: SupportSQLiteDatabase,
table: String,
column: String,
) {
val playlistUidMigration =
db.query(
SupportSQLiteQueryBuilder.builder(table) SupportSQLiteQueryBuilder.builder(table)
.columns(arrayOf(column)) .columns(arrayOf(column))
.create() .create()
).use { )
.use {
val migrations = mutableListOf<Pair<String, String>>() val migrations = mutableListOf<Pair<String, String>>()
val playlistUidIndex = it.getColumnIndexOrThrow(column) val playlistUidIndex = it.getColumnIndexOrThrow(column)
while (it.moveToNext()) { while (it.moveToNext()) {
val oldUid = val oldUid =
requireNotNull(it.getStringOrNull(playlistUidIndex)) { "catastrophic migration failure: $table has no UID" } requireNotNull(
it.getStringOrNull(playlistUidIndex)
) {
"catastrophic migration failure: $table has no UID"
}
val newUid = val newUid =
requireNotNull(Music.UID.fromString(oldUid)) { "catastrophic migration failure: $table has bad UID" }.toString() requireNotNull(Music.UID.fromString(oldUid)) {
"catastrophic migration failure: $table has bad UID"
}
.toString()
migrations.add(oldUid to newUid) migrations.add(oldUid to newUid)
} }
migrations migrations
@@ -85,7 +97,7 @@ internal abstract class PlaylistDatabase : RoomDatabase() {
put(column, old) put(column, old)
}, },
"$column = ?", "$column = ?",
arrayOf(new) arrayOf(new),
) )
} }
for ((old, new) in playlistUidMigration) { for ((old, new) in playlistUidMigration) {
@@ -96,10 +108,11 @@ internal abstract class PlaylistDatabase : RoomDatabase() {
put(column, new) put(column, new)
}, },
"$column = ?", "$column = ?",
arrayOf(old) arrayOf(old),
) )
} }
} }
override fun migrate(db: SupportSQLiteDatabase) { override fun migrate(db: SupportSQLiteDatabase) {
washUids(db, "PlaylistInfo", "playlistUid") washUids(db, "PlaylistInfo", "playlistUid")
washUids(db, "PlaylistSongCrossRef", "playlistUid") washUids(db, "PlaylistSongCrossRef", "playlistUid")
@@ -116,8 +116,9 @@ private class M3UImpl(private val volumeManager: VolumeManager) : M3U() {
// based on the programs that generated it. I more or less have to consider any possible // based on the programs that generated it. I more or less have to consider any possible
// interpretation as valid. // interpretation as valid.
val interpretations = interpretPath(unlikelyToBeNull(path)) val interpretations = interpretPath(unlikelyToBeNull(path))
val possibilities = val possibilities = interpretations.flatMap {
interpretations.flatMap { expandInterpretation(it, workingDirectory, volumes) } expandInterpretation(it, workingDirectory, volumes)
}
paths.add(possibilities) paths.add(possibilities)
} }
@@ -156,8 +157,7 @@ private class M3UImpl(private val volumeManager: VolumeManager) : M3U() {
val relativeInterpretation = val relativeInterpretation =
Path(workingDirectory.volume, path.components.absoluteTo(workingDirectory.components)) Path(workingDirectory.volume, path.components.absoluteTo(workingDirectory.components))
val volumeExactMatch = volumes.find { it.components?.contains(path.components) == true } val volumeExactMatch = volumes.find { it.components?.contains(path.components) == true }
val volumeInterpretation = val volumeInterpretation = volumeExactMatch?.let {
volumeExactMatch?.let {
val components = val components =
unlikelyToBeNull(volumeExactMatch.components).containing(path.components) unlikelyToBeNull(volumeExactMatch.components).containing(path.components)
Path(volumeExactMatch, components) Path(volumeExactMatch, components)
@@ -47,8 +47,7 @@ internal fun String.parseSlashPositionField() =
* *
* @see transformPositionField * @see transformPositionField
*/ */
internal fun parseXiphPositionField(pos: String?, total: String?) = internal fun parseXiphPositionField(pos: String?, total: String?) = pos?.let { posStr ->
pos?.let { posStr ->
posStr.toIntOrNull()?.let { transformPositionField(it, total?.toIntOrNull()) } posStr.toIntOrNull()?.let { transformPositionField(it, total?.toIntOrNull()) }
?: posStr.parseSlashPositionField() ?: posStr.parseSlashPositionField()
} }
@@ -18,12 +18,12 @@
package org.oxycblt.musikr.cache.db package org.oxycblt.musikr.cache.db
import io.mockk.Runs
import io.mockk.coEvery import io.mockk.coEvery
import io.mockk.coVerify import io.mockk.coVerify
import io.mockk.every import io.mockk.every
import io.mockk.just import io.mockk.just
import io.mockk.mockk import io.mockk.mockk
import io.mockk.Runs
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Test import org.junit.Test