Commit 706d5306 authored by topjohnwu's avatar topjohnwu

Rename TransitiveText

parent 0f95a7ba
...@@ -5,7 +5,6 @@ import android.view.KeyEvent ...@@ -5,7 +5,6 @@ import android.view.KeyEvent
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.graphics.Insets
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.databinding.OnRebindCallback import androidx.databinding.OnRebindCallback
import androidx.databinding.ViewDataBinding import androidx.databinding.ViewDataBinding
......
...@@ -6,11 +6,11 @@ import com.google.android.material.snackbar.Snackbar ...@@ -6,11 +6,11 @@ import com.google.android.material.snackbar.Snackbar
import com.topjohnwu.magisk.arch.ActivityExecutor import com.topjohnwu.magisk.arch.ActivityExecutor
import com.topjohnwu.magisk.arch.BaseUIActivity import com.topjohnwu.magisk.arch.BaseUIActivity
import com.topjohnwu.magisk.arch.ViewEvent import com.topjohnwu.magisk.arch.ViewEvent
import com.topjohnwu.magisk.utils.TransitiveText import com.topjohnwu.magisk.utils.TextHolder
import com.topjohnwu.magisk.utils.asTransitive import com.topjohnwu.magisk.utils.asText
class SnackbarEvent constructor( class SnackbarEvent constructor(
private val msg: TransitiveText, private val msg: TextHolder,
private val length: Int = Snackbar.LENGTH_SHORT, private val length: Int = Snackbar.LENGTH_SHORT,
private val builder: Snackbar.() -> Unit = {} private val builder: Snackbar.() -> Unit = {}
) : ViewEvent(), ActivityExecutor { ) : ViewEvent(), ActivityExecutor {
...@@ -19,13 +19,13 @@ class SnackbarEvent constructor( ...@@ -19,13 +19,13 @@ class SnackbarEvent constructor(
@StringRes res: Int, @StringRes res: Int,
length: Int = Snackbar.LENGTH_SHORT, length: Int = Snackbar.LENGTH_SHORT,
builder: Snackbar.() -> Unit = {} builder: Snackbar.() -> Unit = {}
) : this(res.asTransitive(), length, builder) ) : this(res.asText(), length, builder)
constructor( constructor(
msg: String, msg: String,
length: Int = Snackbar.LENGTH_SHORT, length: Int = Snackbar.LENGTH_SHORT,
builder: Snackbar.() -> Unit = {} builder: Snackbar.() -> Unit = {}
) : this(msg.asTransitive(), length, builder) ) : this(msg.asText(), length, builder)
private fun snackbar( private fun snackbar(
......
...@@ -16,7 +16,7 @@ import com.topjohnwu.magisk.events.dialog.EnvFixDialog ...@@ -16,7 +16,7 @@ import com.topjohnwu.magisk.events.dialog.EnvFixDialog
import com.topjohnwu.magisk.events.dialog.ManagerInstallDialog import com.topjohnwu.magisk.events.dialog.ManagerInstallDialog
import com.topjohnwu.magisk.events.dialog.UninstallDialog import com.topjohnwu.magisk.events.dialog.UninstallDialog
import com.topjohnwu.magisk.ktx.await import com.topjohnwu.magisk.ktx.await
import com.topjohnwu.magisk.utils.asTransitive import com.topjohnwu.magisk.utils.asText
import com.topjohnwu.magisk.utils.set import com.topjohnwu.magisk.utils.set
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
...@@ -54,13 +54,13 @@ class HomeViewModel( ...@@ -54,13 +54,13 @@ class HomeViewModel(
val magiskInstalledVersion get() = Info.env.run { val magiskInstalledVersion get() = Info.env.run {
if (isActive) if (isActive)
"$magiskVersionString ($magiskVersionCode)".asTransitive() "$magiskVersionString ($magiskVersionCode)".asText()
else else
R.string.not_available.asTransitive() R.string.not_available.asText()
} }
@get:Bindable @get:Bindable
var managerRemoteVersion = R.string.loading.asTransitive() var managerRemoteVersion = R.string.loading.asText()
set(value) = set(value, field, { field = it }, BR.managerRemoteVersion) set(value) = set(value, field, { field = it }, BR.managerRemoteVersion)
val managerInstalledVersion = Info.stub?.let { val managerInstalledVersion = Info.stub?.let {
...@@ -92,14 +92,14 @@ class HomeViewModel( ...@@ -92,14 +92,14 @@ class HomeViewModel(
} }
managerRemoteVersion = managerRemoteVersion =
"${magisk.version} (${magisk.versionCode}) (${stub.versionCode})".asTransitive() "${magisk.version} (${magisk.versionCode}) (${stub.versionCode})".asText()
launch { launch {
ensureEnv() ensureEnv()
} }
} ?: { } ?: {
state = State.LOADING_FAILED state = State.LOADING_FAILED
managerRemoteVersion = R.string.not_available.asTransitive() managerRemoteVersion = R.string.not_available.asText()
}() }()
} }
......
...@@ -9,8 +9,8 @@ import androidx.databinding.Bindable ...@@ -9,8 +9,8 @@ import androidx.databinding.Bindable
import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.BR
import com.topjohnwu.magisk.R import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.ObservableItem import com.topjohnwu.magisk.databinding.ObservableItem
import com.topjohnwu.magisk.utils.TransitiveText import com.topjohnwu.magisk.utils.TextHolder
import com.topjohnwu.magisk.utils.asTransitive import com.topjohnwu.magisk.utils.asText
import com.topjohnwu.magisk.utils.set import com.topjohnwu.magisk.utils.set
import com.topjohnwu.magisk.view.MagiskDialog import com.topjohnwu.magisk.view.MagiskDialog
import org.koin.core.KoinComponent import org.koin.core.KoinComponent
...@@ -21,9 +21,9 @@ sealed class BaseSettingsItem : ObservableItem<BaseSettingsItem>() { ...@@ -21,9 +21,9 @@ sealed class BaseSettingsItem : ObservableItem<BaseSettingsItem>() {
override val layoutRes get() = R.layout.item_settings override val layoutRes get() = R.layout.item_settings
open val icon: Int get() = 0 open val icon: Int get() = 0
open val title: TransitiveText get() = TransitiveText.EMPTY open val title: TextHolder get() = TextHolder.EMPTY
@get:Bindable @get:Bindable
open val description: TransitiveText get() = TransitiveText.EMPTY open val description: TextHolder get() = TextHolder.EMPTY
// --- // ---
...@@ -151,8 +151,8 @@ sealed class BaseSettingsItem : ObservableItem<BaseSettingsItem>() { ...@@ -151,8 +151,8 @@ sealed class BaseSettingsItem : ObservableItem<BaseSettingsItem>() {
open val entries get() = resources.getArrayOrEmpty(entryRes) open val entries get() = resources.getArrayOrEmpty(entryRes)
open val entryValues get() = resources.getArrayOrEmpty(entryValRes) open val entryValues get() = resources.getArrayOrEmpty(entryValRes)
override val description: TransitiveText override val description: TextHolder
get() = entries.getOrNull(value)?.asTransitive() ?: TransitiveText.EMPTY get() = entries.getOrNull(value)?.asText() ?: TextHolder.EMPTY
private fun Resources.getArrayOrEmpty(id: Int): Array<String> = private fun Resources.getArrayOrEmpty(id: Int): Array<String> =
runCatching { getStringArray(id) }.getOrDefault(emptyArray()) runCatching { getStringArray(id) }.getOrDefault(emptyArray())
......
...@@ -18,7 +18,7 @@ import com.topjohnwu.magisk.events.SnackbarEvent ...@@ -18,7 +18,7 @@ import com.topjohnwu.magisk.events.SnackbarEvent
import com.topjohnwu.magisk.events.dialog.BiometricEvent import com.topjohnwu.magisk.events.dialog.BiometricEvent
import com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog import com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog
import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.utils.asTransitive import com.topjohnwu.magisk.utils.asText
import com.topjohnwu.magisk.view.TappableHeadlineItem import com.topjohnwu.magisk.view.TappableHeadlineItem
import com.topjohnwu.magisk.view.TextItem import com.topjohnwu.magisk.view.TextItem
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
...@@ -116,7 +116,7 @@ class SuperuserViewModel( ...@@ -116,7 +116,7 @@ class SuperuserViewModel(
else -> R.string.su_snack_notif_off else -> R.string.su_snack_notif_off
} }
} }
SnackbarEvent(res.asTransitive(policy.appName)).publish() SnackbarEvent(res.asText(policy.appName)).publish()
} }
fun togglePolicy(item: PolicyRvItem, enable: Boolean) { fun togglePolicy(item: PolicyRvItem, enable: Boolean) {
...@@ -130,7 +130,7 @@ class SuperuserViewModel( ...@@ -130,7 +130,7 @@ class SuperuserViewModel(
db.update(app) db.update(app)
val res = if (app.policy == SuPolicy.ALLOW) R.string.su_snack_grant val res = if (app.policy == SuPolicy.ALLOW) R.string.su_snack_grant
else R.string.su_snack_deny else R.string.su_snack_deny
SnackbarEvent(res.asTransitive(item.item.appName)).publish() SnackbarEvent(res.asText(item.item.appName)).publish()
} }
} }
......
...@@ -3,9 +3,8 @@ package com.topjohnwu.magisk.utils ...@@ -3,9 +3,8 @@ package com.topjohnwu.magisk.utils
import android.content.res.Resources import android.content.res.Resources
import android.widget.TextView import android.widget.TextView
import androidx.databinding.BindingAdapter import androidx.databinding.BindingAdapter
import androidx.databinding.InverseBindingAdapter
sealed class TransitiveText { sealed class TextHolder {
abstract val isEmpty: Boolean abstract val isEmpty: Boolean
abstract fun getText(resources: Resources): CharSequence abstract fun getText(resources: Resources): CharSequence
...@@ -14,21 +13,20 @@ sealed class TransitiveText { ...@@ -14,21 +13,20 @@ sealed class TransitiveText {
class String( class String(
private val value: CharSequence private val value: CharSequence
) : TransitiveText() { ) : TextHolder() {
override val isEmpty = value.isEmpty() override val isEmpty get() = value.isEmpty()
override fun getText(resources: Resources) = value override fun getText(resources: Resources) = value
} }
class Res( class Resource(
private val value: Int, private val value: Int,
private vararg val params: Any private vararg val params: Any
) : TransitiveText() { ) : TextHolder() {
override val isEmpty = value == 0 override val isEmpty get() = value == 0
override fun getText(resources: Resources) = override fun getText(resources: Resources) = resources.getString(value, *params)
resources.getString(value, *params)
} }
...@@ -39,15 +37,11 @@ sealed class TransitiveText { ...@@ -39,15 +37,11 @@ sealed class TransitiveText {
} }
} }
fun Int.asText(vararg params: Any): TextHolder = TextHolder.Resource(this, *params)
fun Int.asTransitive(vararg params: Any): TransitiveText = TransitiveText.Res(this, *params) fun CharSequence.asText(): TextHolder = TextHolder.String(this)
fun CharSequence.asTransitive(): TransitiveText = TransitiveText.String(this)
@BindingAdapter("android:text") @BindingAdapter("android:text")
fun TextView.setText(text: TransitiveText) { fun TextView.setText(text: TextHolder) {
this.text = text.getText(context.resources) this.text = text.getText(context.resources)
} }
@InverseBindingAdapter(attribute = "android:text", event = "android:textAttrChanged")
fun TextView.getTransitiveText() = text.asTransitive()
...@@ -10,7 +10,6 @@ import org.bouncycastle.cms.CMSSignedData; ...@@ -10,7 +10,6 @@ import org.bouncycastle.cms.CMSSignedData;
import org.bouncycastle.cms.CMSSignedDataGenerator; import org.bouncycastle.cms.CMSSignedDataGenerator;
import org.bouncycastle.cms.CMSTypedData; import org.bouncycastle.cms.CMSTypedData;
import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder; import org.bouncycastle.cms.jcajce.JcaSignerInfoGeneratorBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
...@@ -31,7 +30,6 @@ import java.security.InvalidKeyException; ...@@ -31,7 +30,6 @@ import java.security.InvalidKeyException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.Security;
import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment