mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-06 07:20:47 -05:00
Remove RxBus
This commit is contained in:
@@ -4,22 +4,22 @@ import androidx.databinding.Bindable
|
||||
import androidx.databinding.ObservableField
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.extensions.subscribeK
|
||||
import com.topjohnwu.magisk.extensions.value
|
||||
import com.topjohnwu.magisk.model.events.SafetyNetResult
|
||||
import com.topjohnwu.magisk.model.events.UpdateSafetyNetEvent
|
||||
import com.topjohnwu.magisk.model.events.CheckSafetyNetEvent
|
||||
import com.topjohnwu.magisk.ui.base.BaseViewModel
|
||||
import com.topjohnwu.magisk.ui.safetynet.SafetyNetState.*
|
||||
import com.topjohnwu.magisk.utils.RxBus
|
||||
import org.json.JSONObject
|
||||
|
||||
enum class SafetyNetState {
|
||||
LOADING, PASS, FAILED, IDLE
|
||||
}
|
||||
|
||||
class SafetynetViewModel(
|
||||
rxBus: RxBus
|
||||
) : BaseViewModel() {
|
||||
data class SafetyNetResult(
|
||||
val response: JSONObject? = null,
|
||||
val dismiss: Boolean = false
|
||||
)
|
||||
|
||||
class SafetynetViewModel : BaseViewModel() {
|
||||
|
||||
private var currentState = IDLE
|
||||
set(value) {
|
||||
@@ -36,10 +36,6 @@ class SafetynetViewModel(
|
||||
val isSuccess @Bindable get() = currentState == PASS
|
||||
|
||||
init {
|
||||
rxBus.register<SafetyNetResult>()
|
||||
.subscribeK { resolveResponse(it) }
|
||||
.add()
|
||||
|
||||
cachedResult?.also {
|
||||
resolveResponse(SafetyNetResult(it))
|
||||
} ?: attest()
|
||||
@@ -54,7 +50,9 @@ class SafetynetViewModel(
|
||||
|
||||
private fun attest() {
|
||||
currentState = LOADING
|
||||
UpdateSafetyNetEvent().publish()
|
||||
CheckSafetyNetEvent {
|
||||
resolveResponse(it)
|
||||
}.publish()
|
||||
}
|
||||
|
||||
fun reset() = attest()
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.topjohnwu.magisk.extensions.toggle
|
||||
import com.topjohnwu.magisk.model.entity.recycler.PolicyItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.TappableHeadlineItem
|
||||
import com.topjohnwu.magisk.model.entity.recycler.TextItem
|
||||
import com.topjohnwu.magisk.model.events.PolicyUpdateEvent
|
||||
import com.topjohnwu.magisk.model.events.SnackbarEvent
|
||||
import com.topjohnwu.magisk.model.events.dialog.BiometricDialog
|
||||
import com.topjohnwu.magisk.model.events.dialog.SuperuserRevokeDialog
|
||||
@@ -110,24 +109,19 @@ class SuperuserViewModel(
|
||||
|
||||
//---
|
||||
|
||||
fun updatePolicy(it: PolicyUpdateEvent) = viewModelScope.launch {
|
||||
val snackStr = when (it) {
|
||||
is PolicyUpdateEvent.Notification -> {
|
||||
updatePolicy(it.item)
|
||||
when {
|
||||
it.item.notification -> R.string.su_snack_notif_on
|
||||
else -> R.string.su_snack_notif_off
|
||||
}
|
||||
fun updatePolicy(policy: MagiskPolicy, isLogging: Boolean) = viewModelScope.launch {
|
||||
db.update(policy)
|
||||
val str = when {
|
||||
isLogging -> when {
|
||||
policy.logging -> R.string.su_snack_log_on
|
||||
else -> R.string.su_snack_log_off
|
||||
}
|
||||
is PolicyUpdateEvent.Log -> {
|
||||
updatePolicy(it.item)
|
||||
when {
|
||||
it.item.logging -> R.string.su_snack_log_on
|
||||
else -> R.string.su_snack_log_off
|
||||
}
|
||||
else -> when {
|
||||
policy.notification -> R.string.su_snack_notif_on
|
||||
else -> R.string.su_snack_notif_off
|
||||
}
|
||||
}
|
||||
SnackbarEvent(resources.getString(snackStr, it.item.appName)).publish()
|
||||
SnackbarEvent(resources.getString(str, policy.appName)).publish()
|
||||
}
|
||||
|
||||
fun togglePolicy(item: PolicyItem, enable: Boolean) {
|
||||
@@ -136,7 +130,7 @@ class SuperuserViewModel(
|
||||
val app = item.item.copy(policy = policy)
|
||||
|
||||
viewModelScope.launch {
|
||||
updatePolicy(app)
|
||||
db.update(app)
|
||||
val res = if (app.policy == MagiskPolicy.ALLOW) R.string.su_snack_grant
|
||||
else R.string.su_snack_deny
|
||||
SnackbarEvent(resources.getString(res).format(item.item.appName))
|
||||
@@ -152,9 +146,4 @@ class SuperuserViewModel(
|
||||
updateState()
|
||||
}
|
||||
}
|
||||
|
||||
//---
|
||||
|
||||
private suspend fun updatePolicy(policy: MagiskPolicy) = db.update(policy)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user