From 44368383f4874c25f2b95a90fd95005dc60233a0 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 28 Jul 2019 02:21:55 -0700 Subject: [PATCH] Fix fetching repo ordering --- .../topjohnwu/magisk/data/database/RepoDao.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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 b667a0734..8ed234da4 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 @@ -9,11 +9,10 @@ abstract class RepoDao { val repoIDSet: Set get() = getRepoID().map { it.id }.toSet() - val repos: List get() = getReposWithOrder(when (Config.repoOrder) { - Config.Value.ORDER_NAME -> "name COLLATE NOCASE" - Config.Value.ORDER_DATE -> "last_update DESC" - else -> "" - }) + val repos: List get() = when (Config.repoOrder) { + Config.Value.ORDER_NAME -> getReposNameOrder() + else -> getReposDateOrder() + } var etagKey: String set(etag) = addEtagRaw(RepoEtag(0, etag)) @@ -24,8 +23,11 @@ abstract class RepoDao { clearEtag() } - @Query("SELECT * FROM repos ORDER BY :order") - protected abstract fun getReposWithOrder(order: String): List + @Query("SELECT * FROM repos ORDER BY last_update DESC") + protected abstract fun getReposDateOrder(): List + + @Query("SELECT * FROM repos ORDER BY name COLLATE NOCASE") + protected abstract fun getReposNameOrder(): List @Insert(onConflict = OnConflictStrategy.REPLACE) abstract fun addRepo(repo: Repo)