-
Notifications
You must be signed in to change notification settings - Fork 617
Feature:auth to cmp #2360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: kmp-impl
Are you sure you want to change the base?
Feature:auth to cmp #2360
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,11 @@ | |
*/ | ||
package com.mifos.feature.auth.login | ||
|
||
import androidclient.feature.auth.generated.resources.Res | ||
import androidclient.feature.auth.generated.resources.feature_auth_enter_credentials | ||
import androidclient.feature.auth.generated.resources.feature_auth_mifos_logo | ||
import androidclient.feature.auth.generated.resources.feature_auth_password | ||
import androidclient.feature.auth.generated.resources.feature_auth_username | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
|
@@ -23,11 +28,8 @@ import androidx.compose.foundation.rememberScrollState | |
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowForward | ||
import androidx.compose.material.icons.filled.Error | ||
import androidx.compose.material.icons.filled.Lock | ||
import androidx.compose.material.icons.filled.Person | ||
import androidx.compose.material.icons.filled.Visibility | ||
import androidx.compose.material.icons.filled.VisibilityOff | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.ButtonDefaults | ||
import androidx.compose.material3.CircularProgressIndicator | ||
|
@@ -50,28 +52,27 @@ import androidx.compose.runtime.saveable.rememberSaveable | |
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.Color.Companion.DarkGray | ||
import androidx.compose.ui.graphics.Color.Companion.White | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.input.PasswordVisualTransformation | ||
import androidx.compose.ui.text.input.TextFieldValue | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.DialogProperties | ||
import com.mifos.core.designsystem.component.MifosAndroidClientIcon | ||
import com.mifos.core.designsystem.component.MifosOutlinedTextField | ||
import com.mifos.feature.auth.R | ||
import org.koin.androidx.compose.koinViewModel | ||
import com.mifos.core.designsystem.icon.MifosIcons | ||
import org.jetbrains.compose.resources.StringResource | ||
import org.jetbrains.compose.resources.painterResource | ||
import org.jetbrains.compose.resources.stringResource | ||
import org.jetbrains.compose.ui.tooling.preview.Preview | ||
import org.koin.compose.viewmodel.koinViewModel | ||
|
||
/** | ||
* Created by Aditya Gupta on 11/02/24. | ||
|
@@ -86,7 +87,7 @@ internal fun LoginScreen( | |
loginViewModel: LoginViewModel = koinViewModel(), | ||
) { | ||
val state = loginViewModel.loginUiState.collectAsState().value | ||
val context = LocalContext.current | ||
// val context = LocalContext.current | ||
|
||
val snackbarHostState = remember { SnackbarHostState() } | ||
|
||
|
@@ -104,16 +105,16 @@ internal fun LoginScreen( | |
} | ||
var passwordVisibility: Boolean by remember { mutableStateOf(false) } | ||
|
||
val usernameError: MutableState<Int?> = remember { mutableStateOf(null) } | ||
val passwordError: MutableState<Int?> = remember { mutableStateOf(null) } | ||
val usernameError: MutableState<StringResource?> = remember { mutableStateOf(null) } | ||
val passwordError: MutableState<StringResource?> = remember { mutableStateOf(null) } | ||
|
||
when (state) { | ||
is LoginUiState.Empty -> {} | ||
|
||
is LoginUiState.ShowError -> { | ||
showDialog.value = false | ||
LaunchedEffect(key1 = state.message) { | ||
snackbarHostState.showSnackbar(message = context.getString(state.message)) | ||
snackbarHostState.showSnackbar(message = state.message.toString()) | ||
} | ||
} | ||
|
||
|
@@ -122,8 +123,8 @@ internal fun LoginScreen( | |
} | ||
|
||
is LoginUiState.ShowValidationError -> { | ||
usernameError.value = state.usernameError | ||
passwordError.value = state.passwordError | ||
usernameError.value = Res.string.feature_auth_username | ||
passwordError.value = Res.string.feature_auth_password | ||
} | ||
|
||
LoginUiState.HomeActivityIntent -> { | ||
|
@@ -141,7 +142,7 @@ internal fun LoginScreen( | |
modifier = modifier | ||
.fillMaxSize() | ||
.padding(16.dp), | ||
containerColor = Color.White, | ||
containerColor = White, | ||
snackbarHost = { SnackbarHost(snackbarHostState) }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have to remove all explicitly defined colours like how we didit in mifos mobile |
||
bottomBar = { | ||
Box( | ||
|
@@ -179,13 +180,13 @@ internal fun LoginScreen( | |
) { | ||
Spacer(modifier = Modifier.height(80.dp)) | ||
|
||
MifosAndroidClientIcon(imageVector = painterResource(R.drawable.feature_auth_mifos_logo)) | ||
MifosAndroidClientIcon(imageVector = painterResource(Res.drawable.feature_auth_mifos_logo)) | ||
|
||
Text( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 8.dp), | ||
text = stringResource(id = R.string.feature_auth_enter_credentials), | ||
text = stringResource(Res.string.feature_auth_enter_credentials), | ||
textAlign = TextAlign.Center, | ||
style = TextStyle( | ||
fontSize = 16.sp, | ||
|
@@ -203,11 +204,11 @@ internal fun LoginScreen( | |
userName = value | ||
}, | ||
icon = Icons.Filled.Person, | ||
label = stringResource(R.string.feature_auth_username), | ||
label = stringResource(Res.string.feature_auth_username), | ||
error = usernameError.value?.let { it1 -> stringResource(it1) }, | ||
trailingIcon = { | ||
if (usernameError.value != null) { | ||
Icon(imageVector = Icons.Filled.Error, contentDescription = null) | ||
Icon(imageVector = MifosIcons.Error, contentDescription = null) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for content description give any valid string instead of null |
||
}, | ||
) | ||
|
@@ -221,20 +222,20 @@ internal fun LoginScreen( | |
}, | ||
visualTransformation = if (passwordVisibility) VisualTransformation.None else PasswordVisualTransformation(), | ||
icon = Icons.Filled.Lock, | ||
label = stringResource(R.string.feature_auth_password), | ||
label = stringResource(Res.string.feature_auth_password), | ||
error = passwordError.value?.let { it1 -> stringResource(it1) }, | ||
trailingIcon = { | ||
if (passwordError.value == null) { | ||
val image = if (passwordVisibility) { | ||
Icons.Filled.Visibility | ||
MifosIcons.Visibility | ||
} else { | ||
Icons.Filled.VisibilityOff | ||
MifosIcons.VisibilityOff | ||
} | ||
IconButton(onClick = { passwordVisibility = !passwordVisibility }) { | ||
Icon(imageVector = image, null) | ||
} | ||
} else { | ||
Icon(imageVector = Icons.Filled.Error, contentDescription = null) | ||
Icon(imageVector = MifosIcons.Error, contentDescription = null) | ||
} | ||
}, | ||
) | ||
|
@@ -266,7 +267,18 @@ internal fun LoginScreen( | |
} | ||
} | ||
|
||
@Preview(showSystemUi = true, device = "id:pixel_7") | ||
// @Composable | ||
// fun Scaffold( | ||
// modifier: Modifier, | ||
// containerColor: Color, | ||
// snackbarHost: () -> SnackbarHost, | ||
// bottomBar: () -> Unit, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can i know what is it for? |
||
// content: @Composable () -> Unit | ||
// ) { | ||
// TODO("Not yet implemented") | ||
// } | ||
|
||
@Preview | ||
@Composable | ||
private fun LoginScreenPreview() { | ||
LoginScreen({}, {}, {}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,16 +9,16 @@ | |
*/ | ||
package com.mifos.feature.auth.login | ||
|
||
import android.util.Log | ||
import androidclient.feature.auth.generated.resources.Res | ||
import androidclient.feature.auth.generated.resources.feature_auth_error_login_failed | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.mifos.core.common.model.user.User | ||
import com.mifos.core.common.utils.Resource | ||
import com.mifos.core.datastore.UserPreferencesRepository | ||
import com.mifos.core.domain.useCases.LoginUseCase | ||
import com.mifos.core.domain.useCases.PasswordValidationUseCase | ||
import com.mifos.core.domain.useCases.UsernameValidationUseCase | ||
import com.mifos.core.model.objects.users.User | ||
import com.mifos.feature.auth.R | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
|
@@ -85,17 +85,17 @@ class LoginViewModel( | |
viewModelScope.launch(Dispatchers.IO) { | ||
loginUseCase(username, password).collect { result -> | ||
when (result) { | ||
is Resource.Error -> { | ||
is Resource.Error<*> -> { | ||
_loginUiState.value = | ||
LoginUiState.ShowError(R.string.feature_auth_error_login_failed) | ||
LoginUiState.ShowError(Res.string.feature_auth_error_login_failed) | ||
Log.e("@@@", "login: ${result.message}") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you have removed import android.util.Log but didn't used Logger like that didn't it showing any error at Log? |
||
|
||
is Resource.Loading -> { | ||
is Resource.Loading<*> -> { | ||
_loginUiState.value = LoginUiState.ShowProgress | ||
} | ||
|
||
is Resource.Success -> { | ||
is Resource.Success<*> -> { | ||
result.data?.let { | ||
if (it.userId != null && it.authenticated == true) { | ||
onLoginSuccessful(it, username, password) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the testing one instead of commenting