Skip to content

Commit

Permalink
feat: implemented Nav graph client
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Aug 12, 2024
1 parent 8b42ed1 commit a0a26a5
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ import java.util.Objects
@Composable
fun ClientDetailsScreen(
clientDetailsViewModel: ClientDetailsViewModel = hiltViewModel(),
clientId: Int,
onBackPressed: () -> Unit,
addLoanAccount: (Int) -> Unit,
addSavingsAccount: (Int) -> Unit,
Expand All @@ -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()
Expand Down Expand Up @@ -946,7 +946,6 @@ fun MifosClientDetailsText(icon: ImageVector, field: String, value: String) {
@Composable
private fun ClientDetailsScreenPreview() {
ClientDetailsScreen(
clientId = 1,
onBackPressed = {},
addLoanAccount = {},
addSavingsAccount = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>(ClientDetailsUiState.Empty)
val clientDetailsUiState = _clientDetailsUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun ClientListScreen(
paddingValues: PaddingValues,
createNewClient: () -> Unit,
syncClicked: (List<Client>) -> Unit,
onClientSelect: (Client) -> Unit,
onClientSelect: (Int) -> Unit,
) {

val viewModel: ClientListViewModel = hiltViewModel()
Expand Down Expand Up @@ -234,7 +234,7 @@ fun LazyColumnForClientListApi(
isInSelectionMode: MutableState<Boolean>,
selectedItems: SnapshotStateList<Client>,
failedRefresh : () ->Unit,
onClientSelect: (Client) -> Unit
onClientSelect: (Int) -> Unit
) {

when (clientPagingList.loadState.refresh) {
Expand Down Expand Up @@ -270,7 +270,7 @@ fun LazyColumnForClientListApi(
LightGray
}
} else {
clientPagingList[index]?.let { onClientSelect(it) }
clientPagingList[index]?.clientId?.let { onClientSelect(it) }
}
},
onLongClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,16 +25,26 @@ fun NavGraphBuilder.searchScreen(
) {
composable(SEARCH_SCREEN_ROUTE) {
SearchScreenRoute(
modifier = Modifier,
modifier = modifier,
onFabClick = { fabOptions ->
when(fabOptions){
FabType.CLIENT -> TODO()
FabType.CENTER -> TODO()
FabType.GROUP -> TODO()
}
},
onSearchOptionClick = {
onSearchOptionClick = {searchEntity ->
when(searchEntity.entityType) {
Constants.SEARCH_ENTITY_LOAN -> {

}
Constants.SEARCH_ENTITY_CLIENT -> {

}
Constants.SEARCH_ENTITY_CENTER -> {

}
}
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,7 +46,9 @@ fun Navigation(
paddingValues = padding,
createNewClient = {},
syncClicked = {},
onClientSelect = {}
onClientSelect = {
navController.navigateClientDetailsScreen(it)
}
)

centerListScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ClientDetailsFragment : MifosBaseFragment() {
)
setContent {
ClientDetailsScreen(
clientId = requireArguments().getInt(Constants.CLIENT_ID),
onBackPressed = {
requireActivity().onBackPressed()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ClientListFragment : MifosBaseFragment() {

val action =
ClientListFragmentDirections.actionClientListFragmentToClientActivity(
ClientArgs(clientId = client.id)
ClientArgs(clientId = client)
)
findNavController().navigate(action)
})
Expand Down

0 comments on commit a0a26a5

Please sign in to comment.