Commit 7e5f2822 authored by Viktor De Pasquale's avatar Viktor De Pasquale Committed by topjohnwu

Fix superuser fragment crashes

Fix superuser screen encountering inconsistencies when refreshing the data rapidly
parent 12bbc7fd
...@@ -22,6 +22,7 @@ import com.topjohnwu.magisk.utils.toggle ...@@ -22,6 +22,7 @@ import com.topjohnwu.magisk.utils.toggle
import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog
import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.disposables.Disposable
import me.tatarka.bindingcollectionadapter2.ItemBinding import me.tatarka.bindingcollectionadapter2.ItemBinding
class SuperuserViewModel( class SuperuserViewModel(
...@@ -38,6 +39,7 @@ class SuperuserViewModel( ...@@ -38,6 +39,7 @@ class SuperuserViewModel(
} }
private var ignoreNext: PolicyRvItem? = null private var ignoreNext: PolicyRvItem? = null
private var fetchTask: Disposable? = null
init { init {
rxBus.register<PolicyEnableEvent>() rxBus.register<PolicyEnableEvent>()
...@@ -51,7 +53,8 @@ class SuperuserViewModel( ...@@ -51,7 +53,8 @@ class SuperuserViewModel(
} }
fun updatePolicies() { fun updatePolicies() {
appRepo.fetchAll() fetchTask?.dispose()
fetchTask = appRepo.fetchAll()
.flattenAsFlowable { it } .flattenAsFlowable { it }
.map { PolicyRvItem(it, it.applicationInfo.loadIcon(packageManager)) } .map { PolicyRvItem(it, it.applicationInfo.loadIcon(packageManager)) }
.toList() .toList()
...@@ -65,7 +68,6 @@ class SuperuserViewModel( ...@@ -65,7 +68,6 @@ class SuperuserViewModel(
.applySchedulers() .applySchedulers()
.applyViewModel(this) .applyViewModel(this)
.subscribeK { items.update(it.first, it.second) } .subscribeK { items.update(it.first, it.second) }
.add()
} }
fun deletePressed(item: PolicyRvItem) { fun deletePressed(item: PolicyRvItem) {
......
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