diff --git a/feature/auth/build.gradle.kts b/feature/auth/build.gradle.kts index 4dadb520cf0..a5740329099 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 1dad89c8ef1..5d3bfedc5b1 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 a5918e68abc..1dc76da0f7e 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 08d80f378a1..a7b0c754962 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,10 @@ fun LoginScreen( homeIntent: () -> Unit, passcodeIntent: () -> Unit, onClickToUpdateServerConfig: () -> Unit, + modifier: Modifier = Modifier, + loginViewModel: LoginViewModel = hiltViewModel(), ) { - val loginViewModel: LoginViewModel = hiltViewModel() val state = loginViewModel.loginUiState.collectAsState().value val context = LocalContext.current @@ -87,12 +97,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) } @@ -130,9 +140,8 @@ fun LoginScreen( } } - Scaffold( - modifier = Modifier + modifier = modifier .fillMaxSize() .padding(16.dp), containerColor = Color.White, @@ -140,7 +149,7 @@ fun LoginScreen( bottomBar = { Box( modifier = Modifier.fillMaxWidth(), - contentAlignment = Alignment.Center + contentAlignment = Alignment.Center, ) { FilledTonalButton( onClick = onClickToUpdateServerConfig, @@ -148,8 +157,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") @@ -157,18 +166,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)) @@ -185,8 +194,8 @@ fun LoginScreen( fontSize = 16.sp, fontWeight = FontWeight.Bold, fontStyle = FontStyle.Normal, - color = DarkGray - ) + color = DarkGray, + ), ) Spacer(modifier = Modifier.height(16.dp)) @@ -203,7 +212,7 @@ fun LoginScreen( if (usernameError.value != null) { Icon(imageVector = Icons.Filled.Error, contentDescription = null) } - } + }, ) Spacer(modifier = Modifier.height(6.dp)) @@ -219,16 +228,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)) @@ -241,8 +252,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) } @@ -252,8 +263,8 @@ fun LoginScreen( onDismissRequest = { showDialog.value }, properties = DialogProperties( dismissOnBackPress = false, - dismissOnClickOutside = false - ) + dismissOnClickOutside = false, + ), ) { CircularProgressIndicator(color = White) } @@ -263,6 +274,6 @@ fun LoginScreen( @Preview(showSystemUi = true, device = "id:pixel_7") @Composable -fun LoginScreenPreview() { +private fun LoginScreenPreview() { 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 48b5c57ad7b..0e85bb6f3a3 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,5 @@ sealed class LoginUiState { data object PassCodeActivityIntent : 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 3217fec6cc2..be0d1d01665 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) @@ -112,12 +117,11 @@ class LoginViewModel @Inject constructor( prefManager.saveToken("Basic " + user.base64EncodedAuthenticationKey) // Saving user prefManager.savePostAuthenticationResponse(user) - if (prefManager.getPassCodeStatus()) { _loginUiState.value = LoginUiState.HomeActivityIntent } else { _loginUiState.value = LoginUiState.PassCodeActivityIntent } + _loginUiState.value = LoginUiState.HomeActivityIntent } - -} \ 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 d72e070a583..e6eb044ccf3 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 @@ -13,7 +13,7 @@ fun NavGraphBuilder.authNavGraph( ) { navigation( startDestination = AuthScreens.LoginScreen.route, - route = AuthScreens.LoginScreenRoute.route + route = AuthScreens.LoginScreenRoute.route, ) { loginRoute( navigatePasscode = navigatePasscode, @@ -21,16 +21,15 @@ fun NavGraphBuilder.authNavGraph( updateServerConfig = updateServerConfig ) } - } -fun NavGraphBuilder.loginRoute( +private fun NavGraphBuilder.loginRoute( navigateHome: () -> Unit, navigatePasscode: () -> Unit, updateServerConfig: () -> Unit ) { composable( - route = AuthScreens.LoginScreen.route + route = AuthScreens.LoginScreen.route, ) { LoginScreen( homeIntent = navigateHome, @@ -42,4 +41,4 @@ fun NavGraphBuilder.loginRoute( 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 d64d4948e74..834fdcaa919 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 27395229881..bfb07392dac 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 309e783a585..a524ccb27e3 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 +} diff --git a/mifosng-android/src/main/AndroidManifest.xml b/mifosng-android/src/main/AndroidManifest.xml index 79cee3283c7..1b293f3bda9 100755 --- a/mifosng-android/src/main/AndroidManifest.xml +++ b/mifosng-android/src/main/AndroidManifest.xml @@ -46,10 +46,6 @@ - - -} \ 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 52bbe84e9b5..00000000000 --- 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 e9d46286776..00000000000 --- 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 61cdc5df97b..00000000000 --- 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/activity/setting/SettingsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/SettingsFragment.kt index ed7fba8fd25..a2f9d3895b2 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/SettingsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/setting/SettingsFragment.kt @@ -12,7 +12,6 @@ import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import com.mifos.core.common.utils.Constants import com.mifos.feature.settings.settings.SettingsScreen -import com.mifos.mifosxdroid.activity.login.LoginActivity /** * Created by mayankjindal on 22/07/17. @@ -32,9 +31,9 @@ class SettingsFragment : Fragment() { findNavController().popBackStack() }, navigateToLoginScreen = { - Intent(requireContext(), LoginActivity::class.java).also { - startActivity(it) - } +// Intent(requireContext(), LoginActivity::class.java).also { +// startActivity(it) +// } }, changePasscode = { 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 b130f2838b7..4c141f4ba10 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 6a308c06772..00000000000 --- a/mifosng-android/src/main/res/layout/activity_login.xml +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -