Skip to content

Commit

Permalink
feat: implemented compose navigation in group module (openMF#2187)
Browse files Browse the repository at this point in the history
* feat: implemented groupNavGraph

implemented group_nav_graph

fixed  error

fixed topBar

* compose navigation in group module
  • Loading branch information
itsPronay authored Aug 22, 2024
1 parent 330f81b commit bde6483
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.mifos.core.common.utils.Utils
import com.mifos.core.designsystem.component.MifosCircularProgress
import com.mifos.core.designsystem.component.MifosMenuDropDownItem
Expand All @@ -80,7 +81,6 @@ import com.mifos.feature.groups.R

@Composable
fun GroupDetailsScreen(
groupId: Int,
onBackPressed: () -> Unit,
addLoanAccount: (Int) -> Unit,
addSavingsAccount: (Int) -> Unit,
Expand All @@ -93,6 +93,7 @@ fun GroupDetailsScreen(
activateGroup: (Int) -> Unit
) {
val viewModel: GroupDetailsViewModel = hiltViewModel()
val groupId by viewModel.groupId.collectAsStateWithLifecycle()
val state by viewModel.groupDetailsUiState.collectAsStateWithLifecycle()
val loanAccounts by viewModel.loanAccount.collectAsStateWithLifecycle()
val savingsAccounts by viewModel.savingsAccounts.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.mifos.feature.groups.group_details

import androidx.compose.ui.unit.Constraints
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.mifos.core.common.utils.Constants
import com.mifos.core.common.utils.Resource
import com.mifos.core.domain.use_cases.GetGroupAssociateClientsUseCase
import com.mifos.core.domain.use_cases.GetGroupDetailsUseCase
Expand All @@ -19,9 +22,12 @@ import javax.inject.Inject
@HiltViewModel
class GroupDetailsViewModel @Inject constructor(
private val getGroupDetailsUseCase: GetGroupDetailsUseCase,
private val getGroupAssociateClientsUseCase: GetGroupAssociateClientsUseCase
private val getGroupAssociateClientsUseCase: GetGroupAssociateClientsUseCase,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

val groupId = savedStateHandle.getStateFlow(key = Constants.GROUP_ID, initialValue = 0)

private val _groupDetailsUiState =
MutableStateFlow<GroupDetailsUiState>(GroupDetailsUiState.Loading)
val groupDetailsUiState = _groupDetailsUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import kotlinx.coroutines.flow.Flow
fun GroupsListRoute(
paddingValues: PaddingValues,
onAddGroupClick: () -> Unit,
onGroupClick: (Group) -> Unit,
onGroupClick: (groupId : Int) -> Unit,
onSyncClick: (List<Group>) -> Unit,
viewModel: GroupsListViewModel = hiltViewModel()
) {
Expand Down Expand Up @@ -135,14 +135,13 @@ fun GroupsListScreen(
selectedItems: List<Group>,
data: LazyPagingItems<Group>,
onAddGroupClick: () -> Unit,
onGroupClick: (Group) -> Unit,
onGroupClick: (groupId : Int) -> Unit,
onSyncClick: (List<Group>) -> Unit,
onSelectItem: (Group) -> Unit,
resetSelectionMode: () -> Unit,
) {
Scaffold(
modifier = modifier
.fillMaxSize(),
modifier = modifier,
floatingActionButton = {
MifosFAB(icon = Icons.Default.Add, onClick = onAddGroupClick)
},
Expand Down Expand Up @@ -276,7 +275,7 @@ private fun LazyListScope.successState(
pagingItems: LazyPagingItems<Group>,
isInSelectionMode: Boolean,
isSelected: (Group) -> Boolean,
onGroupClick: (Group) -> Unit,
onGroupClick: (groupId : Int) -> Unit,
onSelectItem: (Group) -> Unit
) {
items(
Expand All @@ -288,7 +287,7 @@ private fun LazyListScope.successState(
doesSelected = isSelected(group),
inSelectionMode = isInSelectionMode,
onGroupClick = {
onGroupClick(group)
group.id?.let { onGroupClick(it) }
},
onSelectItem = {
onSelectItem(group)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package com.mifos.feature.groups.navigation

import androidx.compose.foundation.layout.PaddingValues
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.core.objects.client.Client
import com.mifos.core.objects.group.Group
import com.mifos.core.objects.response.SaveResponse
import com.mifos.feature.groups.create_new_group.CreateNewGroupScreen
import com.mifos.feature.groups.group_details.GroupDetailsScreen
import com.mifos.feature.groups.group_list.GroupsListRoute
import com.mifos.feature.groups.sync_group_payloads.SyncGroupPayloadsScreenRoute

/**
* Created by Pronay Sarker on 13/08/2024
*/

fun NavGraphBuilder.groupNavGraph(
paddingValues: PaddingValues,
navController: NavController,
addGroupLoanAccount: (Int) -> Unit,
addSavingsAccount: (Int) -> Unit,
loadDocumentList: (Int) -> Unit,
clientListFragment: (List<Client>) -> Unit,
loadGroupDataTables: (Int) -> Unit,
loadNotes: (Int) -> Unit,
loadLoanAccountSummary: (Int) -> Unit,
loadSavingsAccountSummary: (Int, DepositType) -> Unit,
activateGroup: (Int) -> Unit
) {
navigation(
startDestination = GroupScreen.GroupListScreen.route,
route = "group_list_routes"
) {
groupListScreenRoute(
paddingValues = paddingValues,
onAddGroupClick = navController::navigateToCreateNewGroupScreen,
onGroupClick = navController::navigateToGroupDetailsScreen,
onSyncClick = { }
)

groupDetailsRoute(
onBackPressed = navController::popBackStack,
addGroupLoanAccount = addGroupLoanAccount,
addSavingsAccount = addSavingsAccount,
loadDocumentList = loadDocumentList,
clientListFragment = clientListFragment,
loadGroupDataTables = loadGroupDataTables,
loadNotes = loadNotes,
loadLoanAccountSummary = loadLoanAccountSummary,
loadSavingsAccountSummary = loadSavingsAccountSummary,
activateGroup = activateGroup
)

addNewGroupRoute(
onGroupCreated = { }
)

syncGroupPayloadsRoute(
onBackPressed = navController::popBackStack
)
}
}

fun NavGraphBuilder.groupListScreenRoute(
paddingValues: PaddingValues,
onAddGroupClick: () -> Unit,
onGroupClick: (groupId: Int) -> Unit,
onSyncClick: (List<Group>) -> Unit
) {
composable(route = GroupScreen.GroupListScreen.route) {
GroupsListRoute(
paddingValues = paddingValues,
onAddGroupClick = onAddGroupClick,
onGroupClick = onGroupClick,
onSyncClick = onSyncClick
)
}
}

fun NavGraphBuilder.groupDetailsRoute(
onBackPressed: () -> Unit,
addGroupLoanAccount: (Int) -> Unit,
addSavingsAccount: (Int) -> Unit,
loadDocumentList: (Int) -> Unit,
clientListFragment: (List<Client>) -> Unit,
loadGroupDataTables: (Int) -> Unit,
loadNotes: (Int) -> Unit,
loadLoanAccountSummary: (Int) -> Unit,
loadSavingsAccountSummary: (Int, DepositType) -> Unit,
activateGroup: (Int) -> Unit
) {
composable(
route = GroupScreen.GroupDetailsScreen.route,
arguments = listOf(
navArgument(name = Constants.GROUP_ID, builder = { type = NavType.IntType })
)
) {
GroupDetailsScreen(
onBackPressed = onBackPressed,
addLoanAccount = addGroupLoanAccount,
addSavingsAccount = addSavingsAccount,
documents = loadDocumentList,
groupClients = clientListFragment,
moreGroupInfo = loadGroupDataTables,
notes = loadNotes,
loanAccountSelected = loadLoanAccountSummary,
savingsAccountSelected = loadSavingsAccountSummary,
activateGroup = activateGroup
)
}
}

fun NavGraphBuilder.addNewGroupRoute(
onGroupCreated: (group: SaveResponse?) -> Unit,
) {
composable(route = GroupScreen.CreateNewGroupScreen.route) {
CreateNewGroupScreen(
onGroupCreated = onGroupCreated
)
}
}

fun NavGraphBuilder.syncGroupPayloadsRoute(
onBackPressed: () -> Unit
) {
composable(route = GroupScreen.SyncGroupPayloadScreen.route) {
SyncGroupPayloadsScreenRoute(
onBackPressed = onBackPressed
)
}
}

fun NavController.navigateToCreateNewGroupScreen() {
navigate(GroupScreen.CreateNewGroupScreen.route)
}

fun NavController.navigateToGroupDetailsScreen(groupId: Int) {
navigate(GroupScreen.GroupDetailsScreen.argument(groupId))
}

fun NavController.navigateToSyncGroupPayloadScreen() {
// TODO()
navigate(GroupScreen.SyncGroupPayloadScreen.route)
}






Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mifos.feature.groups.navigation

import com.mifos.core.common.utils.Constants

/**
* Created by Pronay Sarker on 13/08/2024 (10:39 AM)
*/
sealed class GroupScreen(val route: String) {

data object GroupListScreen : GroupScreen("group_list_screen")

data object CreateNewGroupScreen : GroupScreen("create_new_group")

data object GroupDetailsScreen : GroupScreen("group_details_screen/{${Constants.GROUP_ID}}"){
fun argument(groupId : Int) = "group_details_screen/${groupId}"
}

data object SyncGroupPayloadScreen : GroupScreen("sync_group_payload_screen")
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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.checker_inbox_task.navigation.CheckerInboxTaskScreens
import com.mifos.feature.groups.navigation.GROUP_LIST_SCREEN_ROUTE
import com.mifos.feature.groups.navigation.GroupScreen
import com.mifos.feature.path_tracking.navigation.PathTrackingScreens
import com.mifos.feature.search.navigation.SearchScreens
import com.mifos.feature.settings.navigation.SETTINGS_SCREEN_ROUTE
Expand Down Expand Up @@ -44,7 +44,7 @@ sealed class HomeDestinationsScreen(

data object GroupListScreen : HomeDestinationsScreen(
title = "Groups",
route = GROUP_LIST_SCREEN_ROUTE,
route = GroupScreen.GroupListScreen.route,
icon = Icons.Rounded.Group
)

Expand Down
Loading

0 comments on commit bde6483

Please sign in to comment.