You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Do not hold resources in SuperuserViewModel
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.topjohnwu.magisk.ui.superuser
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.databinding.ObservableArrayList
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.topjohnwu.magisk.BR
|
||||
@@ -19,6 +18,7 @@ import com.topjohnwu.magisk.events.SnackbarEvent
|
||||
import com.topjohnwu.magisk.events.dialog.BiometricEvent
|
||||
import com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog
|
||||
import com.topjohnwu.magisk.utils.Utils
|
||||
import com.topjohnwu.magisk.utils.asTransitive
|
||||
import com.topjohnwu.magisk.view.TappableHeadlineItem
|
||||
import com.topjohnwu.magisk.view.TextItem
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -27,8 +27,7 @@ import kotlinx.coroutines.withContext
|
||||
import me.tatarka.bindingcollectionadapter2.collections.MergeObservableList
|
||||
|
||||
class SuperuserViewModel(
|
||||
private val db: PolicyDao,
|
||||
private val resources: Resources
|
||||
private val db: PolicyDao
|
||||
) : BaseViewModel(), TappableHeadlineItem.Listener {
|
||||
|
||||
private val itemNoData = TextItem(R.string.superuser_policy_none)
|
||||
@@ -107,7 +106,7 @@ class SuperuserViewModel(
|
||||
|
||||
fun updatePolicy(policy: SuPolicy, isLogging: Boolean) = viewModelScope.launch {
|
||||
db.update(policy)
|
||||
val str = when {
|
||||
val res = when {
|
||||
isLogging -> when {
|
||||
policy.logging -> R.string.su_snack_log_on
|
||||
else -> R.string.su_snack_log_off
|
||||
@@ -117,7 +116,7 @@ class SuperuserViewModel(
|
||||
else -> R.string.su_snack_notif_off
|
||||
}
|
||||
}
|
||||
SnackbarEvent(resources.getString(str, policy.appName)).publish()
|
||||
SnackbarEvent(res.asTransitive(policy.appName)).publish()
|
||||
}
|
||||
|
||||
fun togglePolicy(item: PolicyRvItem, enable: Boolean) {
|
||||
@@ -131,7 +130,7 @@ class SuperuserViewModel(
|
||||
db.update(app)
|
||||
val res = if (app.policy == SuPolicy.ALLOW) R.string.su_snack_grant
|
||||
else R.string.su_snack_deny
|
||||
SnackbarEvent(resources.getString(res).format(item.item.appName)).publish()
|
||||
SnackbarEvent(res.asTransitive(item.item.appName)).publish()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user