Fix fetching repo ordering

This commit is contained in:
topjohnwu 2019-07-28 02:21:55 -07:00
parent d1ff7e0ffe
commit 44368383f4

View File

@ -9,11 +9,10 @@ abstract class RepoDao {
val repoIDSet: Set<String> get() = getRepoID().map { it.id }.toSet() val repoIDSet: Set<String> get() = getRepoID().map { it.id }.toSet()
val repos: List<Repo> get() = getReposWithOrder(when (Config.repoOrder) { val repos: List<Repo> get() = when (Config.repoOrder) {
Config.Value.ORDER_NAME -> "name COLLATE NOCASE" Config.Value.ORDER_NAME -> getReposNameOrder()
Config.Value.ORDER_DATE -> "last_update DESC" else -> getReposDateOrder()
else -> "" }
})
var etagKey: String var etagKey: String
set(etag) = addEtagRaw(RepoEtag(0, etag)) set(etag) = addEtagRaw(RepoEtag(0, etag))
@ -24,8 +23,11 @@ abstract class RepoDao {
clearEtag() clearEtag()
} }
@Query("SELECT * FROM repos ORDER BY :order") @Query("SELECT * FROM repos ORDER BY last_update DESC")
protected abstract fun getReposWithOrder(order: String): List<Repo> protected abstract fun getReposDateOrder(): List<Repo>
@Query("SELECT * FROM repos ORDER BY name COLLATE NOCASE")
protected abstract fun getReposNameOrder(): List<Repo>
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun addRepo(repo: Repo) abstract fun addRepo(repo: Repo)