diff --git a/core/common/src/main/java/com/mifos/core/common/utils/Constants.kt b/core/common/src/main/java/com/mifos/core/common/utils/Constants.kt index 01eedf617ca..96c444d6a55 100644 --- a/core/common/src/main/java/com/mifos/core/common/utils/Constants.kt +++ b/core/common/src/main/java/com/mifos/core/common/utils/Constants.kt @@ -215,4 +215,5 @@ object Constants { // Compose Navigation KEY const val REPORT_TYPE_ITEM = "report_type_item" const val REPORT_PARAMETER_RESPONSE = "report_parameter_response" + const val PASSCODE_INITIAL_LOGIN = "passcode_initial_login" } \ No newline at end of file diff --git a/core/designsystem/src/main/java/com/mifos/core/designsystem/theme/Color.kt b/core/designsystem/src/main/java/com/mifos/core/designsystem/theme/Color.kt index 8575c31bfed..34932289d9b 100644 --- a/core/designsystem/src/main/java/com/mifos/core/designsystem/theme/Color.kt +++ b/core/designsystem/src/main/java/com/mifos/core/designsystem/theme/Color.kt @@ -9,4 +9,5 @@ val LightGray = Color(0xFFD3D3D3) val BluePrimary = Color(0xFF2D5BA8) val BluePrimaryDark = Color(0xFF9BB1E3) val BlueSecondary = Color(0xFFD7E2FC) -val LightGreen = Color(0xFF99CC00) \ No newline at end of file +val LightGreen = Color(0xFF99CC00) +val SummerSky = Color(0xFF29B6F6) \ No newline at end of file diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginScreen.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt similarity index 99% rename from feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginScreen.kt rename to feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt index 63f753236d4..08d80f378a1 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginScreen.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginScreen.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.auth.login.presentation +package com.mifos.feature.auth.login import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginUiState.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt similarity index 90% rename from feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginUiState.kt rename to feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt index fdb409b0c37..48b5c57ad7b 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginUiState.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginUiState.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.auth.login.presentation +package com.mifos.feature.auth.login /** * Created by Aditya Gupta on 06/08/23. diff --git a/feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginViewModel.kt b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt similarity index 98% rename from feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginViewModel.kt rename to feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt index 65e7ef2c556..3217fec6cc2 100644 --- a/feature/auth/src/main/java/com/mifos/feature/auth/login/presentation/LoginViewModel.kt +++ b/feature/auth/src/main/java/com/mifos/feature/auth/login/LoginViewModel.kt @@ -1,4 +1,4 @@ -package com.mifos.feature.auth.login.presentation +package com.mifos.feature.auth.login import android.content.Context import androidx.lifecycle.ViewModel 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 new file mode 100644 index 00000000000..d72e070a583 --- /dev/null +++ b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthNavigation.kt @@ -0,0 +1,45 @@ +package com.mifos.feature.auth.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable +import androidx.navigation.navigation +import com.mifos.feature.auth.login.LoginScreen + +fun NavGraphBuilder.authNavGraph( + navigateHome: () -> Unit, + navigatePasscode: () -> Unit, + updateServerConfig: () -> Unit +) { + navigation( + startDestination = AuthScreens.LoginScreen.route, + route = AuthScreens.LoginScreenRoute.route + ) { + loginRoute( + navigatePasscode = navigatePasscode, + navigateHome = navigateHome, + updateServerConfig = updateServerConfig + ) + } + +} + +fun NavGraphBuilder.loginRoute( + navigateHome: () -> Unit, + navigatePasscode: () -> Unit, + updateServerConfig: () -> Unit +) { + composable( + route = AuthScreens.LoginScreen.route + ) { + LoginScreen( + homeIntent = navigateHome, + passcodeIntent = navigatePasscode, + onClickToUpdateServerConfig = updateServerConfig + ) + } +} + +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 new file mode 100644 index 00000000000..d64d4948e74 --- /dev/null +++ b/feature/auth/src/main/java/com/mifos/feature/auth/navigation/AuthScreens.kt @@ -0,0 +1,9 @@ +package com.mifos.feature.auth.navigation + +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/passcode/.gitignore b/feature/passcode/.gitignore new file mode 100644 index 00000000000..42afabfd2ab --- /dev/null +++ b/feature/passcode/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/passcode/build.gradle.kts b/feature/passcode/build.gradle.kts new file mode 100644 index 00000000000..f3e8f90b5af --- /dev/null +++ b/feature/passcode/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + alias(libs.plugins.mifos.android.feature) + alias(libs.plugins.mifos.android.library.compose) + alias(libs.plugins.mifos.android.library.jacoco) +} + +android { + namespace = "com.mifos.feature.passcode" +} + +dependencies { + implementation(projects.core.domain) + + //DBFlow dependencies + kapt(libs.dbflow.processor) + implementation(libs.dbflow) + kapt(libs.github.dbflow.processor) + testImplementation(libs.hilt.android.testing) + testImplementation(projects.core.testing) + + androidTestImplementation(projects.core.testing) + + // passcode dependency + implementation("com.github.openMF.mifos-passcode:compose:1.0.3") +} \ No newline at end of file diff --git a/feature/passcode/consumer-rules.pro b/feature/passcode/consumer-rules.pro new file mode 100644 index 00000000000..e69de29bb2d diff --git a/feature/passcode/proguard-rules.pro b/feature/passcode/proguard-rules.pro new file mode 100644 index 00000000000..481bb434814 --- /dev/null +++ b/feature/passcode/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/passcode/src/androidTest/java/com/mifos/feature/passcode/ExampleInstrumentedTest.kt b/feature/passcode/src/androidTest/java/com/mifos/feature/passcode/ExampleInstrumentedTest.kt new file mode 100644 index 00000000000..73c1fc6f9b2 --- /dev/null +++ b/feature/passcode/src/androidTest/java/com/mifos/feature/passcode/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.mifos.feature.passcode + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.mifos.feature.passcode.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/feature/passcode/src/main/AndroidManifest.xml b/feature/passcode/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..a5918e68abc --- /dev/null +++ b/feature/passcode/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/feature/passcode/src/main/java/com/mifos/feature/passcode/navigation/PasscodeNavigation.kt b/feature/passcode/src/main/java/com/mifos/feature/passcode/navigation/PasscodeNavigation.kt new file mode 100644 index 00000000000..72562661abb --- /dev/null +++ b/feature/passcode/src/main/java/com/mifos/feature/passcode/navigation/PasscodeNavigation.kt @@ -0,0 +1,38 @@ +package com.mifos.feature.passcode.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavType +import androidx.navigation.compose.composable +import androidx.navigation.navArgument +import androidx.navigation.navigation +import com.mifos.core.common.utils.Constants +import com.mifos.feature.passcode.passcode.PasscodeScreen + +fun NavGraphBuilder.passcodeNavGraph( + navController: NavController +) { + navigation( + startDestination = PasscodeScreens.PasscodeScreen.route, + route = "passcode_screen_route" + ) { + passcodeScreenRoute() + } +} + +fun NavGraphBuilder.passcodeScreenRoute( + +) { + composable( + route = PasscodeScreens.PasscodeScreen.route, + arguments = listOf( + navArgument( + name = Constants.PASSCODE_INITIAL_LOGIN, + builder = { type = NavType.BoolType }) + ) + ) { + PasscodeScreen( + + ) + } +} \ No newline at end of file diff --git a/feature/passcode/src/main/java/com/mifos/feature/passcode/navigation/PasscodeScreens.kt b/feature/passcode/src/main/java/com/mifos/feature/passcode/navigation/PasscodeScreens.kt new file mode 100644 index 00000000000..35656df6ba4 --- /dev/null +++ b/feature/passcode/src/main/java/com/mifos/feature/passcode/navigation/PasscodeScreens.kt @@ -0,0 +1,7 @@ +package com.mifos.feature.passcode.navigation + +sealed class PasscodeScreens(val route: String) { + + data object PasscodeScreen : PasscodeScreens("passcode_screen") + +} \ No newline at end of file diff --git a/feature/passcode/src/main/java/com/mifos/feature/passcode/passcode/PasscodeScreen.kt b/feature/passcode/src/main/java/com/mifos/feature/passcode/passcode/PasscodeScreen.kt new file mode 100644 index 00000000000..8b8dd7cd27c --- /dev/null +++ b/feature/passcode/src/main/java/com/mifos/feature/passcode/passcode/PasscodeScreen.kt @@ -0,0 +1,44 @@ +package com.mifos.feature.passcode.passcode + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.mifos.core.designsystem.component.MifosScaffold + +@Composable +fun PasscodeScreen( + viewmodel: PasscodeViewmodel = hiltViewModel() +) { + + val passcodeStatus by viewmodel.passcodeStatus.collectAsStateWithLifecycle() + + +} + +@Composable +fun PasscodeScreen( + +) { + + MifosScaffold { paddingValues -> + Column(modifier = Modifier.padding(paddingValues)) { + com.mifos.compose.component.PasscodeScreen( + onForgotButton = { }, + onSkipButton = { }, + onPasscodeConfirm = { }, + onPasscodeRejected = { } + ) + } + } +} + +@Preview +@Composable +private fun PasscodeScreenPreview() { + PasscodeScreen() +} \ No newline at end of file diff --git a/feature/passcode/src/main/java/com/mifos/feature/passcode/passcode/PasscodeViewmodel.kt b/feature/passcode/src/main/java/com/mifos/feature/passcode/passcode/PasscodeViewmodel.kt new file mode 100644 index 00000000000..3d8e63b537e --- /dev/null +++ b/feature/passcode/src/main/java/com/mifos/feature/passcode/passcode/PasscodeViewmodel.kt @@ -0,0 +1,17 @@ +package com.mifos.feature.passcode.passcode + +import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.ViewModel +import com.mifos.core.common.utils.Constants +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class PasscodeViewmodel @Inject constructor( + private val savedStateHandle: SavedStateHandle +) : ViewModel() { + + val passcodeStatus = + savedStateHandle.getStateFlow(key = Constants.PASSCODE_INITIAL_LOGIN, initialValue = false) + +} \ No newline at end of file diff --git a/feature/passcode/src/test/java/com/mifos/feature/passcode/ExampleUnitTest.kt b/feature/passcode/src/test/java/com/mifos/feature/passcode/ExampleUnitTest.kt new file mode 100644 index 00000000000..9a506a4c167 --- /dev/null +++ b/feature/passcode/src/test/java/com/mifos/feature/passcode/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.mifos.feature.passcode + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/feature/splash/.gitignore b/feature/splash/.gitignore new file mode 100644 index 00000000000..42afabfd2ab --- /dev/null +++ b/feature/splash/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/splash/build.gradle.kts b/feature/splash/build.gradle.kts new file mode 100644 index 00000000000..fcdf2a24745 --- /dev/null +++ b/feature/splash/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + alias(libs.plugins.mifos.android.feature) + alias(libs.plugins.mifos.android.library.compose) + alias(libs.plugins.mifos.android.library.jacoco) +} + +android { + namespace = "com.mifos.feature.splash" +} + +dependencies { + implementation(projects.core.domain) + + //DBFlow dependencies + kapt(libs.dbflow.processor) + implementation(libs.dbflow) + kapt(libs.github.dbflow.processor) + testImplementation(libs.hilt.android.testing) + testImplementation(projects.core.testing) + + androidTestImplementation(projects.core.testing) + +} \ No newline at end of file diff --git a/feature/splash/consumer-rules.pro b/feature/splash/consumer-rules.pro new file mode 100644 index 00000000000..e69de29bb2d diff --git a/feature/splash/proguard-rules.pro b/feature/splash/proguard-rules.pro new file mode 100644 index 00000000000..481bb434814 --- /dev/null +++ b/feature/splash/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/splash/src/androidTest/java/com/mifos/feature/splash/ExampleInstrumentedTest.kt b/feature/splash/src/androidTest/java/com/mifos/feature/splash/ExampleInstrumentedTest.kt new file mode 100644 index 00000000000..8992390a5b5 --- /dev/null +++ b/feature/splash/src/androidTest/java/com/mifos/feature/splash/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.mifos.feature.splash + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.mifos.feature.splash.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/feature/splash/src/main/AndroidManifest.xml b/feature/splash/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..a5918e68abc --- /dev/null +++ b/feature/splash/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/feature/splash/src/main/java/com/mifos/feature/splash/navigation/SplashNavigation.kt b/feature/splash/src/main/java/com/mifos/feature/splash/navigation/SplashNavigation.kt new file mode 100644 index 00000000000..6fe06714bda --- /dev/null +++ b/feature/splash/src/main/java/com/mifos/feature/splash/navigation/SplashNavigation.kt @@ -0,0 +1,35 @@ +package com.mifos.feature.splash.navigation + +import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable +import androidx.navigation.navigation +import com.mifos.feature.splash.splash.SplashScreen + +fun NavGraphBuilder.splashNavGraph( + navigatePasscode: () -> Unit, + navigateLogin: () -> Unit +) { + navigation( + startDestination = SplashScreens.SplashScreen.route, + route = SplashScreens.SplashScreenRoute.route, + ) { + splashScreenRoute( + navigateLogin = navigateLogin, + navigatePasscode = navigatePasscode + ) + } +} + +fun NavGraphBuilder.splashScreenRoute( + navigatePasscode: () -> Unit, + navigateLogin: () -> Unit +) { + composable( + route = SplashScreens.SplashScreen.route, + ) { + SplashScreen( + navigatePasscode = navigatePasscode, + navigateLogin = navigateLogin + ) + } +} \ No newline at end of file diff --git a/feature/splash/src/main/java/com/mifos/feature/splash/navigation/SplashScreens.kt b/feature/splash/src/main/java/com/mifos/feature/splash/navigation/SplashScreens.kt new file mode 100644 index 00000000000..ee4762d7ee9 --- /dev/null +++ b/feature/splash/src/main/java/com/mifos/feature/splash/navigation/SplashScreens.kt @@ -0,0 +1,9 @@ +package com.mifos.feature.splash.navigation + +sealed class SplashScreens(val route: String) { + + data object SplashScreenRoute : SplashScreens("splash_screen_route") + + data object SplashScreen : SplashScreens("splash_screen") + +} \ No newline at end of file diff --git a/feature/splash/src/main/java/com/mifos/feature/splash/splash/SplashScreen.kt b/feature/splash/src/main/java/com/mifos/feature/splash/splash/SplashScreen.kt new file mode 100644 index 00000000000..4afc3b89470 --- /dev/null +++ b/feature/splash/src/main/java/com/mifos/feature/splash/splash/SplashScreen.kt @@ -0,0 +1,77 @@ +package com.mifos.feature.splash.splash + +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.mifos.core.designsystem.component.MifosScaffold +import com.mifos.core.designsystem.theme.SummerSky +import com.mifos.feature.splash.R + +@Composable +fun SplashScreen( + viewmodel: SplashScreenViewmodel = hiltViewModel(), + navigatePasscode: () -> Unit, + navigateLogin: () -> Unit +) { + val state by viewmodel.isAuthenticated.collectAsStateWithLifecycle() + + SplashScreen( + state = state, + navigatePasscode = navigatePasscode, + navigateLogin = navigateLogin + ) +} + +@Composable +fun SplashScreen( + state: Boolean?, + navigatePasscode: () -> Unit, + navigateLogin: () -> Unit +) { + + when (state) { + false -> navigateLogin() + true -> navigatePasscode() + else -> {} + } + + MifosScaffold( + containerColor = SummerSky + ) { paddingValues -> + Column( + modifier = Modifier + .padding(paddingValues) + .fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Image( + modifier = Modifier.size(100.dp), + painter = painterResource(id = R.drawable.feature_splash_icon), + contentDescription = null + ) + } + } +} + +@Preview +@Composable +private fun SplashScreenPreview() { + SplashScreen( + state = false, + navigatePasscode = {}, + navigateLogin = {} + ) +} \ No newline at end of file diff --git a/feature/splash/src/main/java/com/mifos/feature/splash/splash/SplashScreenViewmodel.kt b/feature/splash/src/main/java/com/mifos/feature/splash/splash/SplashScreenViewmodel.kt new file mode 100644 index 00000000000..f4883f73a33 --- /dev/null +++ b/feature/splash/src/main/java/com/mifos/feature/splash/splash/SplashScreenViewmodel.kt @@ -0,0 +1,32 @@ +package com.mifos.feature.splash.splash + +import android.util.Log +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.mifos.core.datastore.PrefManager +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class SplashScreenViewmodel @Inject constructor( + private val prefManager: PrefManager +) : ViewModel() { + + private val _isAuthenticated = MutableStateFlow(null) + val isAuthenticated = _isAuthenticated.asStateFlow() + + init { + checkAuthenticationStatus() + } + + private fun checkAuthenticationStatus() = viewModelScope.launch(Dispatchers.IO) { + delay(2000) + _isAuthenticated.value = prefManager.isAuthenticated() + } + +} \ No newline at end of file diff --git a/feature/splash/src/main/res/drawable/feature_splash_icon.png b/feature/splash/src/main/res/drawable/feature_splash_icon.png new file mode 100644 index 00000000000..d8f0bdc33ad Binary files /dev/null and b/feature/splash/src/main/res/drawable/feature_splash_icon.png differ diff --git a/feature/splash/src/test/java/com/mifos/feature/splash/ExampleUnitTest.kt b/feature/splash/src/test/java/com/mifos/feature/splash/ExampleUnitTest.kt new file mode 100644 index 00000000000..8da7f2fdf58 --- /dev/null +++ b/feature/splash/src/test/java/com/mifos/feature/splash/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.mifos.feature.splash + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/mifosng-android/build.gradle.kts b/mifosng-android/build.gradle.kts index 1bb25e05323..ca7b3499c0f 100644 --- a/mifosng-android/build.gradle.kts +++ b/mifosng-android/build.gradle.kts @@ -143,6 +143,8 @@ dependencies { implementation(projects.feature.document) implementation(projects.feature.dataTable) implementation(projects.feature.search) + implementation(projects.feature.splash) + implementation(projects.feature.passcode) implementation(projects.core.common) implementation(projects.core.ui) diff --git a/mifosng-android/src/main/AndroidManifest.xml b/mifosng-android/src/main/AndroidManifest.xml index 8d20d0817f4..8237eccdfed 100755 --- a/mifosng-android/src/main/AndroidManifest.xml +++ b/mifosng-android/src/main/AndroidManifest.xml @@ -36,16 +36,10 @@ android:name="com.google.android.geo.API_KEY" android:value="${GEO_API_KEY}" /> - - + android:screenOrientation="portrait"> diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt new file mode 100644 index 00000000000..5e795b7d9cf --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClient.kt @@ -0,0 +1,41 @@ +package com.mifos.mifosxdroid + +import androidx.compose.runtime.Composable +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.rememberNavController +import com.mifos.feature.auth.navigation.authNavGraph +import com.mifos.feature.auth.navigation.navigateToLogin +import com.mifos.feature.passcode.navigation.passcodeNavGraph +import com.mifos.feature.splash.navigation.SplashScreens +import com.mifos.feature.splash.navigation.splashNavGraph +import com.mifos.mifosxdroid.navigation.HomeScreens +import com.mifos.mifosxdroid.navigation.homeGraph +import com.mifos.mifosxdroid.navigation.navigateHome + +@Composable +fun AndroidClient() { + + val navController = rememberNavController() + + NavHost( + navController = navController, + startDestination = SplashScreens.SplashScreenRoute.route + ) { + splashNavGraph( + navigatePasscode = navController::navigateHome, + navigateLogin = navController::navigateToLogin + ) + + passcodeNavGraph( + navController = navController + ) + + authNavGraph( + navigatePasscode = {}, + navigateHome = navController::navigateHome, + updateServerConfig = {} + ) + + homeGraph() + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/DashboardActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClientActivity.kt similarity index 81% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/DashboardActivity.kt rename to mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClientActivity.kt index ca93dccbca5..07aec95c3de 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/DashboardActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClientActivity.kt @@ -6,12 +6,12 @@ import androidx.activity.compose.setContent import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class DashboardActivity : ComponentActivity() { +class AndroidClientActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { - AndroidClientApp() + AndroidClient() } } 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 d51d7f6cc8f..a352a958093 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 @@ -6,12 +6,8 @@ package com.mifos.mifosxdroid.activity.login import android.content.Intent import android.os.Bundle -import android.util.Log import androidx.activity.compose.setContent -import androidx.navigation.findNavController -import androidx.navigation.fragment.findNavController -import com.mifos.feature.auth.login.presentation.LoginScreen -import com.mifos.mifosxdroid.R +import com.mifos.feature.auth.login.LoginScreen import com.mifos.mifosxdroid.activity.home.HomeActivity import com.mifos.mifosxdroid.activity.setting.UpdateServerConfigFragment import com.mifos.mifosxdroid.core.MifosBaseActivity diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/splashscreen/SplashScreenActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/splashscreen/SplashScreenActivity.kt deleted file mode 100644 index 06646cb6b49..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/activity/splashscreen/SplashScreenActivity.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.activity.splashscreen - -import android.content.Intent -import android.os.Bundle -import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import com.mifos.mifosxdroid.activity.login.LoginActivity -import com.mifos.mifosxdroid.core.MifosBaseActivity -import com.mifos.mifosxdroid.passcode.PassCodeActivity -import com.mifos.mobile.passcode.utils.PassCodeConstants -import com.mifos.utils.PrefManager - -/** - * This is the First Activity which can be used for initial checks, inits at app Startup - */ -class SplashScreenActivity : MifosBaseActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - val splashScreen = installSplashScreen() - super.onCreate(savedInstanceState) - splashScreen.setKeepOnScreenCondition { true } - if (!PrefManager.isAuthenticated()) { - startActivity(Intent(this@SplashScreenActivity, LoginActivity::class.java)) - } else { - val intent = Intent( - this@SplashScreenActivity, - PassCodeActivity::class.java - ) - intent.putExtra(PassCodeConstants.PASSCODE_INITIAL_LOGIN, true) - startActivity(intent) - } - finish() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt index e9f36a0e0f9..7bddb27de68 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/MifosBaseActivity.kt @@ -15,8 +15,8 @@ import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.Toolbar import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager +import com.mifos.mifosxdroid.AndroidClientActivity import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.activity.splashscreen.SplashScreenActivity import com.mifos.mifosxdroid.passcode.PassCodeActivity import com.mifos.mobile.passcode.BasePassCodeActivity import com.mifos.utils.Constants @@ -117,7 +117,7 @@ open class MifosBaseActivity : BasePassCodeActivity(), BaseActivityCallback { startActivity( Intent( this@MifosBaseActivity, - SplashScreenActivity::class.java + AndroidClientActivity::class.java ) ) Toast.makeText( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClientApp.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeNavigation.kt similarity index 92% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClientApp.kt rename to mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeNavigation.kt index 5717539e07a..27a7c173a51 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/AndroidClientApp.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeNavigation.kt @@ -1,6 +1,6 @@ @file:OptIn(ExperimentalMaterial3Api::class) -package com.mifos.mifosxdroid +package com.mifos.mifosxdroid.navigation import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement @@ -51,17 +51,47 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController +import androidx.navigation.navigation import com.mifos.core.designsystem.theme.Black import com.mifos.core.designsystem.theme.White +import com.mifos.feature.splash.navigation.SplashScreens +import com.mifos.mifosxdroid.HomeDestinationsScreen +import com.mifos.mifosxdroid.R import com.mifos.mifosxdroid.components.MifosNavigationBar import com.mifos.mifosxdroid.components.Navigation import com.mifos.mifosxdroid.components.NavigationConstants import kotlinx.coroutines.launch +fun NavGraphBuilder.homeGraph() { + navigation( + startDestination = HomeScreens.HomeScreen.route, + route = "home_screen_route" + ) { + homeNavigate() + } +} + +fun NavGraphBuilder.homeNavigate() { + composable( + route = HomeScreens.HomeScreen.route + ) { + HomeNavigation() + } +} + +fun NavController.navigateHome() { + navigate(HomeScreens.HomeScreen.route) { + popBackStack(route = SplashScreens.SplashScreenRoute.route, inclusive = true) + } +} + @Composable -fun AndroidClientApp() { +fun HomeNavigation() { val navController = rememberNavController() val navBackStackEntry by navController.currentBackStackEntryAsState() diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeScreens.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeScreens.kt new file mode 100644 index 00000000000..8b740caeb45 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/navigation/HomeScreens.kt @@ -0,0 +1,7 @@ +package com.mifos.mifosxdroid.navigation + +sealed class HomeScreens(val route: String) { + + data object HomeScreen : HomeScreens("home_screen") + +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.kt index ec39d577b90..adcbb7e3f35 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/passcode/PassCodeActivity.kt @@ -4,10 +4,8 @@ import android.content.Intent import android.os.Bundle import android.view.View import androidx.core.widget.NestedScrollView -import com.mifos.mifosxdroid.DashboardActivity +import com.mifos.mifosxdroid.AndroidClientActivity import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.activity.home.HomeActivity -import com.mifos.mifosxdroid.activity.splashscreen.SplashScreenActivity import com.mifos.mifosxdroid.core.util.Toaster import com.mifos.mobile.passcode.MifosPassCodeActivity import com.mifos.mobile.passcode.utils.EncryptionUtil @@ -36,7 +34,7 @@ class PassCodeActivity : MifosPassCodeActivity() { } override fun startLoginActivity() { - startActivity(Intent(this, SplashScreenActivity::class.java)) + startActivity(Intent(this, AndroidClientActivity::class.java)) finish() } @@ -49,7 +47,7 @@ class PassCodeActivity : MifosPassCodeActivity() { } override fun startNextActivity() { - startActivity(Intent(this, DashboardActivity::class.java)) + startActivity(Intent(this, AndroidClientActivity::class.java)) } override fun onBackPressed() { diff --git a/settings.gradle.kts b/settings.gradle.kts index 81c609e281b..da9a287441d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -50,3 +50,5 @@ include(":feature:document") include(":feature:savings") include(":feature:data-table") include(":feature:search") +include(":feature:splash") +include(":feature:passcode")