Applied user elevation color thresholds to the radar page (#253)

Co-authored-by: atsunatsu <atsunatsu@users.noreply.github.com>
This commit is contained in:
atsunatsuandatsunatsu authored and GitHub committed 2026-09-19 11:10:50 +01:00
1 parent 1d07f76ada
commit 5e39c945b2
1 file changed
+105 -99
@@ -99,29 +99,43 @@ fun NavRoot(deeplink: String? = null) {
// Reverse: outgoing slides out to the right, incoming drifts in from the left // Reverse: outgoing slides out to the right, incoming drifts in from the left
val popTransition = slideInHorizontally(tween(300)) { -it / 3 } togetherWith val popTransition = slideInHorizontally(tween(300)) { -it / 3 } togetherWith
slideOutHorizontally(tween(300)) { it } slideOutHorizontally(tween(300)) { it }
NavDisplay( // Elevation color thresholds must be provided at the root level so that BOTH
modifier = Modifier.fillMaxSize(), // the tab content (MainScreen) and the root-level RadarDestination see the
backStack = rootBackStack, // user's custom thresholds. RadarDestination is a sibling entry of MainScreen
onBack = navigateBack, // in this NavDisplay, so a provider inside MainScreen never reaches it.
transitionSpec = { pushTransition }, val context = LocalContext.current
popTransitionSpec = { popTransition }, val container = (context.applicationContext as IContainerProvider).getMainContainer()
predictivePopTransitionSpec = { popTransition }, val otherSettings by container.settingsRepo.otherSettings.collectAsStateWithLifecycle()
entryDecorators = listOf( CompositionLocalProvider(
rememberSaveableStateHolderNavEntryDecorator(), LocalElevationThresholds provides ElevationThresholds(
rememberViewModelStoreNavEntryDecorator() low = otherSettings.lowElevation,
), high = otherSettings.highElevation
entryProvider = entryProvider { )
entry<Screen.Passes> { MainScreen(navigateToRadar = navigateToRadar) } ) {
entry<RadarDestination> { NavDisplay(
Surface( modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize(), backStack = rootBackStack,
color = MaterialTheme.colorScheme.background onBack = navigateBack,
) { transitionSpec = { pushTransition },
RadarDestination(navigateUp = navigateBack) popTransitionSpec = { popTransition },
predictivePopTransitionSpec = { popTransition },
entryDecorators = listOf(
rememberSaveableStateHolderNavEntryDecorator(),
rememberViewModelStoreNavEntryDecorator()
),
entryProvider = entryProvider {
entry<Screen.Passes> { MainScreen(navigateToRadar = navigateToRadar) }
entry<RadarDestination> {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
RadarDestination(navigateUp = navigateBack)
}
} }
} }
} )
) }
} }
@Composable @Composable
@@ -129,7 +143,6 @@ private fun MainScreen(navigateToRadar: () -> Unit = {}) {
val context = LocalContext.current val context = LocalContext.current
val container = (context.applicationContext as IContainerProvider).getMainContainer() val container = (context.applicationContext as IContainerProvider).getMainContainer()
val trackingState by container.radioTrackingService.state.collectAsStateWithLifecycle() val trackingState by container.radioTrackingService.state.collectAsStateWithLifecycle()
val otherSettings by container.settingsRepo.otherSettings.collectAsStateWithLifecycle()
val backStack = rememberNavBackStack(Screen.Passes) val backStack = rememberNavBackStack(Screen.Passes)
val currentKey = backStack.lastOrNull() val currentKey = backStack.lastOrNull()
@@ -139,88 +152,81 @@ private fun MainScreen(navigateToRadar: () -> Unit = {}) {
val navItems = val navItems =
listOf(Screen.Satellites, Screen.Passes, Screen.Status, Screen.Map, Screen.Settings) listOf(Screen.Satellites, Screen.Passes, Screen.Status, Screen.Map, Screen.Settings)
CompositionLocalProvider( NavigationSuiteScaffold(
LocalElevationThresholds provides ElevationThresholds( navigationSuiteItems = {
low = otherSettings.lowElevation, navItems.forEach { screen ->
high = otherSettings.highElevation val isSelected = when (currentKey) {
) is Screen.Satellites -> screen is Screen.Satellites
) { is Screen.Passes -> screen is Screen.Passes
NavigationSuiteScaffold( is Screen.Status -> screen is Screen.Status
navigationSuiteItems = { is Screen.Map -> screen is Screen.Map
navItems.forEach { screen -> is Screen.Settings -> screen is Screen.Settings
val isSelected = when (currentKey) { else -> false
is Screen.Satellites -> screen is Screen.Satellites
is Screen.Passes -> screen is Screen.Passes
is Screen.Status -> screen is Screen.Status
is Screen.Map -> screen is Screen.Map
is Screen.Settings -> screen is Screen.Settings
else -> false
}
item(
icon = {
Icon(
painter = painterResource(screen.iconResId),
contentDescription = stringResource(screen.titleResId)
)
},
label = { Text(stringResource(screen.titleResId)) },
selected = isSelected,
onClick = {
if (isSelected) return@item
while (backStack.size > 1) backStack.removeAt(backStack.size - 1)
if (screen !is Screen.Passes) backStack.add(screen)
}
)
} }
}, item(
navigationSuiteColors = NavigationSuiteDefaults.colors( icon = {
navigationRailContainerColor = MaterialTheme.colorScheme.surfaceContainer Icon(
), painter = painterResource(screen.iconResId),
layoutType = when { contentDescription = stringResource(screen.titleResId)
!hasEnoughHeight() && hasEnoughWidth() -> NavigationSuiteType.NavigationRail )
!hasEnoughWidth() -> NavigationSuiteType.ShortNavigationBarCompact },
else -> NavigationSuiteType.ShortNavigationBarMedium label = { Text(stringResource(screen.titleResId)) },
} selected = isSelected,
) { onClick = {
Column { if (isSelected) return@item
NavDisplay( while (backStack.size > 1) backStack.removeAt(backStack.size - 1)
backStack = backStack, if (screen !is Screen.Passes) backStack.add(screen)
modifier = Modifier.weight(1f),
onBack = navigateBack,
transitionSpec = { fadeTransition },
popTransitionSpec = { fadeTransition },
predictivePopTransitionSpec = { fadeTransition },
entryDecorators = listOf(
rememberSaveableStateHolderNavEntryDecorator(),
rememberViewModelStoreNavEntryDecorator()
),
entryProvider = entryProvider {
entry<Screen.Satellites> {
SatellitesDestination(navigateUp = navigateBack)
}
entry<Screen.Passes> {
PassesDestination { catNum, aosTime ->
container.satelliteRepo.selectPass(catNum, aosTime)
navigateToRadar()
}
}
entry<Screen.Status> { SatStatusDestination() }
entry<Screen.Map> { MapDestination() }
entry<Screen.Settings> { SettingsDestination() }
} }
) )
if (trackingState.isActive) { }
TrackingBanner( },
state = trackingState, navigationSuiteColors = NavigationSuiteDefaults.colors(
onClick = { navigationRailContainerColor = MaterialTheme.colorScheme.surfaceContainer
val pass = trackingState.currentPass ),
if (pass != null) { layoutType = when {
container.satelliteRepo.selectPass(pass.catNum, pass.aosTime) !hasEnoughHeight() && hasEnoughWidth() -> NavigationSuiteType.NavigationRail
navigateToRadar() !hasEnoughWidth() -> NavigationSuiteType.ShortNavigationBarCompact
} else -> NavigationSuiteType.ShortNavigationBarMedium
}
) {
Column {
NavDisplay(
backStack = backStack,
modifier = Modifier.weight(1f),
onBack = navigateBack,
transitionSpec = { fadeTransition },
popTransitionSpec = { fadeTransition },
predictivePopTransitionSpec = { fadeTransition },
entryDecorators = listOf(
rememberSaveableStateHolderNavEntryDecorator(),
rememberViewModelStoreNavEntryDecorator()
),
entryProvider = entryProvider {
entry<Screen.Satellites> {
SatellitesDestination(navigateUp = navigateBack)
}
entry<Screen.Passes> {
PassesDestination { catNum, aosTime ->
container.satelliteRepo.selectPass(catNum, aosTime)
navigateToRadar()
} }
) }
entry<Screen.Status> { SatStatusDestination() }
entry<Screen.Map> { MapDestination() }
entry<Screen.Settings> { SettingsDestination() }
} }
)
if (trackingState.isActive) {
TrackingBanner(
state = trackingState,
onClick = {
val pass = trackingState.currentPass
if (pass != null) {
container.satelliteRepo.selectPass(pass.catNum, pass.aosTime)
navigateToRadar()
}
}
)
} }
} }
} }