Fixed cached repos not being ordered by settings

This commit is contained in:
Viktor De Pasquale 2019-05-25 18:03:32 +02:00
parent 6e1aefe6d8
commit 8cd3b603df
2 changed files with 14 additions and 2 deletions

View File

@ -13,7 +13,10 @@ interface RepositoryDao : BaseDao<Repository> {
@Transaction
override fun deleteAll()
@Query("SELECT * FROM repos")
@Query("SELECT * FROM repos ORDER BY lastUpdate DESC")
override fun fetchAll(): List<Repository>
@Query("SELECT * FROM repos ORDER BY name ASC")
fun fetchAllOrderByName(): List<Repository>
}

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.data.repository
import android.content.Context
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.data.database.RepositoryDao
import com.topjohnwu.magisk.data.network.GithubApiServices
import com.topjohnwu.magisk.data.network.GithubRawApiServices
@ -23,7 +24,7 @@ class ModuleRepository(
) {
fun fetchModules(force: Boolean = false) =
if (force) fetchRemoteRepos() else Single.fromCallable { repoDao.fetchAll() }
if (force) fetchRemoteRepos() else fetchCachedOrdered()
.flatMap { if (it.isEmpty()) fetchRemoteRepos() else it.toSingle() }
private fun fetchRemoteRepos() = fetchAllRepos()
@ -36,6 +37,14 @@ class ModuleRepository(
}
.doOnSuccess { repoDao.insert(it) }
private fun fetchCachedOrdered() = Single.fromCallable {
when (Config.get<Int>(Config.Key.REPO_ORDER)) {
Config.Value.ORDER_DATE -> repoDao.fetchAll()
Config.Value.ORDER_NAME -> repoDao.fetchAllOrderByName()
else -> repoDao.fetchAll()
}
}
fun fetchInstalledModules() = Single.fromCallable { Utils.loadModulesLeanback() }
.map { it.values.toList() }