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 import org.matrix.android.sdk.api.session.identity.ThreePid
sealed class ThreePidsSettingsAction : VectorViewModelAction { 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 AddThreePid(val threePid: ThreePid) : ThreePidsSettingsAction()
data class SubmitCode(val threePid: ThreePid.Msisdn, val code: String) : ThreePidsSettingsAction() data class SubmitCode(val threePid: ThreePid.Msisdn, val code: String) : ThreePidsSettingsAction()
data class ContinueThreePid(val threePid: ThreePid) : ThreePidsSettingsAction() data class ContinueThreePid(val threePid: ThreePid) : ThreePidsSettingsAction()

View file

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

View file

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

View file

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

View file

@ -146,7 +146,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
is ThreePidsSettingsAction.CancelThreePid -> handleCancelThreePid(action) is ThreePidsSettingsAction.CancelThreePid -> handleCancelThreePid(action)
is ThreePidsSettingsAction.AccountPassword -> handleAccountPassword(action) is ThreePidsSettingsAction.AccountPassword -> handleAccountPassword(action)
is ThreePidsSettingsAction.DeleteThreePid -> handleDeleteThreePid(action) is ThreePidsSettingsAction.DeleteThreePid -> handleDeleteThreePid(action)
is ThreePidsSettingsAction.ChangeState -> handleChangeState(action) is ThreePidsSettingsAction.ChangeUiState -> handleChangeUiState(action)
}.exhaustive }.exhaustive
} }
@ -183,10 +183,10 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
} }
} }
private fun handleChangeState(action: ThreePidsSettingsAction.ChangeState) { private fun handleChangeUiState(action: ThreePidsSettingsAction.ChangeUiState) {
setState { setState {
copy( copy(
state = action.newState, uiState = action.newUiState,
editTextReinitiator = ReadOnceTrue() editTextReinitiator = ReadOnceTrue()
) )
} }
@ -211,7 +211,7 @@ class ThreePidsSettingsViewModel @AssistedInject constructor(
// Also reset the state // Also reset the state
setState { setState {
copy( copy(
state = ThreePidsSettingsState.Idle uiState = ThreePidsSettingsUiState.Idle
) )
} }
loadingCallback.onSuccess(data) 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 import org.matrix.android.sdk.api.session.identity.ThreePid
data class ThreePidsSettingsViewState( data class ThreePidsSettingsViewState(
val state: ThreePidsSettingsState = ThreePidsSettingsState.Idle, val uiState: ThreePidsSettingsUiState = ThreePidsSettingsUiState.Idle,
val isLoading: Boolean = false, val isLoading: Boolean = false,
val threePids: Async<List<ThreePid>> = Uninitialized, val threePids: Async<List<ThreePid>> = Uninitialized,
val pendingThreePids: Async<List<ThreePid>> = Uninitialized, val pendingThreePids: Async<List<ThreePid>> = Uninitialized,