Impl base app navigation

This commit is contained in:
Shcherbatykh Oleg
2026-02-19 11:56:10 +03:00
parent 40eaa03a67
commit 592d948cd0
39 changed files with 443 additions and 178 deletions

View File

@@ -0,0 +1,47 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.serialization)
}
android {
namespace = "ru.fincode.tsudesk.core.navigation"
compileSdk = libs.versions.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
)
}
}
val jvm = JavaVersion.toVersion(libs.versions.jvmTarget.get())
compileOptions {
sourceCompatibility = jvm
targetCompatibility = jvm
}
kotlinOptions {
jvmTarget = jvm.toString()
}
buildFeatures {
buildConfig = true
compose = true
}
}
dependencies {
implementation(libs.kotlinx.serialization.json)
// Compose
implementation(platform(libs.compose.bom))
implementation(libs.compose.runtime)
// Navigation Compose
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.navigation.common)
implementation(projects.core.ui)
}

View File

21
core/navigation/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,37 @@
package ru.fincode.tsudesk.core.navigation
import kotlinx.serialization.Serializable
@Serializable
sealed interface AppRoute {
@Serializable
data object Splash : AppRoute
/**
* Root-граф приложения после сплеша.
* Внутри него лежат табы: Schedule/News/Progress.
*/
@Serializable
data object Main : AppRoute
// Tabs
@Serializable
data object Schedule : AppRoute
@Serializable
data object News : AppRoute
@Serializable
data object Progress : AppRoute
@Serializable
data class ScheduleDetails(
val lessonId: Long
) : AppRoute
@Serializable
data class NewsDetails(
val id: String
) : AppRoute
}

View File

@@ -0,0 +1,6 @@
package ru.fincode.tsudesk.core.navigation
import androidx.navigation.NavBackStackEntry
import androidx.navigation.toRoute
inline fun <reified T : AppRoute> NavBackStackEntry.route(): T = toRoute()

View File

@@ -0,0 +1,28 @@
package ru.fincode.tsudesk.core.navigation
import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavOptionsBuilder
fun NavController.navigateToTopLevel(destination: TopLevelDestination) {
val route = destination.toRoute()
navigate(route) {
popUpTo(graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
fun NavController.navigateRoute(
route: AppRoute,
builder: (NavOptionsBuilder.() -> Unit)? = null
) {
if (builder == null) {
navigate(route)
} else {
navigate(route, builder)
}
}

View File

@@ -0,0 +1,22 @@
package ru.fincode.tsudesk.core.navigation
import kotlinx.serialization.Serializable
@Serializable
enum class TopLevelDestination {
SCHEDULE,
NEWS,
PROGRESS
}
fun TopLevelDestination.toRoute(): AppRoute = when (this) {
TopLevelDestination.SCHEDULE -> AppRoute.Schedule
TopLevelDestination.NEWS -> AppRoute.News
TopLevelDestination.PROGRESS -> AppRoute.Progress
}
val TOP_LEVEL_DESTINATIONS: List<TopLevelDestination> = listOf(
TopLevelDestination.SCHEDULE,
TopLevelDestination.NEWS,
TopLevelDestination.PROGRESS
)