musikr: hide cache database
This commit is contained in:
parent
503a4854c3
commit
9a38877c2e
4 changed files with 15 additions and 15 deletions
|
@ -25,8 +25,8 @@ import dagger.Provides
|
|||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import org.oxycblt.musikr.cache.Cache
|
||||
import javax.inject.Singleton
|
||||
import org.oxycblt.musikr.cache.CacheDatabase
|
||||
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
||||
|
||||
@Module
|
||||
|
@ -42,7 +42,7 @@ interface MusicModule {
|
|||
class MusikrShimModule {
|
||||
@Singleton
|
||||
@Provides
|
||||
fun tagDatabase(@ApplicationContext context: Context) = CacheDatabase.from(context)
|
||||
fun cache(@ApplicationContext context: Context) = Cache.from(context)
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.oxycblt.musikr.Playlist
|
|||
import org.oxycblt.musikr.Song
|
||||
import org.oxycblt.musikr.Storage
|
||||
import org.oxycblt.musikr.cache.Cache
|
||||
import org.oxycblt.musikr.cache.CacheDatabase
|
||||
import org.oxycblt.musikr.cache.WriteOnlyCache
|
||||
import org.oxycblt.musikr.playlist.db.StoredPlaylists
|
||||
import org.oxycblt.musikr.tag.interpret.Naming
|
||||
import org.oxycblt.musikr.tag.interpret.Separators
|
||||
|
@ -214,7 +214,7 @@ class MusicRepositoryImpl
|
|||
@Inject
|
||||
constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
private val cacheDatabase: CacheDatabase,
|
||||
private val cache: Cache,
|
||||
private val storedPlaylists: StoredPlaylists,
|
||||
private val musicSettings: MusicSettings
|
||||
) : MusicRepository {
|
||||
|
@ -368,14 +368,14 @@ constructor(
|
|||
revision = musicSettings.revision
|
||||
storage =
|
||||
Storage(
|
||||
Cache.full(cacheDatabase),
|
||||
cache,
|
||||
MutableRevisionedStoredCovers(context, revision),
|
||||
storedPlaylists)
|
||||
} else {
|
||||
revision = UUID.randomUUID()
|
||||
storage =
|
||||
Storage(
|
||||
Cache.writeOnly(cacheDatabase),
|
||||
WriteOnlyCache(cache),
|
||||
MutableRevisionedStoredCovers(context, revision),
|
||||
storedPlaylists)
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.oxycblt.musikr.cache
|
||||
|
||||
import android.content.Context
|
||||
import org.oxycblt.musikr.cover.StoredCovers
|
||||
import org.oxycblt.musikr.fs.DeviceFile
|
||||
import org.oxycblt.musikr.pipeline.RawSong
|
||||
|
@ -28,9 +29,7 @@ abstract class Cache {
|
|||
internal abstract suspend fun write(song: RawSong)
|
||||
|
||||
companion object {
|
||||
fun full(db: CacheDatabase): Cache = FullCache(db.cachedSongsDao())
|
||||
|
||||
fun writeOnly(db: CacheDatabase): Cache = WriteOnlyCache(db.cachedSongsDao())
|
||||
fun from(context: Context): Cache = CacheImpl(CacheDatabase.from(context).cachedSongsDao())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +39,7 @@ internal sealed interface CacheResult {
|
|||
data class Miss(val file: DeviceFile) : CacheResult
|
||||
}
|
||||
|
||||
private class FullCache(private val cacheInfoDao: CacheInfoDao) : Cache() {
|
||||
private class CacheImpl(private val cacheInfoDao: CacheInfoDao) : Cache() {
|
||||
override suspend fun read(file: DeviceFile, storedCovers: StoredCovers) =
|
||||
cacheInfoDao.selectSong(file.uri.toString(), file.lastModified)?.let {
|
||||
CacheResult.Hit(it.intoRawSong(file, storedCovers))
|
||||
|
@ -50,9 +49,10 @@ private class FullCache(private val cacheInfoDao: CacheInfoDao) : Cache() {
|
|||
cacheInfoDao.updateSong(CachedSong.fromRawSong(song))
|
||||
}
|
||||
|
||||
private class WriteOnlyCache(private val cacheInfoDao: CacheInfoDao) : Cache() {
|
||||
override suspend fun read(file: DeviceFile, storedCovers: StoredCovers) = CacheResult.Miss(file)
|
||||
class WriteOnlyCache(private val inner: Cache) : Cache() {
|
||||
override suspend fun read(file: DeviceFile, storedCovers: StoredCovers) =
|
||||
CacheResult.Miss(file)
|
||||
|
||||
override suspend fun write(song: RawSong) =
|
||||
cacheInfoDao.updateSong(CachedSong.fromRawSong(song))
|
||||
inner.write(song)
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ import org.oxycblt.musikr.util.correctWhitespace
|
|||
import org.oxycblt.musikr.util.splitEscaped
|
||||
|
||||
@Database(entities = [CachedSong::class], version = 50, exportSchema = false)
|
||||
abstract class CacheDatabase : RoomDatabase() {
|
||||
internal abstract fun cachedSongsDao(): CacheInfoDao
|
||||
internal abstract class CacheDatabase : RoomDatabase() {
|
||||
abstract fun cachedSongsDao(): CacheInfoDao
|
||||
|
||||
companion object {
|
||||
fun from(context: Context) =
|
||||
|
|
Loading…
Reference in a new issue