You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Removed events from modules / replaced with retrofit/rx
This commit is contained in:
@@ -10,28 +10,22 @@ import com.skoumal.teanity.util.DiffObservableList
|
||||
import com.skoumal.teanity.util.KObservableField
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
||||
import com.topjohnwu.magisk.model.entity.OldModule
|
||||
import com.topjohnwu.magisk.model.entity.Repo
|
||||
import com.topjohnwu.magisk.data.repository.ModuleRepository
|
||||
import com.topjohnwu.magisk.model.entity.recycler.ModuleRvItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.RepoRvItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.SectionRvItem
|
||||
import com.topjohnwu.magisk.model.events.InstallModuleEvent
|
||||
import com.topjohnwu.magisk.model.events.OpenChangelogEvent
|
||||
import com.topjohnwu.magisk.model.events.OpenFilePickerEvent
|
||||
import com.topjohnwu.magisk.tasks.UpdateRepos
|
||||
import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
||||
import com.topjohnwu.magisk.utils.Event
|
||||
import com.topjohnwu.magisk.utils.Utils
|
||||
import com.topjohnwu.magisk.utils.toSingle
|
||||
import com.topjohnwu.magisk.utils.update
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.disposables.Disposable
|
||||
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
||||
|
||||
class ModuleViewModel(
|
||||
private val repoDatabase: RepoDatabaseHelper,
|
||||
private val resources: Resources
|
||||
private val resources: Resources,
|
||||
private val moduleRepo: ModuleRepository
|
||||
) : MagiskViewModel() {
|
||||
|
||||
val query = KObservableField("")
|
||||
@@ -52,36 +46,15 @@ class ModuleViewModel(
|
||||
queryDisposable?.dispose()
|
||||
queryDisposable = query()
|
||||
}
|
||||
Event.register(this)
|
||||
refresh()
|
||||
}
|
||||
|
||||
override fun getListeningEvents(): IntArray {
|
||||
return intArrayOf(Event.MODULE_LOAD_DONE, Event.REPO_LOAD_DONE)
|
||||
}
|
||||
|
||||
override fun onEvent(event: Int) = when (event) {
|
||||
Event.MODULE_LOAD_DONE -> updateModules(Event.getResult(event))
|
||||
Event.REPO_LOAD_DONE -> updateRepos()
|
||||
else -> Unit
|
||||
}
|
||||
|
||||
fun fabPressed() = OpenFilePickerEvent().publish()
|
||||
fun repoPressed(item: RepoRvItem) = OpenChangelogEvent(item.item).publish()
|
||||
fun downloadPressed(item: RepoRvItem) = InstallModuleEvent(item.item).publish()
|
||||
|
||||
fun refresh() {
|
||||
state = State.LOADING
|
||||
Utils.loadModules(true)
|
||||
UpdateRepos().exec(true)
|
||||
}
|
||||
|
||||
private fun updateModules(result: Map<String, OldModule>) = result.values
|
||||
.map { ModuleRvItem(it) }
|
||||
.let { itemsInstalled.update(it) }
|
||||
|
||||
internal fun updateRepos() {
|
||||
Single.fromCallable { repoDatabase.repoCursor.toList { Repo(it) } }
|
||||
moduleRepo.fetchModules()
|
||||
.flattenAsFlowable { it }
|
||||
.map { RepoRvItem(it) }
|
||||
.toList()
|
||||
@@ -89,7 +62,13 @@ class ModuleViewModel(
|
||||
.flatMap { queryRaw() }
|
||||
.applyViewModel(this)
|
||||
.subscribeK { itemsRemote.update(it.first, it.second) }
|
||||
.add()
|
||||
|
||||
moduleRepo.fetchInstalledModules()
|
||||
.flattenAsFlowable { it }
|
||||
.map { ModuleRvItem(it) }
|
||||
.toList()
|
||||
.map { it to itemsInstalled.calculateDiff(it) }
|
||||
.subscribeK { itemsInstalled.update(it.first, it.second) }
|
||||
}
|
||||
|
||||
private fun query() = queryRaw()
|
||||
|
||||
@@ -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.updateRepos()
|
||||
viewModel.refresh()
|
||||
d.dismiss()
|
||||
}.show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user