Disable username/password fields when account has been created (until SMS is sent), fixed default values not loaded

This commit is contained in:
Sylvain Berfini 2025-02-03 11:54:15 +01:00
parent e5795ea05f
commit 1c09388266
2 changed files with 12 additions and 6 deletions

View file

@ -33,6 +33,7 @@ import kotlinx.coroutines.withContext
import org.json.JSONException
import org.json.JSONObject
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
import org.linphone.core.Account
import org.linphone.core.AccountManagerServices
@ -82,6 +83,8 @@ class AccountCreationViewModel
val showPassword = MutableLiveData<Boolean>()
val lockUsernameAndPassword = MutableLiveData<Boolean>()
val createEnabled = MediatorLiveData<Boolean>()
val pushNotificationsAvailable = MutableLiveData<Boolean>()
@ -199,12 +202,11 @@ class AccountCreationViewModel
if (account != null) {
coreContext.core.removeAccount(account)
}
createEnabled.postValue(true)
}
else -> {
createEnabled.postValue(true)
}
}
createEnabled.postValue(true)
}
}
@ -258,6 +260,7 @@ class AccountCreationViewModel
init {
operationInProgress.value = false
lockUsernameAndPassword.value = false
coreContext.postOnCoreThread { core ->
pushNotificationsAvailable.postValue(LinphoneUtils.arePushNotificationsAvailable(core))
@ -469,15 +472,16 @@ class AccountCreationViewModel
@WorkerThread
private fun storeAccountInCore(identity: String) {
val passwordValue = password.value
val core = coreContext.core
core.loadConfigFromXml(corePreferences.linphoneDefaultValuesPath)
val sipIdentity = Factory.instance().createAddress(identity)
if (sipIdentity == null) {
Log.e("$TAG Failed to create address from SIP Identity [$identity]!")
return
}
val passwordValue = password.value
// We need to have an AuthInfo for newly created account to authorize phone number linking request
val authInfo = Factory.instance().createAuthInfo(
sipIdentity.username.orEmpty(),
@ -506,6 +510,8 @@ class AccountCreationViewModel
accountCreatedAuthInfo = authInfo
accountCreated = account
lockUsernameAndPassword.postValue(true)
}
@WorkerThread

View file

@ -90,7 +90,7 @@
<androidx.appcompat.widget.AppCompatEditText
style="@style/default_text_style"
android:id="@+id/username"
android:enabled="@{viewModel.pushNotificationsAvailable}"
android:enabled="@{viewModel.pushNotificationsAvailable &amp;&amp; !viewModel.lockUsernameAndPassword}"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
@ -223,7 +223,7 @@
<androidx.appcompat.widget.AppCompatEditText
style="@style/default_text_style"
android:id="@+id/password"
android:enabled="@{viewModel.pushNotificationsAvailable}"
android:enabled="@{viewModel.pushNotificationsAvailable &amp;&amp; !viewModel.lockUsernameAndPassword}"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"