Rename class

This commit is contained in:
Benoit Marty 2020-09-01 10:09:28 +02:00
parent 56261bd741
commit 99343294c6
6 changed files with 30 additions and 30 deletions

View file

@ -20,7 +20,7 @@ import im.vector.app.core.platform.VectorViewModelAction
import org.matrix.android.sdk.api.session.identity.ThreePid
sealed class ThreePidsSettingsAction : VectorViewModelAction {
data class ChangeState(val newState: ThreePidsSettingsState) : ThreePidsSettingsAction()
data class ChangeUiState(val newUiState: ThreePidsSettingsUiState) : ThreePidsSettingsAction()
data class AddThreePid(val threePid: ThreePid) : ThreePidsSettingsAction()
data class SubmitCode(val threePid: ThreePid.Msisdn, val code: String) : ThreePidsSettingsAction()
data class ContinueThreePid(val threePid: ThreePid) : ThreePidsSettingsAction()

View file

@ -72,7 +72,7 @@ class ThreePidsSettingsController @Inject constructor(
override fun buildModels(data: ThreePidsSettingsViewState?) {
if (data == null) return
if (data.state is ThreePidsSettingsState.Idle) {
if (data.uiState is ThreePidsSettingsUiState.Idle) {
currentInputValue = ""
}
@ -123,15 +123,15 @@ class ThreePidsSettingsController @Inject constructor(
pendingList.forEach { buildPendingThreePid(data, "p_email ", it) }
}
when (data.state) {
ThreePidsSettingsState.Idle ->
when (data.uiState) {
ThreePidsSettingsUiState.Idle ->
genericButtonItem {
id("addEmail")
text(stringProvider.getString(R.string.settings_add_email_address))
textColor(colorProvider.getColor(R.color.riotx_accent))
buttonClickAction(View.OnClickListener { interactionListener?.addEmail() })
}
is ThreePidsSettingsState.AddingEmail -> {
is ThreePidsSettingsUiState.AddingEmail -> {
settingsEditTextItem {
id("addingEmail")
inputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
@ -139,7 +139,7 @@ class ThreePidsSettingsController @Inject constructor(
if (data.editTextReinitiator?.isTrue() == true) {
value("")
}
errorText(data.state.error)
errorText(data.uiState.error)
interactionListener(object : SettingsEditTextItem.Listener {
override fun onValidate() {
interactionListener?.doAddEmail(currentInputValue)
@ -156,7 +156,7 @@ class ThreePidsSettingsController @Inject constructor(
cancelOnClick { interactionListener?.cancelAdding() }
}
}
is ThreePidsSettingsState.AddingPhoneNumber -> Unit
is ThreePidsSettingsUiState.AddingPhoneNumber -> Unit
}.exhaustive
settingsSectionTitleItem {
@ -181,16 +181,16 @@ class ThreePidsSettingsController @Inject constructor(
pendingList.forEach { buildPendingThreePid(data, "p_msisdn ", it) }
}
when (data.state) {
ThreePidsSettingsState.Idle ->
when (data.uiState) {
ThreePidsSettingsUiState.Idle ->
genericButtonItem {
id("addMsisdn")
text(stringProvider.getString(R.string.settings_add_phone_number))
textColor(colorProvider.getColor(R.color.riotx_accent))
buttonClickAction(View.OnClickListener { interactionListener?.addMsisdn() })
}
is ThreePidsSettingsState.AddingEmail -> Unit
is ThreePidsSettingsState.AddingPhoneNumber -> {
is ThreePidsSettingsUiState.AddingEmail -> Unit
is ThreePidsSettingsUiState.AddingPhoneNumber -> {
settingsInfoItem {
id("addingMsisdnInfo")
helperText(stringProvider.getString(R.string.login_msisdn_notice))
@ -202,7 +202,7 @@ class ThreePidsSettingsController @Inject constructor(
if (data.editTextReinitiator?.isTrue() == true) {
value("")
}
errorText(data.state.error)
errorText(data.uiState.error)
interactionListener(object : SettingsEditTextItem.Listener {
override fun onValidate() {
interactionListener?.doAddMsisdn(currentInputValue)

View file

@ -92,17 +92,17 @@ class ThreePidsSettingsFragment @Inject constructor(
}
override fun addEmail() {
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingEmail(null)))
viewModel.handle(ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.AddingEmail(null)))
}
override fun doAddEmail(email: String) {
// Sanity
val safeEmail = email.trim().replace(" ", "")
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingEmail(null)))
viewModel.handle(ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.AddingEmail(null)))
// Check that email is valid
if (!safeEmail.isEmail()) {
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingEmail(getString(R.string.auth_invalid_email))))
viewModel.handle(ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.AddingEmail(getString(R.string.auth_invalid_email))))
return
}
@ -110,26 +110,26 @@ class ThreePidsSettingsFragment @Inject constructor(
}
override fun addMsisdn() {
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingPhoneNumber(null)))
viewModel.handle(ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.AddingPhoneNumber(null)))
}
override fun doAddMsisdn(msisdn: String) {
// Sanity
val safeMsisdn = msisdn.trim().replace(" ", "")
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingPhoneNumber(null)))
viewModel.handle(ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.AddingPhoneNumber(null)))
// Check that phone number is valid
if (!msisdn.startsWith("+")) {
viewModel.handle(
ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingPhoneNumber(getString(R.string.login_msisdn_error_not_international)))
ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.AddingPhoneNumber(getString(R.string.login_msisdn_error_not_international)))
)
return
}
if (!msisdn.isMsisdn()) {
viewModel.handle(
ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.AddingPhoneNumber(getString(R.string.login_msisdn_error_other)))
ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.AddingPhoneNumber(getString(R.string.login_msisdn_error_other)))
)
return
}
@ -144,7 +144,7 @@ class ThreePidsSettingsFragment @Inject constructor(
}
override fun cancelAdding() {
viewModel.handle(ThreePidsSettingsAction.ChangeState(ThreePidsSettingsState.Idle))
viewModel.handle(ThreePidsSettingsAction.ChangeUiState(ThreePidsSettingsUiState.Idle))
// Hide the keyboard
view?.hideKeyboard()
}
@ -170,7 +170,7 @@ class ThreePidsSettingsFragment @Inject constructor(
override fun onBackPressed(toolbarButton: Boolean): Boolean {
return withState(viewModel) {
if (it.state is ThreePidsSettingsState.Idle) {
if (it.uiState is ThreePidsSettingsUiState.Idle) {
false
} else {
cancelAdding()

View file

@ -16,8 +16,8 @@
package im.vector.app.features.settings.threepids
sealed class ThreePidsSettingsState {
object Idle : ThreePidsSettingsState()
data class AddingEmail(val error: String?) : ThreePidsSettingsState()
data class AddingPhoneNumber(val error: String?) : ThreePidsSettingsState()
sealed class ThreePidsSettingsUiState {
object Idle : ThreePidsSettingsUiState()
data class AddingEmail(val error: String?) : ThreePidsSettingsUiState()
data class AddingPhoneNumber(val error: String?) : ThreePidsSettingsUiState()
}

View file

@ -146,7 +146,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
is ThreePidsSettingsAction.CancelThreePid -> handleCancelThreePid(action)
is ThreePidsSettingsAction.AccountPassword -> handleAccountPassword(action)
is ThreePidsSettingsAction.DeleteThreePid -> handleDeleteThreePid(action)
is ThreePidsSettingsAction.ChangeState -> handleChangeState(action)
is ThreePidsSettingsAction.ChangeUiState -> handleChangeUiState(action)
}.exhaustive
}
@ -183,10 +183,10 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
}
}
private fun handleChangeState(action: ThreePidsSettingsAction.ChangeState) {
private fun handleChangeUiState(action: ThreePidsSettingsAction.ChangeUiState) {
setState {
copy(
state = action.newState,
uiState = action.newUiState,
editTextReinitiator = ReadOnceTrue()
)
}
@ -211,7 +211,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
// Also reset the state
setState {
copy(
state = ThreePidsSettingsState.Idle
uiState = ThreePidsSettingsUiState.Idle
)
}
loadingCallback.onSuccess(data)

View file

@ -23,7 +23,7 @@ import im.vector.app.core.utils.ReadOnceTrue
import org.matrix.android.sdk.api.session.identity.ThreePid
data class ThreePidsSettingsViewState(
val state: ThreePidsSettingsState = ThreePidsSettingsState.Idle,
val uiState: ThreePidsSettingsUiState = ThreePidsSettingsUiState.Idle,
val isLoading: Boolean = false,
val threePids: Async<List<ThreePid>> = Uninitialized,
val pendingThreePids: Async<List<ThreePid>> = Uninitialized,