Fixed manager beginning to hide immediately on field change
Bug was caused by lenient usage of "value" property defined in the "line item" in settings. Developer error allowed to use the internal value, that was not properly protected, in a way that did not conform with the latest "Observer" rewrite. Additional comments were added to hopefully prevent bugs of this kind in the future. The property is now properly protected so it gives away clues that this access is considered "not cool".
This commit is contained in:
parent
ac2a9da4c4
commit
79aa261ca2
@ -60,7 +60,20 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
|
||||
|
||||
abstract class Value<T> : SettingsItem() {
|
||||
|
||||
/**
|
||||
* Represents last agreed-upon value by the validation process and the user for current
|
||||
* child. Be very aware that this shouldn't be **set** unless both sides agreed that _that_
|
||||
* is the new value.
|
||||
*
|
||||
* Annotating [value] as [Bindable] property should raise red flags immediately. If you
|
||||
* need a [Bindable] property create another one. Seriously.
|
||||
* */
|
||||
abstract var value: T
|
||||
/**
|
||||
* We don't want this to be accessible to be set from outside the instances. It will
|
||||
* introduce unwanted bugs!
|
||||
* */
|
||||
protected set
|
||||
|
||||
protected var callbackVars: Pair<View, Callback>? = null
|
||||
|
||||
@ -76,7 +89,7 @@ sealed class SettingsItem : ObservableItem<SettingsItem>() {
|
||||
|
||||
protected inline fun <reified T> setV(
|
||||
new: T, old: T, setter: (T) -> Unit, afterChanged: (T) -> Unit = {}) {
|
||||
set(new, old, setter, BR.value, BR.description, BR.checked) {
|
||||
set(new, old, setter, BR.description, BR.checked) {
|
||||
afterChanged(it)
|
||||
callbackVars?.let { (view, callback) ->
|
||||
callbackVars = null
|
||||
|
@ -80,19 +80,23 @@ object Hide : SettingsItem.Input() {
|
||||
override val title = R.string.settings_hide_manager_title.asTransitive()
|
||||
override val description = R.string.settings_hide_manager_summary.asTransitive()
|
||||
|
||||
@get:Bindable
|
||||
override var value = "Manager"
|
||||
set(value) = setV(value, field, { field = it }) {
|
||||
notifyPropertyChanged(BR.error)
|
||||
}
|
||||
set(value) = setV(value, field, { field = it })
|
||||
|
||||
override val inputResult
|
||||
get() = if (isError) null else result
|
||||
|
||||
@get:Bindable
|
||||
val isError get() = value.length > 14 || value.isBlank()
|
||||
var result = value
|
||||
set(value) = set(value, field, { field = it }, BR.result, BR.error)
|
||||
|
||||
override val inputResult get() = if (isError) null else value
|
||||
@get:Bindable
|
||||
val isError
|
||||
get() = value.length > 14 || value.isBlank()
|
||||
|
||||
override fun getView(context: Context) = DialogSettingsAppNameBinding
|
||||
.inflate(LayoutInflater.from(context)).also { it.data = this }.root
|
||||
|
||||
}
|
||||
|
||||
object Restore : SettingsItem.Blank() {
|
||||
@ -119,7 +123,8 @@ object DownloadPath : SettingsItem.Input() {
|
||||
set(value) = set(value, field, { field = it }, BR.result, BR.path)
|
||||
|
||||
@get:Bindable
|
||||
val path get() = File(Environment.getExternalStorageDirectory(), result).absolutePath.orEmpty()
|
||||
val path
|
||||
get() = File(Environment.getExternalStorageDirectory(), result).absolutePath.orEmpty()
|
||||
|
||||
override fun getView(context: Context) = DialogSettingsDownloadPathBinding
|
||||
.inflate(LayoutInflater.from(context)).also { it.data = this }.root
|
||||
@ -130,7 +135,8 @@ object UpdateChannel : SettingsItem.Selector() {
|
||||
set(value) = setV(value, field, { field = it }) { Config.updateChannel = it }
|
||||
|
||||
override val title = R.string.settings_update_channel_title.asTransitive()
|
||||
override val entries get() = resources.getStringArray(R.array.update_channel).let {
|
||||
override val entries
|
||||
get() = resources.getStringArray(R.array.update_channel).let {
|
||||
if (BuildConfig.DEBUG) it.toMutableList().apply { add("Canary") }.toTypedArray() else it
|
||||
}
|
||||
override val entryValRes = R.array.value_array
|
||||
|
@ -40,7 +40,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textCapWords"
|
||||
android:text="@={data.value}"
|
||||
android:text="@={data.result}"
|
||||
android:textAppearance="@style/AppearanceFoundation.Body"
|
||||
android:textColor="?colorOnSurface"
|
||||
tools:text="@tools:sample/lorem" />
|
||||
|
Loading…
Reference in New Issue
Block a user