mirror of
https://github.com/topjohnwu/Magisk
synced 2024-11-13 20:54:12 +01:00
Do not hold resources in SuperuserViewModel
This commit is contained in:
parent
7cb2806878
commit
0f95a7babe
@ -23,12 +23,10 @@ val viewModelModules = module {
|
||||
viewModel { ModuleViewModel(get(), get()) }
|
||||
viewModel { SafetynetViewModel() }
|
||||
viewModel { SettingsViewModel(get()) }
|
||||
viewModel { SuperuserViewModel(get(), get()) }
|
||||
viewModel { SuperuserViewModel(get()) }
|
||||
viewModel { ThemeViewModel() }
|
||||
viewModel { InstallViewModel(get()) }
|
||||
viewModel { MainViewModel() }
|
||||
|
||||
// Legacy
|
||||
viewModel { (args: FlashFragmentArgs) -> FlashViewModel(args) }
|
||||
viewModel { SuRequestViewModel(get(), get(), get(SUTimeout), get()) }
|
||||
}
|
||||
|
@ -7,31 +7,32 @@ import com.topjohnwu.magisk.arch.ActivityExecutor
|
||||
import com.topjohnwu.magisk.arch.BaseUIActivity
|
||||
import com.topjohnwu.magisk.arch.ViewEvent
|
||||
import com.topjohnwu.magisk.utils.TransitiveText
|
||||
import com.topjohnwu.magisk.utils.asTransitive
|
||||
|
||||
class SnackbarEvent private constructor(
|
||||
class SnackbarEvent constructor(
|
||||
private val msg: TransitiveText,
|
||||
private val length: Int,
|
||||
private val builder: Snackbar.() -> Unit
|
||||
private val length: Int = Snackbar.LENGTH_SHORT,
|
||||
private val builder: Snackbar.() -> Unit = {}
|
||||
) : ViewEvent(), ActivityExecutor {
|
||||
|
||||
constructor(
|
||||
@StringRes res: Int,
|
||||
length: Int = Snackbar.LENGTH_SHORT,
|
||||
builder: Snackbar.() -> Unit = {}
|
||||
) : this(TransitiveText.Res(res), length, builder)
|
||||
) : this(res.asTransitive(), length, builder)
|
||||
|
||||
constructor(
|
||||
message: String,
|
||||
msg: String,
|
||||
length: Int = Snackbar.LENGTH_SHORT,
|
||||
builder: Snackbar.() -> Unit = {}
|
||||
) : this(TransitiveText.String(message), length, builder)
|
||||
) : this(msg.asTransitive(), length, builder)
|
||||
|
||||
|
||||
private fun snackbar(
|
||||
view: View,
|
||||
message: String,
|
||||
length: Int = Snackbar.LENGTH_SHORT,
|
||||
builder: Snackbar.() -> Unit = {}
|
||||
length: Int,
|
||||
builder: Snackbar.() -> Unit
|
||||
) = Snackbar.make(view, message, length).apply(builder).show()
|
||||
|
||||
override fun invoke(activity: BaseUIActivity<*, *>) {
|
||||
@ -39,5 +40,4 @@ class SnackbarEvent private constructor(
|
||||
msg.getText(activity.resources).toString(),
|
||||
length, builder)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@ sealed class TransitiveText {
|
||||
companion object {
|
||||
val EMPTY = String("")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user