Skip to content

Commit

Permalink
MIFOSAC-263 implemented compose navigation in Collection sheet module (
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay committed Aug 20, 2024
1 parent e074088 commit c83d295
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ fun GenerateCollectionSheetScreen(
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun GenerateCollectionSheetContent(
centerDetailsState: List<CenterDetail>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fun IndividualCollectionSheetScreen(
onBackPressed: () -> Unit,
onDetail: (String, IndividualCollectionSheet) -> Unit,
) {

val snackbarHostState = remember { SnackbarHostState() }

val pagerState = rememberPagerState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ import com.mifos.feature.collection_sheet.R

@Composable
fun IndividualCollectionSheetDetailsScreen(
sheet: IndividualCollectionSheet,
onBackPressed: () -> Unit,
submit: (Int, IndividualCollectionSheetPayload, List<String>, LoanAndClientName, List<PaymentTypeOptions>, Int) -> Unit
) {

val viewModel: IndividualCollectionSheetDetailsViewModel = hiltViewModel()
val state by viewModel.individualCollectionSheetDetailsUiState.collectAsStateWithLifecycle()
val loansAndClientNames = viewModel.filterLoanAndClientNames(sheet.clients ?: emptyList())
val loansAndClientNames = viewModel.filterLoanAndClientNames(viewModel.sheet.clients ?: emptyList())

IndividualCollectionSheetDetailsScreen(
sheet = sheet,
sheet = viewModel.sheet,
loansAndClientNames = loansAndClientNames,
state = state,
onBackPressed = onBackPressed,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.mifos.feature.individual_collection_sheet.individual_collection_sheet_details

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.gson.Gson
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.Resource
import com.mifos.core.domain.use_cases.SaveIndividualCollectionSheetUseCase
import com.mifos.core.network.model.IndividualCollectionSheetPayload
import com.mifos.core.objects.collectionsheet.ClientCollectionSheet
import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet
import com.mifos.core.objects.collectionsheet.LoanAndClientName
import com.mifos.feature.collection_sheet.R
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -18,9 +22,13 @@ import javax.inject.Inject

@HiltViewModel
class IndividualCollectionSheetDetailsViewModel @Inject constructor(
private val saveIndividualCollectionSheetUseCase: SaveIndividualCollectionSheetUseCase
private val saveIndividualCollectionSheetUseCase: SaveIndividualCollectionSheetUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

private val arg = savedStateHandle.getStateFlow(key = Constants.INDIVIDUAL_SHEET, initialValue = "" )
val sheet : IndividualCollectionSheet = Gson().fromJson(arg.value, IndividualCollectionSheet::class.java)

private val _individualCollectionSheetDetailsUiState =
MutableStateFlow<IndividualCollectionSheetDetailsUiState>(
IndividualCollectionSheetDetailsUiState.Empty
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.mifos.feature.individual_collection_sheet.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.network.model.IndividualCollectionSheetPayload
import com.mifos.core.objects.accounts.loan.PaymentTypeOptions
import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet
import com.mifos.core.objects.collectionsheet.LoanAndClientName
import com.mifos.feature.individual_collection_sheet.generate_collection_sheet.GenerateCollectionSheetScreen
import com.mifos.feature.individual_collection_sheet.individual_collection_sheet.ui.IndividualCollectionSheetScreen
import com.mifos.feature.individual_collection_sheet.individual_collection_sheet_details.IndividualCollectionSheetDetailsScreen

/**
* Created by Pronay Sarker on 20/08/2024 (4:06 PM)
*/
fun NavGraphBuilder.individualCollectionSheetNavGraph(
navController: NavController,
onBackPressed: () -> Unit,
navigateToPaymentDetails: (Int, IndividualCollectionSheetPayload, List<String>, LoanAndClientName, List<PaymentTypeOptions>, Int) -> Unit
) {
navigation(
route = "generate_collection_sheet",
startDestination = CollectionSheetScreens.IndividualCollectionSheetScreen.route
) {
individualCollectionSheetScreen(
onBackPressed = onBackPressed,
onDetail = { _, sheet -> navController.navigateToIndividualCollectionSheetDetailScreen(sheet) }
)

individualCollectionSheetDetailScreen(
onBackPressed = onBackPressed,
submit = navigateToPaymentDetails
)
}
}

private fun NavGraphBuilder.individualCollectionSheetScreen(
onBackPressed: () -> Unit,
onDetail: (String, IndividualCollectionSheet) -> Unit
) {
composable(
route = CollectionSheetScreens.IndividualCollectionSheetScreen.route
) {
IndividualCollectionSheetScreen(
onBackPressed = onBackPressed,
onDetail = onDetail
)
}
}

private fun NavGraphBuilder.individualCollectionSheetDetailScreen(
onBackPressed: () -> Unit,
submit: (Int, IndividualCollectionSheetPayload, List<String>, LoanAndClientName, List<PaymentTypeOptions>, Int) -> Unit
) {
composable(
route = CollectionSheetScreens.IndividualCollectionSheetDetailScreen.route,
arguments = listOf(
navArgument(name = Constants.INDIVIDUAL_SHEET, builder = { NavType.StringType })
)
) {
IndividualCollectionSheetDetailsScreen(
onBackPressed = onBackPressed,
submit = submit
)
}
}

fun NavGraphBuilder.generateCollectionSheetScreen(
onBackPressed: () -> Unit
) {
composable(CollectionSheetScreens.GenerateCollectionSheetScreen.route) {
GenerateCollectionSheetScreen(
onBackPressed = onBackPressed
)
}
}

fun NavController.navigateToIndividualCollectionSheetDetailScreen(sheet: IndividualCollectionSheet) {
navigate(CollectionSheetScreens.IndividualCollectionSheetDetailScreen.argument(sheet))
}

fun NavController.navigateToIndividualCollectionSheet() {
navigate(CollectionSheetScreens.IndividualCollectionSheetScreen.route)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mifos.feature.individual_collection_sheet.navigation

import com.google.gson.Gson
import com.mifos.core.common.utils.Constants
import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet
import com.mifos.core.objects.db.CollectionSheet
import com.mifos.feature.individual_collection_sheet.generate_collection_sheet.GenerateCollectionSheetUiState

/**
* Created by Pronay Sarker on 20/08/2024 (4:11 PM)
*/
sealed class CollectionSheetScreens(val route: String) {

data object GenerateCollectionSheetScreen : CollectionSheetScreens("generate_collection_sheet_route")

data object IndividualCollectionSheetScreen : CollectionSheetScreens("individual_collection_sheet_route")

data object IndividualCollectionSheetDetailScreen : CollectionSheetScreens("individual_collection_sheet_detail/{${Constants.INDIVIDUAL_SHEET}}") {
fun argument(sheet: IndividualCollectionSheet): String {
val gson = Gson()
val sheetInGsonString = gson.toJson(sheet)

return "individual_collection_sheet_detail/$sheetInGsonString"
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
import com.mifos.feature.about.navigation.ABOUT_SCREEN_ROUTE
import com.mifos.feature.checker_inbox_task.navigation.CHECKER_INBOX_TASK_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
import com.mifos.feature.path_tracking.navigation.PATH_TRACKING_SCREEN_ROUTE
import com.mifos.feature.search.Navigation.SEARCH_SCREEN_ROUTE
import com.mifos.feature.settings.navigation.SETTINGS_SCREEN_ROUTE
Expand Down Expand Up @@ -59,13 +57,13 @@ sealed class HomeDestinationsScreen(

data object IndividualCollectionSheetScreen : HomeDestinationsScreen(
title = "Individual Collection Sheet",
route = INDIVIDUAL_COLLECTION_SHEET_SCREEN_ROUTE,
route = "individual_collection_sheet_route",
icon = Icons.AutoMirrored.Rounded.Assignment
)

data object CollectionSheetScreen : HomeDestinationsScreen(
title = "Collection Sheet",
route = GENERATE_COLLECTION_SHEET_SCREEN_ROUTE,
route = "generate_collection_sheet",
icon = Icons.AutoMirrored.Rounded.Assignment
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.mifos.feature.document.navigation.documentListScreen
import com.mifos.feature.document.navigation.navigateToDocumentListScreen
import com.mifos.feature.groups.navigation.groupListScreen
import com.mifos.feature.individual_collection_sheet.navigation.generateCollectionSheetScreen
import com.mifos.feature.individual_collection_sheet.navigation.individualCollectionSheetScreen
import com.mifos.feature.individual_collection_sheet.navigation.individualCollectionSheetNavGraph
import com.mifos.feature.loan.navigation.addLoanAccountScreen
import com.mifos.feature.loan.navigation.loanNavGraph
import com.mifos.feature.loan.navigation.navigateToLoanAccountScreen
Expand Down Expand Up @@ -123,18 +123,6 @@ fun Navigation(
checkerInboxTasksScreen(
onBackPressed = { navController.popBackStack() },
)

individualCollectionSheetScreen(
onBackClicked = { navController.popBackStack() },
onDetail = { String, IndividualCollectionSheet ->

}
)

generateCollectionSheetScreen(
onBackPressed = { navController.popBackStack() }
)

pathTrackingScreen(
onBackPressed = { navController.popBackStack() }
)
Expand All @@ -151,5 +139,13 @@ fun Navigation(
onBackPressed = { navController.popBackStack() }
)

individualCollectionSheetNavGraph(
onBackPressed = { navController.popBackStack() } ,
navController = navController,
navigateToPaymentDetails = { _, _, _, _, _, _ ->
// TODO() navigate to payment details
}
)
generateCollectionSheetScreen ( onBackPressed = navController::popBackStack )
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment() {
private val arg: IndividualCollectionSheetDetailsFragmentArgs by navArgs()

private lateinit var sheet: IndividualCollectionSheet
private lateinit var actualDisbursementDate: String
private lateinit var transactionDate: String
// private lateinit var actualDisbursementDate: String
// private lateinit var transactionDate: String

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sheet = arg.sheet
actualDisbursementDate = arg.actualDisbursementDate
transactionDate = arg.transactionDate
// actualDisbursementDate = arg.actualDisbursementDate
// transactionDate = arg.transactionDate
}

override fun onCreateView(
Expand All @@ -41,7 +41,7 @@ class IndividualCollectionSheetDetailsFragment : MifosBaseFragment() {
return ComposeView(requireContext()).apply {
setContent {
IndividualCollectionSheetDetailsScreen(
sheet = sheet,
// sheet = sheet,
onBackPressed = {
findNavController().popBackStack()
},
Expand Down

0 comments on commit c83d295

Please sign in to comment.