Skip to content

Commit

Permalink
refactor(main): use NavigationSuiteScaffold to use the right NavBar.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Nov 16, 2023
1 parent eff7a36 commit ac1ab62
Show file tree
Hide file tree
Showing 38 changed files with 662 additions and 951 deletions.
2 changes: 1 addition & 1 deletion androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ android {
}

dependencies {
implementation(projects.themeM3.main.mobile)
implementation(projects.themeM3.main)
implementation(projects.shared.core)
implementation(libs.settings)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.gdglille.devfest.AlarmScheduler
import org.gdglille.devfest.AndroidContext
import org.gdglille.devfest.Platform
import org.gdglille.devfest.QrCodeGeneratorAndroid
import org.gdglille.devfest.android.theme.MainMobile
import org.gdglille.devfest.android.theme.Main
import org.gdglille.devfest.android.theme.m3.style.R
import org.gdglille.devfest.database.DatabaseWrapper
import org.gdglille.devfest.database.EventDao
Expand Down Expand Up @@ -114,7 +114,7 @@ class MainActivity : ComponentActivity() {
val exportSubject = stringResource(id = R.string.text_export_subject)
val reportSubject = stringResource(id = R.string.text_report_subject)
val reportAppTarget = stringResource(id = R.string.text_report_app_target)
MainMobile(
Main(
eventRepository = eventRepository,
agendaRepository = agendaRepository,
userRepository = userRepository,
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", versi
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-foundation-layout = { group = "androidx.compose.foundation", name = "foundation-layout" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-compose-material3-windowsizeclass = { group = "androidx.compose.material3", name = "material3-window-size-class" }
androidx-compose-material3-adaptive = { group = "androidx.compose.material3", name = "material3-adaptive" }
androidx-compose-material3-adaptive-navigation-suite = { group = "androidx.compose.material3", name = "material3-adaptive-navigation-suite", version = "1.0.0-alpha01" }
androidx-compose-icons = { group = "androidx.compose.material", name = "material-icons-extended" }
androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime-livedata" }
androidx-compose-lifecycle = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose" }
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include(":shared:models")
include(":shared:ui-models")
include(":backend")
include(":benchmark")
include(":theme-m3:main:mobile")
include(":theme-m3:main")
include(":theme-m3:schedules:schedules-ui")
include(":theme-m3:schedules:schedules-screens")
include(":theme-m3:schedules:schedules-feature")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.launch
import org.gdglille.devfest.android.theme.m3.events.ui.EventItem
import org.gdglille.devfest.android.theme.m3.navigation.TabActions
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.Scaffold
import org.gdglille.devfest.android.theme.m3.style.R
import org.gdglille.devfest.android.theme.m3.style.Scaffold
import org.gdglille.devfest.android.theme.m3.style.actions.TabActionsUi
import org.gdglille.devfest.models.ui.EventItemListUi

Expand All @@ -31,18 +29,16 @@ fun EventList(
events: EventItemListUi,
onEventClicked: (String) -> Unit,
modifier: Modifier = Modifier,
pagerState: PagerState = rememberPagerState(pageCount = { 2 }),
isLoading: Boolean = false,
) {
val scope = rememberCoroutineScope()
val tabActions = remember { persistentListOf(TabActions.futureEvents, TabActions.pastEvents) }
val tabActions = remember {
TabActionsUi(actions = persistentListOf(TabActions.futureEvents, TabActions.pastEvents))
}
val pagerState = rememberPagerState(pageCount = { tabActions.actions.count() })
Scaffold(
title = R.string.screen_events,
tabActions = TabActionsUi(actions = tabActions),
tabSelectedIndex = pagerState.currentPage,
onTabClicked = {
scope.launch { pagerState.animateScrollToPage(tabActions.indexOf(it)) }
}
title = stringResource(id = R.string.screen_events),
tabActions = tabActions,
pagerState = pagerState
) { padding ->
HorizontalPager(state = pagerState) { page ->
val items = if (page == 0) events.future else events.past
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.gdglille.devfest.android.theme.m3.events.feature

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
Expand All @@ -25,21 +24,20 @@ fun EventListVM(
when (uiState.value) {
is EventListUiState.Loading -> EventList(
events = (uiState.value as EventListUiState.Loading).events,
onEventClicked = {},
modifier = modifier,
isLoading = true,
pagerState = rememberPagerState(pageCount = { 1 }),
onEventClicked = {}
isLoading = true
)

is EventListUiState.Failure -> Text(text = stringResource(id = R.string.text_error))
is EventListUiState.Success -> EventList(
events = (uiState.value as EventListUiState.Success).events,
modifier = modifier,
isLoading = false,
onEventClicked = {
viewModel.savedEventId(it)
onEventClicked()
}
},
modifier = modifier,
isLoading = false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.gdglille.devfest.android.theme.m3.infos.feature

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Text
Expand All @@ -14,7 +15,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import org.gdglille.devfest.android.theme.m3.navigation.ActionIds
import org.gdglille.devfest.android.theme.m3.navigation.TabActions
import org.gdglille.devfest.android.theme.m3.style.R
import org.gdglille.devfest.android.theme.m3.style.appbars.TopAppBarContentLayout
import org.gdglille.devfest.android.theme.m3.style.Scaffold
import org.gdglille.devfest.repositories.AgendaRepository
import org.gdglille.devfest.repositories.EventRepository

Expand All @@ -25,10 +26,10 @@ fun InfoCompactVM(
eventRepository: EventRepository,
onItineraryClicked: (lat: Double, lng: Double) -> Unit,
onLinkClicked: (url: String?) -> Unit,
onTicketScannerClicked: () -> Unit,
onDisconnectedClicked: () -> Unit,
onReportByPhoneClicked: (String) -> Unit,
onReportByEmailClicked: (String) -> Unit,
onInnerScreenOpened: (String) -> Unit,
modifier: Modifier = Modifier,
viewModel: InfoViewModel = viewModel(
factory = InfoViewModel.Factory.create(agendaRepository, eventRepository)
Expand All @@ -37,7 +38,7 @@ fun InfoCompactVM(
val uiState = viewModel.uiState.collectAsState()
val title = stringResource(id = R.string.screen_info)
when (uiState.value) {
is InfoUiState.Loading -> TopAppBarContentLayout(title = title, modifier = modifier) {
is InfoUiState.Loading -> Scaffold(title = title, modifier = modifier) {
EventVM(
agendaRepository = agendaRepository,
modifier = Modifier.fillMaxSize(),
Expand All @@ -51,12 +52,14 @@ fun InfoCompactVM(
val pagerState =
rememberPagerState(pageCount = { uiModel.tabActionsUi.actions.count() })
LaunchedEffect(pagerState.currentPage) {
onInnerScreenOpened(uiModel.tabActionsUi.actions[pagerState.currentPage].route)
viewModel.innerScreenConfig(uiModel.tabActionsUi.actions[pagerState.currentPage].route)
}
TopAppBarContentLayout(
Scaffold(
title = title,
modifier = modifier,
topActions = uiModel.topActionsUi,
tabActions = uiModel.tabActionsUi,
fabAction = uiModel.fabAction,
onActionClicked = {
when (it.id) {
ActionIds.DISCONNECT -> {
Expand All @@ -65,10 +68,21 @@ fun InfoCompactVM(
}
}
},
pagerState = pagerState,
modifier = modifier
onFabActionClicked = {
when (it.id) {
ActionIds.SCAN_TICKET -> {
onTicketScannerClicked()
}

else -> TODO("Fab not implemented")
}
},
pagerState = pagerState
) {
HorizontalPager(state = pagerState) { page ->
HorizontalPager(
state = pagerState,
modifier = Modifier.padding(it)
) { page ->
when (uiModel.tabActionsUi.actions[page].route) {
TabActions.event.route -> EventVM(
agendaRepository = agendaRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.gdglille.devfest.android.theme.m3.navigation.FabActions
import org.gdglille.devfest.android.theme.m3.navigation.Screen
import org.gdglille.devfest.android.theme.m3.navigation.TabActions
import org.gdglille.devfest.android.theme.m3.navigation.TopActions
import org.gdglille.devfest.android.theme.m3.style.actions.FabAction
import org.gdglille.devfest.android.theme.m3.style.actions.TabAction
import org.gdglille.devfest.android.theme.m3.style.actions.TabActionsUi
import org.gdglille.devfest.android.theme.m3.style.actions.TopActionsUi
Expand All @@ -22,8 +28,11 @@ import org.gdglille.devfest.repositories.EventRepository

sealed class InfoUiState {
data object Loading : InfoUiState()
data class Success(val topActionsUi: TopActionsUi, val tabActionsUi: TabActionsUi) :
InfoUiState()
data class Success(
val topActionsUi: TopActionsUi,
val tabActionsUi: TabActionsUi,
val fabAction: FabAction?
) : InfoUiState()

data class Failure(val throwable: Throwable) : InfoUiState()
}
Expand All @@ -32,8 +41,11 @@ class InfoViewModel(
private val agendaRepository: AgendaRepository,
private val eventRepository: EventRepository
) : ViewModel() {
val uiState = agendaRepository.scaffoldConfig()
.map { config ->
private val _innerRoute = MutableStateFlow<String?>(null)
val uiState = combine(
_innerRoute,
agendaRepository.scaffoldConfig(),
transform = { route, config ->
InfoUiState.Success(
topActionsUi = TopActionsUi(
actions = persistentListOf(TopActions.disconnect),
Expand All @@ -51,18 +63,25 @@ class InfoViewModel(
}
add(TabActions.coc)
}.toImmutableList()
)
),
fabAction = when (route) {
Screen.Event.route -> if (config.hasBilletWebTicket) FabActions.scanTicket else null
else -> null
}
)
}
.catch {
Firebase.crashlytics.recordException(it)
InfoUiState.Failure(it)
}
.stateIn(
scope = viewModelScope,
initialValue = InfoUiState.Loading,
started = SharingStarted.WhileSubscribed()
)
).catch {
Firebase.crashlytics.recordException(it)
InfoUiState.Failure(it)
}.stateIn(
scope = viewModelScope,
initialValue = InfoUiState.Loading,
started = SharingStarted.WhileSubscribed()
)

fun innerScreenConfig(route: String) = viewModelScope.launch {
_innerRoute.update { route }
}

fun disconnect() = viewModelScope.launch {
eventRepository.deleteEventId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ dependencies {

implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.material3.windowsizeclass)
implementation(libs.androidx.compose.material3.adaptive)
implementation(libs.androidx.compose.material3.adaptive.navigation.suite)
implementation(libs.androidx.compose.tooling)
implementation(libs.androidx.compose.lifecycle)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.navigation)
Expand Down
1 change: 0 additions & 1 deletion theme-m3/main/mobile/.gitignore

This file was deleted.

Loading

0 comments on commit ac1ab62

Please sign in to comment.