From c247172db4724d5a36ebc1a4055d4e0872d5c928 Mon Sep 17 00:00:00 2001 From: Darkeye14 Date: Wed, 13 Nov 2024 19:09:34 +0530 Subject: [PATCH 1/5] Post Login Navigation Issue --- .../java/com/mifos/feature/auth/login/LoginScreen.kt | 7 ++++++- .../com/mifos/feature/auth/login/LoginUiState.kt | 2 ++ .../com/mifos/feature/auth/login/LoginViewModel.kt | 1 + .../mifos/feature/auth/navigation/AuthNavigation.kt | 12 ++++++++---- .../main/java/com/mifos/mifosxdroid/AndroidClient.kt | 3 ++- .../mifosxdroid/activity/login/LoginActivity.kt | 4 ++++ 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt index 08d80f378a..e3f38b79c5 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt @@ -75,6 +75,7 @@ fun LoginScreen( homeIntent: () -> Unit, passcodeIntent: () -> Unit, onClickToUpdateServerConfig: () -> Unit, + onSuccessNavigate: () -> Unit ) { val loginViewModel: LoginViewModel = hiltViewModel() @@ -128,6 +129,10 @@ fun LoginScreen( showDialog.value = false passcodeIntent() } + LoginUiState.NavigateToHome ->{ + showDialog.value = false + onSuccessNavigate() + } } @@ -264,5 +269,5 @@ fun LoginScreen( @Preview(showSystemUi = true, device = "id:pixel_7") @Composable fun LoginScreenPreview() { - LoginScreen({}, {}, {}) + LoginScreen({}, {}, {},{}) } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt index 48b5c57ad7..dc4dd47169 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt @@ -19,4 +19,6 @@ sealed class LoginUiState { data object PassCodeActivityIntent : LoginUiState() + data object NavigateToHome : LoginUiState() + } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt index 3217fec6cc..144f0ec2a1 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt @@ -118,6 +118,7 @@ class LoginViewModel @Inject constructor( } else { _loginUiState.value = LoginUiState.PassCodeActivityIntent } + _loginUiState.value = LoginUiState.NavigateToHome } } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt index d72e070a58..ceee92b0a3 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt @@ -9,7 +9,8 @@ import com.mifos.feature.auth.login.LoginScreen fun NavGraphBuilder.authNavGraph( navigateHome: () -> Unit, navigatePasscode: () -> Unit, - updateServerConfig: () -> Unit + updateServerConfig: () -> Unit, + onSuccessNavigate : () -> Unit ) { navigation( startDestination = AuthScreens.LoginScreen.route, @@ -18,7 +19,8 @@ fun NavGraphBuilder.authNavGraph( loginRoute( navigatePasscode = navigatePasscode, navigateHome = navigateHome, - updateServerConfig = updateServerConfig + updateServerConfig = updateServerConfig, + onSuccessNavigate = onSuccessNavigate ) } @@ -27,7 +29,8 @@ fun NavGraphBuilder.authNavGraph( fun NavGraphBuilder.loginRoute( navigateHome: () -> Unit, navigatePasscode: () -> Unit, - updateServerConfig: () -> Unit + updateServerConfig: () -> Unit, + onSuccessNavigate: () -> Unit ) { composable( route = AuthScreens.LoginScreen.route @@ -35,7 +38,8 @@ fun NavGraphBuilder.loginRoute( LoginScreen( homeIntent = navigateHome, passcodeIntent = navigatePasscode, - onClickToUpdateServerConfig = updateServerConfig + onClickToUpdateServerConfig = updateServerConfig, + onSuccessNavigate = onSuccessNavigate ) } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt index adf72a8324..5873958068 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt @@ -32,7 +32,8 @@ fun AndroidClient() { authNavGraph( navigatePasscode = {}, navigateHome = navController::navigateHome, - updateServerConfig = {} + updateServerConfig = {}, + onSuccessNavigate = navController ::navigateHome ) homeGraph() diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginActivity.kt index a829dccfc5..5180c7573b 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginActivity.kt @@ -37,6 +37,10 @@ class LoginActivity : MifosBaseActivity() { supportFragmentManager, "UpdateServerConfigFragment" ) + }, + onSuccessNavigate = { + startActivity(Intent(this, HomeActivity::class.java)) + finish() } ) } From 6b518aac0f640b2df9b3934027ae35b1378897d6 Mon Sep 17 00:00:00 2001 From: Darkeye14 Date: Wed, 13 Nov 2024 19:32:28 +0530 Subject: [PATCH 2/5] Applying Spotless --- feature/auth/build.gradle.kts | 9 +++ .../feature/auth/ExampleInstrumentedTest.kt | 17 ++++-- feature/auth/src/main/AndroidManifest.xml | 9 +++ .../mifos/feature/auth/login/LoginScreen.kt | 59 +++++++++++-------- .../mifos/feature/auth/login/LoginUiState.kt | 12 +++- .../feature/auth/login/LoginViewModel.kt | 24 ++++---- .../feature/auth/navigation/AuthNavigation.kt | 26 +++++--- .../feature/auth/navigation/AuthScreens.kt | 12 +++- feature/auth/src/main/res/values/strings.xml | 9 +++ .../com/mifos/feature/auth/ExampleUnitTest.kt | 14 ++++- 10 files changed, 135 insertions(+), 56 deletions(-) diff --git a/feature/auth/build.gradle.kts b/feature/auth/build.gradle.kts index 4dadb520cf..a574032909 100644 --- a/feature/auth/build.gradle.kts +++ b/feature/auth/build.gradle.kts @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ plugins { alias(libs.plugins.mifos.android.feature) alias(libs.plugins.mifos.android.library.compose) diff --git a/feature/auth/src/androidTest/java/com/mifos/feature/auth/ExampleInstrumentedTest.kt b/feature/auth/src/androidTest/java/com/mifos/feature/auth/ExampleInstrumentedTest.kt index 1dad89c8ef..5d3bfedc5b 100644 --- a/feature/auth/src/androidTest/java/com/mifos/feature/auth/ExampleInstrumentedTest.kt +++ b/feature/auth/src/androidTest/java/com/mifos/feature/auth/ExampleInstrumentedTest.kt @@ -1,13 +1,20 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.auth -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * @@ -21,4 +28,4 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.mifos.feature.auth.test", appContext.packageName) } -} \ No newline at end of file +} diff --git a/feature/auth/src/main/AndroidManifest.xml b/feature/auth/src/main/AndroidManifest.xml index a5918e68ab..1dc76da0f7 100644 --- a/feature/auth/src/main/AndroidManifest.xml +++ b/feature/auth/src/main/AndroidManifest.xml @@ -1,4 +1,13 @@ + \ No newline at end of file diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt index e3f38b79c5..96962f5554 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.auth.login import androidx.compose.foundation.isSystemInDarkTheme @@ -75,9 +84,8 @@ fun LoginScreen( homeIntent: () -> Unit, passcodeIntent: () -> Unit, onClickToUpdateServerConfig: () -> Unit, - onSuccessNavigate: () -> Unit + onSuccessNavigate: () -> Unit, ) { - val loginViewModel: LoginViewModel = hiltViewModel() val state = loginViewModel.loginUiState.collectAsState().value val context = LocalContext.current @@ -88,12 +96,12 @@ fun LoginScreen( var userName by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf( - TextFieldValue("") + TextFieldValue(""), ) } var password by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf( - TextFieldValue("") + TextFieldValue(""), ) } var passwordVisibility: Boolean by remember { mutableStateOf(false) } @@ -129,13 +137,12 @@ fun LoginScreen( showDialog.value = false passcodeIntent() } - LoginUiState.NavigateToHome ->{ + LoginUiState.NavigateToHome -> { showDialog.value = false onSuccessNavigate() } } - Scaffold( modifier = Modifier .fillMaxSize() @@ -145,7 +152,7 @@ fun LoginScreen( bottomBar = { Box( modifier = Modifier.fillMaxWidth(), - contentAlignment = Alignment.Center + contentAlignment = Alignment.Center, ) { FilledTonalButton( onClick = onClickToUpdateServerConfig, @@ -153,8 +160,8 @@ fun LoginScreen( .align(Alignment.Center), colors = ButtonDefaults.filledTonalButtonColors( containerColor = MaterialTheme.colorScheme.tertiaryContainer, - contentColor = MaterialTheme.colorScheme.tertiary - ) + contentColor = MaterialTheme.colorScheme.tertiary, + ), ) { Text(text = "Update Server Configuration") @@ -162,18 +169,18 @@ fun LoginScreen( Icon( imageVector = Icons.AutoMirrored.Filled.ArrowForward, - contentDescription = "ArrowForward" + contentDescription = "ArrowForward", ) } } - } + }, ) { Column( modifier = Modifier .fillMaxWidth() .padding(it) .verticalScroll(rememberScrollState()), - horizontalAlignment = Alignment.CenterHorizontally + horizontalAlignment = Alignment.CenterHorizontally, ) { Spacer(modifier = Modifier.height(80.dp)) @@ -190,8 +197,8 @@ fun LoginScreen( fontSize = 16.sp, fontWeight = FontWeight.Bold, fontStyle = FontStyle.Normal, - color = DarkGray - ) + color = DarkGray, + ), ) Spacer(modifier = Modifier.height(16.dp)) @@ -208,7 +215,7 @@ fun LoginScreen( if (usernameError.value != null) { Icon(imageVector = Icons.Filled.Error, contentDescription = null) } - } + }, ) Spacer(modifier = Modifier.height(6.dp)) @@ -224,16 +231,18 @@ fun LoginScreen( error = passwordError.value, trailingIcon = { if (passwordError.value == null) { - val image = if (passwordVisibility) + val image = if (passwordVisibility) { Icons.Filled.Visibility - else Icons.Filled.VisibilityOff + } else { + Icons.Filled.VisibilityOff + } IconButton(onClick = { passwordVisibility = !passwordVisibility }) { Icon(imageVector = image, null) } } else { Icon(imageVector = Icons.Filled.Error, contentDescription = null) } - } + }, ) Spacer(modifier = Modifier.height(8.dp)) @@ -246,8 +255,8 @@ fun LoginScreen( .padding(start = 16.dp, end = 16.dp), contentPadding = PaddingValues(), colors = ButtonDefaults.buttonColors( - containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary - ) + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, + ), ) { Text(text = "Login", fontSize = 16.sp) } @@ -257,8 +266,8 @@ fun LoginScreen( onDismissRequest = { showDialog.value }, properties = DialogProperties( dismissOnBackPress = false, - dismissOnClickOutside = false - ) + dismissOnClickOutside = false, + ), ) { CircularProgressIndicator(color = White) } @@ -268,6 +277,6 @@ fun LoginScreen( @Preview(showSystemUi = true, device = "id:pixel_7") @Composable -fun LoginScreenPreview() { - LoginScreen({}, {}, {},{}) -} \ No newline at end of file +private fun LoginScreenPreview() { + LoginScreen({}, {}, {}, {}) +} diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt index dc4dd47169..3d76b4080c 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.auth.login /** @@ -20,5 +29,4 @@ sealed class LoginUiState { data object PassCodeActivityIntent : LoginUiState() data object NavigateToHome : LoginUiState() - -} \ No newline at end of file +} diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt index 144f0ec2a1..4b881cbfee 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.auth.login import android.content.Context @@ -31,16 +40,14 @@ class LoginViewModel @Inject constructor( private val usernameValidationUseCase: UsernameValidationUseCase, private val passwordValidationUseCase: PasswordValidationUseCase, private val baseApiManager: BaseApiManager, - private val loginUseCase: com.mifos.core.domain.use_cases.LoginUseCase + private val loginUseCase: com.mifos.core.domain.use_cases.LoginUseCase, ) : ViewModel() { private val _loginUiState = MutableStateFlow(LoginUiState.Empty) val loginUiState = _loginUiState.asStateFlow() - fun validateUserInputs(username: String, password: String) { - val usernameValidationResult = usernameValidationUseCase(username) val passwordValidationResult = passwordValidationUseCase(password) @@ -50,7 +57,7 @@ class LoginViewModel @Inject constructor( if (hasError) { _loginUiState.value = LoginUiState.ShowValidationError( usernameValidationResult.message, - passwordValidationResult.message + passwordValidationResult.message, ) return } @@ -66,7 +73,7 @@ class LoginViewModel @Inject constructor( password, prefManager.getServerConfig.getInstanceUrl(), prefManager.getServerConfig.tenant, - true + true, ) if (Network.isOnline(context)) { login(username, password) @@ -76,7 +83,6 @@ class LoginViewModel @Inject constructor( } } - fun login(username: String, password: String) { viewModelScope.launch(Dispatchers.IO) { loginUseCase(username, password).collect { result -> @@ -98,11 +104,10 @@ class LoginViewModel @Inject constructor( } } - private fun onLoginSuccessful( user: PostAuthenticationResponse, username: String, - password: String + password: String, ) { // Saving username password prefManager.usernamePassword = Pair(username, password) @@ -120,5 +125,4 @@ class LoginViewModel @Inject constructor( } _loginUiState.value = LoginUiState.NavigateToHome } - -} \ No newline at end of file +} diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt index ceee92b0a3..57112cc494 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.auth.navigation import androidx.navigation.NavController @@ -10,40 +19,39 @@ fun NavGraphBuilder.authNavGraph( navigateHome: () -> Unit, navigatePasscode: () -> Unit, updateServerConfig: () -> Unit, - onSuccessNavigate : () -> Unit + onSuccessNavigate: () -> Unit, ) { navigation( startDestination = AuthScreens.LoginScreen.route, - route = AuthScreens.LoginScreenRoute.route + route = AuthScreens.LoginScreenRoute.route, ) { loginRoute( navigatePasscode = navigatePasscode, navigateHome = navigateHome, updateServerConfig = updateServerConfig, - onSuccessNavigate = onSuccessNavigate + onSuccessNavigate = onSuccessNavigate, ) } - } -fun NavGraphBuilder.loginRoute( +private fun NavGraphBuilder.loginRoute( navigateHome: () -> Unit, navigatePasscode: () -> Unit, updateServerConfig: () -> Unit, - onSuccessNavigate: () -> Unit + onSuccessNavigate: () -> Unit, ) { composable( - route = AuthScreens.LoginScreen.route + route = AuthScreens.LoginScreen.route, ) { LoginScreen( homeIntent = navigateHome, passcodeIntent = navigatePasscode, onClickToUpdateServerConfig = updateServerConfig, - onSuccessNavigate = onSuccessNavigate + onSuccessNavigate = onSuccessNavigate, ) } } fun NavController.navigateToLogin() { navigate(AuthScreens.LoginScreen.route) -} \ No newline at end of file +} diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthScreens.kt b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthScreens.kt index d64d4948e7..834fdcaa91 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthScreens.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthScreens.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.auth.navigation sealed class AuthScreens(val route: String) { @@ -5,5 +14,4 @@ sealed class AuthScreens(val route: String) { data object LoginScreenRoute : AuthScreens("login_screen_route") data object LoginScreen : AuthScreens("login_screen") - -} \ No newline at end of file +} diff --git a/feature/auth/src/main/res/values/strings.xml b/feature/auth/src/main/res/values/strings.xml index 2739522988..bfb07392da 100644 --- a/feature/auth/src/main/res/values/strings.xml +++ b/feature/auth/src/main/res/values/strings.xml @@ -1,4 +1,13 @@ + Login Please enter your credentials diff --git a/feature/auth/src/test/java/com/mifos/feature/auth/ExampleUnitTest.kt b/feature/auth/src/test/java/com/mifos/feature/auth/ExampleUnitTest.kt index 309e783a58..a524ccb27e 100644 --- a/feature/auth/src/test/java/com/mifos/feature/auth/ExampleUnitTest.kt +++ b/feature/auth/src/test/java/com/mifos/feature/auth/ExampleUnitTest.kt @@ -1,9 +1,17 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.auth +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * @@ -14,4 +22,4 @@ class ExampleUnitTest { fun addition_isCorrect() { assertEquals(4, 2 + 2) } -} \ No newline at end of file +} From 983dc2b3db17b48fb4424503d6bb204d240e6a1e Mon Sep 17 00:00:00 2001 From: Darkeye14 Date: Wed, 13 Nov 2024 20:09:17 +0530 Subject: [PATCH 3/5] Applying Detekt --- .../main/java/com/mifos/feature/auth/login/LoginScreen.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt index 96962f5554..28ddcca43c 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt @@ -85,8 +85,10 @@ fun LoginScreen( passcodeIntent: () -> Unit, onClickToUpdateServerConfig: () -> Unit, onSuccessNavigate: () -> Unit, + modifier: Modifier = Modifier, + loginViewModel: LoginViewModel = hiltViewModel(), ) { - val loginViewModel: LoginViewModel = hiltViewModel() + val state = loginViewModel.loginUiState.collectAsState().value val context = LocalContext.current @@ -144,7 +146,7 @@ fun LoginScreen( } Scaffold( - modifier = Modifier + modifier = modifier .fillMaxSize() .padding(16.dp), containerColor = Color.White, From 9ba2607474deb906b2fa680fce2d9844db804520 Mon Sep 17 00:00:00 2001 From: Darkeye14 Date: Wed, 13 Nov 2024 21:05:39 +0530 Subject: [PATCH 4/5] CleanUp-> Auth Module --- .../activity/login/LoginRepository.kt | 14 -- .../activity/login/LoginRepositoryImp.kt | 18 --- .../activity/login/LoginUiState.kt | 17 -- .../activity/login/LoginViewModel.kt | 43 ----- .../injection/module/RepositoryModule.kt | 7 - .../src/main/res/layout/activity_login.xml | 149 ------------------ 6 files changed, 248 deletions(-) delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepository.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepositoryImp.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginUiState.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginViewModel.kt delete mode 100755 mifosng-android/src/main/res/layout/activity_login.xml diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepository.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepository.kt deleted file mode 100644 index 7c04b29729..0000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepository.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.mifos.mifosxdroid.activity.login - -import org.apache.fineract.client.models.PostAuthenticationResponse -import rx.Observable - -/** - * Created by Aditya Gupta on 06/08/23. - */ - -interface LoginRepository { - - fun login(username: String, password: String): Observable - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepositoryImp.kt deleted file mode 100644 index 52bbe84e9b..0000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginRepositoryImp.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.mifos.mifosxdroid.activity.login - -import com.mifos.core.network.datamanager.DataManagerAuth -import org.apache.fineract.client.models.PostAuthenticationResponse -import rx.Observable -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 06/08/23. - */ - -class LoginRepositoryImp @Inject constructor(private val dataManagerAuth: DataManagerAuth) : - LoginRepository { - - override fun login(username: String, password: String): Observable { - return dataManagerAuth.login(username, password) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginUiState.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginUiState.kt deleted file mode 100644 index e9d4628677..0000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginUiState.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.mifosxdroid.activity.login - -import org.apache.fineract.client.models.PostAuthenticationResponse - -/** - * Created by Aditya Gupta on 06/08/23. - */ - -sealed class LoginUiState { - - data class ShowProgress(val state: Boolean) : LoginUiState() - - data class ShowError(val message: String) : LoginUiState() - - data class ShowLoginSuccessful(val user: PostAuthenticationResponse) : LoginUiState() - -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginViewModel.kt deleted file mode 100644 index 61cdc5df97..0000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/login/LoginViewModel.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.mifos.mifosxdroid.activity.login - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import org.apache.fineract.client.models.PostAuthenticationResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 06/08/23. - */ - -@HiltViewModel -class LoginViewModel @Inject constructor(private val loginRepository: LoginRepository) : - ViewModel() { - - private val _loginUiState = MutableLiveData() - val loginUiState: LiveData - get() = _loginUiState - - fun login(username: String, password: String) { - _loginUiState.value = LoginUiState.ShowProgress(true) - loginRepository.login(username, password) - .observeOn(AndroidSchedulers.mainThread()) - ?.subscribeOn(Schedulers.io()) - ?.subscribe(object : Subscriber() { - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - _loginUiState.value = LoginUiState.ShowError(e.message.toString()) - } - - override fun onNext(user: PostAuthenticationResponse) { - _loginUiState.value = LoginUiState.ShowLoginSuccessful(user) - } - }) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt index b130f2838b..4c141f4ba1 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt @@ -51,8 +51,6 @@ import com.mifos.core.network.datamanager.DataManagerStaff import com.mifos.core.network.datamanager.DataManagerSurveys import com.mifos.feature.settings.syncSurvey.SyncSurveysDialogRepository import com.mifos.feature.settings.syncSurvey.SyncSurveysDialogRepositoryImp -import com.mifos.mifosxdroid.activity.login.LoginRepository -import com.mifos.mifosxdroid.activity.login.LoginRepositoryImp import com.mifos.mifosxdroid.online.centerlist.CenterListRepository import com.mifos.mifosxdroid.online.centerlist.CenterListRepositoryImp import com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetRepository @@ -70,11 +68,6 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) class RepositoryModule { - @Provides - fun providesLoginRepository(dataManagerAuth: DataManagerAuth): LoginRepository { - return LoginRepositoryImp(dataManagerAuth) - } - @Provides fun providesCenterListRepository(dataManagerCenter: DataManagerCenter): CenterListRepository { return CenterListRepositoryImp(dataManagerCenter) diff --git a/mifosng-android/src/main/res/layout/activity_login.xml b/mifosng-android/src/main/res/layout/activity_login.xml deleted file mode 100755 index 6a308c0677..0000000000 --- a/mifosng-android/src/main/res/layout/activity_login.xml +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -