Fixed cached repos not being ordered by settings
This commit is contained in:
parent
6e1aefe6d8
commit
8cd3b603df
@ -13,7 +13,10 @@ interface RepositoryDao : BaseDao<Repository> {
|
|||||||
@Transaction
|
@Transaction
|
||||||
override fun deleteAll()
|
override fun deleteAll()
|
||||||
|
|
||||||
@Query("SELECT * FROM repos")
|
@Query("SELECT * FROM repos ORDER BY lastUpdate DESC")
|
||||||
override fun fetchAll(): List<Repository>
|
override fun fetchAll(): List<Repository>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM repos ORDER BY name ASC")
|
||||||
|
fun fetchAllOrderByName(): List<Repository>
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk.data.repository
|
package com.topjohnwu.magisk.data.repository
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import com.topjohnwu.magisk.Config
|
||||||
import com.topjohnwu.magisk.data.database.RepositoryDao
|
import com.topjohnwu.magisk.data.database.RepositoryDao
|
||||||
import com.topjohnwu.magisk.data.network.GithubApiServices
|
import com.topjohnwu.magisk.data.network.GithubApiServices
|
||||||
import com.topjohnwu.magisk.data.network.GithubRawApiServices
|
import com.topjohnwu.magisk.data.network.GithubRawApiServices
|
||||||
@ -23,7 +24,7 @@ class ModuleRepository(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
fun fetchModules(force: Boolean = false) =
|
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() }
|
.flatMap { if (it.isEmpty()) fetchRemoteRepos() else it.toSingle() }
|
||||||
|
|
||||||
private fun fetchRemoteRepos() = fetchAllRepos()
|
private fun fetchRemoteRepos() = fetchAllRepos()
|
||||||
@ -36,6 +37,14 @@ class ModuleRepository(
|
|||||||
}
|
}
|
||||||
.doOnSuccess { repoDao.insert(it) }
|
.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() }
|
fun fetchInstalledModules() = Single.fromCallable { Utils.loadModulesLeanback() }
|
||||||
.map { it.values.toList() }
|
.map { it.values.toList() }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user