mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Update errors
This commit is contained in:
parent
4aa0e55dc6
commit
f4cb0b8e6d
@ -95,6 +95,7 @@ private fun EnterAccountId(
|
|||||||
onChange = callbacks::onChange,
|
onChange = callbacks::onChange,
|
||||||
onContinue = callbacks::onContinue,
|
onContinue = callbacks::onContinue,
|
||||||
error = state.error?.string(),
|
error = state.error?.string(),
|
||||||
|
isTextErrorColor = state.isTextErrorColor
|
||||||
)
|
)
|
||||||
|
|
||||||
BorderlessButtonWithIcon(
|
BorderlessButtonWithIcon(
|
||||||
|
@ -45,16 +45,16 @@ internal class NewMessageViewModel @Inject constructor(
|
|||||||
loadOnsJob?.cancel()
|
loadOnsJob?.cancel()
|
||||||
loadOnsJob = null
|
loadOnsJob = null
|
||||||
|
|
||||||
_state.update { State(newMessageIdOrOns = value) }
|
_state.update { it.copy(newMessageIdOrOns = value, isTextErrorColor = false, loading = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onContinue() {
|
override fun onContinue() {
|
||||||
val idOrONS = state.value.newMessageIdOrOns
|
val idOrONS = state.value.newMessageIdOrOns
|
||||||
|
|
||||||
if (PublicKeyValidation.isValid(idOrONS, isPrefixRequired = false)) {
|
if (PublicKeyValidation.isValid(idOrONS, isPrefixRequired = false)) {
|
||||||
onUnvalidatedPublicKey(idOrONS)
|
onUnvalidatedPublicKey(publicKey = idOrONS)
|
||||||
} else {
|
} else {
|
||||||
resolveONS(idOrONS)
|
resolveONS(ons = idOrONS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ internal class NewMessageViewModel @Inject constructor(
|
|||||||
if (loadOnsJob?.isActive == true) return
|
if (loadOnsJob?.isActive == true) return
|
||||||
|
|
||||||
// This could be an ONS name
|
// This could be an ONS name
|
||||||
_state.update { it.copy(error = null, loading = true) }
|
_state.update { it.copy(isTextErrorColor = false, error = null, loading = true) }
|
||||||
|
|
||||||
loadOnsJob = viewModelScope.launch(Dispatchers.IO) {
|
loadOnsJob = viewModelScope.launch(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
@ -83,7 +83,7 @@ internal class NewMessageViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onError(e: Exception) {
|
private fun onError(e: Exception) {
|
||||||
_state.update { it.copy(loading = false, error = GetString(e) { it.toMessage() }) }
|
_state.update { it.copy(loading = false, isTextErrorColor = true, error = GetString(e) { it.toMessage() }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPublicKey(publicKey: String) {
|
private fun onPublicKey(publicKey: String) {
|
||||||
@ -95,7 +95,7 @@ internal class NewMessageViewModel @Inject constructor(
|
|||||||
if (PublicKeyValidation.hasValidPrefix(publicKey)) {
|
if (PublicKeyValidation.hasValidPrefix(publicKey)) {
|
||||||
onPublicKey(publicKey)
|
onPublicKey(publicKey)
|
||||||
} else {
|
} else {
|
||||||
_state.update { it.copy(error = GetString(R.string.accountIdErrorInvalid), loading = false) }
|
_state.update { it.copy(isTextErrorColor = true, error = GetString(R.string.accountIdErrorInvalid), loading = false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +108,7 @@ internal class NewMessageViewModel @Inject constructor(
|
|||||||
|
|
||||||
internal data class State(
|
internal data class State(
|
||||||
val newMessageIdOrOns: String = "",
|
val newMessageIdOrOns: String = "",
|
||||||
|
val isTextErrorColor: Boolean = false,
|
||||||
val error: GetString? = null,
|
val error: GetString? = null,
|
||||||
val loading: Boolean = false
|
val loading: Boolean = false
|
||||||
) {
|
) {
|
||||||
|
@ -107,7 +107,8 @@ private fun RecoveryPassword(state: State, onChange: (String) -> Unit = {}, onCo
|
|||||||
placeholder = stringResource(R.string.recoveryPasswordEnter),
|
placeholder = stringResource(R.string.recoveryPasswordEnter),
|
||||||
onChange = onChange,
|
onChange = onChange,
|
||||||
onContinue = onContinue,
|
onContinue = onContinue,
|
||||||
error = state.error
|
error = state.error,
|
||||||
|
isTextErrorColor = state.isTextErrorColor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ class LoadAccountEvent(val mnemonic: ByteArray)
|
|||||||
|
|
||||||
internal data class State(
|
internal data class State(
|
||||||
val recoveryPhrase: String = "",
|
val recoveryPhrase: String = "",
|
||||||
|
val isTextErrorColor: Boolean = false,
|
||||||
val error: String? = null
|
val error: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ internal class LinkDeviceViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onChange(recoveryPhrase: String) {
|
fun onChange(recoveryPhrase: String) {
|
||||||
state.value = State(recoveryPhrase)
|
state.update { it.copy(recoveryPhrase = recoveryPhrase, isTextErrorColor = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onSuccess(seed: ByteArray) {
|
private fun onSuccess(seed: ByteArray) {
|
||||||
@ -73,6 +74,7 @@ internal class LinkDeviceViewModel @Inject constructor(
|
|||||||
private fun onFailure(error: Throwable) {
|
private fun onFailure(error: Throwable) {
|
||||||
state.update {
|
state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
isTextErrorColor = true,
|
||||||
error = when (error) {
|
error = when (error) {
|
||||||
is InvalidWord -> R.string.recoveryPasswordErrorMessageIncorrect
|
is InvalidWord -> R.string.recoveryPasswordErrorMessageIncorrect
|
||||||
is InputTooShort -> R.string.recoveryPasswordErrorMessageShort
|
is InputTooShort -> R.string.recoveryPasswordErrorMessageShort
|
||||||
|
@ -57,7 +57,8 @@ internal fun DisplayName(state: State, onChange: (String) -> Unit = {}, onContin
|
|||||||
placeholder = stringResource(R.string.displayNameEnter),
|
placeholder = stringResource(R.string.displayNameEnter),
|
||||||
onChange = onChange,
|
onChange = onChange,
|
||||||
onContinue = onContinue,
|
onContinue = onContinue,
|
||||||
error = state.error?.let { stringResource(it) }
|
error = state.error?.let { stringResource(it) },
|
||||||
|
isTextErrorColor = state.isTextErrorColor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ internal class PickDisplayNameViewModel(
|
|||||||
val displayName = _states.value.displayName
|
val displayName = _states.value.displayName
|
||||||
|
|
||||||
when {
|
when {
|
||||||
displayName.isEmpty() -> { _states.update { it.copy(error = R.string.displayNameErrorDescription) } }
|
displayName.isEmpty() -> { _states.update { it.copy(isTextErrorColor = true, error = R.string.displayNameErrorDescription) } }
|
||||||
displayName.length > NAME_PADDED_LENGTH -> { _states.update { it.copy(error = R.string.displayNameErrorDescriptionShorter) } }
|
displayName.length > NAME_PADDED_LENGTH -> { _states.update { it.copy(isTextErrorColor = true, error = R.string.displayNameErrorDescriptionShorter) } }
|
||||||
else -> {
|
else -> {
|
||||||
prefs.setProfileName(displayName)
|
prefs.setProfileName(displayName)
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ internal class PickDisplayNameViewModel(
|
|||||||
_states.update { state ->
|
_states.update { state ->
|
||||||
state.copy(
|
state.copy(
|
||||||
displayName = value,
|
displayName = value,
|
||||||
error = value.takeIf { it.length > NAME_PADDED_LENGTH }?.let { R.string.displayNameErrorDescriptionShorter }
|
isTextErrorColor = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,6 +103,7 @@ internal class PickDisplayNameViewModel(
|
|||||||
data class State(
|
data class State(
|
||||||
@StringRes val title: Int = R.string.displayNamePick,
|
@StringRes val title: Int = R.string.displayNamePick,
|
||||||
@StringRes val description: Int = R.string.displayNameDescription,
|
@StringRes val description: Int = R.string.displayNameDescription,
|
||||||
|
val isTextErrorColor: Boolean = false,
|
||||||
@StringRes val error: Int? = null,
|
@StringRes val error: Int? = null,
|
||||||
val displayName: String = ""
|
val displayName: String = ""
|
||||||
)
|
)
|
||||||
|
@ -55,13 +55,26 @@ fun PreviewSessionOutlinedTextField() {
|
|||||||
verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||||
SessionOutlinedTextField(
|
SessionOutlinedTextField(
|
||||||
text = "text",
|
text = "text",
|
||||||
placeholder = "placeholder"
|
placeholder = "",
|
||||||
)
|
)
|
||||||
|
|
||||||
SessionOutlinedTextField(
|
SessionOutlinedTextField(
|
||||||
text = "",
|
text = "",
|
||||||
placeholder = "placeholder"
|
placeholder = "placeholder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SessionOutlinedTextField(
|
||||||
|
text = "text",
|
||||||
|
placeholder = "",
|
||||||
|
error = "error"
|
||||||
|
)
|
||||||
|
|
||||||
|
SessionOutlinedTextField(
|
||||||
|
text = "text onChange after error",
|
||||||
|
placeholder = "",
|
||||||
|
error = "error",
|
||||||
|
isTextErrorColor = false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,7 +88,8 @@ fun SessionOutlinedTextField(
|
|||||||
textStyle: TextStyle = base,
|
textStyle: TextStyle = base,
|
||||||
placeholder: String = "",
|
placeholder: String = "",
|
||||||
onContinue: () -> Unit = {},
|
onContinue: () -> Unit = {},
|
||||||
error: String? = null
|
error: String? = null,
|
||||||
|
isTextErrorColor: Boolean = error != null
|
||||||
) {
|
) {
|
||||||
Column(modifier = modifier.animateContentSize()) {
|
Column(modifier = modifier.animateContentSize()) {
|
||||||
Box(
|
Box(
|
||||||
@ -93,7 +107,7 @@ fun SessionOutlinedTextField(
|
|||||||
Text(
|
Text(
|
||||||
text = placeholder,
|
text = placeholder,
|
||||||
style = base,
|
style = base,
|
||||||
color = LocalColors.current.textSecondary(error != null),
|
color = LocalColors.current.textSecondary(isTextErrorColor),
|
||||||
modifier = Modifier.wrapContentSize()
|
modifier = Modifier.wrapContentSize()
|
||||||
.align(Alignment.CenterStart)
|
.align(Alignment.CenterStart)
|
||||||
.wrapContentSize()
|
.wrapContentSize()
|
||||||
@ -104,7 +118,7 @@ fun SessionOutlinedTextField(
|
|||||||
value = text,
|
value = text,
|
||||||
onValueChange = onChange,
|
onValueChange = onChange,
|
||||||
modifier = Modifier.wrapContentHeight().fillMaxWidth().contentDescription(contentDescription),
|
modifier = Modifier.wrapContentHeight().fillMaxWidth().contentDescription(contentDescription),
|
||||||
textStyle = textStyle.copy(color = LocalColors.current.text(error != null)),
|
textStyle = textStyle.copy(color = LocalColors.current.text(isTextErrorColor)),
|
||||||
cursorBrush = SolidColor(LocalColors.current.text(error != null)),
|
cursorBrush = SolidColor(LocalColors.current.text(error != null)),
|
||||||
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
|
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
|
||||||
keyboardActions = KeyboardActions(
|
keyboardActions = KeyboardActions(
|
||||||
|
Loading…
Reference in New Issue
Block a user