mirror of
https://github.com/AdrianKuta/android-challange-adrian-kuta.git
synced 2025-07-02 05:17:58 +02:00
Refactor: Update package structure and implement bottom navigation
This commit refactors the package structure for Gradle convention plugins and introduces bottom navigation to the application. Key changes: - Moved Gradle convention plugin files from `dev.adriankuta.partymania` to `dev.adriankuta.flights`. - Added `TopLevelDestination.kt` to define top-level navigation destinations with icons, titles, and routes. - Implemented `FlightsBottomBar` Composable in `FlightsApp.kt` to display a `NavigationBar` with items for each `TopLevelDestination`. - Updated `FlightsNavGraph.kt`: - Renamed from `FlightsNavGraph.kt` to `navigation/FlightsNavGraph.kt`. - Added `navigateToTopLevelDestination` extension function for `NavController` to handle navigation to top-level destinations with appropriate `NavOptions`. - Updated `HomeNavigation.kt`: - Added `navigateToHome` extension function for `NavController`. - Added `strings.xml` for `ui:home` module with `home_screen_title`. - Ensured Kotlin serialization plugin is correctly applied in `app/build.gradle.kts`.
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
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
|
||||
|
||||
@Composable
|
||||
fun FlightsNavGraph(
|
||||
modifier: Modifier = Modifier,
|
||||
navController: NavHostController = rememberNavController(),
|
||||
) {
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = HomeRoute,
|
||||
modifier = modifier,
|
||||
) {
|
||||
homeScreen()
|
||||
}
|
||||
}
|
||||
|
||||
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 -> navigateToHome(topLevelNavOptions)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user