Cleaned up usage of rx subscribers
This commit is contained in:
parent
2d55632430
commit
ad80804461
@ -5,6 +5,7 @@ import android.content.res.Resources
|
|||||||
import com.skoumal.teanity.databinding.ComparableRvItem
|
import com.skoumal.teanity.databinding.ComparableRvItem
|
||||||
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
import com.skoumal.teanity.extensions.addOnPropertyChangedCallback
|
||||||
import com.skoumal.teanity.extensions.applySchedulers
|
import com.skoumal.teanity.extensions.applySchedulers
|
||||||
|
import com.skoumal.teanity.extensions.subscribeK
|
||||||
import com.skoumal.teanity.util.DiffObservableList
|
import com.skoumal.teanity.util.DiffObservableList
|
||||||
import com.skoumal.teanity.viewevents.SnackbarEvent
|
import com.skoumal.teanity.viewevents.SnackbarEvent
|
||||||
import com.topjohnwu.magisk.BR
|
import com.topjohnwu.magisk.BR
|
||||||
@ -19,7 +20,6 @@ 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 me.tatarka.bindingcollectionadapter2.ItemBinding
|
import me.tatarka.bindingcollectionadapter2.ItemBinding
|
||||||
import timber.log.Timber
|
|
||||||
|
|
||||||
class SuperuserViewModel(
|
class SuperuserViewModel(
|
||||||
private val database: MagiskDB,
|
private val database: MagiskDB,
|
||||||
@ -46,17 +46,13 @@ class SuperuserViewModel(
|
|||||||
.toList()
|
.toList()
|
||||||
.applySchedulers()
|
.applySchedulers()
|
||||||
.applyViewModel(this)
|
.applyViewModel(this)
|
||||||
.subscribe({
|
.subscribeK { items.update(it) }
|
||||||
items.update(it)
|
|
||||||
}, Timber::e)
|
|
||||||
.add()
|
.add()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deletePressed(item: PolicyRvItem) {
|
fun deletePressed(item: PolicyRvItem) {
|
||||||
fun updateState() = deletePolicy(item.item)
|
fun updateState() = deletePolicy(item.item)
|
||||||
.subscribe({
|
.subscribeK { items.remove(item) }
|
||||||
items.remove(item)
|
|
||||||
}, Timber::e)
|
|
||||||
.add()
|
.add()
|
||||||
|
|
||||||
withView {
|
withView {
|
||||||
@ -88,11 +84,11 @@ class SuperuserViewModel(
|
|||||||
|
|
||||||
updatePolicy(item)
|
updatePolicy(item)
|
||||||
.map { it.policy == Policy.ALLOW }
|
.map { it.policy == Policy.ALLOW }
|
||||||
.subscribe({
|
.subscribeK {
|
||||||
val textId = if (it) R.string.su_snack_grant else R.string.su_snack_deny
|
val textId = if (it) R.string.su_snack_grant else R.string.su_snack_deny
|
||||||
val text = resources.getString(textId).format(item.appName)
|
val text = resources.getString(textId).format(item.appName)
|
||||||
SnackbarEvent(text).publish()
|
SnackbarEvent(text).publish()
|
||||||
}, Timber::e)
|
}
|
||||||
.add()
|
.add()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,11 +109,11 @@ class SuperuserViewModel(
|
|||||||
|
|
||||||
updatePolicy(item)
|
updatePolicy(item)
|
||||||
.map { it.notification }
|
.map { it.notification }
|
||||||
.subscribe({
|
.subscribeK {
|
||||||
val textId = if (it) R.string.su_snack_notif_on else R.string.su_snack_notif_off
|
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)
|
val text = resources.getString(textId).format(item.appName)
|
||||||
SnackbarEvent(text).publish()
|
SnackbarEvent(text).publish()
|
||||||
}, Timber::e)
|
}
|
||||||
.add()
|
.add()
|
||||||
}
|
}
|
||||||
shouldLog.addOnPropertyChangedCallback {
|
shouldLog.addOnPropertyChangedCallback {
|
||||||
@ -126,11 +122,11 @@ class SuperuserViewModel(
|
|||||||
|
|
||||||
updatePolicy(item)
|
updatePolicy(item)
|
||||||
.map { it.logging }
|
.map { it.logging }
|
||||||
.subscribe({
|
.subscribeK {
|
||||||
val textId = if (it) R.string.su_snack_log_on else R.string.su_snack_log_off
|
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)
|
val text = resources.getString(textId).format(item.appName)
|
||||||
SnackbarEvent(text).publish()
|
SnackbarEvent(text).publish()
|
||||||
}, Timber::e)
|
}
|
||||||
.add()
|
.add()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user