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

@@ -29,6 +29,9 @@ android {
kotlinOptions {
jvmTarget = jvm.toString()
}
buildFeatures {
buildConfig = true
}
}
dependencies {

View File

@@ -22,6 +22,9 @@ android {
kotlinOptions {
jvmTarget = jvm.toString()
}
buildFeatures {
buildConfig = true
}
}
kapt {
correctErrorTypes = true
@@ -30,9 +33,8 @@ dependencies {
kapt(libs.hilt.compiler)
implementation(libs.hilt.android)
// Kotlin Serialization
implementation(libs.kotlinx.serialization.json)
implementation(project(":core:network"))
implementation(project(":core:common"))
implementation(projects.core.network)
implementation(projects.core.common)
}

View File

@@ -29,6 +29,9 @@ android {
kotlinOptions {
jvmTarget = jvm.toString()
}
buildFeatures {
buildConfig = true
}
}
kapt {
correctErrorTypes = true

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
)

View File

@@ -13,9 +13,6 @@ android {
minSdk = libs.versions.minSdk.get().toInt()
consumerProguardFiles("consumer-rules.pro")
}
buildFeatures {
buildConfig = true
}
buildTypes {
release {
isMinifyEnabled = false
@@ -33,6 +30,9 @@ android {
kotlinOptions {
jvmTarget = jvm.toString()
}
buildFeatures {
buildConfig = true
}
}
kapt {
correctErrorTypes = true
@@ -51,5 +51,5 @@ dependencies {
api(libs.moshiKotlin)
api(libs.retrofitMoshi)
implementation(project(":core:common"))
implementation(projects.core.common)
}

View File

@@ -6,7 +6,7 @@ import okhttp3.Response
import javax.inject.Inject
import javax.inject.Singleton
private const val TAG = "NETWORK_DEBUG"
private const val LOG_DEBUG_TAG = "LOG_DEBUG_TAG"
@Singleton
class DebugInterceptor @Inject constructor() : Interceptor {
@@ -14,8 +14,8 @@ class DebugInterceptor @Inject constructor() : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
Log.d(TAG, "URL: ${request.url}")
Log.d(TAG, "Method: ${request.method}")
Log.d(LOG_DEBUG_TAG, "URL: ${request.url}")
Log.d(LOG_DEBUG_TAG, "Method: ${request.method}")
return chain.proceed(request)
}

View File

@@ -6,15 +6,15 @@ import okhttp3.EventListener
import java.io.IOException
import java.net.InetAddress
private const val LOG_TAG = "NETWORK_DEBUG"
private const val LOG_DEBUG_TAG = "LOG_DEBUG_TAG"
class NetEventLogger : EventListener() {
override fun dnsStart(call: Call, domainName: String) {
Log.d(LOG_TAG, "dnsStart: $domainName")
Log.d(LOG_DEBUG_TAG, "dnsStart: $domainName")
}
override fun dnsEnd(call: Call, domainName: String, inetAddressList: List<InetAddress>) {
Log.d(LOG_TAG, "dnsEnd: $domainName -> $inetAddressList")
Log.d(LOG_DEBUG_TAG, "dnsEnd: $domainName -> $inetAddressList")
}
override fun connectStart(
@@ -22,30 +22,30 @@ class NetEventLogger : EventListener() {
inetSocketAddress: java.net.InetSocketAddress,
proxy: java.net.Proxy
) {
Log.d(LOG_TAG, "connectStart: $inetSocketAddress proxy=$proxy")
Log.d(LOG_DEBUG_TAG, "connectStart: $inetSocketAddress proxy=$proxy")
}
override fun secureConnectStart(call: Call) {
Log.d(LOG_TAG, "tlsStart")
Log.d(LOG_DEBUG_TAG, "tlsStart")
}
override fun secureConnectEnd(call: Call, handshake: okhttp3.Handshake?) {
Log.d(LOG_TAG, "tlsEnd: $handshake")
Log.d(LOG_DEBUG_TAG, "tlsEnd: $handshake")
}
override fun requestHeadersStart(call: Call) {
Log.d(LOG_TAG, "reqHeadersStart")
Log.d(LOG_DEBUG_TAG, "reqHeadersStart")
}
override fun responseHeadersStart(call: Call) {
Log.d(LOG_TAG, "respHeadersStart")
Log.d(LOG_DEBUG_TAG, "respHeadersStart")
}
override fun callFailed(call: Call, ioe: IOException) {
Log.e(LOG_TAG, "callFailed", ioe)
Log.e(LOG_DEBUG_TAG, "callFailed", ioe)
}
override fun callEnd(call: Call) {
Log.d(LOG_TAG, "callEnd")
Log.d(LOG_DEBUG_TAG, "callEnd")
}
}

View File

@@ -30,6 +30,9 @@ android {
kotlinOptions {
jvmTarget = jvm.toString()
}
buildFeatures {
buildConfig = true
}
}
dependencies {
implementation(libs.core.ktx)