From ad808044617b693b1c23ec067e3473ec836e829d Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Fri, 19 Apr 2019 16:41:17 +0200 Subject: [PATCH] Cleaned up usage of rx subscribers --- .../magisk/ui/superuser/SuperuserViewModel.kt | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 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 bf5e0935c..36de6183e 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 @@ -5,6 +5,7 @@ import android.content.res.Resources import com.skoumal.teanity.databinding.ComparableRvItem import com.skoumal.teanity.extensions.addOnPropertyChangedCallback import com.skoumal.teanity.extensions.applySchedulers +import com.skoumal.teanity.extensions.subscribeK import com.skoumal.teanity.util.DiffObservableList import com.skoumal.teanity.viewevents.SnackbarEvent import com.topjohnwu.magisk.BR @@ -19,7 +20,6 @@ import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog import io.reactivex.Single import me.tatarka.bindingcollectionadapter2.ItemBinding -import timber.log.Timber class SuperuserViewModel( private val database: MagiskDB, @@ -46,17 +46,13 @@ class SuperuserViewModel( .toList() .applySchedulers() .applyViewModel(this) - .subscribe({ - items.update(it) - }, Timber::e) + .subscribeK { items.update(it) } .add() } fun deletePressed(item: PolicyRvItem) { fun updateState() = deletePolicy(item.item) - .subscribe({ - items.remove(item) - }, Timber::e) + .subscribeK { items.remove(item) } .add() withView { @@ -88,11 +84,11 @@ class SuperuserViewModel( updatePolicy(item) .map { it.policy == Policy.ALLOW } - .subscribe({ + .subscribeK { val textId = if (it) R.string.su_snack_grant else R.string.su_snack_deny val text = resources.getString(textId).format(item.appName) SnackbarEvent(text).publish() - }, Timber::e) + } .add() } @@ -113,11 +109,11 @@ class SuperuserViewModel( updatePolicy(item) .map { it.notification } - .subscribe({ + .subscribeK { val textId = if (it) R.string.su_snack_notif_on else R.string.su_snack_notif_off val text = resources.getString(textId).format(item.appName) SnackbarEvent(text).publish() - }, Timber::e) + } .add() } shouldLog.addOnPropertyChangedCallback { @@ -126,11 +122,11 @@ class SuperuserViewModel( updatePolicy(item) .map { it.logging } - .subscribe({ + .subscribeK { val textId = if (it) R.string.su_snack_log_on else R.string.su_snack_log_off val text = resources.getString(textId).format(item.appName) SnackbarEvent(text).publish() - }, Timber::e) + } .add() } }