Fixed updating lists being to heavy for the UI thread
Moved list diff recalculation to the computing thread instead
This commit is contained in:
parent
3f748b4d2a
commit
a181fa0652
@ -18,6 +18,7 @@ import com.topjohnwu.magisk.model.events.HideProcessEvent
|
|||||||
import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
||||||
import com.topjohnwu.magisk.utils.Utils
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
import com.topjohnwu.magisk.utils.toSingle
|
import com.topjohnwu.magisk.utils.toSingle
|
||||||
|
import com.topjohnwu.magisk.utils.update
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
||||||
@ -31,7 +32,7 @@ class HideViewModel(
|
|||||||
val query = KObservableField("")
|
val query = KObservableField("")
|
||||||
val isShowSystem = KObservableField(false)
|
val isShowSystem = KObservableField(false)
|
||||||
|
|
||||||
private val allItems = DiffObservableList(ComparableRvItem.callback)
|
private val allItems = mutableListOf<ComparableRvItem<*>>()
|
||||||
val items = DiffObservableList(ComparableRvItem.callback)
|
val items = DiffObservableList(ComparableRvItem.callback)
|
||||||
val itemBinding = OnItemBind<ComparableRvItem<*>> { itemBinding, _, item ->
|
val itemBinding = OnItemBind<ComparableRvItem<*>> { itemBinding, _, item ->
|
||||||
item.bind(itemBinding)
|
item.bind(itemBinding)
|
||||||
@ -72,16 +73,21 @@ class HideViewModel(
|
|||||||
.map { HideRvItem(it, hideTargets.blockingGet()) }
|
.map { HideRvItem(it, hideTargets.blockingGet()) }
|
||||||
.toList()
|
.toList()
|
||||||
.map { it.sortBy { it.item.info.name }; it }
|
.map { it.sortBy { it.item.info.name }; it }
|
||||||
|
.doOnSuccess { allItems.update(it) }
|
||||||
|
.flatMap { queryRaw() }
|
||||||
.applyViewModel(this)
|
.applyViewModel(this)
|
||||||
.subscribeK(onError = Timber::e) {
|
.subscribeK(onError = Timber::e) { items.update(it.first, it.second) }
|
||||||
allItems.update(it)
|
|
||||||
query()
|
|
||||||
}
|
|
||||||
.add()
|
.add()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun query(showSystem: Boolean = isShowSystem.value, query: String = this.query.value) {
|
private fun query() = queryRaw()
|
||||||
allItems.toSingle()
|
.subscribeK { items.update(it.first, it.second) }
|
||||||
|
.add()
|
||||||
|
|
||||||
|
private fun queryRaw(
|
||||||
|
showSystem: Boolean = isShowSystem.value,
|
||||||
|
query: String = this.query.value
|
||||||
|
) = allItems.toSingle()
|
||||||
.map { it.filterIsInstance<HideRvItem>() }
|
.map { it.filterIsInstance<HideRvItem>() }
|
||||||
.flattenAsFlowable { it }
|
.flattenAsFlowable { it }
|
||||||
.filter {
|
.filter {
|
||||||
@ -90,9 +96,7 @@ class HideViewModel(
|
|||||||
}
|
}
|
||||||
.filter { if (showSystem) true else it.item.info.flags and ApplicationInfo.FLAG_SYSTEM == 0 }
|
.filter { if (showSystem) true else it.item.info.flags and ApplicationInfo.FLAG_SYSTEM == 0 }
|
||||||
.toList()
|
.toList()
|
||||||
.subscribeK { items.update(it) }
|
.map { it to items.calculateDiff(it) }
|
||||||
.add()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun toggleItem(item: HideProcessRvItem) {
|
private fun toggleItem(item: HideProcessRvItem) {
|
||||||
val state = if (item.isHidden.value) "add" else "rm"
|
val state = if (item.isHidden.value) "add" else "rm"
|
||||||
|
@ -20,6 +20,7 @@ import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
|||||||
import com.topjohnwu.magisk.utils.Event
|
import com.topjohnwu.magisk.utils.Event
|
||||||
import com.topjohnwu.magisk.utils.Utils
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
import com.topjohnwu.magisk.utils.toSingle
|
import com.topjohnwu.magisk.utils.toSingle
|
||||||
|
import com.topjohnwu.magisk.utils.update
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
import me.tatarka.bindingcollectionadapter2.OnItemBind
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ class ModuleViewModel(
|
|||||||
|
|
||||||
val query = KObservableField("")
|
val query = KObservableField("")
|
||||||
|
|
||||||
private val allItems = DiffObservableList(ComparableRvItem.callback)
|
private val allItems = mutableListOf<ComparableRvItem<*>>()
|
||||||
|
|
||||||
val itemsInstalled = DiffObservableList(ComparableRvItem.callback)
|
val itemsInstalled = DiffObservableList(ComparableRvItem.callback)
|
||||||
val itemsRemote = DiffObservableList(ComparableRvItem.callback)
|
val itemsRemote = DiffObservableList(ComparableRvItem.callback)
|
||||||
@ -73,16 +74,18 @@ class ModuleViewModel(
|
|||||||
.flattenAsFlowable { it }
|
.flattenAsFlowable { it }
|
||||||
.map { RepoRvItem(it) }
|
.map { RepoRvItem(it) }
|
||||||
.toList()
|
.toList()
|
||||||
|
.doOnSuccess { allItems.update(it) }
|
||||||
|
.flatMap { queryRaw() }
|
||||||
.applyViewModel(this)
|
.applyViewModel(this)
|
||||||
.subscribeK {
|
.subscribeK { itemsRemote.update(it.first, it.second) }
|
||||||
allItems.update(it)
|
|
||||||
query()
|
|
||||||
}
|
|
||||||
.add()
|
.add()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun query(query: String = this.query.value) {
|
private fun query() = queryRaw()
|
||||||
allItems.toSingle()
|
.subscribeK { itemsRemote.update(it.first, it.second) }
|
||||||
|
.add()
|
||||||
|
|
||||||
|
private fun queryRaw(query: String = this.query.value) = allItems.toSingle()
|
||||||
.map { it.filterIsInstance<RepoRvItem>() }
|
.map { it.filterIsInstance<RepoRvItem>() }
|
||||||
.flattenAsFlowable { it }
|
.flattenAsFlowable { it }
|
||||||
.filter {
|
.filter {
|
||||||
@ -91,9 +94,7 @@ class ModuleViewModel(
|
|||||||
it.item.description.contains(query, ignoreCase = true)
|
it.item.description.contains(query, ignoreCase = true)
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
.subscribeK { itemsRemote.update(it) }
|
.map { it to itemsRemote.calculateDiff(it) }
|
||||||
.add()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <Result> Cursor.toList(transformer: (Cursor) -> Result): List<Result> {
|
private fun <Result> Cursor.toList(transformer: (Cursor) -> Result): List<Result> {
|
||||||
val out = mutableListOf<Result>()
|
val out = mutableListOf<Result>()
|
||||||
|
6
app/src/main/java/com/topjohnwu/magisk/utils/XList.kt
Normal file
6
app/src/main/java/com/topjohnwu/magisk/utils/XList.kt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package com.topjohnwu.magisk.utils
|
||||||
|
|
||||||
|
fun <T> MutableList<T>.update(newList: List<T>) {
|
||||||
|
clear()
|
||||||
|
addAll(newList)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user