From 2ef088cb60d6f17a7d311e0a15d4a9a9f1d6dbcf Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 13 Nov 2019 13:23:58 -0500 Subject: [PATCH] Update RepoDao --- .../topjohnwu/magisk/data/database/RepoDao.kt | 21 ++++++++----------- .../magisk/data/database/RepoDatabase.kt | 11 ---------- .../com/topjohnwu/magisk/di/DatabaseModule.kt | 3 +-- 3 files changed, 10 insertions(+), 25 deletions(-) delete mode 100644 app/src/main/java/com/topjohnwu/magisk/data/database/RepoDatabase.kt diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDao.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDao.kt index 63ea6e9d6..21a10f488 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDao.kt @@ -4,8 +4,14 @@ import androidx.room.* import com.topjohnwu.magisk.Config 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 -abstract class RepoDao { +abstract class RepoDao(private val db: RepoDatabase) { val repoIDList get() = getRepoID().map { it.id } @@ -15,13 +21,10 @@ abstract class RepoDao { } var etagKey: String - set(etag) = addEtagRaw(RepoEtag(0, etag)) + set(value) = addEtagRaw(RepoEtag(0, value)) get() = etagRaw()?.key.orEmpty() - fun clear() { - clearRepos() - clearEtag() - } + fun clear() = db.clearAllTables() @Query("SELECT * FROM repos ORDER BY last_update DESC") protected abstract fun getReposDateOrder(): List @@ -52,12 +55,6 @@ abstract class RepoDao { @Insert(onConflict = OnConflictStrategy.REPLACE) 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( diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDatabase.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDatabase.kt deleted file mode 100644 index c7ad3a00e..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/RepoDatabase.kt +++ /dev/null @@ -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 -} diff --git a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt index 5a5cbeb47..bf3b566c9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt @@ -12,8 +12,7 @@ val databaseModule = module { single { PolicyDao(get()) } single { SettingsDao() } single { StringDao() } - single { createRepoDatabase(get()) } - single { get().repoDao() } + single { createRepoDatabase(get()).repoDao() } single { RepoUpdater(get(), get()) } }