mirror of
https://github.com/AdrianKuta/android-challange-adrian-kuta.git
synced 2025-07-01 15:37:59 +02:00
This commit introduces a new "Stations" screen that displays airports grouped by country. Key changes: - Added a new Gradle module: `ui:stations`. - Created `StationsScreen.kt` to display a list of airports grouped by country using `LazyColumn`. Airports within each country are displayed as `AirportInfoItem` and countries as `CountryItem`. - Implemented `StationsScreenViewModel.kt` to fetch and manage the state of airports grouped by country. It uses `ObserveAirportsGroupedByCountry` use case. - Defined `ObserveAirportsGroupedByCountry.kt` use case in `domain:stations` module to provide a flow of airports grouped by country. - Implemented `ObserveAirportsGroupedByCountryImpl.kt` in the repository layer, which fetches data using `AirportService`, stores it in `AirportsDatasource`, and maps it to the domain model. - Added Hilt module `ObserveAirportsGroupedByCountryModule.kt` to provide the use case implementation. - Added `stationsScreen()` and `navigateToStations()` to `FlightsNavGraph.kt` and `TopLevelDestination.kt` for navigation. - Updated `settings.gradle.kts` and `app/build.gradle.kts` to include the new `ui:stations` and `domain:stations` modules. - Updated `CacheObservers.kt` to make `mapToDomain` a suspend function. - Added string resources for the stations screen title.
55 lines
2.0 KiB
Kotlin
55 lines
2.0 KiB
Kotlin
package dev.adriankuta.flights.navigation
|
|
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.util.trace
|
|
import androidx.navigation.NavController
|
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
|
import androidx.navigation.NavHostController
|
|
import androidx.navigation.compose.NavHost
|
|
import androidx.navigation.compose.rememberNavController
|
|
import androidx.navigation.navOptions
|
|
import dev.adriankuta.flights.ui.home.navigation.HomeRoute
|
|
import dev.adriankuta.flights.ui.home.navigation.homeScreen
|
|
import dev.adriankuta.flights.ui.home.navigation.navigateToHome
|
|
import dev.adriankuta.flights.ui.home.navigation.navigateToStations
|
|
import dev.adriankuta.flights.ui.home.navigation.stationsScreen
|
|
|
|
@Composable
|
|
fun FlightsNavGraph(
|
|
modifier: Modifier = Modifier,
|
|
navController: NavHostController = rememberNavController(),
|
|
) {
|
|
NavHost(
|
|
navController = navController,
|
|
startDestination = HomeRoute,
|
|
modifier = modifier,
|
|
) {
|
|
homeScreen()
|
|
stationsScreen()
|
|
}
|
|
}
|
|
|
|
fun NavController.navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) {
|
|
trace("Navigation: ${topLevelDestination.name}") {
|
|
val topLevelNavOptions = navOptions {
|
|
// Pop up to the start destination of the graph to
|
|
// avoid building up a large stack of destinations
|
|
// on the back stack as users select items
|
|
popUpTo(graph.findStartDestination().id) {
|
|
saveState = true
|
|
}
|
|
// Avoid multiple copies of the same destination when
|
|
// reselecting the same item
|
|
launchSingleTop = true
|
|
// Restore state when reselecting a previously selected item
|
|
restoreState = true
|
|
}
|
|
|
|
when (topLevelDestination) {
|
|
TopLevelDestination.HOME -> navigateToHome(topLevelNavOptions)
|
|
TopLevelDestination.STATIONS -> navigateToStations(topLevelNavOptions)
|
|
}
|
|
}
|
|
}
|