Commit 2ef088cb authored by topjohnwu's avatar topjohnwu

Update RepoDao

parent 7c320b6f
...@@ -4,8 +4,14 @@ import androidx.room.* ...@@ -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 { ...@@ -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 { ...@@ -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(
......
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
}
...@@ -12,8 +12,7 @@ val databaseModule = module { ...@@ -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()) }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment