Update RepoDao

This commit is contained in:
topjohnwu 2019-11-13 13:23:58 -05:00
parent 7c320b6fc4
commit 2ef088cb60
3 changed files with 10 additions and 25 deletions

View File

@ -4,8 +4,14 @@ import androidx.room.*
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.model.entity.module.Repo import com.topjohnwu.magisk.model.entity.module.Repo
@Database(version = 6, entities = [Repo::class, RepoEtag::class])
abstract class RepoDatabase : RoomDatabase() {
abstract fun repoDao() : RepoDao
}
@Dao @Dao
abstract class RepoDao { abstract class RepoDao(private val db: RepoDatabase) {
val repoIDList get() = getRepoID().map { it.id } val repoIDList get() = getRepoID().map { it.id }
@ -15,13 +21,10 @@ abstract class RepoDao {
} }
var etagKey: String var etagKey: String
set(etag) = addEtagRaw(RepoEtag(0, etag)) set(value) = addEtagRaw(RepoEtag(0, value))
get() = etagRaw()?.key.orEmpty() get() = etagRaw()?.key.orEmpty()
fun clear() { fun clear() = db.clearAllTables()
clearRepos()
clearEtag()
}
@Query("SELECT * FROM repos ORDER BY last_update DESC") @Query("SELECT * FROM repos ORDER BY last_update DESC")
protected abstract fun getReposDateOrder(): List<Repo> protected abstract fun getReposDateOrder(): List<Repo>
@ -52,12 +55,6 @@ abstract class RepoDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
protected abstract fun addEtagRaw(etag: RepoEtag) protected abstract fun addEtagRaw(etag: RepoEtag)
@Query("DELETE FROM repos")
protected abstract fun clearRepos()
@Query("DELETE FROM etag")
protected abstract fun clearEtag()
} }
data class RepoID( data class RepoID(

View File

@ -1,11 +0,0 @@
package com.topjohnwu.magisk.data.database
import androidx.room.Database
import androidx.room.RoomDatabase
import com.topjohnwu.magisk.model.entity.module.Repo
@Database(version = 6, entities = [Repo::class, RepoEtag::class])
abstract class RepoDatabase : RoomDatabase() {
abstract fun repoDao() : RepoDao
}

View File

@ -12,8 +12,7 @@ val databaseModule = module {
single { PolicyDao(get()) } single { PolicyDao(get()) }
single { SettingsDao() } single { SettingsDao() }
single { StringDao() } single { StringDao() }
single { createRepoDatabase(get()) } single { createRepoDatabase(get()).repoDao() }
single { get<RepoDatabase>().repoDao() }
single { RepoUpdater(get(), get()) } single { RepoUpdater(get(), get()) }
} }