Skip to content

Commit

Permalink
Navigation multiplatform
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed May 15, 2024
1 parent dbe7a15 commit 4ee8ec9
Show file tree
Hide file tree
Showing 28 changed files with 211 additions and 85 deletions.
10 changes: 2 additions & 8 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,11 @@ val gmsImplementation by configurations
val hmsImplementation by configurations
val fossImplementation by configurations
dependencies {
implementation(project(":feature:main-impl"))
gmsImplementation(project(":core:platform-services:inject-android"))
hmsImplementation(project(":core:platform-services:inject-android"))
fossImplementation(project(":core:platform-services:inject-android"))
implementation(project(":feature:account"))
implementation(project(":feature:auth"))
implementation(project(":feature:details"))
implementation(project(":feature:feed"))
implementation(project(":feature:gallery"))
implementation(project(":feature:search"))
implementation(project(":feature:settings"))
implementation(project(":feature:debug"))
implementation(project(":feature:main-impl"))
implementation(libs.bundles.kotlin.reflect.android)
testImplementation(libs.bundles.junit.android)
androidTestImplementation(libs.bundles.test.espresso.android)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.michaelbel.movies

import android.app.Activity
import android.app.Activity.ScreenCaptureCallback
import android.os.Build
import android.os.Bundle
import androidx.activity.SystemBarStyle
Expand All @@ -10,6 +10,8 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.fragment.app.FragmentActivity
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.michaelbel.movies.common.ktx.launchAndCollectIn
import org.michaelbel.movies.main.MainContent
import org.michaelbel.movies.main.MainViewModel
import org.michaelbel.movies.ui.ktx.resolveNotificationPreferencesIntent
import org.michaelbel.movies.ui.ktx.setScreenshotBlockEnabled
import org.michaelbel.movies.ui.ktx.supportRegisterScreenCaptureCallback
Expand All @@ -23,7 +25,7 @@ internal class MainActivity: FragmentActivity() {
private val screenCaptureCallback: Any
get() {
return if (Build.VERSION.SDK_INT >= 34) {
Activity.ScreenCaptureCallback {}
ScreenCaptureCallback {}
} else {
Unit
}
Expand All @@ -34,7 +36,7 @@ internal class MainActivity: FragmentActivity() {
super.onCreate(savedInstanceState)
installShortcuts()
setContent {
MainActivityContent { statusBarStyle, navigationBarStyle ->
MainContent { statusBarStyle, navigationBarStyle ->
enableEdgeToEdge(statusBarStyle as SystemBarStyle, navigationBarStyle as SystemBarStyle)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.michaelbel.movies.debug.di.debugKoinModule
import org.michaelbel.movies.details.di.detailsKoinModule
import org.michaelbel.movies.feed.di.feedAndroidKoinModule
import org.michaelbel.movies.gallery.di.galleryKoinModule
import org.michaelbel.movies.main.di.mainKoinModule
import org.michaelbel.movies.platform.inject.flavorServiceKtorModule
import org.michaelbel.movies.search.di.searchKoinModule
import org.michaelbel.movies.settings.di.settingsKoinModule
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ kotlin {
val desktopMain by getting
desktopMain.dependencies {
api(libs.bundles.kotlinx.coroutines.desktop)
api(libs.bundles.compose.viewmodel.common)
api(libs.bundles.jetbrains.androidx.lifecycle.viewmodel.compose.common)
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions core/navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ kotlin {
jvm("desktop")

sourceSets {
androidMain.dependencies {
/*androidMain.dependencies {
api(libs.bundles.navigation.android)
}*/
commonMain.dependencies {
api(libs.bundles.jetbrains.androidx.navigation.compose.common)
api(libs.bundles.jetbrains.androidx.core.bundle.common)
}
val desktopMain by getting
desktopMain.dependencies {
api(libs.bundles.compose.navigation.common)
api(libs.bundles.compose.viewmodel.common)
api(libs.bundles.jetbrains.androidx.lifecycle.viewmodel.compose.common)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.michaelbel.movies.navigation.ktx

import android.os.Bundle
import androidx.core.bundle.Bundle
import androidx.navigation.NavDestination
import androidx.navigation.NavHostController

Expand Down
10 changes: 2 additions & 8 deletions desktopApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ kotlin {
sourceSets {
jvmMain.dependencies {
implementation(project(":core:platform-services:inject-desktop"))
implementation(project(":feature:account"))
implementation(project(":feature:auth"))
implementation(project(":feature:details"))
implementation(project(":feature:feed"))
implementation(project(":feature:gallery"))
implementation(project(":feature:search"))
implementation(project(":feature:settings"))
implementation(project(":feature:main-impl"))
implementation(compose.desktop.currentOs)
implementation(compose.desktop.common)
implementation(compose.runtime)
Expand All @@ -33,7 +27,7 @@ kotlin {

compose.desktop {
application {
mainClass = "org.michaelbel.movies.MoviesDesktopKt"
mainClass = "org.michaelbel.movies.MainWindowKt"

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import org.koin.compose.KoinApplication
import org.koin.compose.koinInject
import org.michaelbel.movies.common.ThemeData
import org.michaelbel.movies.di.appKoinModule
import org.michaelbel.movies.main.MainContent
import org.michaelbel.movies.main.MainViewModel
import org.michaelbel.movies.ui.theme.MoviesTheme

fun main() = application {
Expand Down Expand Up @@ -49,7 +51,7 @@ private fun App() {
theme = themeData.appTheme,
enableEdgeToEdge = { _,_ -> }
) {
MainWindowContent()
MainContent()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.michaelbel.movies.account.di.accountKoinModule
import org.michaelbel.movies.auth.di.authKoinModule
import org.michaelbel.movies.details.di.detailsKoinModule
import org.michaelbel.movies.gallery.di.galleryKoinModule
import org.michaelbel.movies.main.di.mainKoinModule
import org.michaelbel.movies.platform.inject.flavorServiceKtorModule
import org.michaelbel.movies.search.di.searchKoinModule
import org.michaelbel.movies.settings.di.settingsKoinModule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package org.michaelbel.movies.auth

import androidx.compose.ui.window.DialogProperties
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.dialog
import org.michaelbel.movies.auth.ktx.authGraphInternal
import org.michaelbel.movies.auth.ui.AuthRoute

fun NavController.navigateToAuth() {
navigate(AuthDestination.route)
}

fun NavGraphBuilder.authGraph(
navigateBack: () -> Unit
) {
dialog(
route = AuthDestination.route,
dialogProperties = DialogProperties(
usePlatformDefaultWidth = false
)
) {
authGraphInternal {
AuthRoute(
onBackClick = navigateBack
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.michaelbel.movies.auth

internal actual const val USE_PLATFORM_DEFAULT_WIDTH: Boolean = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.michaelbel.movies.auth

internal expect val USE_PLATFORM_DEFAULT_WIDTH: Boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.michaelbel.movies.auth.ktx

import androidx.compose.runtime.Composable
import androidx.compose.ui.window.DialogProperties
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.dialog
import org.michaelbel.movies.auth.AuthDestination
import org.michaelbel.movies.auth.USE_PLATFORM_DEFAULT_WIDTH

fun NavController.navigateToAuth() {
navigate(AuthDestination.route)
}

internal fun NavGraphBuilder.authGraphInternal(
content: @Composable (NavBackStackEntry) -> Unit
) {
dialog(
route = AuthDestination.route,
dialogProperties = DialogProperties(
usePlatformDefaultWidth = USE_PLATFORM_DEFAULT_WIDTH
),
content = content
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package org.michaelbel.movies.auth

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.dialog
import org.michaelbel.movies.auth.ui.AuthRoute

fun NavController.navigateToAuth() {
navigate(AuthDestination.route)
}

fun NavGraphBuilder.authGraph(
navigateBack: () -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.michaelbel.movies.auth

internal actual const val USE_PLATFORM_DEFAULT_WIDTH: Boolean = true
1 change: 1 addition & 0 deletions feature/main-impl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
90 changes: 90 additions & 0 deletions feature/main-impl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.compose)
alias(libs.plugins.android.library)
}

kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = rootProject.extra.get("jvmTarget") as String
}
}
}
jvm("desktop")

sourceSets {
commonMain.dependencies {
api(project(":feature:account"))
api(project(":feature:auth"))
api(project(":feature:details"))
api(project(":feature:feed"))
api(project(":feature:gallery"))
api(project(":feature:search"))
api(project(":feature:settings"))
}
androidMain.dependencies {
api(project(":feature:debug"))
}
val desktopMain by getting
desktopMain.dependencies {
implementation(project(":core:platform-services:inject-desktop"))
implementation(libs.koin.compose)
}
}
}

android {
namespace = "org.michaelbel.movies.main_impl"
flavorDimensions += "version"

defaultConfig {
minSdk = libs.versions.min.sdk.get().toInt()
compileSdk = libs.versions.compile.sdk.get().toInt()
}

productFlavors {
create("gms") {
dimension = "version"
isDefault = true
}
create("hms") {
dimension = "version"
}
create("foss") {
dimension = "version"
}
}

buildFeatures {
buildConfig = true
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get()
}

compileOptions {
sourceCompatibility = JavaVersion.toVersion(rootProject.extra.get("jvmTarget") as String)
targetCompatibility = JavaVersion.toVersion(rootProject.extra.get("jvmTarget") as String)
}

lint {
quiet = true
abortOnError = false
ignoreWarnings = true
checkDependencies = true
lintConfig = file("${project.rootDir}/config/codestyle/lint.xml")
}

val gmsImplementation by configurations
val hmsImplementation by configurations
val fossImplementation by configurations
dependencies {
gmsImplementation(project(":core:platform-services:inject-android"))
hmsImplementation(project(":core:platform-services:inject-android"))
fossImplementation(project(":core:platform-services:inject-android"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.michaelbel.movies.main

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.koin.androidx.compose.koinViewModel

@Composable
fun MainContent(
viewModel: MainViewModel = koinViewModel(),
enableEdgeToEdge: (Any, Any) -> Unit
) {
val themeData by viewModel.themeData.collectAsStateWithLifecycle()

MainNavigationContent(
themeData = themeData,
enableEdgeToEdge = enableEdgeToEdge
)
}
Loading

0 comments on commit 4ee8ec9

Please sign in to comment.