Commit 8cd3b603 authored by Viktor De Pasquale's avatar Viktor De Pasquale

Fixed cached repos not being ordered by settings

parent 6e1aefe6
......@@ -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>
}
\ No newline at end of file
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() }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment