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