Add threePid: improve UI for phone numbers
This commit is contained in:
parent
e92cf38cde
commit
ee3e10a4b0
|
@ -31,6 +31,7 @@ import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.core.ui.list.genericButtonItem
|
import im.vector.app.core.ui.list.genericButtonItem
|
||||||
import im.vector.app.core.ui.list.genericFooterItem
|
import im.vector.app.core.ui.list.genericFooterItem
|
||||||
import im.vector.app.features.discovery.settingsContinueCancelItem
|
import im.vector.app.features.discovery.settingsContinueCancelItem
|
||||||
|
import im.vector.app.features.discovery.settingsInfoItem
|
||||||
import im.vector.app.features.discovery.settingsInformationItem
|
import im.vector.app.features.discovery.settingsInformationItem
|
||||||
import im.vector.app.features.discovery.settingsSectionTitleItem
|
import im.vector.app.features.discovery.settingsSectionTitleItem
|
||||||
import im.vector.app.features.form.formEditTextItem
|
import im.vector.app.features.form.formEditTextItem
|
||||||
|
@ -149,6 +150,10 @@ class ThreePidsSettingsController @Inject constructor(
|
||||||
}
|
}
|
||||||
is ThreePidsSettingsState.AddingEmail -> Unit
|
is ThreePidsSettingsState.AddingEmail -> Unit
|
||||||
is ThreePidsSettingsState.AddingPhoneNumber -> {
|
is ThreePidsSettingsState.AddingPhoneNumber -> {
|
||||||
|
settingsInfoItem {
|
||||||
|
id("addingMsisdnInfo")
|
||||||
|
helperText(stringProvider.getString(R.string.login_msisdn_notice))
|
||||||
|
}
|
||||||
formEditTextItem {
|
formEditTextItem {
|
||||||
id("addingMsisdn")
|
id("addingMsisdn")
|
||||||
inputType(InputType.TYPE_CLASS_PHONE)
|
inputType(InputType.TYPE_CLASS_PHONE)
|
||||||
|
|
|
@ -94,15 +94,17 @@ class ThreePidsSettingsFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doAddEmail(email: String) {
|
override fun doAddEmail(email: String) {
|
||||||
|
// Sanity
|
||||||
|
val safeEmail = email.trim().replace(" ", "")
|
||||||
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingEmail(null)))
|
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingEmail(null)))
|
||||||
|
|
||||||
// Check that email is valid
|
// Check that email is valid
|
||||||
if (!email.isEmail()) {
|
if (!safeEmail.isEmail()) {
|
||||||
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingEmail(getString(R.string.auth_invalid_email))))
|
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingEmail(getString(R.string.auth_invalid_email))))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.handle(ThreePidsSettingsAction.AddThreePid(ThreePid.Email(email)))
|
viewModel.handle(ThreePidsSettingsAction.AddThreePid(ThreePid.Email(safeEmail)))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addMsisdn() {
|
override fun addMsisdn() {
|
||||||
|
@ -110,9 +112,18 @@ class ThreePidsSettingsFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doAddMsisdn(msisdn: String) {
|
override fun doAddMsisdn(msisdn: String) {
|
||||||
|
// Sanity
|
||||||
|
val safeMsisdn = msisdn.trim().replace(" ", "")
|
||||||
|
|
||||||
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingPhoneNumber(null)))
|
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingPhoneNumber(null)))
|
||||||
|
|
||||||
TODO("Not yet implemented")
|
// Check that phone number is valid
|
||||||
|
if (!msisdn.startsWith("+")) {
|
||||||
|
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingPhoneNumber(getString(R.string.login_msisdn_error_not_international))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.handle(ThreePidsSettingsAction.AddThreePid(ThreePid.Msisdn(safeMsisdn)))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cancelAdding() {
|
override fun cancelAdding() {
|
||||||
|
|
|
@ -155,7 +155,21 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
|
||||||
_viewEvents.post(ThreePidsSettingsViewEvents.Failure(IllegalArgumentException(stringProvider.getString(R.string.auth_email_already_defined))))
|
_viewEvents.post(ThreePidsSettingsViewEvents.Failure(IllegalArgumentException(stringProvider.getString(R.string.auth_email_already_defined))))
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
session.addThreePid(action.threePid, loadingCallback)
|
session.addThreePid(action.threePid, object : MatrixCallback<Unit> {
|
||||||
|
override fun onSuccess(data: Unit) {
|
||||||
|
// Also reset the state
|
||||||
|
setState {
|
||||||
|
copy(
|
||||||
|
state = ThreePidsSettingsState.Idle
|
||||||
|
)
|
||||||
|
}
|
||||||
|
loadingCallback.onSuccess(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(failure: Throwable) {
|
||||||
|
loadingCallback.onFailure(failure)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1951,6 +1951,7 @@
|
||||||
<string name="login_msisdn_confirm_send_again">Send again</string>
|
<string name="login_msisdn_confirm_send_again">Send again</string>
|
||||||
<string name="login_msisdn_confirm_submit">Next</string>
|
<string name="login_msisdn_confirm_submit">Next</string>
|
||||||
|
|
||||||
|
<string name="login_msisdn_notice">"Please use the international format (phone number must start with '+')"</string>
|
||||||
<string name="login_msisdn_error_not_international">"International phone numbers must start with '+'"</string>
|
<string name="login_msisdn_error_not_international">"International phone numbers must start with '+'"</string>
|
||||||
<string name="login_msisdn_error_other">"Phone number seems invalid. Please check it"</string>
|
<string name="login_msisdn_error_other">"Phone number seems invalid. Please check it"</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue