Skip to content

Commit

Permalink
Refactor : Registration Screen from XML to Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
akashmeruva9 committed Jun 29, 2024
1 parent feb2208 commit ba0d5fe
Showing 1 changed file with 32 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,16 @@ fun RegistrationScreen(
onVerified = onVerified,
navigateBack = navigateBack,
register = { account, username, firstname, lastname, phoneNumber, email, password, confirmPassword, authenticationMode, countryCode ->

val error = areFieldsValidated(
context = context,
accountNumberContent = account,
usernameContent = username,
firstNameContent = firstname,
lastNameContent = lastname,
phoneNumberContent = phoneNumber,
emailContent = email,
passwordContent = password,
confirmPasswordContent = confirmPassword
viewModel.registerUser(
accountNumber = account,
authenticationMode = authenticationMode,
email = email,
firstName = firstname,
lastName = lastname,
mobileNumber = "$countryCode$phoneNumber",
password = password,
username = username
)

if (error == "") {
viewModel.registerUser(
accountNumber = account,
authenticationMode = authenticationMode,
email = email,
firstName = firstname,
lastName = lastname,
mobileNumber = "$countryCode$phoneNumber",
password = password,
username = username
)
}
error
},
progress = { updatePasswordStrengthView(it, context) }
)
Expand All @@ -126,7 +110,7 @@ fun RegistrationScreen(
uiState: RegistrationUiState,
onVerified: () -> Unit,
navigateBack: () -> Unit,
register: (accountNumber: String, username: String, firstName: String, lastName: String, phoneNumber: String, email: String, password: String, confirmPassword: String, authMode: String, countryCode: String) -> String,
register: (accountNumber: String, username: String, firstName: String, lastName: String, phoneNumber: String, email: String, password: String, confirmPassword: String, authMode: String, countryCode: String) -> Unit,
progress: (String) -> Float
) {
val context = LocalContext.current
Expand Down Expand Up @@ -174,10 +158,12 @@ fun RegistrationScreen(

@Composable
fun RegistrationContent(
register: (accountNumber: String, username: String, firstName: String, lastName: String, phoneNumber: String, email: String, password: String, confirmPassword: String, authMode: String, countryCode: String) -> String,
register: (accountNumber: String, username: String, firstName: String, lastName: String, phoneNumber: String, email: String, password: String, confirmPassword: String, authMode: String, countryCode: String) -> Unit,
progress: (String) -> Float,
snackBarHostState: SnackbarHostState,
) {
val context = LocalContext.current

val keyboardController = LocalSoftwareKeyboardController.current

var accountNumber by rememberSaveable(stateSaver = TextFieldValue.Saver) {
Expand Down Expand Up @@ -371,19 +357,20 @@ fun RegistrationContent(

Button(
onClick = {
val error = register.invoke(
accountNumber.text,
username.text,
firstName.text,
lastName.text,
phoneNumber.text,
email.text,
password.text,
confirmPassword.text,
authenticationMode,
countryCode
val error = areFieldsValidated(
context = context,
accountNumberContent = accountNumber.text,
usernameContent = username.text,
firstNameContent = firstName.text,
lastNameContent = lastName.text,
phoneNumberContent = phoneNumber.text,
emailContent = email.text,
passwordContent = password.text,
confirmPasswordContent = confirmPassword.text,
)
if (error != "") {
if (error == "") {

}else {
coroutineScope.launch {
snackBarHostState.showSnackbar(
message = error,
Expand Down Expand Up @@ -559,12 +546,12 @@ fun updatePasswordStrengthView(password: String, context: Context): Float {
class RegistrationScreenPreviewProvider : PreviewParameterProvider<RegistrationUiState> {

override val values: Sequence<RegistrationUiState>
get() = sequenceOf(
RegistrationUiState.Loading,
RegistrationUiState.Error(1),
RegistrationUiState.Success,
RegistrationUiState.Initial,
)
get() = sequenceOf(
RegistrationUiState.Loading,
RegistrationUiState.Error(1),
RegistrationUiState.Success,
RegistrationUiState.Initial,
)
}

@Preview(showSystemUi = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
Expand Down

0 comments on commit ba0d5fe

Please sign in to comment.