Skip to content

Commit

Permalink
feat: implemented compose navigation in search module
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Aug 21, 2024
1 parent 68f2813 commit 0fe0c09
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -78,6 +81,10 @@ fun NavGraphBuilder.clientNavGraph(
clientSurveyQuestionRoute(
onBackPressed = navController::popBackStack
)
createClientRoute(
onBackPressed = navController::popBackStack,
hasDatatables = { _, _ -> }
)
}
}

Expand Down Expand Up @@ -221,6 +228,20 @@ fun NavGraphBuilder.clientSurveyQuestionRoute(
}
}

fun NavGraphBuilder.createClientRoute(
onBackPressed: () -> Unit,
hasDatatables: (List<DataTable>, ClientPayload) -> Unit
) {
composable(
route = ClientScreens.CreateClientScreen.route
) {
CreateNewClientScreen(
navigateBack = onBackPressed,
hasDatatables = hasDatatables
)
}
}

fun NavController.navigateClientDetailsScreen(clientId: Int) {
navigate(ClientScreens.ClientDetailScreen.argument(clientId))
}
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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>(FabButtonState.Collapsed) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -30,16 +33,16 @@ 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
fun Navigation(
navController: NavHostController,
padding: PaddingValues,
modifier: Modifier = Modifier,
startDestination: String = SEARCH_SCREEN_ROUTE
startDestination: String = SearchScreens.SearchScreenRoute.route
) {
NavHost(
navController = navController,
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 0fe0c09

Please sign in to comment.