musikr: fix custom covers not being obtained
This commit is contained in:
parent
216d9802ef
commit
2e4a147b55
3 changed files with 22 additions and 12 deletions
|
@ -43,7 +43,7 @@ class CoverProvider @Inject constructor(private val settingCovers: SettingCovers
|
||||||
}
|
}
|
||||||
val id = uri.lastPathSegment ?: return null
|
val id = uri.lastPathSegment ?: return null
|
||||||
return runBlocking {
|
return runBlocking {
|
||||||
when (val result = settingCovers.obtain(requireNotNull(context), id)) {
|
when (val result = settingCovers.immutable(requireNotNull(context)).obtain(id)) {
|
||||||
is CoverResult.Hit -> result.cover.fd()
|
is CoverResult.Hit -> result.cover.fd()
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,12 @@ import org.oxycblt.musikr.cover.Cover
|
||||||
import org.oxycblt.musikr.cover.CoverIdentifier
|
import org.oxycblt.musikr.cover.CoverIdentifier
|
||||||
import org.oxycblt.musikr.cover.CoverParams
|
import org.oxycblt.musikr.cover.CoverParams
|
||||||
import org.oxycblt.musikr.cover.CoverResult
|
import org.oxycblt.musikr.cover.CoverResult
|
||||||
|
import org.oxycblt.musikr.cover.Covers
|
||||||
import org.oxycblt.musikr.cover.FileCover
|
import org.oxycblt.musikr.cover.FileCover
|
||||||
import org.oxycblt.musikr.cover.MutableCovers
|
import org.oxycblt.musikr.cover.MutableCovers
|
||||||
|
|
||||||
interface SettingCovers {
|
interface SettingCovers {
|
||||||
suspend fun obtain(context: Context, id: String): CoverResult<FileCover>
|
suspend fun immutable(context: Context): Covers<out FileCover>
|
||||||
|
|
||||||
suspend fun mutate(context: Context, revision: UUID): MutableCovers<out Cover>
|
suspend fun mutate(context: Context, revision: UUID): MutableCovers<out Cover>
|
||||||
}
|
}
|
||||||
|
@ -40,6 +41,9 @@ class SettingCoversImpl
|
||||||
@Inject
|
@Inject
|
||||||
constructor(private val imageSettings: ImageSettings, private val identifier: CoverIdentifier) :
|
constructor(private val imageSettings: ImageSettings, private val identifier: CoverIdentifier) :
|
||||||
SettingCovers {
|
SettingCovers {
|
||||||
|
override suspend fun immutable(context: Context): Covers<out FileCover> =
|
||||||
|
CompatCovers(context, BaseSiloedCovers(context))
|
||||||
|
|
||||||
override suspend fun mutate(context: Context, revision: UUID): MutableCovers<out Cover> =
|
override suspend fun mutate(context: Context, revision: UUID): MutableCovers<out Cover> =
|
||||||
when (imageSettings.coverMode) {
|
when (imageSettings.coverMode) {
|
||||||
CoverMode.OFF -> NullCovers(context)
|
CoverMode.OFF -> NullCovers(context)
|
||||||
|
@ -48,13 +52,6 @@ constructor(private val imageSettings: ImageSettings, private val identifier: Co
|
||||||
CoverMode.HIGH_QUALITY -> siloedCovers(context, revision, CoverParams.of(1000, 100))
|
CoverMode.HIGH_QUALITY -> siloedCovers(context, revision, CoverParams.of(1000, 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun obtain(context: Context, id: String): CoverResult<FileCover> {
|
|
||||||
val coverId = SiloedCoverId.parse(id) ?: return CoverResult.Miss()
|
|
||||||
val siloedCovers = SiloedCovers.from(context, coverId.silo)
|
|
||||||
val covers = CompatCovers(context, siloedCovers)
|
|
||||||
return covers.obtain(coverId.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun siloedCovers(context: Context, revision: UUID, with: CoverParams) =
|
private suspend fun siloedCovers(context: Context, revision: UUID, with: CoverParams) =
|
||||||
MutableCompatCovers(
|
MutableCompatCovers(
|
||||||
context, MutableSiloedCovers.from(context, CoverSilo(revision, with), identifier))
|
context, MutableSiloedCovers.from(context, CoverSilo(revision, with), identifier))
|
||||||
|
|
|
@ -35,11 +35,23 @@ import org.oxycblt.musikr.fs.DeviceFile
|
||||||
import org.oxycblt.musikr.fs.app.AppFiles
|
import org.oxycblt.musikr.fs.app.AppFiles
|
||||||
import org.oxycblt.musikr.metadata.Metadata
|
import org.oxycblt.musikr.metadata.Metadata
|
||||||
|
|
||||||
|
class BaseSiloedCovers(private val context: Context) : Covers<FileCover> {
|
||||||
|
override suspend fun obtain(id: String): CoverResult<FileCover> {
|
||||||
|
val siloedId = SiloedCoverId.parse(id) ?: return CoverResult.Miss()
|
||||||
|
val core = SiloCore.from(context, siloedId.silo)
|
||||||
|
val fileCovers = FileCovers(core.files, core.format)
|
||||||
|
return when (val result = fileCovers.obtain(siloedId.id)) {
|
||||||
|
is CoverResult.Hit -> CoverResult.Hit(SiloedCover(siloedId.silo, result.cover))
|
||||||
|
is CoverResult.Miss -> CoverResult.Miss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class SiloedCovers(private val silo: CoverSilo, private val fileCovers: FileCovers) :
|
open class SiloedCovers(private val silo: CoverSilo, private val fileCovers: FileCovers) :
|
||||||
Covers<FileCover> {
|
Covers<FileCover> {
|
||||||
override suspend fun obtain(id: String): CoverResult<FileCover> {
|
override suspend fun obtain(id: String): CoverResult<FileCover> {
|
||||||
val coverId = SiloedCoverId.parse(id) ?: return CoverResult.Miss()
|
val coverId = SiloedCoverId.parse(id) ?: return CoverResult.Miss()
|
||||||
if (coverId.silo != silo) return CoverResult.Miss()
|
if (silo != coverId.silo) return CoverResult.Miss()
|
||||||
return when (val result = fileCovers.obtain(coverId.id)) {
|
return when (val result = fileCovers.obtain(coverId.id)) {
|
||||||
is CoverResult.Hit -> CoverResult.Hit(SiloedCover(silo, result.cover))
|
is CoverResult.Hit -> CoverResult.Hit(SiloedCover(silo, result.cover))
|
||||||
is CoverResult.Miss -> CoverResult.Miss()
|
is CoverResult.Miss -> CoverResult.Miss()
|
||||||
|
@ -84,7 +96,8 @@ private constructor(
|
||||||
): MutableSiloedCovers {
|
): MutableSiloedCovers {
|
||||||
val core = SiloCore.from(context, silo)
|
val core = SiloCore.from(context, silo)
|
||||||
return MutableSiloedCovers(
|
return MutableSiloedCovers(
|
||||||
core.rootDir, silo, MutableFileCovers(core.files, core.format, coverIdentifier))
|
core.rootDir, silo, MutableFileCovers(core.files, core.format, coverIdentifier)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue