99 */
1010package com.mifos.feature.auth.login
1111
12+ import androidclient.feature.auth.generated.resources.Res
13+ import androidclient.feature.auth.generated.resources.feature_auth_enter_credentials
14+ import androidclient.feature.auth.generated.resources.feature_auth_mifos_logo
15+ import androidclient.feature.auth.generated.resources.feature_auth_password
16+ import androidclient.feature.auth.generated.resources.feature_auth_username
1217import androidx.compose.foundation.layout.Box
1318import androidx.compose.foundation.layout.Column
1419import androidx.compose.foundation.layout.PaddingValues
@@ -21,13 +26,7 @@ import androidx.compose.foundation.layout.padding
2126import androidx.compose.foundation.layout.width
2227import androidx.compose.foundation.rememberScrollState
2328import androidx.compose.foundation.verticalScroll
24- import androidx.compose.material.icons.Icons
2529import androidx.compose.material.icons.automirrored.filled.ArrowForward
26- import androidx.compose.material.icons.filled.Error
27- import androidx.compose.material.icons.filled.Lock
28- import androidx.compose.material.icons.filled.Person
29- import androidx.compose.material.icons.filled.Visibility
30- import androidx.compose.material.icons.filled.VisibilityOff
3130import androidx.compose.material3.Button
3231import androidx.compose.material3.ButtonDefaults
3332import androidx.compose.material3.CircularProgressIndicator
@@ -46,32 +45,30 @@ import androidx.compose.runtime.collectAsState
4645import androidx.compose.runtime.getValue
4746import androidx.compose.runtime.mutableStateOf
4847import androidx.compose.runtime.remember
48+ import androidx.compose.runtime.rememberCoroutineScope
4949import androidx.compose.runtime.saveable.rememberSaveable
5050import androidx.compose.runtime.setValue
5151import androidx.compose.ui.Alignment
5252import androidx.compose.ui.Modifier
53- import androidx.compose.ui.graphics.Color
54- import androidx.compose.ui.graphics.Color.Companion.DarkGray
5553import androidx.compose.ui.graphics.Color.Companion.White
56- import androidx.compose.ui.platform.LocalContext
57- import androidx.compose.ui.res.painterResource
58- import androidx.compose.ui.res.stringResource
59- import androidx.compose.ui.text.TextStyle
60- import androidx.compose.ui.text.font.FontStyle
61- import androidx.compose.ui.text.font.FontWeight
6254import androidx.compose.ui.text.input.PasswordVisualTransformation
6355import androidx.compose.ui.text.input.TextFieldValue
6456import androidx.compose.ui.text.input.VisualTransformation
6557import androidx.compose.ui.text.style.TextAlign
66- import androidx.compose.ui.tooling.preview.Preview
6758import androidx.compose.ui.unit.dp
6859import androidx.compose.ui.unit.sp
6960import androidx.compose.ui.window.Dialog
7061import androidx.compose.ui.window.DialogProperties
7162import com.mifos.core.designsystem.component.MifosAndroidClientIcon
7263import com.mifos.core.designsystem.component.MifosOutlinedTextField
73- import com.mifos.feature.auth.R
74- import org.koin.androidx.compose.koinViewModel
64+ import com.mifos.core.designsystem.icon.MifosIcons
65+ import com.mifos.core.ui.util.DevicePreview
66+ import kotlinx.coroutines.launch
67+ import org.jetbrains.compose.resources.StringResource
68+ import org.jetbrains.compose.resources.getString
69+ import org.jetbrains.compose.resources.painterResource
70+ import org.jetbrains.compose.resources.stringResource
71+ import org.koin.compose.viewmodel.koinViewModel
7572
7673/* *
7774 * Created by Aditya Gupta on 11/02/24.
@@ -86,7 +83,7 @@ internal fun LoginScreen(
8683 loginViewModel : LoginViewModel = koinViewModel(),
8784) {
8885 val state = loginViewModel.loginUiState.collectAsState().value
89- val context = LocalContext .current
86+ val coroutineScope = rememberCoroutineScope()
9087
9188 val snackbarHostState = remember { SnackbarHostState () }
9289
@@ -104,16 +101,16 @@ internal fun LoginScreen(
104101 }
105102 var passwordVisibility: Boolean by remember { mutableStateOf(false ) }
106103
107- val usernameError: MutableState <Int ?> = remember { mutableStateOf(null ) }
108- val passwordError: MutableState <Int ?> = remember { mutableStateOf(null ) }
104+ val usernameError: MutableState <StringResource ?> = remember { mutableStateOf(null ) }
105+ val passwordError: MutableState <StringResource ?> = remember { mutableStateOf(null ) }
109106
110107 when (state) {
111108 is LoginUiState .Empty -> {}
112109
113110 is LoginUiState .ShowError -> {
114111 showDialog.value = false
115112 LaunchedEffect (key1 = state.message) {
116- snackbarHostState.showSnackbar(message = context. getString(state.message))
113+ snackbarHostState.showSnackbar(message = getString(state.message))
117114 }
118115 }
119116
@@ -141,7 +138,7 @@ internal fun LoginScreen(
141138 modifier = modifier
142139 .fillMaxSize()
143140 .padding(16 .dp),
144- containerColor = Color . White ,
141+ containerColor = White ,
145142 snackbarHost = { SnackbarHost (snackbarHostState) },
146143 bottomBar = {
147144 Box (
@@ -162,7 +159,7 @@ internal fun LoginScreen(
162159 Spacer (modifier = Modifier .width(4 .dp))
163160
164161 Icon (
165- imageVector = Icons . AutoMirrored . Filled .ArrowForward ,
162+ imageVector = MifosIcons .ArrowForward ,
166163 contentDescription = " ArrowForward" ,
167164 )
168165 }
@@ -179,20 +176,15 @@ internal fun LoginScreen(
179176 ) {
180177 Spacer (modifier = Modifier .height(80 .dp))
181178
182- MifosAndroidClientIcon (imageVector = painterResource(R .drawable.feature_auth_mifos_logo))
179+ MifosAndroidClientIcon (imageVector = painterResource(Res .drawable.feature_auth_mifos_logo))
183180
184181 Text (
185182 modifier = Modifier
186183 .fillMaxWidth()
187184 .padding(top = 8 .dp),
188- text = stringResource(id = R .string.feature_auth_enter_credentials),
185+ text = stringResource(Res .string.feature_auth_enter_credentials),
189186 textAlign = TextAlign .Center ,
190- style = TextStyle (
191- fontSize = 16 .sp,
192- fontWeight = FontWeight .Bold ,
193- fontStyle = FontStyle .Normal ,
194- color = DarkGray ,
195- ),
187+ style = MaterialTheme .typography.bodyMedium,
196188 )
197189
198190 Spacer (modifier = Modifier .height(16 .dp))
@@ -202,12 +194,12 @@ internal fun LoginScreen(
202194 onValueChanged = { value ->
203195 userName = value
204196 },
205- icon = Icons . Filled .Person ,
206- label = stringResource(R .string.feature_auth_username),
197+ icon = MifosIcons .Person ,
198+ label = stringResource(Res .string.feature_auth_username),
207199 error = usernameError.value?.let { it1 -> stringResource(it1) },
208200 trailingIcon = {
209201 if (usernameError.value != null ) {
210- Icon (imageVector = Icons . Filled . Error , contentDescription = null )
202+ Icon (imageVector = MifosIcons . Error , contentDescription = " Error Icon " )
211203 }
212204 },
213205 )
@@ -220,29 +212,33 @@ internal fun LoginScreen(
220212 password = value
221213 },
222214 visualTransformation = if (passwordVisibility) VisualTransformation .None else PasswordVisualTransformation (),
223- icon = Icons . Filled .Lock ,
224- label = stringResource(R .string.feature_auth_password),
215+ icon = MifosIcons .Lock ,
216+ label = stringResource(Res .string.feature_auth_password),
225217 error = passwordError.value?.let { it1 -> stringResource(it1) },
226218 trailingIcon = {
227219 if (passwordError.value == null ) {
228220 val image = if (passwordVisibility) {
229- Icons . Filled .Visibility
221+ MifosIcons .Visibility
230222 } else {
231- Icons . Filled .VisibilityOff
223+ MifosIcons .VisibilityOff
232224 }
233225 IconButton (onClick = { passwordVisibility = ! passwordVisibility }) {
234- Icon (imageVector = image, null )
226+ Icon (imageVector = image, " PasswordVisibility Icon " )
235227 }
236228 } else {
237- Icon (imageVector = Icons . Filled .Error , contentDescription = null )
229+ Icon (MifosIcons .Error , contentDescription = null )
238230 }
239231 },
240232 )
241233
242234 Spacer (modifier = Modifier .height(8 .dp))
243235
244236 Button (
245- onClick = { loginViewModel.validateUserInputs(userName.text, password.text) },
237+ onClick = {
238+ coroutineScope.launch {
239+ loginViewModel.validateUserInputs(userName.text, password.text)
240+ }
241+ },
246242 modifier = Modifier
247243 .fillMaxWidth()
248244 .heightIn(44 .dp)
@@ -266,7 +262,7 @@ internal fun LoginScreen(
266262 }
267263}
268264
269- @Preview(showSystemUi = true , device = " id:pixel_7 " )
265+ @DevicePreview( )
270266@Composable
271267private fun LoginScreenPreview () {
272268 LoginScreen ({}, {}, {})
0 commit comments