From 7e5f2822aebdd45d2178187c82ed7e5be322ead7 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Tue, 18 Jun 2019 11:54:11 +0200 Subject: [PATCH] Fix superuser fragment crashes Fix superuser screen encountering inconsistencies when refreshing the data rapidly --- .../com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index df1564e9c..ea70e895b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -22,6 +22,7 @@ import com.topjohnwu.magisk.utils.toggle import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog import io.reactivex.Single +import io.reactivex.disposables.Disposable import me.tatarka.bindingcollectionadapter2.ItemBinding class SuperuserViewModel( @@ -38,6 +39,7 @@ class SuperuserViewModel( } private var ignoreNext: PolicyRvItem? = null + private var fetchTask: Disposable? = null init { rxBus.register() @@ -51,7 +53,8 @@ class SuperuserViewModel( } fun updatePolicies() { - appRepo.fetchAll() + fetchTask?.dispose() + fetchTask = appRepo.fetchAll() .flattenAsFlowable { it } .map { PolicyRvItem(it, it.applicationInfo.loadIcon(packageManager)) } .toList() @@ -65,7 +68,6 @@ class SuperuserViewModel( .applySchedulers() .applyViewModel(this) .subscribeK { items.update(it.first, it.second) } - .add() } fun deletePressed(item: PolicyRvItem) {