From 0fe0c0920be4e116af291226c16d68d156e4b589 Mon Sep 17 00:00:00 2001 From: Aditya-gupta99 Date: Wed, 21 Aug 2024 23:48:04 +0530 Subject: [PATCH] feat: implemented compose navigation in search module --- .../client/navigation/ClientNavigation.kt | 25 +++++ .../client/navigation/ClientScreens.kt | 2 + .../search/Navigation/SearchNavigation.kt | 51 ---------- .../com/mifos/feature/search/SearchScreen.kt | 2 +- .../search/navigation/SearchNavigation.kt | 92 +++++++++++++++++++ .../search/navigation/SearchScreens.kt | 7 ++ .../mifosxdroid/HomeDestinationsScreen.kt | 11 +-- .../mifosxdroid/components/Navigation.kt | 57 ++++++++---- 8 files changed, 169 insertions(+), 78 deletions(-) delete mode 100644 feature/search/src/main/java/com/mifos/feature/search/Navigation/SearchNavigation.kt create mode 100644 feature/search/src/main/java/com/mifos/feature/search/navigation/SearchNavigation.kt create mode 100644 feature/search/src/main/java/com/mifos/feature/search/navigation/SearchScreens.kt diff --git a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt index 00844a7c4b3..ca7b94f76aa 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt @@ -10,6 +10,8 @@ import androidx.navigation.navigation import com.mifos.core.common.utils.Constants import com.mifos.core.objects.accounts.savings.DepositType import com.mifos.core.objects.client.Client +import com.mifos.core.objects.client.ClientPayload +import com.mifos.core.objects.noncore.DataTable import com.mifos.core.objects.survey.Survey import com.mifos.feature.client.clientCharges.ClientChargesScreen import com.mifos.feature.client.clientDetails.ui.ClientDetailsScreen @@ -19,6 +21,7 @@ import com.mifos.feature.client.clientPinpoint.PinpointClientScreen import com.mifos.feature.client.clientSignature.SignatureScreen import com.mifos.feature.client.clientSurveyList.SurveyListScreen import com.mifos.feature.client.clientSurveyQuestion.SurveyQuestionScreen +import com.mifos.feature.client.createNewClient.CreateNewClientScreen fun NavGraphBuilder.clientNavGraph( navController: NavController, @@ -78,6 +81,10 @@ fun NavGraphBuilder.clientNavGraph( clientSurveyQuestionRoute( onBackPressed = navController::popBackStack ) + createClientRoute( + onBackPressed = navController::popBackStack, + hasDatatables = { _, _ -> } + ) } } @@ -221,6 +228,20 @@ fun NavGraphBuilder.clientSurveyQuestionRoute( } } +fun NavGraphBuilder.createClientRoute( + onBackPressed: () -> Unit, + hasDatatables: (List, ClientPayload) -> Unit +) { + composable( + route = ClientScreens.CreateClientScreen.route + ) { + CreateNewClientScreen( + navigateBack = onBackPressed, + hasDatatables = hasDatatables + ) + } +} + fun NavController.navigateClientDetailsScreen(clientId: Int) { navigate(ClientScreens.ClientDetailScreen.argument(clientId)) } @@ -243,4 +264,8 @@ fun NavController.navigateClientSignatureScreen(clientId: Int) { fun NavController.navigateClientSurveyListScreen(clientId: Int) { navigate(ClientScreens.ClientSurveyListScreen.argument(clientId)) +} + +fun NavController.navigateCreateClientScreen() { + navigate(ClientScreens.CreateClientScreen.route) } \ No newline at end of file diff --git a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientScreens.kt b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientScreens.kt index 40e08ae37ce..8e95af1af51 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientScreens.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientScreens.kt @@ -37,4 +37,6 @@ sealed class ClientScreens(val route: String) { } data object ClientSurveyQuestionScreen : ClientScreens("client_survey_question_screen") + + data object CreateClientScreen : ClientScreens("create_client_screen") } \ No newline at end of file diff --git a/feature/search/src/main/java/com/mifos/feature/search/Navigation/SearchNavigation.kt b/feature/search/src/main/java/com/mifos/feature/search/Navigation/SearchNavigation.kt deleted file mode 100644 index f06da4e918f..00000000000 --- a/feature/search/src/main/java/com/mifos/feature/search/Navigation/SearchNavigation.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.mifos.feature.search.Navigation - -import androidx.compose.ui.Modifier -import androidx.navigation.NavController -import androidx.navigation.NavGraphBuilder -import androidx.navigation.compose.composable -import com.mifos.core.common.utils.Constants -import com.mifos.core.ui.components.FabType -import com.mifos.feature.search.SearchScreenRoute - -/** - * Created by Pronay Sarker on 10/08/2024 (6:35 AM) - */ -const val SEARCH_SCREEN_ROUTE = "search_screen" - -fun NavController.navigateToSearchScreen() { - this.navigate(SEARCH_SCREEN_ROUTE) -} - -fun NavGraphBuilder.searchScreen( - modifier: Modifier = Modifier, - centerListScreen: () -> Unit, - groupListScreen: () -> Unit, - clientListScreen: () -> Unit, -) { - composable(SEARCH_SCREEN_ROUTE) { - SearchScreenRoute( - modifier = modifier, - onFabClick = { fabOptions -> - when(fabOptions){ - FabType.CLIENT -> TODO() - FabType.CENTER -> TODO() - FabType.GROUP -> TODO() - } - }, - onSearchOptionClick = {searchEntity -> - when(searchEntity.entityType) { - Constants.SEARCH_ENTITY_LOAN -> { - - } - Constants.SEARCH_ENTITY_CLIENT -> { - - } - Constants.SEARCH_ENTITY_CENTER -> { - - } - } - }, - ) - } -} \ No newline at end of file diff --git a/feature/search/src/main/java/com/mifos/feature/search/SearchScreen.kt b/feature/search/src/main/java/com/mifos/feature/search/SearchScreen.kt index 63ee0ad4b03..5125f5b9cf8 100644 --- a/feature/search/src/main/java/com/mifos/feature/search/SearchScreen.kt +++ b/feature/search/src/main/java/com/mifos/feature/search/SearchScreen.kt @@ -55,7 +55,7 @@ internal fun SearchScreenContent( searchResultState: SearchResultState, onEvent: (SearchScreenEvent) -> Unit, onFabClick: (FabType) -> Unit, - onResultItemClick: (SearchedEntity) -> Unit, + onResultItemClick: (SearchedEntity) -> Unit ) { val snackbarHostState = remember { SnackbarHostState() } var fabButtonState by remember { mutableStateOf(FabButtonState.Collapsed) } diff --git a/feature/search/src/main/java/com/mifos/feature/search/navigation/SearchNavigation.kt b/feature/search/src/main/java/com/mifos/feature/search/navigation/SearchNavigation.kt new file mode 100644 index 00000000000..1f4051c0611 --- /dev/null +++ b/feature/search/src/main/java/com/mifos/feature/search/navigation/SearchNavigation.kt @@ -0,0 +1,92 @@ +package com.mifos.feature.search.navigation + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.padding +import androidx.compose.ui.Modifier +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable +import androidx.navigation.navigation +import com.mifos.core.common.utils.Constants +import com.mifos.core.objects.SearchedEntity +import com.mifos.core.ui.components.FabType +import com.mifos.feature.search.SearchScreenRoute + +fun NavGraphBuilder.searchNavGraph( + paddingValues: PaddingValues, + onCreateClient: () -> Unit, + onCreateCenter: () -> Unit, + onCreateGroup: () -> Unit, + onClient: (Int) -> Unit, + onCenter: (Int) -> Unit, + onGroup: (Int) -> Unit, + onSavings: (Int) -> Unit, + onLoan: (Int) -> Unit +) { + navigation( + startDestination = SearchScreens.SearchScreen.route, + route = SearchScreens.SearchScreenRoute.route + ) { + searchRoute( + modifier = Modifier.padding(paddingValues), + onFabClick = { + when (it) { + FabType.CLIENT -> { + onCreateClient() + } + + FabType.CENTER -> { + onCreateCenter() + } + + FabType.GROUP -> { + onCreateGroup() + } + } + }, + onSearchOptionClick = { searchedEntity -> + when (searchedEntity.entityType) { + Constants.SEARCH_ENTITY_LOAN -> { + onLoan(searchedEntity.entityId) + } + + Constants.SEARCH_ENTITY_CLIENT -> { + onClient(searchedEntity.entityId) + } + + Constants.SEARCH_ENTITY_GROUP -> { + onGroup(searchedEntity.entityId) + } + + Constants.SEARCH_ENTITY_SAVING -> { + onSavings(searchedEntity.entityId) + } + + Constants.SEARCH_ENTITY_CENTER -> { + onCenter(searchedEntity.entityId) + } + } + } + ) + } +} + +fun NavGraphBuilder.searchRoute( + modifier: Modifier, + onFabClick: (FabType) -> Unit, + onSearchOptionClick: (SearchedEntity) -> Unit +) { + composable( + route = SearchScreens.SearchScreen.route + ) { + SearchScreenRoute( + modifier = modifier, + onFabClick = onFabClick, + onSearchOptionClick = onSearchOptionClick + ) + } +} + +fun NavController.navigateSearchScreen() { + navigate(SearchScreens.SearchScreen.route) +} \ No newline at end of file diff --git a/feature/search/src/main/java/com/mifos/feature/search/navigation/SearchScreens.kt b/feature/search/src/main/java/com/mifos/feature/search/navigation/SearchScreens.kt new file mode 100644 index 00000000000..27ff0d1b021 --- /dev/null +++ b/feature/search/src/main/java/com/mifos/feature/search/navigation/SearchScreens.kt @@ -0,0 +1,7 @@ +package com.mifos.feature.search.navigation + +sealed class SearchScreens(val route: String) { + data object SearchScreenRoute : SearchScreens("search_screen_route") + + data object SearchScreen : SearchScreens("search_screen") +} \ 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 d587cf8a15c..7681c6cc550 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/HomeDestinationsScreen.kt @@ -13,17 +13,10 @@ import androidx.compose.material.icons.rounded.PowerSettingsNew 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.checker_inbox_task.navigation.CheckerInboxTaskScreens - - - 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 import com.mifos.feature.path_tracking.navigation.PathTrackingScreens -import com.mifos.feature.search.Navigation.SEARCH_SCREEN_ROUTE +import com.mifos.feature.search.navigation.SearchScreens import com.mifos.feature.settings.navigation.SETTINGS_SCREEN_ROUTE sealed class HomeDestinationsScreen( @@ -33,7 +26,7 @@ sealed class HomeDestinationsScreen( ) { data object SearchScreen : HomeDestinationsScreen( title = "Search", - route = SEARCH_SCREEN_ROUTE, + route = SearchScreens.SearchScreen.route, icon = Icons.Rounded.Dashboard ) 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 c2a479efb4d..36000ba646b 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 @@ -1,7 +1,6 @@ package com.mifos.mifosxdroid.components import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.navigation.NavHostController @@ -11,8 +10,12 @@ 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.center.navigation.navigateCenterDetailsScreenRoute +import com.mifos.feature.center.navigation.navigateCreateCenterScreenRoute import com.mifos.feature.checker_inbox_task.navigation.checkerInboxTaskGraph import com.mifos.feature.client.navigation.clientNavGraph +import com.mifos.feature.client.navigation.navigateClientDetailsScreen +import com.mifos.feature.client.navigation.navigateCreateClientScreen import com.mifos.feature.document.navigation.documentListScreen import com.mifos.feature.document.navigation.navigateToDocumentListScreen import com.mifos.feature.groups.navigation.groupListScreen @@ -30,8 +33,8 @@ import com.mifos.feature.savings.navigation.addSavingsAccountScreen import com.mifos.feature.savings.navigation.navigateToAddSavingsAccount import com.mifos.feature.savings.navigation.navigateToSavingsAccountSummaryScreen import com.mifos.feature.savings.navigation.savingsNavGraph -import com.mifos.feature.search.Navigation.SEARCH_SCREEN_ROUTE -import com.mifos.feature.search.Navigation.searchScreen +import com.mifos.feature.search.navigation.SearchScreens +import com.mifos.feature.search.navigation.searchNavGraph import com.mifos.feature.settings.navigation.settingsScreen @Composable @@ -39,7 +42,7 @@ fun Navigation( navController: NavHostController, padding: PaddingValues, modifier: Modifier = Modifier, - startDestination: String = SEARCH_SCREEN_ROUTE + startDestination: String = SearchScreens.SearchScreenRoute.route ) { NavHost( navController = navController, @@ -51,21 +54,36 @@ fun Navigation( paddingValues = padding, addLoanAccount = { navController.navigateToLoanAccountScreen(it) }, addSavingsAccount = { navController.navigateToAddSavingsAccount(it, 0, false) }, - documents = { navController.navigateToDocumentListScreen(it, Constants.ENTITY_TYPE_CLIENTS) }, + documents = { + navController.navigateToDocumentListScreen( + it, + Constants.ENTITY_TYPE_CLIENTS + ) + }, moreClientInfo = {}, - notes = { navController.navigateToNoteScreen(it, Constants.ENTITY_TYPE_CLIENTS)}, + notes = { navController.navigateToNoteScreen(it, Constants.ENTITY_TYPE_CLIENTS) }, loanAccountSelected = { navController.navigateToLoanAccountSummaryScreen(it) }, savingsAccountSelected = { id, type -> navController.navigateToSavingsAccountSummaryScreen(id, type) }, - activateClient = { navController.navigateToActivateScreen(it, Constants.ACTIVATE_CLIENT) } + activateClient = { + navController.navigateToActivateScreen( + it, + Constants.ACTIVATE_CLIENT + ) + } ) savingsNavGraph( navController = navController, onBackPressed = navController::popBackStack, loadMoreSavingsAccountInfo = { }, - loadDocuments = { navController.navigateToDocumentListScreen(it, Constants.ENTITY_TYPE_SAVINGS) }, + loadDocuments = { + navController.navigateToDocumentListScreen( + it, + Constants.ENTITY_TYPE_SAVINGS + ) + }, ) loanNavGraph( @@ -91,13 +109,18 @@ fun Navigation( onBackPressed = navController::popBackStack ) - activateScreen ( onBackPressed = navController::popBackStack ) + activateScreen(onBackPressed = navController::popBackStack) - searchScreen( - modifier = Modifier.padding(padding), - centerListScreen = { }, - groupListScreen = { }, - clientListScreen = { } + searchNavGraph( + paddingValues = padding, + onCreateCenter = navController::navigateCreateCenterScreenRoute, + onCreateClient = navController::navigateCreateClientScreen, + onCreateGroup = {}, + onCenter = navController::navigateCenterDetailsScreenRoute, + onClient = navController::navigateClientDetailsScreen, + onLoan = {}, + onGroup = {}, + onSavings = {} ) centerNavGraph( @@ -145,12 +168,12 @@ fun Navigation( ) individualCollectionSheetNavGraph( - onBackPressed = { navController.popBackStack() } , + onBackPressed = { navController.popBackStack() }, navController = navController, - navigateToPaymentDetails = { _, _, _, _, _, _ -> + navigateToPaymentDetails = { _, _, _, _, _, _ -> // TODO() navigate to payment details } ) - generateCollectionSheetScreen ( onBackPressed = navController::popBackStack ) + generateCollectionSheetScreen(onBackPressed = navController::popBackStack) } } \ No newline at end of file