From 89da45f9acc50ee51df0913dd738c9d6faf0aaf8 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Fri, 29 Nov 2019 21:04:47 +0100 Subject: [PATCH] Fixed state not being propagated correctly on startup --- .../magisk/redesign/settings/SettingsItems.kt | 8 ++++++++ .../magisk/redesign/settings/SettingsViewModel.kt | 15 +++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsItems.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsItems.kt index 688528315..49cd2bc4b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsItems.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsItems.kt @@ -129,6 +129,14 @@ object UpdateChannelUrl : SettingsItem.Input() { notifyChange(BR.result) } + init { + updateState() + } + + fun updateState() { + isEnabled = UpdateChannel.value == Config.Value.CUSTOM_CHANNEL + } + override fun getView(context: Context) = DialogSettingsUpdateChannelBinding .inflate(LayoutInflater.from(context)).also { it.data = this }.root } diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt index ce0282f15..c431f10c0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/settings/SettingsViewModel.kt @@ -9,7 +9,6 @@ import androidx.databinding.Bindable import androidx.databinding.ViewDataBinding import androidx.recyclerview.widget.StaggeredGridLayoutManager import com.topjohnwu.magisk.BR -import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.R import com.topjohnwu.magisk.model.entity.recycler.ObservableItem import com.topjohnwu.magisk.model.events.DieEvent @@ -49,18 +48,14 @@ class SettingsViewModel : CompatViewModel(), SettingsItem.Callback { // use only instances you want, don't declare everything is Theme -> Navigation.theme().publish() is Redesign -> DieEvent().publish() - is UpdateChannel -> item.openUrlIfNecessary(view) + is UpdateChannel -> openUrlIfNecessary(view) else -> Unit } - private fun UpdateChannel.openUrlIfNecessary(view: View) { - if (value == Config.Value.CUSTOM_CHANNEL) { - if (UpdateChannelUrl.value.isBlank()) { - UpdateChannelUrl.onPressed(view, this@SettingsViewModel) - } - UpdateChannelUrl.isEnabled = true - } else { - UpdateChannelUrl.isEnabled = false + private fun openUrlIfNecessary(view: View) { + UpdateChannelUrl.updateState() + if (UpdateChannelUrl.value.isBlank()) { + UpdateChannelUrl.onPressed(view, this@SettingsViewModel) } }