mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-28 16:36:36 +00:00
Remove strip in settings item
This commit is contained in:
@@ -10,6 +10,7 @@ import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.databinding.ObservableItem
|
||||
import com.topjohnwu.magisk.utils.TransitiveText
|
||||
import com.topjohnwu.magisk.utils.asTransitive
|
||||
import com.topjohnwu.magisk.utils.set
|
||||
import com.topjohnwu.magisk.view.MagiskDialog
|
||||
import org.koin.core.KoinComponent
|
||||
@@ -94,22 +95,20 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Input : Value<String>(), KoinComponent {
|
||||
abstract class Input : Value<String>() {
|
||||
|
||||
override val layoutRes = R.layout.item_settings_input
|
||||
open val showStrip = true
|
||||
|
||||
protected val resources get() = get<Resources>()
|
||||
protected abstract val intermediate: String?
|
||||
protected abstract val inputResult: String?
|
||||
|
||||
override fun onPressed(view: View) {
|
||||
MagiskDialog(view.context)
|
||||
.applyTitle(title.getText(resources))
|
||||
.applyTitle(title.getText(view.resources))
|
||||
.applyView(getView(view.context))
|
||||
.applyButton(MagiskDialog.ButtonType.POSITIVE) {
|
||||
titleRes = android.R.string.ok
|
||||
onClick {
|
||||
intermediate?.let { result ->
|
||||
inputResult?.let { result ->
|
||||
preventDismiss = false
|
||||
value = result
|
||||
it.dismiss()
|
||||
@@ -125,7 +124,6 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
|
||||
}
|
||||
|
||||
abstract fun getView(context: Context): View
|
||||
|
||||
}
|
||||
|
||||
abstract class Selector : Value<Int>(), KoinComponent {
|
||||
@@ -141,12 +139,12 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
|
||||
open val entryValues get() = resources.getArrayOrEmpty(entryValRes)
|
||||
|
||||
@get:Bindable
|
||||
val selectedEntry
|
||||
get() = entries.getOrNull(value)
|
||||
override val description: TransitiveText
|
||||
get() = entries.getOrNull(value)?.asTransitive() ?: TransitiveText.EMPTY
|
||||
|
||||
protected inline fun <reified T> setS(
|
||||
new: T, old: T, setter: (T) -> Unit, afterChanged: (T) -> Unit = {}) {
|
||||
setV(new, old, setter, BR.selectedEntry, BR.description, afterChanged = afterChanged)
|
||||
setV(new, old, setter, BR.description, afterChanged = afterChanged)
|
||||
}
|
||||
|
||||
private fun Resources.getArrayOrEmpty(id: Int): Array<String> =
|
||||
|
||||
@@ -79,15 +79,15 @@ object ClearRepoCache : SettingsItem.Blank() {
|
||||
object Hide : SettingsItem.Input() {
|
||||
override val title = R.string.settings_hide_manager_title.asTransitive()
|
||||
override val description = R.string.settings_hide_manager_summary.asTransitive()
|
||||
override val showStrip = false
|
||||
override var value = resources.getString(R.string.re_app_name)
|
||||
|
||||
@get:Bindable
|
||||
override var value = "Manager"
|
||||
set(value) = setV(value, field, { field = it }, BR.error)
|
||||
|
||||
@get:Bindable
|
||||
val isError get() = value.length > 14 || value.isBlank()
|
||||
|
||||
override val intermediate: String?
|
||||
get() = if (isError) null else value
|
||||
override val inputResult get() = if (isError) null else value
|
||||
|
||||
override fun getView(context: Context) = DialogSettingsAppNameBinding
|
||||
.inflate(LayoutInflater.from(context)).also { it.data = this }.root
|
||||
@@ -105,8 +105,11 @@ fun HideOrRestore() =
|
||||
object DownloadPath : SettingsItem.Input() {
|
||||
override var value = Config.downloadPath
|
||||
set(value) = setV(value, field, { field = it }) { Config.downloadPath = it }
|
||||
|
||||
override val title = R.string.settings_download_path_title.asTransitive()
|
||||
override val intermediate: String?
|
||||
override val description get() = path.asTransitive()
|
||||
|
||||
override val inputResult: String?
|
||||
get() = if (Utils.ensureDownloadPath(result) != null) result else null
|
||||
|
||||
@get:Bindable
|
||||
@@ -135,7 +138,8 @@ object UpdateChannelUrl : SettingsItem.Input() {
|
||||
override val title = R.string.settings_update_custom.asTransitive()
|
||||
override var value = Config.customChannelUrl
|
||||
set(value) = setV(value, field, { field = it }) { Config.customChannelUrl = it }
|
||||
override val intermediate: String? get() = result
|
||||
|
||||
override val inputResult get() = result
|
||||
|
||||
@get:Bindable
|
||||
var result = value
|
||||
|
||||
@@ -259,7 +259,6 @@ fun setState(view: IndeterminateCheckBox, state: Boolean?) {
|
||||
@InverseBindingAdapter(attribute = "state")
|
||||
fun getState(view: IndeterminateCheckBox) = view.state
|
||||
|
||||
|
||||
@BindingAdapter("stateAttrChanged")
|
||||
fun setListeners(
|
||||
view: IndeterminateCheckBox,
|
||||
|
||||
Reference in New Issue
Block a user