diff --git a/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt b/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt index f493a3c5c00..068752425d2 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt @@ -112,7 +112,6 @@ import java.util.Objects @Composable fun ClientDetailsScreen( clientDetailsViewModel: ClientDetailsViewModel = hiltViewModel(), - clientId: Int, onBackPressed: () -> Unit, addLoanAccount: (Int) -> Unit, addSavingsAccount: (Int) -> Unit, @@ -128,6 +127,7 @@ fun ClientDetailsScreen( savingsAccountSelected: (Int, DepositType) -> Unit, activateClient: (Int) -> Unit ) { + val clientId by clientDetailsViewModel.clientId.collectAsStateWithLifecycle() val context = LocalContext.current val scope = rememberCoroutineScope() @@ -946,7 +946,6 @@ fun MifosClientDetailsText(icon: ImageVector, field: String, value: String) { @Composable private fun ClientDetailsScreenPreview() { ClientDetailsScreen( - clientId = 1, onBackPressed = {}, addLoanAccount = {}, addSavingsAccount = {}, diff --git a/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsViewModel.kt b/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsViewModel.kt index 0c417d7d7ff..c1d24c3ab98 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsViewModel.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsViewModel.kt @@ -2,9 +2,11 @@ package com.mifos.feature.client.clientDetails.ui import android.graphics.Bitmap import android.os.Environment +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import coil.request.ImageResult +import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.Resource import com.mifos.core.domain.use_cases.DeleteClientImageUseCase import com.mifos.core.domain.use_cases.GetClientDetailsUseCase @@ -31,9 +33,12 @@ class ClientDetailsViewModel @Inject constructor( private val uploadClientImageUseCase: UploadClientImageUseCase, private val getClientDetailsUseCase: GetClientDetailsUseCase, private val deleteClientImageUseCase: DeleteClientImageUseCase, - private val imageLoaderUtils: ImageLoaderUtils + private val imageLoaderUtils: ImageLoaderUtils, + savedStateHandle: SavedStateHandle ) : ViewModel() { + val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0) + private val _clientDetailsUiState = MutableStateFlow(ClientDetailsUiState.Empty) val clientDetailsUiState = _clientDetailsUiState.asStateFlow() diff --git a/feature/client/src/main/java/com/mifos/feature/client/clientList/presentation/ClientListScreen.kt b/feature/client/src/main/java/com/mifos/feature/client/clientList/presentation/ClientListScreen.kt index 4f8123bce01..bf0e9123e4e 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/clientList/presentation/ClientListScreen.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientList/presentation/ClientListScreen.kt @@ -79,7 +79,7 @@ fun ClientListScreen( paddingValues: PaddingValues, createNewClient: () -> Unit, syncClicked: (List) -> Unit, - onClientSelect: (Client) -> Unit, + onClientSelect: (Int) -> Unit, ) { val viewModel: ClientListViewModel = hiltViewModel() @@ -234,7 +234,7 @@ fun LazyColumnForClientListApi( isInSelectionMode: MutableState, selectedItems: SnapshotStateList, failedRefresh : () ->Unit, - onClientSelect: (Client) -> Unit + onClientSelect: (Int) -> Unit ) { when (clientPagingList.loadState.refresh) { @@ -270,7 +270,7 @@ fun LazyColumnForClientListApi( LightGray } } else { - clientPagingList[index]?.let { onClientSelect(it) } + clientPagingList[index]?.clientId?.let { onClientSelect(it) } } }, onLongClick = { 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 index 5e933c964f8..e27632fab6f 100644 --- 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 @@ -4,6 +4,7 @@ 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 /** @@ -19,14 +20,14 @@ fun NavGraphBuilder.clientListScreen( paddingValues: PaddingValues, createNewClient : () -> Unit, syncClicked : () -> Unit, - onClientSelect : () -> Unit + onClientSelect : (Int) -> Unit ) { composable(CLIENT_LIST_SCREEN_ROUTE) { ClientListScreen( paddingValues = paddingValues, createNewClient = { }, syncClicked = { }, - onClientSelect = { } + onClientSelect = onClientSelect ) } } \ No newline at end of file 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 new file mode 100644 index 00000000000..5e3ca5fd608 --- /dev/null +++ b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientNavigation.kt @@ -0,0 +1,81 @@ +package com.mifos.feature.client.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.core.objects.accounts.savings.DepositType +import com.mifos.feature.client.clientDetails.ui.ClientDetailsScreen + +fun NavController.navigateClientDetailsScreen(clientId: Int) { + navigate(ClientScreens.ClientDetailScreen.argument(clientId)) +} + + +fun NavGraphBuilder.clientNavGraph( + navController: NavController +) { + navigation( + startDestination = ClientScreens.ClientListScreen.route, + route = "" + ) { + clientDetailRoute( + onBackPressed = navController::popBackStack, + addLoanAccount = {}, + addSavingsAccount = {}, + charges = {}, + documents = {}, + identifiers = {}, + moreClientInfo = {}, + notes = {}, + pinpointLocation = {}, + survey = {}, + uploadSignature = {}, + loanAccountSelected = {}, + savingsAccountSelected = { _, _ -> }, + activateClient = {} + ) + } +} + +fun NavGraphBuilder.clientDetailRoute( + onBackPressed: () -> Unit, + addLoanAccount: (Int) -> Unit, + addSavingsAccount: (Int) -> Unit, + charges: (Int) -> Unit, + documents: (Int) -> Unit, + identifiers: (Int) -> Unit, + moreClientInfo: (Int) -> Unit, + notes: (Int) -> Unit, + pinpointLocation: (Int) -> Unit, + survey: (Int) -> Unit, + uploadSignature: (Int) -> Unit, + loanAccountSelected: (Int) -> Unit, + savingsAccountSelected: (Int, DepositType) -> Unit, + activateClient: (Int) -> Unit +) { + composable( + route = ClientScreens.ClientDetailScreen.route, + arguments = listOf(navArgument(Constants.CLIENT_ID, builder = { type = NavType.IntType })) + ) { + ClientDetailsScreen( + onBackPressed = onBackPressed, + addLoanAccount = addLoanAccount, + addSavingsAccount = addSavingsAccount, + charges = charges, + documents = documents, + identifiers = identifiers, + moreClientInfo = moreClientInfo, + notes = notes, + pinpointLocation = pinpointLocation, + survey = survey, + uploadSignature = uploadSignature, + loanAccountSelected = loanAccountSelected, + savingsAccountSelected = savingsAccountSelected, + activateClient = activateClient + ) + } +} \ 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 new file mode 100644 index 00000000000..630ccb52b9b --- /dev/null +++ b/feature/client/src/main/java/com/mifos/feature/client/navigation/ClientScreens.kt @@ -0,0 +1,24 @@ +package com.mifos.feature.client.navigation + +import com.mifos.core.common.utils.Constants + +sealed class ClientScreens(val route : String) { + + data object ClientListScreen : ClientScreens("client_list_screen") + + data object ClientDetailScreen : ClientScreens("client_detail_screen/{${Constants.CLIENT_ID}}") { + fun argument(clientId : Int) = "client_detail_screen/${clientId}" + } + + data object ClientChargesScreen : ClientScreens("client_charges_screen") + + data object ClientIdentifierScreen : ClientScreens("client_identifier_screen") + + data object ClientPinPointScreen : ClientScreens("client_pin_point_screen") + + data object ClientSignatureScreen : ClientScreens("client_signature_screen") + + data object ClientSurveyListScreen : ClientScreens("client_survey_list_screen") + + data object ClientSurveyQuestionScreen : ClientScreens("client_survey_question_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 index f80f70344a8..f06da4e918f 100644 --- 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 @@ -4,6 +4,7 @@ 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 @@ -24,7 +25,7 @@ fun NavGraphBuilder.searchScreen( ) { composable(SEARCH_SCREEN_ROUTE) { SearchScreenRoute( - modifier = Modifier, + modifier = modifier, onFabClick = { fabOptions -> when(fabOptions){ FabType.CLIENT -> TODO() @@ -32,8 +33,18 @@ fun NavGraphBuilder.searchScreen( FabType.GROUP -> TODO() } }, - onSearchOptionClick = { + onSearchOptionClick = {searchEntity -> + when(searchEntity.entityType) { + Constants.SEARCH_ENTITY_LOAN -> { + } + Constants.SEARCH_ENTITY_CLIENT -> { + + } + Constants.SEARCH_ENTITY_CENTER -> { + + } + } }, ) } 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 2de773deb3a..98b3b2777df 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 @@ -11,6 +11,7 @@ import com.mifos.feature.center.navigation.centerListScreen import com.mifos.feature.center.navigation.navigateToCenterList import com.mifos.feature.checker_inbox_task.navigation.checkerInboxTasksScreen import com.mifos.feature.client.navigation.clientListScreen +import com.mifos.feature.client.navigation.navigateClientDetailsScreen import com.mifos.feature.client.navigation.navigateToClientListScreen import com.mifos.feature.groups.navigation.groupListScreen import com.mifos.feature.groups.navigation.navigateToGroupList @@ -45,7 +46,9 @@ fun Navigation( paddingValues = padding, createNewClient = {}, syncClicked = {}, - onClientSelect = {} + onClientSelect = { + navController.navigateClientDetailsScreen(it) + } ) centerListScreen( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt index 654f7e5c688..0a6d150bad9 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientdetails/ClientDetailsFragment.kt @@ -33,7 +33,6 @@ class ClientDetailsFragment : MifosBaseFragment() { ) setContent { ClientDetailsScreen( - clientId = requireArguments().getInt(Constants.CLIENT_ID), onBackPressed = { requireActivity().onBackPressed() }, diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt index 740b21d2bb1..1bec7c74038 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt @@ -78,7 +78,7 @@ class ClientListFragment : MifosBaseFragment() { val action = ClientListFragmentDirections.actionClientListFragmentToClientActivity( - ClientArgs(clientId = client.id) + ClientArgs(clientId = client) ) findNavController().navigate(action) })