musikr: introduce null covers
Will be used once covers are made configurable.
This commit is contained in:
parent
d3f4ed5dd4
commit
c6e83d1e18
4 changed files with 55 additions and 12 deletions
|
@ -40,6 +40,7 @@ import org.oxycblt.musikr.Playlist
|
||||||
import org.oxycblt.musikr.Song
|
import org.oxycblt.musikr.Song
|
||||||
import org.oxycblt.musikr.Storage
|
import org.oxycblt.musikr.Storage
|
||||||
import org.oxycblt.musikr.cache.StoredCache
|
import org.oxycblt.musikr.cache.StoredCache
|
||||||
|
import org.oxycblt.musikr.cover.CoverIdentifier
|
||||||
import org.oxycblt.musikr.cover.CoverParams
|
import org.oxycblt.musikr.cover.CoverParams
|
||||||
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
||||||
import org.oxycblt.musikr.tag.interpret.Naming
|
import org.oxycblt.musikr.tag.interpret.Naming
|
||||||
|
@ -244,11 +245,15 @@ constructor(
|
||||||
) : MusicRepository {
|
) : MusicRepository {
|
||||||
private val updateListeners = mutableListOf<MusicRepository.UpdateListener>()
|
private val updateListeners = mutableListOf<MusicRepository.UpdateListener>()
|
||||||
private val indexingListeners = mutableListOf<MusicRepository.IndexingListener>()
|
private val indexingListeners = mutableListOf<MusicRepository.IndexingListener>()
|
||||||
@Volatile private var indexingWorker: MusicRepository.IndexingWorker? = null
|
@Volatile
|
||||||
|
private var indexingWorker: MusicRepository.IndexingWorker? = null
|
||||||
|
|
||||||
@Volatile override var library: MutableLibrary? = null
|
@Volatile
|
||||||
@Volatile private var previousCompletedState: IndexingState.Completed? = null
|
override var library: MutableLibrary? = null
|
||||||
@Volatile private var currentIndexingState: IndexingState? = null
|
@Volatile
|
||||||
|
private var previousCompletedState: IndexingState.Completed? = null
|
||||||
|
@Volatile
|
||||||
|
private var currentIndexingState: IndexingState? = null
|
||||||
override val indexingState: IndexingState?
|
override val indexingState: IndexingState?
|
||||||
get() = currentIndexingState ?: previousCompletedState
|
get() = currentIndexingState ?: previousCompletedState
|
||||||
|
|
||||||
|
@ -388,7 +393,11 @@ constructor(
|
||||||
val currentRevision = musicSettings.revision
|
val currentRevision = musicSettings.revision
|
||||||
val newRevision = currentRevision?.takeIf { withCache } ?: UUID.randomUUID()
|
val newRevision = currentRevision?.takeIf { withCache } ?: UUID.randomUUID()
|
||||||
val cache = if (withCache) storedCache.visible() else storedCache.invisible()
|
val cache = if (withCache) storedCache.visible() else storedCache.invisible()
|
||||||
val covers = SiloedCovers.at(context, CoverSilo(newRevision, CoverParams.of(750, 80)))
|
val covers = SiloedCovers.from(
|
||||||
|
context,
|
||||||
|
CoverSilo(newRevision, CoverParams.of(750, 80)),
|
||||||
|
CoverIdentifier.md5()
|
||||||
|
)
|
||||||
val storage = Storage(cache, covers, storedPlaylists)
|
val storage = Storage(cache, covers, storedPlaylists)
|
||||||
val interpretation = Interpretation(nameFactory, separators)
|
val interpretation = Interpretation(nameFactory, separators)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.oxycblt.auxio.music.covers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
suspend fun Context.coversDir() = withContext(Dispatchers.IO) {
|
||||||
|
filesDir.resolve("covers").apply { mkdirs() }
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.oxycblt.auxio.music.covers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import org.oxycblt.musikr.cover.Cover
|
||||||
|
import org.oxycblt.musikr.cover.CoverIdentifier
|
||||||
|
import org.oxycblt.musikr.cover.Covers
|
||||||
|
import org.oxycblt.musikr.cover.MutableCovers
|
||||||
|
import org.oxycblt.musikr.cover.ObtainResult
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
class NullCovers(private val context: Context, private val identifier: CoverIdentifier) : MutableCovers {
|
||||||
|
override suspend fun obtain(id: String) = ObtainResult.Hit(NullCover(id))
|
||||||
|
|
||||||
|
override suspend fun write(data: ByteArray): Cover =
|
||||||
|
NullCover(identifier.identify(data))
|
||||||
|
|
||||||
|
override suspend fun cleanup(excluding: Collection<Cover>) {
|
||||||
|
context.coversDir().listFiles()?.forEach { it.deleteRecursively() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NullCover(override val id: String) : Cover {
|
||||||
|
override suspend fun open() = null
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ import kotlinx.coroutines.withContext
|
||||||
import org.oxycblt.musikr.cover.Cover
|
import org.oxycblt.musikr.cover.Cover
|
||||||
import org.oxycblt.musikr.cover.CoverFiles
|
import org.oxycblt.musikr.cover.CoverFiles
|
||||||
import org.oxycblt.musikr.cover.CoverFormat
|
import org.oxycblt.musikr.cover.CoverFormat
|
||||||
|
import org.oxycblt.musikr.cover.CoverIdentifier
|
||||||
import org.oxycblt.musikr.cover.Covers
|
import org.oxycblt.musikr.cover.Covers
|
||||||
import org.oxycblt.musikr.cover.MutableCovers
|
import org.oxycblt.musikr.cover.MutableCovers
|
||||||
import org.oxycblt.musikr.cover.ObtainResult
|
import org.oxycblt.musikr.cover.ObtainResult
|
||||||
|
@ -56,16 +57,16 @@ class SiloedCovers(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
suspend fun at(context: Context, silo: CoverSilo): SiloedCovers {
|
suspend fun from(context: Context, silo: CoverSilo, identifier: CoverIdentifier): SiloedCovers {
|
||||||
val rootDir: File
|
val rootDir: File
|
||||||
val revisionDir: File
|
val revisionDir: File
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
rootDir = context.filesDir.resolve("covers").apply { mkdirs() }
|
rootDir = context.coversDir()
|
||||||
revisionDir = rootDir.resolve(silo.toString()).apply { mkdirs() }
|
revisionDir = rootDir.resolve(silo.toString()).apply { mkdirs() }
|
||||||
}
|
}
|
||||||
val files = CoverFiles.at(revisionDir)
|
val files = CoverFiles.at(revisionDir)
|
||||||
val format = CoverFormat.jpeg(silo.params)
|
val format = CoverFormat.jpeg(silo.params)
|
||||||
return SiloedCovers(rootDir, silo, Covers.from(files, format))
|
return SiloedCovers(rootDir, silo, Covers.from(files, format, identifier))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue