diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt index 1acb56137f8..0c1620d111d 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt @@ -42,8 +42,8 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import androidx.lifecycle.viewmodel.compose.viewModel import com.mifos.core.common.utils.Utils import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosMenuDropDownItem @@ -61,14 +61,14 @@ import com.mifos.feature.center.R @Composable fun CenterDetailsScreen( - centerId: Int, onBackPressed: () -> Unit, - onActivateCenter: () -> Unit, + onActivateCenter: (Int) -> Unit, addSavingsAccount: (Int) -> Unit, groupList: (Int) -> Unit ) { - val viewModel: CenterDetailsViewModel = viewModel() + val viewModel: CenterDetailsViewModel = hiltViewModel() + val centerId by viewModel.centerId.collectAsStateWithLifecycle() val state by viewModel.centerDetailsUiState.collectAsStateWithLifecycle() LaunchedEffect(Unit) { @@ -88,7 +88,7 @@ fun CenterDetailsScreen( onRetryClick = { viewModel.loadClientDetails(centerId) }, - onActivateCenter = onActivateCenter + onActivateCenter = { onActivateCenter(centerId) } ) } diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt index b1c48221aa7..e475304f600 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt @@ -1,7 +1,9 @@ package com.mifos.feature.center.center_details +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.GetCenterDetailsUseCase import com.mifos.core.objects.group.CenterInfo @@ -16,9 +18,12 @@ import javax.inject.Inject @HiltViewModel class CenterDetailsViewModel @Inject constructor( - private val getCenterDetailsUseCase: GetCenterDetailsUseCase + private val getCenterDetailsUseCase: GetCenterDetailsUseCase, + private val savedStateHandle: SavedStateHandle ) : ViewModel() { + val centerId = savedStateHandle.getStateFlow(key = Constants.CENTER_ID, initialValue = 0) + private val _centerDetailsUiState = MutableStateFlow(CenterDetailsUiState.Loading) val centerDetailsUiState = _centerDetailsUiState.asStateFlow() diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListScreen.kt b/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListScreen.kt index fd10e2189b2..fedbf0afa0a 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListScreen.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListScreen.kt @@ -45,12 +45,12 @@ import com.mifos.feature.center.R @Composable fun GroupListScreen( - centerId: Int, onBackPressed: () -> Unit, loadClientsOfGroup: (List) -> Unit ) { val viewModel: GroupListViewModel = hiltViewModel() + val centerId by viewModel.centerId.collectAsStateWithLifecycle() val state by viewModel.groupListUiState.collectAsStateWithLifecycle() val groupAssociationState by viewModel.groupAssociationState.collectAsStateWithLifecycle() var groupClicked by remember { mutableStateOf(false) } diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListViewModel.kt b/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListViewModel.kt index 9a587d6ee4a..b910938d27e 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListViewModel.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/center_group_list/GroupListViewModel.kt @@ -1,7 +1,9 @@ package com.mifos.feature.center.center_group_list +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.GetGroupsByCenterUseCase import com.mifos.core.domain.use_cases.GetGroupsUseCase @@ -18,9 +20,12 @@ import javax.inject.Inject @HiltViewModel class GroupListViewModel @Inject constructor( private val getGroupsUseCase: GetGroupsUseCase, - private val getGroupsByCenterUseCase: GetGroupsByCenterUseCase + private val getGroupsByCenterUseCase: GetGroupsByCenterUseCase, + private val savedStateHandle: SavedStateHandle ) : ViewModel() { + val centerId = savedStateHandle.getStateFlow(key = Constants.CENTER_ID, initialValue = 0) + private val _groupListUiState = MutableStateFlow(GroupListUiState.Loading) val groupListUiState = _groupListUiState.asStateFlow() diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt b/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt index bc14aa26090..0be04d07e41 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt @@ -79,7 +79,7 @@ fun CenterListScreen( paddingValues: PaddingValues, createNewCenter: () -> Unit, syncClicked: (List
) -> Unit, - onCenterSelect: (Center) -> Unit + onCenterSelect: (Int) -> Unit ) { val viewModel: CenterListViewModel = hiltViewModel() @@ -111,7 +111,7 @@ fun CenterListScreen( onRefresh: () -> Unit, refreshState: Boolean, syncClicked: (List
) -> Unit, - onCenterSelect: (Center) -> Unit + onCenterSelect: (Int) -> Unit ) { val snackbarHostState = remember { SnackbarHostState() } @@ -226,7 +226,7 @@ fun CenterListContent( isInSelectionMode: Boolean, selectedItems: SnapshotStateList
, onRefresh: () -> Unit, - onCenterSelect: (Center) -> Unit, + onCenterSelect: (Int) -> Unit, selectedMode: () -> Unit ) { @@ -263,7 +263,7 @@ fun CenterListContent( LightGray } } else { - centerPagingList[index]?.let { onCenterSelect(it) } + centerPagingList[index]?.id?.let { onCenterSelect(it) } } }, onLongClick = { diff --git a/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterListNavigation.kt b/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterListNavigation.kt deleted file mode 100644 index bdf8f5c9b06..00000000000 --- a/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterListNavigation.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.mifos.feature.center.navigation - -import androidx.compose.foundation.layout.PaddingValues -import androidx.navigation.NavController -import androidx.navigation.NavGraphBuilder -import androidx.navigation.compose.composable -import com.mifos.feature.center.center_list.ui.CenterListScreen - -/** - * Created by Pronay Sarker on 10/08/2024 (6:55 AM) - */ -const val CENTER_LIST_SCREEN_ROUTE = "center_list_route" - -fun NavController.navigateToCenterList() { - this.navigate(CENTER_LIST_SCREEN_ROUTE) -} - -fun NavGraphBuilder.centerListScreen( - paddingValues: PaddingValues, - createNewCenter: () -> Unit, - syncClicked: () -> Unit, - onCenterSelect: () -> Unit -) { - composable(CENTER_LIST_SCREEN_ROUTE) { - CenterListScreen( - paddingValues = paddingValues, - createNewCenter = { /*TODO*/ }, - syncClicked = { }, - onCenterSelect = { } - ) - } -} \ No newline at end of file diff --git a/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterNavigation.kt b/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterNavigation.kt new file mode 100644 index 00000000000..8f719ebc17f --- /dev/null +++ b/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterNavigation.kt @@ -0,0 +1,148 @@ +package com.mifos.feature.center.navigation + +import androidx.compose.foundation.layout.PaddingValues +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.core.objects.client.Client +import com.mifos.core.objects.group.Center +import com.mifos.feature.center.center_details.CenterDetailsScreen +import com.mifos.feature.center.center_group_list.GroupListScreen +import com.mifos.feature.center.center_list.ui.CenterListScreen +import com.mifos.feature.center.create_center.CreateNewCenterScreen +import com.mifos.feature.center.sync_center_payloads.SyncCenterPayloadsScreenRoute + +fun NavGraphBuilder.centerNavGraph( + navController: NavController, + paddingValues: PaddingValues, + onActivateCenter: (Int,String) -> Unit, + addSavingsAccount: (Int) -> Unit +) { + navigation( + startDestination = CenterScreens.CenterListScreen.route, + route = "center_screen_route" + ) { + centerListScreenRoute( + paddingValues = paddingValues, + createNewCenter = navController::navigateCreateCenterScreenRoute, + syncClicked = { }, // TODO open sync dialog inside center list screen + onCenterSelect = navController::navigateCenterDetailsScreenRoute + ) + centerDetailScreenRoute( + onBackPressed = navController::popBackStack, + onActivateCenter = onActivateCenter, + addSavingsAccount = addSavingsAccount, + groupList = navController::navigateCenterGroupListScreenRoute + ) + centerGroupListScreenRoute( + onBackPressed = navController::popBackStack, + loadClientsOfGroup = { } + ) + createCenterScreenRoute( + onCreateSuccess = navController::popBackStack + ) + syncCenterPayloadsScreenRoute( + onBackPressed = navController::popBackStack + ) + } +} + +fun NavGraphBuilder.centerListScreenRoute( + paddingValues: PaddingValues, + createNewCenter: () -> Unit, + syncClicked: (List
) -> Unit, + onCenterSelect: (Int) -> Unit +) { + composable( + route = CenterScreens.CenterListScreen.route + ) { + CenterListScreen( + paddingValues = paddingValues, + createNewCenter = createNewCenter, + syncClicked = syncClicked, + onCenterSelect = onCenterSelect + ) + } +} + +fun NavGraphBuilder.centerDetailScreenRoute( + onBackPressed: () -> Unit, + onActivateCenter: (Int,String) -> Unit, + addSavingsAccount: (Int) -> Unit, + groupList: (Int) -> Unit +) { + composable( + route = CenterScreens.CenterDetailScreen.route, + arguments = listOf(navArgument(Constants.CENTER_ID, builder = { type = NavType.IntType })) + ) { + CenterDetailsScreen( + onBackPressed = onBackPressed, + onActivateCenter = {onActivateCenter(it,Constants.ACTIVATE_CENTER)}, + addSavingsAccount = addSavingsAccount, + groupList = groupList + ) + } +} + +fun NavGraphBuilder.centerGroupListScreenRoute( + onBackPressed: () -> Unit, + loadClientsOfGroup: (List) -> Unit +) { + composable( + route = CenterScreens.CenterGroupListScreen.route, + arguments = listOf(navArgument(Constants.CENTER_ID, builder = { type = NavType.IntType })) + ) { + GroupListScreen( + onBackPressed = onBackPressed, + loadClientsOfGroup = loadClientsOfGroup + ) + } +} + +fun NavGraphBuilder.createCenterScreenRoute( + onCreateSuccess: () -> Unit +) { + composable( + route = CenterScreens.CreateCenterScreen.route + ) { + CreateNewCenterScreen( + onCreateSuccess = onCreateSuccess + ) + } +} + +fun NavGraphBuilder.syncCenterPayloadsScreenRoute( + onBackPressed: () -> Unit +) { + composable( + route = CenterScreens.SyncCenterPayloadsScreen.route + ) { + SyncCenterPayloadsScreenRoute( + onBackPressed = onBackPressed + ) + } +} + +fun NavController.navigateCenterListScreenRoute() { + navigate(CenterScreens.CenterListScreen.route) +} + +fun NavController.navigateCenterDetailsScreenRoute(centerId: Int) { + navigate(CenterScreens.CenterDetailScreen.argument(centerId)) +} + +fun NavController.navigateCreateCenterScreenRoute() { + navigate(CenterScreens.CreateCenterScreen.route) +} + +fun NavController.navigateCenterGroupListScreenRoute(centerId: Int) { + navigate(CenterScreens.CenterGroupListScreen.arguments(centerId)) +} + +fun NavController.navigateCenterSyncPayloadsScreenRoute() { + navigate(CenterScreens.SyncCenterPayloadsScreen.route) +} \ No newline at end of file diff --git a/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterScreens.kt b/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterScreens.kt new file mode 100644 index 00000000000..0739d2b9ba9 --- /dev/null +++ b/feature/center/src/main/java/com/mifos/feature/center/navigation/CenterScreens.kt @@ -0,0 +1,20 @@ +package com.mifos.feature.center.navigation + +import com.mifos.core.common.utils.Constants + +sealed class CenterScreens(val route: String) { + + data object CenterListScreen : CenterScreens("center_list_screen") + + data object CenterDetailScreen : CenterScreens("center_detail_screen/{${Constants.CENTER_ID}}") { + fun argument(centerId: Int) = "center_detail_screen/${centerId}" + } + + data object CenterGroupListScreen : CenterScreens("center_group_list_screen/{${Constants.CENTER_ID}}") { + fun arguments(centerId: Int) = "center_group_list_screen/${centerId}" + } + + data object CreateCenterScreen : CenterScreens("create_center_screen/{${Constants.CENTER_ID}}") + + data object SyncCenterPayloadsScreen : CenterScreens("sync_center_payloads_screen") +} \ No newline at end of file diff --git a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientListNavigation.kt b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientListNavigation.kt deleted file mode 100644 index e27632fab6f..00000000000 --- a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientListNavigation.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.mifos.feature.client.navigation - -import androidx.compose.foundation.layout.PaddingValues -import androidx.navigation.NavController -import androidx.navigation.NavGraphBuilder -import androidx.navigation.compose.composable -import com.mifos.core.objects.client.Client -import com.mifos.feature.client.clientList.presentation.ClientListScreen - -/** - * Created by Pronay Sarker on 10/08/2024 (6:47 AM) - */ -const val CLIENT_LIST_SCREEN_ROUTE = "client_list_screen" - -fun NavController.navigateToClientListScreen() { - this.navigate(CLIENT_LIST_SCREEN_ROUTE) -} - -fun NavGraphBuilder.clientListScreen( - paddingValues: PaddingValues, - createNewClient : () -> Unit, - syncClicked : () -> Unit, - onClientSelect : (Int) -> Unit -) { - composable(CLIENT_LIST_SCREEN_ROUTE) { - ClientListScreen( - paddingValues = paddingValues, - createNewClient = { }, - syncClicked = { }, - onClientSelect = onClientSelect - ) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt index 1faecdabd11..ce8d8438528 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt @@ -14,9 +14,7 @@ import androidx.compose.material.icons.rounded.Settings import androidx.compose.material.icons.rounded.Task import androidx.compose.ui.graphics.vector.ImageVector import com.mifos.feature.about.navigation.ABOUT_SCREEN_ROUTE -import com.mifos.feature.center.navigation.CENTER_LIST_SCREEN_ROUTE import com.mifos.feature.checker_inbox_task.navigation.CHECKER_INBOX_TASK_SCREEN_ROUTE -import com.mifos.feature.client.navigation.CLIENT_LIST_SCREEN_ROUTE import com.mifos.feature.groups.navigation.GROUP_LIST_SCREEN_ROUTE import com.mifos.feature.individual_collection_sheet.navigation.GENERATE_COLLECTION_SHEET_SCREEN_ROUTE import com.mifos.feature.individual_collection_sheet.navigation.INDIVIDUAL_COLLECTION_SHEET_SCREEN_ROUTE @@ -38,13 +36,13 @@ sealed class HomeDestinationsScreen( data object ClientListScreen : HomeDestinationsScreen( title = "Clients", - route = CLIENT_LIST_SCREEN_ROUTE, + route = "client_list_screen", icon = Icons.Rounded.Person ) data object CenterListScreen : HomeDestinationsScreen( title = "Centers", - route = CENTER_LIST_SCREEN_ROUTE, + route = "center_list_screen", icon = Icons.Rounded.Business ) 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 4772fad584f..6abb98d4e9a 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 @@ -7,7 +7,7 @@ import androidx.compose.ui.Modifier import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import com.mifos.feature.about.navigation.aboutScreen -import com.mifos.feature.center.navigation.centerListScreen +import com.mifos.feature.center.navigation.centerNavGraph import com.mifos.feature.checker_inbox_task.navigation.checkerInboxTasksScreen import com.mifos.feature.client.navigation.clientNavGraph import com.mifos.feature.groups.navigation.groupListScreen @@ -51,11 +51,11 @@ fun Navigation( clientListScreen = { } ) - centerListScreen( + centerNavGraph( + navController = navController, paddingValues = padding, - createNewCenter = {}, - syncClicked = {}, - onCenterSelect = {} + onActivateCenter = { _, _ -> }, + addSavingsAccount = { } ) groupListScreen( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt index 7f37a176778..14c986c0709 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt @@ -35,7 +35,6 @@ class CenterDetailsFragment : MifosBaseFragment() { return ComposeView(requireActivity()).apply { setContent { CenterDetailsScreen( - centerId = centerId, onBackPressed = { requireActivity().onBackPressed() }, diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt index 60b08fcd869..fd600cb99e1 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt @@ -36,18 +36,18 @@ class CenterListFragment : MifosBaseFragment() { (activity as HomeActivity).supportActionBar?.title = getString(R.string.centers) setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { - CenterListScreen( - paddingValues = PaddingValues(), - createNewCenter = { - onClickCreateNewCenter() - }, - onCenterSelect = { center -> - selectedCenters(center) - }, - syncClicked = { selectedCenters -> - syncCenters(selectedCenters) - } - ) +// CenterListScreen( +// paddingValues = PaddingValues(), +// createNewCenter = { +// onClickCreateNewCenter() +// }, +// onCenterSelect = { center -> +// selectedCenters(center) +// }, +// syncClicked = { selectedCenters -> +// syncCenters(selectedCenters) +// } +// ) } } } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt index 5710809fdb0..91b9be122d7 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/grouplist/GroupListFragment.kt @@ -39,7 +39,6 @@ class GroupListFragment : Fragment() { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { GroupListScreen( - centerId = centerId, onBackPressed = { findNavController().popBackStack() },