diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/RepositoryDao.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/RepositoryDao.kt index ebd827cd5..946c31332 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/RepositoryDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/RepositoryDao.kt @@ -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 { @Query("DELETE FROM repos") + @Transaction override fun deleteAll() @Query("SELECT * FROM repos") diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/ModuleRepository.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/ModuleRepository.kt index 407e3ee1d..86ac5f319 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/ModuleRepository.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/ModuleRepository.kt @@ -1,7 +1,6 @@ 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() } - .flatMap { if (it.isEmpty()) fetchRemoteRepos() else it.toSingle() } - .doOnSuccess { fetchRemoteRepos().subscribeK() } // cache changed for next time or next hot reload + fun fetchModules(force: Boolean = false) = + if (force) fetchRemoteRepos() else Single.fromCallable { repoDao.fetchAll() } + .flatMap { if (it.isEmpty()) fetchRemoteRepos() else it.toSingle() } private fun fetchRemoteRepos() = fetchAllRepos() .map { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index 9d898b2a9..b878b4c87 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -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 } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt index 2ed02d623..61e4c57f8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ReposFragment.kt @@ -56,7 +56,7 @@ class ReposFragment : MagiskFragment(), Config.get(Config.Key.REPO_ORDER)!! ) { d, which -> Config.set(Config.Key.REPO_ORDER, which) - viewModel.refresh() + viewModel.refresh(false) d.dismiss() }.show() } diff --git a/app/src/main/res/layout/fragment_modules.xml b/app/src/main/res/layout/fragment_modules.xml index d8492a4d0..6c6b8f6da 100644 --- a/app/src/main/res/layout/fragment_modules.xml +++ b/app/src/main/res/layout/fragment_modules.xml @@ -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}">