From bd1948b4db91c580f6be62c2219ebad552eba111 Mon Sep 17 00:00:00 2001 From: Pronay Sarker Date: Wed, 21 Aug 2024 16:54:56 +0600 Subject: [PATCH] feat: Implemented compose navigation in activate module (#2195) * implemented compose navigation in activateModule * MIFOSAC-260 implemented compose navigation in document module (#2193) * MIFOSAC-258: compose navigation in activate module --- .../com/mifos/core/common/utils/Constants.kt | 1 + .../mifos/feature/activate/ActivateScreen.kt | 4 +-- .../feature/activate/ActivateViewModel.kt | 8 ++++- .../activate/navigation/ActivateNavigation.kt | 32 +++++++++++++++++++ .../activate/navigation/ActivateScreens.kt | 12 +++++++ .../mifosxdroid/components/Navigation.kt | 8 +++-- .../online/activate/ActivateFragment.kt | 10 +++--- 7 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateNavigation.kt create mode 100644 feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateScreens.kt 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 bc86777a765..e8d249f3740 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 @@ -79,6 +79,7 @@ object Constants { const val ACTIVATE_CENTER = "activate_center" const val ACTIVATE_GROUP = "activate_group" const val ACTIVATE_TYPE = "activation_type" + const val ACTIVATE_ID = "activation_id" const val INTIAL_LOGIN = "initial_login" const val INDIVIDUAL_SHEET = "collection_sheet" const val DISBURSEMENT_DATE = "disbursement_date" diff --git a/feature/activate/src/main/java/com/mifos/feature/activate/ActivateScreen.kt b/feature/activate/src/main/java/com/mifos/feature/activate/ActivateScreen.kt index 6c9beba63f6..8ebcbfb5542 100644 --- a/feature/activate/src/main/java/com/mifos/feature/activate/ActivateScreen.kt +++ b/feature/activate/src/main/java/com/mifos/feature/activate/ActivateScreen.kt @@ -52,13 +52,13 @@ import java.util.Locale @Composable fun ActivateScreen( - id: Int, - activateType: String, onBackPressed: () -> Unit ) { val viewModel: ActivateViewModel = hiltViewModel() val state by viewModel.activateUiState.collectAsStateWithLifecycle() + val id by viewModel.id.collectAsStateWithLifecycle() + val activateType by viewModel.activateType.collectAsStateWithLifecycle() ActivateScreen( state = state, diff --git a/feature/activate/src/main/java/com/mifos/feature/activate/ActivateViewModel.kt b/feature/activate/src/main/java/com/mifos/feature/activate/ActivateViewModel.kt index 8e5e802987b..c0a43b26ca7 100644 --- a/feature/activate/src/main/java/com/mifos/feature/activate/ActivateViewModel.kt +++ b/feature/activate/src/main/java/com/mifos/feature/activate/ActivateViewModel.kt @@ -1,7 +1,9 @@ package com.mifos.feature.activate +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.Resource import com.mifos.core.domain.use_cases.ActivateCenterUseCase import com.mifos.core.domain.use_cases.ActivateClientUseCase @@ -18,9 +20,13 @@ import javax.inject.Inject class ActivateViewModel @Inject constructor( private val activateClientUseCase: ActivateClientUseCase, private val activateCenterUseCase: ActivateCenterUseCase, - private val activateGroupUseCase: ActivateGroupUseCase + private val activateGroupUseCase: ActivateGroupUseCase, + savedStateHandle: SavedStateHandle ) : ViewModel() { + val id = savedStateHandle.getStateFlow(key = Constants.ACTIVATE_ID, initialValue = 0) + val activateType = savedStateHandle.getStateFlow(key = Constants.ACTIVATE_TYPE, initialValue = "") + private val _activateUiState = MutableStateFlow(ActivateUiState.Initial) val activateUiState = _activateUiState.asStateFlow() diff --git a/feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateNavigation.kt b/feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateNavigation.kt new file mode 100644 index 00000000000..4aebcb69bda --- /dev/null +++ b/feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateNavigation.kt @@ -0,0 +1,32 @@ +package com.mifos.feature.activate.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavType +import androidx.navigation.compose.composable +import androidx.navigation.navArgument +import com.mifos.core.common.utils.Constants +import com.mifos.feature.activate.ActivateScreen + +/** + * Created by Pronay Sarker on 18/08/2024 (1:40 PM) + */ +fun NavGraphBuilder.activateScreen( + onBackPressed: () -> Unit +) { + composable( + route = ActivateScreens.ActivateScreen.route, + arguments = listOf( + navArgument(name = Constants.ACTIVATE_ID, builder = { NavType.IntType }), + navArgument(name = Constants.ACTIVATE_TYPE, builder = { NavType.StringType }) + ) + ) { + ActivateScreen( + onBackPressed = onBackPressed + ) + } +} + +fun NavController.navigateToActivateScreen(id : Int, type : String){ + navigate(ActivateScreens.ActivateScreen.argument(id, type)) +} \ No newline at end of file diff --git a/feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateScreens.kt b/feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateScreens.kt new file mode 100644 index 00000000000..5b466e3257d --- /dev/null +++ b/feature/activate/src/main/java/com/mifos/feature/activate/navigation/ActivateScreens.kt @@ -0,0 +1,12 @@ +package com.mifos.feature.activate.navigation + +import com.mifos.core.common.utils.Constants + +/** + * Created by Pronay Sarker on 18/08/2024 (1:40 PM) + */ +sealed class ActivateScreens(val route: String) { + data object ActivateScreen : ActivateScreens("activate_screen/{${Constants.ACTIVATE_ID}}/{${Constants.ACTIVATE_TYPE}}") { + fun argument(id: Int, type: String) = "activate_screen/$id/$type" + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt index 3f25ab39a97..16e1443cde6 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt @@ -8,6 +8,8 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import com.mifos.core.common.utils.Constants import com.mifos.feature.about.navigation.aboutScreen +import com.mifos.feature.activate.navigation.activateScreen +import com.mifos.feature.activate.navigation.navigateToActivateScreen import com.mifos.feature.center.navigation.centerNavGraph import com.mifos.feature.checker_inbox_task.navigation.checkerInboxTasksScreen import com.mifos.feature.client.navigation.clientNavGraph @@ -56,7 +58,7 @@ fun Navigation( savingsAccountSelected = { id, type -> navController.navigateToSavingsAccountSummaryScreen(id, type) }, - activateClient = { } + activateClient = { navController.navigateToActivateScreen(it, Constants.ACTIVATE_CLIENT) } ) savingsNavGraph( @@ -89,6 +91,8 @@ fun Navigation( onBackPressed = navController::popBackStack ) + activateScreen ( onBackPressed = navController::popBackStack ) + searchScreen( modifier = Modifier.padding(padding), centerListScreen = { }, @@ -99,7 +103,7 @@ fun Navigation( centerNavGraph( navController = navController, paddingValues = padding, - onActivateCenter = { _, _ -> }, + onActivateCenter = navController::navigateToActivateScreen, addSavingsAccount = { // navController.navigateToAddSavingsAccount(0, it, true) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/activate/ActivateFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/activate/ActivateFragment.kt index b2b11e6c0a6..78bcd0fb646 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/activate/ActivateFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/activate/ActivateFragment.kt @@ -19,14 +19,14 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class ActivateFragment : Fragment() { - private val arg: ActivateFragmentArgs by navArgs() +// private val arg: ActivateFragmentArgs by navArgs() private var id = 0 private lateinit var activateType: String override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - id = arg.clientId - activateType = arg.activationType +// id = arg.clientId +// activateType = arg.activationType } override fun onCreateView( @@ -38,8 +38,8 @@ class ActivateFragment : Fragment() { ) setContent { ActivateScreen( - id = id, - activateType = activateType, +// id = id, +// activateType = activateType, onBackPressed = { findNavController().popBackStack() }