Commit 6e1aefe6 authored by Viktor De Pasquale's avatar Viktor De Pasquale

Added feature that prevents repositories from being downloaded every single...

Added feature that prevents repositories from being downloaded every single time that user requests to show Module/Download fragment unless requested by user
parent 1c90b6ec
......@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.data.database
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import com.skoumal.teanity.database.BaseDao
import com.topjohnwu.magisk.model.entity.Repository
......@@ -9,6 +10,7 @@ import com.topjohnwu.magisk.model.entity.Repository
interface RepositoryDao : BaseDao<Repository> {
@Query("DELETE FROM repos")
@Transaction
override fun deleteAll()
@Query("SELECT * FROM repos")
......
package com.topjohnwu.magisk.data.repository
import android.content.Context
import com.skoumal.teanity.extensions.subscribeK
import com.topjohnwu.magisk.data.database.RepositoryDao
import com.topjohnwu.magisk.data.network.GithubApiServices
import com.topjohnwu.magisk.data.network.GithubRawApiServices
......@@ -23,9 +22,9 @@ class ModuleRepository(
private val repoDao: RepositoryDao
) {
fun fetchModules() = Single.fromCallable { repoDao.fetchAll() }
fun fetchModules(force: Boolean = false) =
if (force) fetchRemoteRepos() else Single.fromCallable { repoDao.fetchAll() }
.flatMap { if (it.isEmpty()) fetchRemoteRepos() else it.toSingle() }
.doOnSuccess { fetchRemoteRepos().subscribeK() } // cache changed for next time or next hot reload
private fun fetchRemoteRepos() = fetchAllRepos()
.map {
......
......@@ -48,14 +48,14 @@ class ModuleViewModel(
queryDisposable?.dispose()
queryDisposable = query()
}
refresh()
refresh(false)
}
fun fabPressed() = OpenFilePickerEvent().publish()
fun repoPressed(item: RepoRvItem) = OpenChangelogEvent(item.item).publish()
fun downloadPressed(item: RepoRvItem) = InstallModuleEvent(item.item).publish()
fun refresh() {
fun refresh(forceReload: Boolean) {
val updateInstalled = moduleRepo.fetchInstalledModules()
.flattenAsFlowable { it }
.map { ModuleRvItem(it) }
......@@ -63,7 +63,7 @@ class ModuleViewModel(
.map { it to itemsInstalled.calculateDiff(it) }
.doOnSuccessUi { itemsInstalled.update(it.first, it.second) }
val updateRemote = moduleRepo.fetchModules()
val updateRemote = moduleRepo.fetchModules(forceReload)
zip(updateInstalled, updateRemote) { _, remote -> remote }
.flattenAsFlowable { it }
......
......@@ -56,7 +56,7 @@ class ReposFragment : MagiskFragment<ModuleViewModel, FragmentReposBinding>(),
Config.get<Int>(Config.Key.REPO_ORDER)!!
) { d, which ->
Config.set(Config.Key.REPO_ORDER, which)
viewModel.refresh()
viewModel.refresh(false)
d.dismiss()
}.show()
}
......
......@@ -21,7 +21,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:onRefreshListener="@{() -> viewModel.refresh()}"
app:onRefreshListener="@{() -> viewModel.refresh(false)}"
app:refreshing="@{viewModel.loading}">
<androidx.recyclerview.widget.RecyclerView
......
......@@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:onRefreshListener="@{() -> viewModel.refresh()}"
app:onRefreshListener="@{() -> viewModel.refresh(true)}"
app:refreshing="@{viewModel.loading}">
<androidx.recyclerview.widget.RecyclerView
......
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