diff --git a/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationScreen.kt b/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationScreen.kt index 09a5a492d6..a2ecce1a79 100644 --- a/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationScreen.kt +++ b/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationScreen.kt @@ -22,9 +22,9 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Surface import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.material3.TextField import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -319,7 +319,11 @@ private fun PinInputLabel( modifier: Modifier = Modifier ) { Text( - text = state.inputLabel ?: "", + text = when { + state.isConfirmEnabled -> stringResource(R.string.PinCreationScreen__reenter_pin) + state.isAlphanumericKeyboard -> stringResource(R.string.PinCreationScreen__pin_at_least_4_characters) + else -> stringResource(R.string.PinCreationScreen__pin_at_least_4_digits) + }, style = MaterialTheme.typography.bodyMedium, textAlign = TextAlign.Center, color = MaterialTheme.colorScheme.onSurfaceVariant, @@ -333,7 +337,7 @@ private fun KeyboardToggleButton( onToggleKeyboard: () -> Unit, modifier: Modifier = Modifier ) { - OutlinedButton( + TextButton( onClick = onToggleKeyboard, modifier = modifier.fillMaxWidth() ) { @@ -383,11 +387,11 @@ private fun NextButton( @AllDevicePreviews @Composable -private fun PinCreationScreenPreview() { +private fun PinCreationScreenNumericPreview() { Previews.Preview { PinCreationScreen( state = PinCreationState( - inputLabel = "PIN must be at least 4 digits" + isAlphanumericKeyboard = false ), onEvent = {} ) @@ -400,8 +404,7 @@ private fun PinCreationScreenAlphanumericPreview() { Previews.Preview { PinCreationScreen( state = PinCreationState( - isAlphanumericKeyboard = false, - inputLabel = "PIN must be at least 4 characters" + isAlphanumericKeyboard = true ), onEvent = {} ) diff --git a/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationState.kt b/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationState.kt index bde1766d72..1e866bcfbe 100644 --- a/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationState.kt +++ b/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationState.kt @@ -10,7 +10,6 @@ import org.signal.registration.util.DebugLoggableModel data class PinCreationState( val isAlphanumericKeyboard: Boolean = false, - val inputLabel: String? = null, val isConfirmEnabled: Boolean = false, val accountEntropyPool: AccountEntropyPool? = null ) : DebugLoggableModel() diff --git a/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationViewModel.kt b/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationViewModel.kt index 50160e9f0f..cb31f04b95 100644 --- a/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationViewModel.kt +++ b/feature/registration/src/main/java/org/signal/registration/screens/pincreation/PinCreationViewModel.kt @@ -38,16 +38,12 @@ class PinCreationViewModel( private val TAG = Log.tag(PinCreationViewModel::class) } - private val _state = MutableStateFlow( - PinCreationState( - inputLabel = "PIN must be at least 4 digits" - ) - ) + private val _state = MutableStateFlow(PinCreationState()) val state: StateFlow = _state .combine(parentState) { state, parentState -> applyParentState(state, parentState) } .onEach { Log.d(TAG, "[State] $it") } - .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), PinCreationState(inputLabel = "PIN must be at least 4 digits")) + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), PinCreationState()) override suspend fun processEvent(event: PinCreationScreenEvents) { applyEvent(state.value, event) @@ -61,13 +57,13 @@ class PinCreationViewModel( val result = applyPinSubmitted(state, event.pin) _state.value = result } + is PinCreationScreenEvents.ToggleKeyboard -> { - val newValue = !state.isAlphanumericKeyboard _state.value = state.copy( - isAlphanumericKeyboard = newValue, - inputLabel = if (newValue) "PIN must be at least 4 digits" else "PIN must be at least 4 characters" + isAlphanumericKeyboard = !state.isAlphanumericKeyboard ) } + is PinCreationScreenEvents.LearnMore -> { // TODO [registration] - Show learn more dialog or navigate to help screen throw NotImplementedError("Show learn more dialog or navigate to help screen") @@ -98,6 +94,7 @@ class PinCreationViewModel( parentEventEmitter(RegistrationFlowEvent.RegistrationComplete) state } + is RequestResult.NonSuccess -> { when (val error = result.error) { is NetworkController.BackupMasterKeyError.EnclaveNotFound -> { @@ -105,6 +102,7 @@ class PinCreationViewModel( // TODO [registration] - Report to UI and indicate to library user that pin could not be created throw NotImplementedError("Report to UI and indicate to library user that pin could not be created") } + is NetworkController.BackupMasterKeyError.NotRegistered -> { Log.w(TAG, "[PinSubmitted] Account not registered. This should not happen. Resetting.") parentEventEmitter(RegistrationFlowEvent.ResetState) @@ -112,11 +110,13 @@ class PinCreationViewModel( } } } + is RequestResult.RetryableNetworkError -> { Log.w(TAG, "[PinSubmitted] Network error when backing up master key.", result.networkError) // TODO [registration] - Report to UI and indicate to library user that pin could not be created throw NotImplementedError("Report to UI and indicate to library user that pin could not be created") } + is RequestResult.ApplicationError -> { Log.w(TAG, "[PinSubmitted] Application error when backing up master key.", result.cause) // TODO [registration] - Report to UI and indicate to library user that pin could not be created diff --git a/feature/registration/src/main/java/org/signal/registration/screens/pinentry/PinEntryScreen.kt b/feature/registration/src/main/java/org/signal/registration/screens/pinentry/PinEntryScreen.kt index de6247cfed..c4fa601a88 100644 --- a/feature/registration/src/main/java/org/signal/registration/screens/pinentry/PinEntryScreen.kt +++ b/feature/registration/src/main/java/org/signal/registration/screens/pinentry/PinEntryScreen.kt @@ -341,7 +341,7 @@ private fun KeyboardToggleButton( onToggleKeyboard: () -> Unit, modifier: Modifier = Modifier ) { - OutlinedButton( + TextButton( onClick = onToggleKeyboard, modifier = modifier.fillMaxWidth() ) { diff --git a/feature/registration/src/main/res/values/strings.xml b/feature/registration/src/main/res/values/strings.xml index 8cad883008..5d0a4af745 100644 --- a/feature/registration/src/main/res/values/strings.xml +++ b/feature/registration/src/main/res/values/strings.xml @@ -327,6 +327,12 @@ Switch to alphanumeric Next + + PIN must be at least 4 digits + + PIN must be at least 4 characters + + Re-enter PIN Registration Lock