From 72433f2a2f2fd4ba50a6fb8a4fccbe99a6ace98f Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 20 May 2021 17:54:04 +0200 Subject: [PATCH] Improved how text input based settings work --- .../viewmodels/AccountSettingsViewModel.kt | 17 ++++++++++++++--- .../java/org/linphone/utils/DataBindingUtils.kt | 17 +---------------- .../layout/settings_widget_switch_and_text.xml | 2 +- .../main/res/layout/settings_widget_text.xml | 13 ++++++------- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/AccountSettingsViewModel.kt b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/AccountSettingsViewModel.kt index 884f86721..19057172c 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/AccountSettingsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/AccountSettingsViewModel.kt @@ -109,7 +109,10 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel( override fun onTextValueChanged(newValue: String) { val authInfo = account.findAuthInfo() if (authInfo != null) { - authInfo.userid = newValue + val newAuthInfo = authInfo.clone() + newAuthInfo.userid = newValue + core.removeAuthInfo(authInfo) + core.addAuthInfo(newAuthInfo) } else { Log.e("[Account Settings] Failed to find the matching auth info") } @@ -121,7 +124,10 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel( override fun onTextValueChanged(newValue: String) { val authInfo = account.findAuthInfo() if (authInfo != null) { - authInfo.password = newValue + val newAuthInfo = authInfo.clone() + newAuthInfo.password = newValue + core.removeAuthInfo(authInfo) + core.addAuthInfo(newAuthInfo) } else { Log.w("[Account Settings] Failed to find the matching auth info") val params = account.params @@ -145,7 +151,10 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel( if (identity != null) { val authInfo = account.findAuthInfo() if (authInfo != null) { - authInfo.domain = newValue + val newAuthInfo = authInfo.clone() + newAuthInfo.domain = newValue + core.removeAuthInfo(authInfo) + core.addAuthInfo(newAuthInfo) } else { Log.e("[Account Settings] Failed to find the matching auth info") } @@ -264,6 +273,8 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel( params.serverAddress = address account.params = params transportIndex.value = account.params.transport.toInt() + } else { + Log.e("[Account Settings] Couldn't parse address: $address") } } } diff --git a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt index 86bea09eb..db8b28770 100644 --- a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt +++ b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt @@ -29,7 +29,6 @@ import android.util.Patterns import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.inputmethod.EditorInfo import android.widget.* import android.widget.SeekBar.OnSeekBarChangeListener import androidx.constraintlayout.widget.ConstraintLayout @@ -175,23 +174,9 @@ fun switchSetting(view: View, switchId: Int) { @BindingAdapter("onValueChanged") fun editTextSetting(view: EditText, lambda: () -> Unit) { - view.setOnFocusChangeListener { _, hasFocus -> - if (!hasFocus) lambda() - } - - view.setOnEditorActionListener { _, actionId, _ -> - if (actionId == EditorInfo.IME_ACTION_DONE) { - lambda() - true - } - false - } - view.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable?) { - if (s?.isEmpty() == true) { - lambda() - } + lambda() } override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} diff --git a/app/src/main/res/layout/settings_widget_switch_and_text.xml b/app/src/main/res/layout/settings_widget_switch_and_text.xml index e78ee39cf..242ab56ae 100644 --- a/app/src/main/res/layout/settings_widget_switch_and_text.xml +++ b/app/src/main/res/layout/settings_widget_switch_and_text.xml @@ -94,10 +94,10 @@ @@ -46,7 +46,7 @@ android:id="@+id/settings_input_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_toLeftOf="@id/settings_clear_input" + android:layout_toLeftOf="@id/settings_commit_input" android:layout_marginTop="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" @@ -57,8 +57,7 @@