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