Skip to content

Commit

Permalink
feat: implemented Nav graph center module (#2188)
Browse files Browse the repository at this point in the history
* feat: implemented Nav graph client

* feat: compose nav implementation in client module

* feat: nav graph client module implementation

* feat: navigation components center module
  • Loading branch information
Aditya-gupta99 authored Aug 14, 2024
1 parent de6f0bc commit 774ce74
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
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 @@ -61,14 +61,14 @@ import com.mifos.feature.center.R

@Composable
fun CenterDetailsScreen(
centerId: Int,
onBackPressed: () -> Unit,
onActivateCenter: () -> Unit,
onActivateCenter: (Int) -> Unit,
addSavingsAccount: (Int) -> Unit,
groupList: (Int) -> Unit
) {

val viewModel: CenterDetailsViewModel = viewModel()
val viewModel: CenterDetailsViewModel = hiltViewModel()
val centerId by viewModel.centerId.collectAsStateWithLifecycle()
val state by viewModel.centerDetailsUiState.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
Expand All @@ -88,7 +88,7 @@ fun CenterDetailsScreen(
onRetryClick = {
viewModel.loadClientDetails(centerId)
},
onActivateCenter = onActivateCenter
onActivateCenter = { onActivateCenter(centerId) }
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.center.center_details

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.GetCenterDetailsUseCase
import com.mifos.core.objects.group.CenterInfo
Expand All @@ -16,9 +18,12 @@ import javax.inject.Inject

@HiltViewModel
class CenterDetailsViewModel @Inject constructor(
private val getCenterDetailsUseCase: GetCenterDetailsUseCase
private val getCenterDetailsUseCase: GetCenterDetailsUseCase,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

val centerId = savedStateHandle.getStateFlow(key = Constants.CENTER_ID, initialValue = 0)

private val _centerDetailsUiState =
MutableStateFlow<CenterDetailsUiState>(CenterDetailsUiState.Loading)
val centerDetailsUiState = _centerDetailsUiState.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ import com.mifos.feature.center.R

@Composable
fun GroupListScreen(
centerId: Int,
onBackPressed: () -> Unit,
loadClientsOfGroup: (List<Client>) -> Unit
) {

val viewModel: GroupListViewModel = hiltViewModel()
val centerId by viewModel.centerId.collectAsStateWithLifecycle()
val state by viewModel.groupListUiState.collectAsStateWithLifecycle()
val groupAssociationState by viewModel.groupAssociationState.collectAsStateWithLifecycle()
var groupClicked by remember { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.feature.center.center_group_list

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.GetGroupsByCenterUseCase
import com.mifos.core.domain.use_cases.GetGroupsUseCase
Expand All @@ -18,9 +20,12 @@ import javax.inject.Inject
@HiltViewModel
class GroupListViewModel @Inject constructor(
private val getGroupsUseCase: GetGroupsUseCase,
private val getGroupsByCenterUseCase: GetGroupsByCenterUseCase
private val getGroupsByCenterUseCase: GetGroupsByCenterUseCase,
private val savedStateHandle: SavedStateHandle
) : ViewModel() {

val centerId = savedStateHandle.getStateFlow(key = Constants.CENTER_ID, initialValue = 0)

private val _groupListUiState = MutableStateFlow<GroupListUiState>(GroupListUiState.Loading)
val groupListUiState = _groupListUiState.asStateFlow()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun CenterListScreen(
paddingValues: PaddingValues,
createNewCenter: () -> Unit,
syncClicked: (List<Center>) -> Unit,
onCenterSelect: (Center) -> Unit
onCenterSelect: (Int) -> Unit
) {

val viewModel: CenterListViewModel = hiltViewModel()
Expand Down Expand Up @@ -111,7 +111,7 @@ fun CenterListScreen(
onRefresh: () -> Unit,
refreshState: Boolean,
syncClicked: (List<Center>) -> Unit,
onCenterSelect: (Center) -> Unit
onCenterSelect: (Int) -> Unit
) {

val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -226,7 +226,7 @@ fun CenterListContent(
isInSelectionMode: Boolean,
selectedItems: SnapshotStateList<Center>,
onRefresh: () -> Unit,
onCenterSelect: (Center) -> Unit,
onCenterSelect: (Int) -> Unit,
selectedMode: () -> Unit

) {
Expand Down Expand Up @@ -263,7 +263,7 @@ fun CenterListContent(
LightGray
}
} else {
centerPagingList[index]?.let { onCenterSelect(it) }
centerPagingList[index]?.id?.let { onCenterSelect(it) }
}
},
onLongClick = {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.mifos.feature.center.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.client.Client
import com.mifos.core.objects.group.Center
import com.mifos.feature.center.center_details.CenterDetailsScreen
import com.mifos.feature.center.center_group_list.GroupListScreen
import com.mifos.feature.center.center_list.ui.CenterListScreen
import com.mifos.feature.center.create_center.CreateNewCenterScreen
import com.mifos.feature.center.sync_center_payloads.SyncCenterPayloadsScreenRoute

fun NavGraphBuilder.centerNavGraph(
navController: NavController,
paddingValues: PaddingValues,
onActivateCenter: (Int,String) -> Unit,
addSavingsAccount: (Int) -> Unit
) {
navigation(
startDestination = CenterScreens.CenterListScreen.route,
route = "center_screen_route"
) {
centerListScreenRoute(
paddingValues = paddingValues,
createNewCenter = navController::navigateCreateCenterScreenRoute,
syncClicked = { }, // TODO open sync dialog inside center list screen
onCenterSelect = navController::navigateCenterDetailsScreenRoute
)
centerDetailScreenRoute(
onBackPressed = navController::popBackStack,
onActivateCenter = onActivateCenter,
addSavingsAccount = addSavingsAccount,
groupList = navController::navigateCenterGroupListScreenRoute
)
centerGroupListScreenRoute(
onBackPressed = navController::popBackStack,
loadClientsOfGroup = { }
)
createCenterScreenRoute(
onCreateSuccess = navController::popBackStack
)
syncCenterPayloadsScreenRoute(
onBackPressed = navController::popBackStack
)
}
}

fun NavGraphBuilder.centerListScreenRoute(
paddingValues: PaddingValues,
createNewCenter: () -> Unit,
syncClicked: (List<Center>) -> Unit,
onCenterSelect: (Int) -> Unit
) {
composable(
route = CenterScreens.CenterListScreen.route
) {
CenterListScreen(
paddingValues = paddingValues,
createNewCenter = createNewCenter,
syncClicked = syncClicked,
onCenterSelect = onCenterSelect
)
}
}

fun NavGraphBuilder.centerDetailScreenRoute(
onBackPressed: () -> Unit,
onActivateCenter: (Int,String) -> Unit,
addSavingsAccount: (Int) -> Unit,
groupList: (Int) -> Unit
) {
composable(
route = CenterScreens.CenterDetailScreen.route,
arguments = listOf(navArgument(Constants.CENTER_ID, builder = { type = NavType.IntType }))
) {
CenterDetailsScreen(
onBackPressed = onBackPressed,
onActivateCenter = {onActivateCenter(it,Constants.ACTIVATE_CENTER)},
addSavingsAccount = addSavingsAccount,
groupList = groupList
)
}
}

fun NavGraphBuilder.centerGroupListScreenRoute(
onBackPressed: () -> Unit,
loadClientsOfGroup: (List<Client>) -> Unit
) {
composable(
route = CenterScreens.CenterGroupListScreen.route,
arguments = listOf(navArgument(Constants.CENTER_ID, builder = { type = NavType.IntType }))
) {
GroupListScreen(
onBackPressed = onBackPressed,
loadClientsOfGroup = loadClientsOfGroup
)
}
}

fun NavGraphBuilder.createCenterScreenRoute(
onCreateSuccess: () -> Unit
) {
composable(
route = CenterScreens.CreateCenterScreen.route
) {
CreateNewCenterScreen(
onCreateSuccess = onCreateSuccess
)
}
}

fun NavGraphBuilder.syncCenterPayloadsScreenRoute(
onBackPressed: () -> Unit
) {
composable(
route = CenterScreens.SyncCenterPayloadsScreen.route
) {
SyncCenterPayloadsScreenRoute(
onBackPressed = onBackPressed
)
}
}

fun NavController.navigateCenterListScreenRoute() {
navigate(CenterScreens.CenterListScreen.route)
}

fun NavController.navigateCenterDetailsScreenRoute(centerId: Int) {
navigate(CenterScreens.CenterDetailScreen.argument(centerId))
}

fun NavController.navigateCreateCenterScreenRoute() {
navigate(CenterScreens.CreateCenterScreen.route)
}

fun NavController.navigateCenterGroupListScreenRoute(centerId: Int) {
navigate(CenterScreens.CenterGroupListScreen.arguments(centerId))
}

fun NavController.navigateCenterSyncPayloadsScreenRoute() {
navigate(CenterScreens.SyncCenterPayloadsScreen.route)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mifos.feature.center.navigation

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

sealed class CenterScreens(val route: String) {

data object CenterListScreen : CenterScreens("center_list_screen")

data object CenterDetailScreen : CenterScreens("center_detail_screen/{${Constants.CENTER_ID}}") {
fun argument(centerId: Int) = "center_detail_screen/${centerId}"
}

data object CenterGroupListScreen : CenterScreens("center_group_list_screen/{${Constants.CENTER_ID}}") {
fun arguments(centerId: Int) = "center_group_list_screen/${centerId}"
}

data object CreateCenterScreen : CenterScreens("create_center_screen/{${Constants.CENTER_ID}}")

data object SyncCenterPayloadsScreen : CenterScreens("sync_center_payloads_screen")
}

This file was deleted.

Loading

0 comments on commit 774ce74

Please sign in to comment.