mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-02 14:35:29 +00:00
Update RepoDao
This commit is contained in:
parent
7c320b6fc4
commit
2ef088cb60
@ -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(
|
||||||
|
@ -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
|
|
||||||
}
|
|
@ -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()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user