Skip to content

Commit

Permalink
refactor(m3): expose screen configuration in only one model ui.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Oct 14, 2023
1 parent 84a8fc7 commit a6890e7
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@ fun InfoPages(
onLinkClicked: (url: String?) -> Unit,
onReportByPhoneClicked: (String) -> Unit,
onReportByEmailClicked: (String) -> Unit,
onEventScreenOpened: () -> Unit,
onMenusScreenOpened: () -> Unit,
onQAndAScreenOpened: () -> Unit,
onCoCScreenOpened: () -> Unit,
onInnerScreenOpened: (String) -> Unit,
modifier: Modifier = Modifier
) {
LaunchedEffect(pagerState.currentPage) {
when (tabs.actions[pagerState.currentPage].route) {
TabActions.event.route -> onEventScreenOpened()
TabActions.menus.route -> onMenusScreenOpened()
TabActions.qanda.route -> onQAndAScreenOpened()
TabActions.coc.route -> onCoCScreenOpened()
}
onInnerScreenOpened(tabs.actions[pagerState.currentPage].route)
}
HorizontalPager(state = pagerState) { page ->
when (tabs.actions[page].route) {
Expand Down
3 changes: 3 additions & 0 deletions theme-m3/main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ dependencies {
implementation(libs.androidx.compose.navigation)

implementation(libs.kotlinx.collections)

implementation(platform(libs.google.firebase))
implementation("com.google.firebase:firebase-crashlytics-ktx")
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,7 @@ fun Home(
}
}
val uiState = viewModel.uiState.collectAsState()
val uiTopState = viewModel.uiTopState.collectAsState()
val uiTabState = viewModel.uiTabState.collectAsState()
val uiFabState = viewModel.uiFabState.collectAsState()
val uiBottomState = viewModel.uiBottomState.collectAsState()
val exportPath = viewModel.exportPath.collectAsState(null)
val actions = uiTopState.value
val tabActions = uiTabState.value
val agendaPagerState = rememberPagerState(pageCount = {
if (tabActions.actions.isEmpty()) 1 else tabActions.actions.count()
})
val networkingPagerState = rememberPagerState(pageCount = {
if (tabActions.actions.isEmpty()) 1 else tabActions.actions.count()
})
val infoPagerState = rememberPagerState(pageCount = {
if (tabActions.actions.isEmpty()) 1 else tabActions.actions.count()
})
val currentRoute = navController
.currentBackStackEntryFlow
.collectAsState(initial = navController.currentBackStackEntry)
Expand All @@ -110,29 +95,36 @@ fun Home(
when (uiState.value) {
is HomeUiState.Success -> {
val screenUi = (uiState.value as HomeUiState.Success).screenUi
val pageCount = if (screenUi.tabActionsUi.actions.isEmpty()) 1
else screenUi.tabActionsUi.actions.count()
val agendaPagerState = rememberPagerState(pageCount = { pageCount })
val networkingPagerState = rememberPagerState(pageCount = { pageCount })
val infoPagerState = rememberPagerState(pageCount = { pageCount })
ScaffoldNavigation(
title = screenUi.title,
startDestination = Screen.Agenda.route,
modifier = modifier,
navController = navController,
topActions = actions,
tabActions = tabActions,
bottomActions = uiBottomState.value,
fabAction = uiFabState.value,
topActions = screenUi.topActionsUi,
tabActions = screenUi.tabActionsUi,
bottomActions = screenUi.bottomActionsUi,
fabAction = screenUi.fabAction,
pagerState = when (currentRoute.value?.destination?.route) {
Screen.Info.route -> infoPagerState
Screen.Networking.route -> networkingPagerState
Screen.Event.route, Screen.Menus.route, Screen.QAndA.route, Screen.CoC.route -> infoPagerState
Screen.MyProfile.route, Screen.Contacts.route -> networkingPagerState
else -> agendaPagerState
},
onTopActionClicked = {
when (it.id) {
ActionIds.FILTERS -> {
onFilterClicked()
}

ActionIds.DISCONNECT -> {
viewModel.disconnect()
onDisconnectedClicked()
}

ActionIds.EXPORT -> {
viewModel.exportNetworking()
}
Expand All @@ -158,7 +150,7 @@ fun Home(
builder = {
composable(Screen.Agenda.route) {
AgendaVM(
tabs = tabActions,
tabs = screenUi.tabActionsUi,
agendaRepository = agendaRepository,
alarmScheduler = alarmScheduler,
pagerState = agendaPagerState,
Expand All @@ -171,17 +163,13 @@ fun Home(
onSpeakerClicked = onSpeakerClicked
)
}
composable(Screen.Networking.route) {
composable(Screen.MyProfile.route) {
NetworkingPages(
tabs = screenUi.tabActionsUi,
userRepository = userRepository,
pagerState = networkingPagerState,
onCreateProfileClicked = onCreateProfileClicked,
onProfileScreenOpened = {
viewModel.updateFabUi(Screen.MyProfile.route)
},
onContactListScreenOpened = {
viewModel.updateFabUi(Screen.Contacts.route)
}
onInnerScreenOpened = viewModel::innerScreenConfig
)
}
composable(Screen.Partners.route) {
Expand All @@ -190,27 +178,16 @@ fun Home(
onPartnerClick = onPartnerClicked
)
}
composable(Screen.Info.route) {
composable(Screen.Event.route) {
InfoPages(
tabs = tabActions,
tabs = screenUi.tabActionsUi,
agendaRepository = agendaRepository,
pagerState = infoPagerState,
onItineraryClicked = onItineraryClicked,
onLinkClicked = onLinkClicked,
onReportByPhoneClicked = onReportByPhoneClicked,
onReportByEmailClicked = onReportByEmailClicked,
onEventScreenOpened = {
viewModel.updateFabUi(Screen.Event.route)
},
onMenusScreenOpened = {
viewModel.updateFabUi(Screen.Menus.route)
},
onQAndAScreenOpened = {
viewModel.updateFabUi(Screen.QAndA.route)
},
onCoCScreenOpened = {
viewModel.updateFabUi(Screen.CoC.route)
}
onInnerScreenOpened = viewModel::innerScreenConfig
)
}
}
Expand Down
Loading

0 comments on commit a6890e7

Please sign in to comment.