From 9b36f14e5146287f5946bfc18bf5d3ec96a83c3c Mon Sep 17 00:00:00 2001 From: AdamKobus Date: Tue, 3 Dec 2024 20:11:49 +0100 Subject: [PATCH] Updated depenencies;kotlin 2.0.0 --- .editorconfig | 6 + .github/workflows/publish-release.yml | 8 +- .github/workflows/publish-snapshot.yml | 7 +- .github/workflows/pull-request.yml | 26 +- .gitignore | 2 + .idea/deploymentTargetSelector.xml | 16 + .idea/inspectionProfiles/Project_Default.xml | 20 -- .idea/kotlinc.xml | 2 +- .idea/migrations.xml | 10 + .idea/runConfigurations.xml | 17 ++ CHANGELOG.md | 12 + README.md | 4 +- build.gradle | 64 +--- buildSrc/.gitignore | 1 - buildSrc/build.gradle.kts | 7 - buildSrc/build/libs/buildSrc.jar | Bin 0 -> 261 bytes buildSrc/build/tmp/jar/MANIFEST.MF | 2 + composenav/build.gradle | 38 ++- .../compose/navigation/ComposeNavHost.kt | 18 +- .../compose/navigation/ComposeNavigation.kt | 14 +- .../compose/navigation/NavActionVerifier.kt | 6 +- .../compose/navigation/NavIntentResolver.kt | 5 +- .../compose/navigation/NavigationId.kt | 2 +- .../navigation/TabBarIntentResolver.kt | 70 +++-- .../compose/navigation/VerifyResult.kt | 2 +- .../compose/navigation/action/NavAction.kt | 3 +- .../navigation/action/NavActionWrapper.kt | 3 +- .../compose/navigation/action/NavOptions.kt | 21 +- .../navigation/action/NavigateAction.kt | 11 +- .../navigation/action/NavigationResult.kt | 5 - .../compose/navigation/action/PopAction.kt | 3 +- .../navigation/action/PopUpToAction.kt | 3 +- .../destination/DialogDestination.kt | 5 +- .../navigation/destination/GlobalGraph.kt | 1 - .../navigation/destination/INavDestination.kt | 1 - .../navigation/destination/NavDestination.kt | 17 +- .../navigation/destination/NavGraph.kt | 15 +- .../navigation/destination/NavRoute.kt | 45 +-- .../navigation/destination/NavRoutePart.kt | 4 - .../navigation/destination/NavStackEntry.kt | 12 +- .../navigation/destination/NavState.kt | 4 +- .../navigation/destination/PopDestination.kt | 3 +- .../destination/ScreenDestination.kt | 5 +- .../destination/UnknownDestination.kt | 2 +- .../navigation/destination/UnknownGraph.kt | 1 - .../navigation/ext/NavGraphBuilderExt.kt | 16 +- .../compose/navigation/intent/NavIntent.kt | 21 +- .../navigation/intent/NavIntentHistory.kt | 4 +- .../intent/NavIntentResolvingManager.kt | 12 +- .../navigation/intent/ResolveResult.kt | 1 - .../compose/navigation/logger/NavLogger.kt | 25 +- .../navigation/logger/NavLoggerImpl.kt | 25 +- .../navigation/model/ActionConsumer.kt | 1 + .../model/KnownDestinationsSource.kt | 15 +- .../compose/navigation/model/NavDelegate.kt | 15 +- .../compose/navigation/model/NavGatekeeper.kt | 15 +- .../model/NavGraphNamesExtractor.kt | 12 +- .../navigation/model/NavStateManager.kt | 41 +-- .../model/NavigationConsumerImpl.kt | 1 - .../navigation/model/NavigationProcessor.kt | 90 +++--- .../model/PendingActionDispatcher.kt | 56 ++-- .../model/ProcessorInitializedState.kt | 3 +- .../compose/navigation/model/ProcessorTask.kt | 1 - .../navigation/model/ReservedNamesHandler.kt | 9 +- .../compose/navigation/ui/NavComposable.kt | 15 +- .../navigation/ui/NavComposableState.kt | 2 +- .../compose/navigation/ui/NavComposableVM.kt | 8 +- .../navigation/ui/PendingActionState.kt | 1 - .../navigation/ComposeNavigationTest.kt | 1 - .../navigation/action/NavigateActionTest.kt | 1 - .../navigation/destination/GlobalGraphTest.kt | 1 - .../destination/NavRoutePartTest.kt | 1 - .../navigation/destination/NavRouteTest.kt | 52 ++-- .../destination/NavStackEntryTest.kt | 105 ++++--- .../destination/ScreenDestinationTest.kt | 1 - .../navigation/intent/NavIntentHistoryTest.kt | 19 +- .../intent/NavIntentResolvingManagerTest.kt | 146 ++++----- .../navigation/intent/NavIntentTest.kt | 1 - .../navigation/model/NavGatekeeperTest.kt | 1 - .../model/ReservedNamesHandlerTest.kt | 1 - demo-common-ui/build.gradle | 42 +-- .../navigation/demo/ui/DemoAppBackground.kt | 17 +- .../compose/navigation/demo/ui/Paddings.kt | 13 +- .../navigation/demo/ui/PreviewComponent.kt | 6 +- .../demo/ui/appbar/AnimatedAppBar.kt | 70 +++-- .../demo/ui/appbar/AnimatedAppBarDefaults.kt | 2 +- .../demo/ui/appbar/AnimatedAppBarState.kt | 23 +- .../demo/ui/appbar/AnimatedAppBarVM.kt | 2 +- .../navigation/demo/ui/di/NavModule.kt | 1 - .../demo/ui/di/NavModuleInternalBinds.kt | 1 - .../compose/navigation/demo/ui/di/UiModule.kt | 1 - .../demo/ui/ext/LifecycleEventExt.kt | 5 +- .../demo/ui/loading/LoadingScreen.kt | 2 +- .../compose/navigation/demo/ui/nav/Actions.kt | 30 +- .../demo/ui/nav/ApplyNavGraphsTask.kt | 2 +- .../demo/ui/nav/CatsBrowserGraph.kt | 7 +- .../demo/ui/nav/DogsBrowserGraph.kt | 14 +- .../demo/ui/overlay/AppBarOverlayProvider.kt | 7 +- .../navigation/demo/ui/overlay/AppOverlays.kt | 2 +- .../navigation/demo/ui/theme/DemoTheme.kt | 25 +- .../compose/navigation/demo/ui/theme/Shape.kt | 13 +- .../compose/navigation/demo/ui/theme/Type.kt | 27 +- demo-core/build.gradle | 29 +- .../navigation/democore/data/CatInfo.kt | 2 +- .../navigation/democore/data/DogInfo.kt | 2 +- .../navigation/democore/model/CatsSource.kt | 11 +- .../navigation/democore/model/DogsSource.kt | 3 +- .../navigation/democore/util/AsyncData.kt | 2 + demo-devmenu/build.gradle | 22 +- .../devmenu/di/DevMenuModuleInternalBinds.kt | 1 - .../devmenu/nav/DevMenuNavIntentResolver.kt | 18 +- .../demo/devmenu/nav/DevMenuRootGraph.kt | 1 - .../devmenu/nav/tabhost/DevMenuInfoGraph.kt | 1 - .../nav/tabhost/DevMenuSettingsGraph.kt | 1 - .../tabhost/DevMenuTabHostIntentResolver.kt | 7 +- .../demo/devmenu/theme/DevMenuTheme.kt | 71 +++-- .../demo/devmenu/ui/DevMenuPaddings.kt | 13 +- .../demo/devmenu/ui/info/home/InfoHome.kt | 2 +- .../demo/devmenu/ui/root/DevMenuRoot.kt | 11 +- .../ui/root/DevMenuRootInteractions.kt | 2 +- .../demo/devmenu/ui/root/DevMenuRootVM.kt | 14 +- .../devmenu/ui/settings/home/SettingsHome.kt | 15 +- .../settings/home/SettingsHomeInteractions.kt | 9 +- .../ui/settings/home/SettingsHomeVM.kt | 14 +- .../demo/devmenu/ui/tabhost/DevMenuTabData.kt | 4 +- .../demo/devmenu/ui/tabhost/DevMenuTabHost.kt | 21 +- .../ui/tabhost/DevMenuTabHostInteractions.kt | 9 +- .../devmenu/ui/tabhost/DevMenuTabHostState.kt | 15 +- .../devmenu/ui/tabhost/DevMenuTabHostVM.kt | 36 +-- demo-ui-cats-browser/build.gradle | 19 +- .../demo/ui/catdetails/CatDetailsScreen.kt | 18 +- .../ui/catdetails/CatDetailsScreenState.kt | 2 +- .../demo/ui/catdetails/CatDetailsScreenVM.kt | 19 +- .../demo/ui/catslist/CatsListInteractions.kt | 2 +- .../demo/ui/catslist/CatsListScreen.kt | 21 +- .../demo/ui/catslist/CatsListScreenState.kt | 2 +- .../demo/ui/catslist/CatsListScreenVM.kt | 41 +-- demo-ui-dogs-browser/build.gradle | 19 +- .../demo/ui/demodialog/DemoDialog.kt | 13 +- .../ui/demodialog/DemoDialogInteractions.kt | 2 +- .../demo/ui/demodialog/DemoDialogVM.kt | 18 +- .../demo/ui/dogdetails/DogDetailsScreen.kt | 22 +- .../DogDetailsScreenInteractions.kt | 2 +- .../ui/dogdetails/DogDetailsScreenState.kt | 2 +- .../demo/ui/dogdetails/DogDetailsScreenVM.kt | 46 +-- .../demo/ui/doggallery/DogGalleryScreen.kt | 9 +- .../DogGalleryScreenInteractions.kt | 2 +- .../demo/ui/doggallery/DogGalleryScreenVM.kt | 23 +- .../demo/ui/dogslist/DogsListInteractions.kt | 2 +- .../demo/ui/dogslist/DogsListScreen.kt | 24 +- .../demo/ui/dogslist/DogsListScreenState.kt | 2 +- .../demo/ui/dogslist/DogsListScreenVM.kt | 43 +-- demo-ui-on-boarding/build.gradle | 19 +- .../demo/ui/welcome/WelcomeScreen.kt | 18 +- .../ui/welcome/WelcomeScreenInteractions.kt | 2 +- .../demo/ui/welcome/WelcomeScreenVM.kt | 20 +- demo-ui-settings/build.gradle | 19 +- .../demo/settings/ui/home/HomeScreenVM.kt | 12 +- .../settings/ui/home/SettingsHomeScreen.kt | 11 +- demo/build.gradle | 24 +- demo/src/main/AndroidManifest.xml | 2 +- .../compose/navigation/demo/app/DemoApp.kt | 1 - .../navigation/demo/di/AppModuleBinds.kt | 1 - .../navigation/demo/di/NavigationModule.kt | 1 - .../demo/nav/AppNavActionVerifier.kt | 5 +- .../demo/nav/RestartAppNavIntentResolver.kt | 12 +- .../nav/tabhost/DemoTabBarIntentResolver.kt | 4 +- .../demo/ui/DevMenuLauncherOverlayProvider.kt | 15 +- .../navigation/demo/ui/app/DemoAppRoot.kt | 6 +- .../navigation/demo/ui/app/DemoAppRootVM.kt | 2 +- .../demo/ui/splash/SplashScreenVM.kt | 3 +- .../navigation/demo/ui/tabhost/DemoTabData.kt | 3 +- .../demo/ui/tabhost/DemoTabsInteractions.kt | 2 +- .../demo/ui/tabhost/DemoTabsNavigation.kt | 23 +- .../DemoTabsNavigationOverlayProvider.kt | 8 +- .../ui/tabhost/DemoTabsNavigationState.kt | 6 +- .../demo/ui/tabhost/DemoTabsNavigationVM.kt | 58 ++-- demo/src/main/res/values/themes.xml | 29 +- detekt/config/custom.yml | 2 +- detekt/config/default.yml | 205 +++++++++---- docs/tutorial/02_first_graph.md | 4 +- docs/tutorial/03_navigation_basics.md | 10 +- .../tutorial/05_using_navigation_arguments.md | 2 +- docs/tutorial/06_back_navigation.md | 8 +- docs/tutorial/07_displaying_dialog.md | 2 +- gradle/android-setup.gradle | 9 +- gradle/dependency-updates.gradle | 13 - gradle/libs.versions.toml | 53 ++++ gradle/version.gradle | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin 59203 -> 43504 bytes gradle/wrapper/gradle-wrapper.properties | 5 +- gradlew | 285 +++++++++++------- gradlew.bat | 37 ++- poc-multiple-nav-hosts/build.gradle | 39 ++- .../poc/multinavhost/PocApplication.kt | 5 +- .../poc/multinavhost/di/PocModule.kt | 1 - .../poc/multinavhost/green/nav/GreenGraph.kt | 1 - .../multinavhost/green/nav/GreenNavHost.kt | 7 +- .../green/ui/dialog/GreenDialog.kt | 15 +- .../ui/dialog/GreenDialogInteractions.kt | 2 +- .../green/ui/dialog/GreenDialogVM.kt | 14 +- .../green/ui/home/GreenHomeScreen.kt | 6 +- .../ui/home/GreenHomeScreenInteractions.kt | 2 +- .../green/ui/home/GreenHomeScreenVM.kt | 14 +- .../green/ui/next/GreenNextScreen.kt | 9 +- .../ui/next/GreenNextScreenInteractions.kt | 2 +- .../green/ui/next/GreenNextScreenVM.kt | 14 +- .../poc/multinavhost/main/nav/MainNavHost.kt | 6 +- .../multinavhost/main/ui/demo/DemoScreen.kt | 40 ++- .../multinavhost/main/ui/home/HomeScreen.kt | 14 +- .../main/ui/home/HomeScreenInteractions.kt | 2 +- .../multinavhost/main/ui/home/HomeScreenVM.kt | 13 +- .../ui/common/ScreenBackground.kt | 11 +- .../poc/multinavhost/ui/theme/Shape.kt | 13 +- .../poc/multinavhost/ui/theme/Theme.kt | 38 +-- .../poc/multinavhost/ui/theme/Type.kt | 28 +- .../multinavhost/yellow/nav/YellowGraph.kt | 1 - .../multinavhost/yellow/nav/YellowNavHost.kt | 7 +- .../yellow/ui/dialog/YellowDialog.kt | 15 +- .../ui/dialog/YellowDialogInteractions.kt | 2 +- .../yellow/ui/dialog/YellowDialogVM.kt | 14 +- .../yellow/ui/home/YellowHomeScreen.kt | 10 +- .../ui/home/YellowHomeScreenInteractions.kt | 2 +- .../yellow/ui/home/YellowHomeScreenVM.kt | 14 +- .../yellow/ui/next/YellowNextScreen.kt | 4 +- .../ui/next/YellowNextScreenInteractions.kt | 2 +- .../yellow/ui/next/YellowNextScreenVM.kt | 14 +- settings.gradle | 15 + tutorial/build.gradle | 39 ++- .../navigation/tutorial/MainActivity.kt | 6 +- .../tutorial/nav/NavigationModule.kt | 1 - .../nav/OpenRandomItemIntentResolver.kt | 5 +- .../navigation/tutorial/nav/TutorialGraph.kt | 14 +- .../tutorial/nav/TutorialIntents.kt | 4 +- .../tutorial/nav/TutorialNavActionVerifier.kt | 5 +- .../tutorial/ui/detail/DetailScreen.kt | 50 +-- .../tutorial/ui/image/ImageScreen.kt | 20 +- .../navigation/tutorial/ui/list/ListScreen.kt | 42 +-- .../navigation/tutorial/ui/theme/Shape.kt | 13 +- .../navigation/tutorial/ui/theme/Theme.kt | 55 ++-- .../navigation/tutorial/ui/theme/Type.kt | 28 +- .../tutorial/ui/welcome/WelcomeScreen.kt | 56 ++-- tutorial/src/main/res/values/themes.xml | 3 +- 243 files changed, 2149 insertions(+), 1774 deletions(-) create mode 100644 .editorconfig create mode 100644 .idea/deploymentTargetSelector.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/migrations.xml create mode 100644 .idea/runConfigurations.xml delete mode 100644 buildSrc/.gitignore delete mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/build/libs/buildSrc.jar create mode 100644 buildSrc/build/tmp/jar/MANIFEST.MF delete mode 100644 gradle/dependency-updates.gradle create mode 100644 gradle/libs.versions.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f795f5a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +[*.{kt,kts}] +ktlint_function_naming_ignore_when_annotated_with = Composable +ktlint_standard_multiline-expression-wrapping = disabled +ktlint_standard_string-template-indent = disabled +ktlint_standard_annotation = disabled = disabled +ktlint_code_style = intellij_idea \ No newline at end of file diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index be9f7cc..cc334c6 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -11,20 +11,24 @@ jobs: publish: name: Publish release build runs-on: ubuntu-latest + timeout-minutes: 15 steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Configure JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' cache: 'gradle' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Decrypt secrets run: scripts/decrypt-secrets.sh "${{ secrets.SECRETS_PASSPHRASE }}" diff --git a/.github/workflows/publish-snapshot.yml b/.github/workflows/publish-snapshot.yml index f9047a4..7c8b197 100644 --- a/.github/workflows/publish-snapshot.yml +++ b/.github/workflows/publish-snapshot.yml @@ -11,17 +11,20 @@ jobs: timeout-minutes: 10 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Configure JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' cache: 'gradle' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Decrypt secrets run: scripts/decrypt-secrets.sh "${{ secrets.SECRETS_PASSPHRASE }}" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index cc2d2f0..666538d 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -14,32 +14,26 @@ jobs: timeout-minutes: 10 steps: - - uses: actions/checkout@v2 - - - uses: gradle/wrapper-validation-action@v1 + - uses: actions/checkout@v4 - name: Configure JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' cache: 'gradle' - - name: Set Up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - bundler-cache: true - - - name: Danger Checks - run: | - ./gradlew dependencyUpdates -DoutputDir=build/danger - bundle exec danger - env: - DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 - name: Run tests run: ./gradlew testDebugUnitTest + - name: Publish Test Report + uses: mikepenz/action-junit-report@v5 + if: success() || failure() + with: + report_paths: '**/build/test-results/**/TEST-*.xml' + - name: Run static analysis run: ./gradlew ktlintCheck detekt diff --git a/.gitignore b/.gitignore index 454a446..03480f4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,8 @@ signing.gpg .idea/compiler.xml .idea/jarRepositories.xml .idea/deploymentTargetDropDown.xml +.idea/deploymentTargetSelector.xml +.idea/inspectionProfiles/Project_Default.xml gradle.xml *.iml diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..11b79c2 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 2842237..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index fdf8d99..6d0ee1c 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e20f6c9..6f9e3f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,18 @@ ### Changes +# 1.0.0 + +### Changes + +- Updated Kotlin to `2.0.0` +- Switched to version catalogs for dependency management. +- Updated to Jetpack Compose BoM `2024.11.00` +- Accompanist navigation got replaced with AndroidX library. + +Migration: +- Replace `rememberAnimatedNavController()` with `rememberNavController()` + # 0.3.4 ### Changes diff --git a/README.md b/README.md index f06bca1..2903d87 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ repositories { } dependencies { - implementation "com.adamkobus:compose-navigation:0.3.0" + implementation "com.adamkobus:compose-navigation:1.0.0" } ``` @@ -34,7 +34,7 @@ repositories { } dependencies { - implementation "com.adamkobus:compose-navigation:0.3.0-SNAPSHOT" + implementation "com.adamkobus:compose-navigation:1.0.0-SNAPSHOT" } ``` diff --git a/build.gradle b/build.gradle index b368e4c..8ec33f6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,60 +1,18 @@ -import com.adamkobus.compose.navigation.Lib - -apply plugin: "io.github.gradle-nexus.publish-plugin" -apply plugin: "com.github.ben-manes.versions" - -buildscript { - ext { - // https://github.com/JLLeitschuh/ktlint-gradle/releases - ktlintPluginVersion = "11.5.0" - - // https://github.com/detekt/detekt/releases - detektPluginVersion = "1.21.0" - - // https://github.com/ben-manes/gradle-versions-plugin/releases - versionsPluginVersion = "0.47.0" - - // https://github.com/gradle-nexus/publish-plugin/releases - publishPluginVersion = "1.3.0" - - // https://developer.android.com/studio/releases/gradle-plugin - androidBuildtoolsPluginVersion = '8.0.2' - } - - repositories { - google() - mavenCentral() - gradlePluginPortal() - } - - dependencies { - classpath "com.android.tools.build:gradle:$androidBuildtoolsPluginVersion" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${Lib.KOTLIN_VERSION}" - classpath "com.google.dagger:hilt-android-gradle-plugin:${Lib.HILT_VERSION}" - classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlintPluginVersion" - classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detektPluginVersion" - classpath "com.github.ben-manes:gradle-versions-plugin:$versionsPluginVersion" - classpath "io.github.gradle-nexus:publish-plugin:$publishPluginVersion" - classpath "org.jetbrains.dokka:dokka-gradle-plugin:${Lib.DOKKA_VERSION}" - } - rootProject.ext -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -allprojects { - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - kotlinOptions { - freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn" - } - } +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.kotlin.compose) apply false + alias(libs.plugins.hilt) apply false + alias(libs.plugins.dokka) apply false + alias(libs.plugins.detekt) apply false + alias(libs.plugins.ktlint) apply false + alias(libs.plugins.kotlin.ksp) apply false + alias(libs.plugins.nexus.publish) } apply from: "gradle/utils.gradle" apply from: "gradle/version.gradle" -apply from: "gradle/dependency-updates.gradle" apply from: "gradle/android-setup.gradle" apply from: "gradle/publishing-root.gradle" apply from: "gradle/dokka-config.gradle" diff --git a/buildSrc/.gitignore b/buildSrc/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/buildSrc/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index f155244..0000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,7 +0,0 @@ -repositories { - mavenCentral() -} - -plugins { - `kotlin-dsl` -} \ No newline at end of file diff --git a/buildSrc/build/libs/buildSrc.jar b/buildSrc/build/libs/buildSrc.jar new file mode 100644 index 0000000000000000000000000000000000000000..26e681c8213076daa6bafaadb39fac83b0a29067 GIT binary patch literal 261 zcmWIWW@Zs#VBp|jIJT-ek^u;qKm-tQ0~t1dKY=Ub+yi&Ilno`;EM5sr;na80S#kh5@E(|FVI9F t5MX%g2%_PxK-Y%u3XozDSkkBoB;neS+!Wx=$_7%w1ca49x(vi&003!7GOGXp literal 0 HcmV?d00001 diff --git a/buildSrc/build/tmp/jar/MANIFEST.MF b/buildSrc/build/tmp/jar/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/buildSrc/build/tmp/jar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/composenav/build.gradle b/composenav/build.gradle index 33705c8..c45330e 100644 --- a/composenav/build.gradle +++ b/composenav/build.gradle @@ -1,36 +1,32 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'org.jetbrains.dokka' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.dokka) + alias(libs.plugins.kotlin.compose) } android { - namespace 'com.adamkobus.compose.navigation' + namespace "com.adamkobus.compose.navigation" } dependencies { - implementation Lib.AndroidX.Core - implementation Lib.AndroidX.Appcompat - implementation Lib.Kotlin.Coroutines - implementation Lib.Google.Material - implementation Lib.AdamKobus.LifecycleAwareViewModel + implementation libs.androidx.core + implementation libs.androidx.appcompat + implementation libs.androidx.composenavigation + implementation libs.kotlin.coroutines // compose - implementation Lib.Compose.Ui - implementation Lib.Compose.Activity - implementation Lib.Compose.Material - implementation Lib.Compose.ToolingPreview - debugImplementation Lib.Compose.UiTooling + implementation platform(libs.compose.bom) + implementation libs.compose.ui + implementation libs.compose.tooling.preview + debugImplementation libs.compose.tooling.ui - implementation Lib.Accompanist.NavigationAnimation + implementation libs.ak.lifecycle.vm // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk - testImplementation Lib.Test.CoroutinesTest + testImplementation libs.test.junit + testImplementation libs.test.mockk + testImplementation libs.test.coroutines } ext { diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavHost.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavHost.kt index e98da23..3163764 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavHost.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavHost.kt @@ -4,6 +4,7 @@ import androidx.compose.animation.AnimatedContentTransitionScope import androidx.compose.animation.EnterTransition import androidx.compose.animation.ExitTransition import androidx.compose.animation.ExperimentalAnimationApi +import androidx.compose.animation.SizeTransform import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut @@ -14,16 +15,16 @@ import androidx.compose.ui.Modifier import androidx.navigation.NavBackStackEntry import androidx.navigation.NavGraphBuilder import androidx.navigation.NavHostController +import androidx.navigation.compose.NavHost import com.adamkobus.compose.navigation.destination.NavGraph import com.adamkobus.compose.navigation.model.NavGraphNamesExtractor import com.adamkobus.compose.navigation.ui.NavComposable -import com.google.accompanist.navigation.animation.AnimatedNavHost /*** - * Configures nested [AnimatedNavHost] + * Configures nested [NavHost] * * @param startGraph This graph's [NavGraph.startDestination] will be the first navigation displayed to the user. - * @see [AnimatedNavHost] + * @see [NavHost] */ @Suppress("LongParameterList") @ExperimentalAnimationApi @@ -40,21 +41,24 @@ fun ComposeNavHost( { fadeOut(animationSpec = tween(DEFAULT_ANIM_DURATION_MS)) }, popEnterTransition: (AnimatedContentTransitionScope.() -> EnterTransition) = enterTransition, popExitTransition: (AnimatedContentTransitionScope.() -> ExitTransition) = exitTransition, - builder: NavGraphBuilder.() -> Unit + sizeTransform: (AnimatedContentTransitionScope.() -> SizeTransform?)? = null, + builder: NavGraphBuilder.() -> Unit, ) { val graphRoutes = remember { NavGraphNamesExtractor.extractGraphNames(controller, startGraph.serializedRoute, builder) } NavComposable(navController = controller, navigationId = navigationId, observedGraphs = graphRoutes) - AnimatedNavHost( + val route: String? = null + NavHost( navController = controller, startDestination = startGraph.serializedRoute, modifier = modifier, - route = null, contentAlignment = contentAlignment, + route = route, enterTransition = enterTransition, exitTransition = exitTransition, popEnterTransition = popEnterTransition, popExitTransition = popExitTransition, - builder = builder + sizeTransform = sizeTransform, + builder = builder, ) } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavigation.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavigation.kt index 9b25a62..15fb12b 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavigation.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/ComposeNavigation.kt @@ -36,7 +36,6 @@ import kotlinx.coroutines.Dispatchers * - Current [NavLogger] via [ComposeNavigation.getLogger] */ object ComposeNavigation { - private const val DEFAULT_RESERVED_NAMES_ENABLED = true private const val DEFAULT_NAVIGATION_PROCESSING_TIMEOUT_MS = 1000L @@ -113,7 +112,9 @@ object ComposeNavigation { * * @see [NavLogLevel] */ - fun setLogLevel(@NavLogLevel level: Int): ComposeNavigation { + fun setLogLevel( + @NavLogLevel level: Int, + ): ComposeNavigation { this.logLevel = level navLogger.setLogLevel(level) return this @@ -227,12 +228,12 @@ object ComposeNavigation { internal fun getNavGatekeeper(): NavGatekeeper = navGatekeeper internal fun getIoDispatcher(): CoroutineDispatcher = ioDispatcher + internal fun getMainDispatcher(): CoroutineDispatcher = mainDispatcher internal fun getKnownDestinationsSource() = knownDestinationsSource - internal fun getNavDelegate(navigationId: NavigationId): NavDelegate = - navigationProcessor.getDispatcher(navigationId = navigationId) + internal fun getNavDelegate(navigationId: NavigationId): NavDelegate = navigationProcessor.getDispatcher(navigationId = navigationId) private fun createNavigationProcessor(): NavigationProcessor = NavigationProcessor( @@ -242,9 +243,8 @@ object ComposeNavigation { timeoutProvider = provider { getNavigationProcessingTimeout() }, loggerProvider = provider { getLogger() }, navIntentResolver = navIntentResolvingManager, - navGatekeeper = navGatekeeper + navGatekeeper = navGatekeeper, ) - internal fun getNavProcessor(): NavigationProcessor = - navigationProcessor + internal fun getNavProcessor(): NavigationProcessor = navigationProcessor } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/NavActionVerifier.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/NavActionVerifier.kt index bedb3b0..316d6f0 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/NavActionVerifier.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/NavActionVerifier.kt @@ -9,7 +9,6 @@ import com.adamkobus.compose.navigation.destination.NavState * As an example, it could be used to prevent duplicate nav action if user clicks list item twice. */ interface NavActionVerifier { - /** * @param navState Represents the state of the back stack at the moment of performing this check * @param action Action that was produced via [NavigationConsumer.offer] @@ -20,5 +19,8 @@ interface NavActionVerifier { * @see [NavState] * @see [NavAction] */ - fun isNavActionAllowed(navState: NavState, action: NavAction): VerifyResult + fun isNavActionAllowed( + navState: NavState, + action: NavAction, + ): VerifyResult } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/NavIntentResolver.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/NavIntentResolver.kt index 7e0e983..b7e1cfe 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/NavIntentResolver.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/NavIntentResolver.kt @@ -28,5 +28,8 @@ interface NavIntentResolver { * * - [ResolveResult.None] - should be returned when the implementation of [NavIntentResolver] doesn't recognize provided [intent] */ - suspend fun resolve(intent: NavIntent, navState: NavState): ResolveResult + suspend fun resolve( + intent: NavIntent, + navState: NavState, + ): ResolveResult } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/NavigationId.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/NavigationId.kt index 73d9a81..070b24d 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/NavigationId.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/NavigationId.kt @@ -12,7 +12,7 @@ import com.adamkobus.compose.navigation.ui.NavComposable * @param id value of this field will be used to identify [ComposeNavHost] or [NavComposable] */ data class NavigationId( - val id: String + val id: String, ) { /** * Returns string representation of [NavigationId] diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/TabBarIntentResolver.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/TabBarIntentResolver.kt index 030e3fe..78bae4b 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/TabBarIntentResolver.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/TabBarIntentResolver.kt @@ -44,12 +44,14 @@ open class TabBarIntentResolver( private val tabsMapping: Map, private val tabsRootGraph: NavGraph, private val popToTabHostIntent: NavIntent? = null, - private val tabStateSavingBehaviour: TabStateSavingBehaviour = SAVE_START_DESTINATION + private val tabStateSavingBehaviour: TabStateSavingBehaviour = SAVE_START_DESTINATION, ) : NavIntentResolver { - private val allGraphs = tabsMapping.values.toSet() - override suspend fun resolve(intent: NavIntent, navState: NavState): ResolveResult { + override suspend fun resolve( + intent: NavIntent, + navState: NavState, + ): ResolveResult { if (intent == popToTabHostIntent) { return handlePopIntent(navState) } @@ -58,7 +60,10 @@ open class TabBarIntentResolver( } ?: ResolveResult.None } - private fun resolveInternal(intent: NavIntent, navState: NavState): NavAction? { + private fun resolveInternal( + intent: NavIntent, + navState: NavState, + ): NavAction? { val mappedGraph = tabsMapping[intent.name] ?: return null intent.origin?.let { if (!navState.isCurrent(it)) return null @@ -77,48 +82,53 @@ open class TabBarIntentResolver( // we're already at the destination that clicking this tab would take us to if (currentDest == graphStartDestination) return null - val navOptions = if (currentDest.graph !in allGraphs) { - intent.popOptions?.copy(launchSingleTop = true) - } else { - navActionOptions { - popUpTo(graphStartDestination) - launchSingleTop = true + val navOptions = + if (currentDest.graph !in allGraphs) { + intent.popOptions?.copy(launchSingleTop = true) + } else { + navActionOptions { + popUpTo(graphStartDestination) + launchSingleTop = true + } } - } // Current destination doesn't belong to tab host and intent didn't provide nav options if (navOptions == null) return null // tab item's starting destination is already in back stack and we can pop back to it if (navState.isInBackStack(graphStartDestination)) { - return currentDest goTo graphStartDestination withOptions navActionOptions { - popUpTo(graphStartDestination) - launchSingleTop = true - } + return currentDest goTo graphStartDestination withOptions + navActionOptions { + popUpTo(graphStartDestination) + launchSingleTop = true + } } // we know we're in tab host based on the back stack, but the graph of different tab is being displayed // in such situation we will pop to the root of the tab host and save state based on [tabStateSavingBehaviour] - return currentDest goTo mappedGraph withOptions navActionOptions { - popUpTo(tabsRootGraph) { - saveState = tabStateSavingBehaviour == SAVE_ALL || - ( - tabStateSavingBehaviour == SAVE_START_DESTINATION && - currentDest == currentDest.graph.startDestination() - ) + return currentDest goTo mappedGraph withOptions + navActionOptions { + popUpTo(tabsRootGraph) { + saveState = tabStateSavingBehaviour == SAVE_ALL || + ( + tabStateSavingBehaviour == SAVE_START_DESTINATION && + currentDest == currentDest.graph.startDestination() + ) + } + restoreState = true + launchSingleTop = true } - restoreState = true - launchSingleTop = true - } } private fun handlePopIntent(navState: NavState): ResolveResult { val controllerState = navState.find(tabsRootGraph) ?: return ResolveResult.None val currentDest = controllerState.currentDestination ?: return ResolveResult.None controllerState.backStack.findLast { it.destination.graph in allGraphs }?.let { - val ret = currentDest.destination goTo it.destination withOptions navActionOptions { - popUpTo(it.destination) - launchSingleTop = true - } + val ret = + currentDest.destination goTo it.destination withOptions + navActionOptions { + popUpTo(it.destination) + launchSingleTop = true + } return ret.asResult() } ?: return ResolveResult.None } @@ -144,5 +154,5 @@ enum class TabStateSavingBehaviour { /** * The state of the tabs will always be preserved when switching between them. */ - SAVE_ALL + SAVE_ALL, } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/VerifyResult.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/VerifyResult.kt index 5a21ceb..edbbc56 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/VerifyResult.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/VerifyResult.kt @@ -15,5 +15,5 @@ enum class VerifyResult { /** * [NavAction] has been discarded by a verifier and it will no longer be processed. */ - Discard + Discard, } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavAction.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavAction.kt index 4ae53d4..d6d4385 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavAction.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavAction.kt @@ -11,9 +11,8 @@ import com.adamkobus.compose.navigation.intent.ResolveResult */ abstract class NavAction( val fromDestination: INavDestination, - val toDestination: INavDestination + val toDestination: INavDestination, ) { - /** * Compares other [NavAction] by [fromDestination] and [toDestination] fields */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavActionWrapper.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavActionWrapper.kt index 38bca25..3cfd439 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavActionWrapper.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavActionWrapper.kt @@ -10,9 +10,8 @@ import com.adamkobus.compose.navigation.NavigationConsumer * @param action actual action that will be processed when offered to [NavigationConsumer] */ open class NavActionWrapper( - val action: NavAction + val action: NavAction, ) { - /** * Compares other [NavActionWrapper] by [action] field */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavOptions.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavOptions.kt index e4213ba..78cea31 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavOptions.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavOptions.kt @@ -19,7 +19,7 @@ data class NavOptions internal constructor( val launchSingleTop: Boolean, val restoreState: Boolean, val popOptions: PopOptions?, - val anim: AnimBuilder? + val anim: AnimBuilder?, ) { /** * [NavOptions] were introduced for internal use by Compose Navigation library. @@ -60,9 +60,8 @@ data class NavOptionsBuilder internal constructor( var launchSingleTop: Boolean = false, var restoreState: Boolean = false, private var popOptions: PopOptions? = null, - private var animBuilder: AnimBuilder? = null + private var animBuilder: AnimBuilder? = null, ) { - /** * Creates [PopOptions] * @@ -82,7 +81,10 @@ data class NavOptionsBuilder internal constructor( * * @see [androidx.navigation.NavOptionsBuilder.popUpTo] */ - fun popUpTo(destination: NavDestination, init: PopOptionsBuilder.() -> Unit) { + fun popUpTo( + destination: NavDestination, + init: PopOptionsBuilder.() -> Unit, + ) { this.popOptions = PopOptionsBuilder(destination).apply(init).build() } @@ -116,7 +118,7 @@ data class NavOptionsBuilder internal constructor( launchSingleTop = launchSingleTop, restoreState = restoreState, popOptions = popOptions, - anim = animBuilder + anim = animBuilder, ) } @@ -136,7 +138,7 @@ data class NavOptionsBuilder internal constructor( data class PopOptions internal constructor( val destination: NavDestination, val saveState: Boolean, - val inclusive: Boolean + val inclusive: Boolean, ) /** @@ -160,13 +162,13 @@ data class PopOptions internal constructor( data class PopOptionsBuilder internal constructor( var destination: NavDestination, var saveState: Boolean = false, - var inclusive: Boolean = false + var inclusive: Boolean = false, ) { internal fun build(): PopOptions = PopOptions( destination = destination, saveState = saveState, - inclusive = inclusive + inclusive = inclusive, ) } @@ -178,5 +180,4 @@ data class PopOptionsBuilder internal constructor( * @see NavOptions * @see NavOptionsBuilder */ -fun navActionOptions(init: NavOptionsBuilder.() -> Unit): NavOptions = - NavOptionsBuilder().apply(init).build() +fun navActionOptions(init: NavOptionsBuilder.() -> Unit): NavOptions = NavOptionsBuilder().apply(init).build() diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigateAction.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigateAction.kt index c38d32e..f7f73a9 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigateAction.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigateAction.kt @@ -15,9 +15,8 @@ class NavigateAction( private val fromNavDestination: NavDestination, private val toNavDestination: NavDestination, private val params: List = emptyList(), - private val options: NavOptions? = null + private val options: NavOptions? = null, ) : NavAction(fromDestination = fromNavDestination, toDestination = toNavDestination) { - /** * This constructor allows you to copy other [NavigateAction] */ @@ -25,7 +24,7 @@ class NavigateAction( navAction.fromNavDestination, navAction.toNavDestination, navAction.params, - navAction.options + navAction.options, ) /** @@ -61,7 +60,7 @@ class NavigateAction( fromNavDestination, toNavDestination, params = this.params + param, - options = options + options = options, ) /** @@ -74,7 +73,7 @@ class NavigateAction( fromNavDestination, toNavDestination, params, - options = param + options = param, ) /** @@ -87,7 +86,7 @@ class NavigateAction( fromNavDestination, toNavDestination, params, - options = navActionOptions(init) + options = navActionOptions(init), ) override fun navigate(controller: NavHostController): Boolean { diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigationResult.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigationResult.kt index 3fff0b1..052f750 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigationResult.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/action/NavigationResult.kt @@ -15,7 +15,6 @@ sealed class NavigationResult { * Indicates that navigation action was executed. */ object Accepted : NavigationResult() { - /** * Returns a formatted String representation of [Accepted] */ @@ -64,7 +63,6 @@ sealed class DiscardReason { * @param verifier [NavActionVerifier] that discarded a [NavAction] */ class RejectedByVerifier(val verifier: NavActionVerifier) : DiscardReason() { - /** * Compares other [RejectedByVerifier] based on [verifier] field */ @@ -89,7 +87,6 @@ sealed class DiscardReason { * Indicates that [NavIntent] could not be mapped to actual action */ object NotMapped : DiscardReason() { - /** * Returns a formatted String representation of [NotMapped] */ @@ -100,7 +97,6 @@ sealed class DiscardReason { * Action could not be delivered because of invalid state */ object NotDelivered : DiscardReason() { - /** * Returns a formatted String representation of [NotDelivered] */ @@ -114,7 +110,6 @@ sealed class DiscardReason { * This might be removed in future once the solution is proven tobe stable. */ object Timeout : DiscardReason() { - /** * Returns a formatted String representation of [Timeout] */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopAction.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopAction.kt index 3cbb872..e54178f 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopAction.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopAction.kt @@ -10,9 +10,8 @@ import com.adamkobus.compose.navigation.destination.PopDestination */ class PopAction( fromDestination: NavDestination, - toDestination: PopDestination = GlobalGraph.Back + toDestination: PopDestination = GlobalGraph.Back, ) : NavAction(fromDestination = fromDestination, toDestination = toDestination) { - /** * Calls [NavHostController.popBackStack] */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopUpToAction.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopUpToAction.kt index e570dbc..814bee1 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopUpToAction.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/action/PopUpToAction.kt @@ -15,9 +15,8 @@ class PopUpToAction( fromDestination: INavDestination, toDestination: INavDestination, private val inclusive: Boolean = false, - private val saveState: Boolean = false + private val saveState: Boolean = false, ) : NavAction(fromDestination, toDestination) { - /** * Calls [NavHostController.popBackStack] * diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/DialogDestination.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/DialogDestination.kt index 0b7b6cd..04089c0 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/DialogDestination.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/DialogDestination.kt @@ -8,9 +8,8 @@ package com.adamkobus.compose.navigation.destination */ open class DialogDestination( override val graph: NavGraph, - override val route: NavRoute + override val route: NavRoute, ) : NavDestination { - /** * @return formatted String representation of [DialogDestination] */ @@ -39,7 +38,7 @@ internal fun dialogDestination( graph: NavGraph, pathName: String, reservedNameCheck: Boolean = true, - init: NavRoute.Builder.() -> Unit = {} + init: NavRoute.Builder.() -> Unit = {}, ): DialogDestination { val route = navRoute(graphName = graph.name, path = pathName, reservedNamesCheck = reservedNameCheck, init) return DialogDestination(graph, route) diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/GlobalGraph.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/GlobalGraph.kt index 0fa8267..c2038c6 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/GlobalGraph.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/GlobalGraph.kt @@ -8,7 +8,6 @@ import com.adamkobus.compose.navigation.action.NavigateAction * It might be a bad idea though as it increases chance for your [NavActionVerifier]s to not work properly. */ object GlobalGraph : NavGraph(name = "__global__", reservedNameCheck = false) { - /** * Start destination of [GlobalGraph]. Please keep in mind that navigating to GlobalGraph should be avoided */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/INavDestination.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/INavDestination.kt index 9a09e1c..00aae40 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/INavDestination.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/INavDestination.kt @@ -4,7 +4,6 @@ package com.adamkobus.compose.navigation.destination * Base type for all of the destinations. */ interface INavDestination { - /** * Graph that this destination belongs to */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavDestination.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavDestination.kt index 8f592e5..16ae948 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavDestination.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavDestination.kt @@ -11,19 +11,16 @@ import com.adamkobus.compose.navigation.intent.navIntent * Represents a destination that can be added to back stack */ interface NavDestination : INavDestination { - /** * Creates [PopDestination] with this [NavDestination] destination's [graph] */ - fun popDestination(): PopDestination = - popDestination(this.graph) + fun popDestination(): PopDestination = popDestination(this.graph) /** * Creates [PopAction] that uses this [NavDestination] as a source destination * and uses this destination's graph in target [PopDestination] */ - fun pop(): PopAction = - PopAction(this, popDestination()) + fun pop(): PopAction = PopAction(this, popDestination()) /** * Creates [PopAction] that originates from this [NavDestination] and targets [other]. @@ -40,8 +37,11 @@ interface NavDestination : INavDestination { * @param saveState if true then popped destinations' state will be saved and it will be possible to restore it later * by navigating to any of them with [NavOptions.restoreState] set to true */ - fun popUpTo(destination: NavDestination, inclusive: Boolean = false, saveState: Boolean = false): PopUpToAction = - PopUpToAction(this, destination, inclusive = inclusive, saveState = saveState) + fun popUpTo( + destination: NavDestination, + inclusive: Boolean = false, + saveState: Boolean = false, + ): PopUpToAction = PopUpToAction(this, destination, inclusive = inclusive, saveState = saveState) /** * Creates [NavigateAction] that originates from this [NavDestination] and targets [other]. @@ -53,6 +53,5 @@ interface NavDestination : INavDestination { /** * Creates new [NavIntent]. It will be initialized with provided name and this destination as [NavIntent.origin] */ - fun navIntent(name: String): NavIntent = - navIntent(name, this) + fun navIntent(name: String): NavIntent = navIntent(name, this) } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavGraph.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavGraph.kt index 05285ed..95855f2 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavGraph.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavGraph.kt @@ -9,9 +9,8 @@ package com.adamkobus.compose.navigation.destination */ abstract class NavGraph internal constructor( val name: String, - private val reservedNameCheck: Boolean = true + private val reservedNameCheck: Boolean = true, ) : NavDestination { - /** * @param name It is used to identify this graph. All destinations created in this graph will also be prefixed by the graph's name. */ @@ -35,14 +34,18 @@ abstract class NavGraph internal constructor( /** * Creates new type-safe builder for [ScreenDestination]. It will be initialized with this graph and provided [name] */ - fun screenDestination(name: String, init: NavRoute.Builder.() -> Unit = {}): ScreenDestination = - screenDestination(this, pathName = name, reservedNameCheck = reservedNameCheck, init = init) + fun screenDestination( + name: String, + init: NavRoute.Builder.() -> Unit = {}, + ): ScreenDestination = screenDestination(this, pathName = name, reservedNameCheck = reservedNameCheck, init = init) /** * Creates new type-safe builder for [DialogDestination]. It will be initialized with this graph and provided [name] */ - fun dialogDestination(pathName: String, init: NavRoute.Builder.() -> Unit = {}): DialogDestination = - dialogDestination(this, pathName = pathName, reservedNameCheck = reservedNameCheck, init = init) + fun dialogDestination( + pathName: String, + init: NavRoute.Builder.() -> Unit = {}, + ): DialogDestination = dialogDestination(this, pathName = pathName, reservedNameCheck = reservedNameCheck, init = init) /** * In case of [NavGraph], [graph] always points to itself diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoute.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoute.kt index 106ab60..f09505a 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoute.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoute.kt @@ -6,18 +6,18 @@ package com.adamkobus.compose.navigation.destination * @param parts Initial parts */ data class NavRoute constructor( - private val parts: List + private val parts: List, ) { - private val paramsCount: Int by lazy { parts.count { it is NavRoutePart.Param } } /** * Returns the names of all of the params present in this route. */ val paramNames: List - get() = parts.mapNotNull { part -> - part as? NavRoutePart.Param - }.map { it.paramName } + get() = + parts.mapNotNull { part -> + part as? NavRoutePart.Param + }.map { it.paramName } /** * @return route definition that can be later used with TODO refer class from Jetpack navigation @@ -39,8 +39,8 @@ data class NavRoute constructor( * @throws [IllegalArgumentException] if number of provided params doesn't match the expected params count. */ fun buildPath(params: List): String { - if (params.size != paramsCount) { - throw IllegalArgumentException("Wrong number of params, expected $paramsCount but got ${params.size} | $params") + require(params.size == paramsCount) { + "Wrong number of params, expected $paramsCount but got ${params.size} | $params" } var currentParamIndex = 0 return parts.joinToString(separator = PART_SEPARATOR) { @@ -55,10 +55,12 @@ data class NavRoute constructor( /** * Starts building a new route using builder that is populated with [NavRoutePart]s from the [NavRoute] on which [next] was invoked. */ - fun next(init: Builder.() -> Unit = {}): NavRoute = - next(reservedNamesCheck = true, init) + fun next(init: Builder.() -> Unit = {}): NavRoute = next(reservedNamesCheck = true, init) - internal fun next(reservedNamesCheck: Boolean = true, init: Builder.() -> Unit = {}): NavRoute { + internal fun next( + reservedNamesCheck: Boolean = true, + init: Builder.() -> Unit = {}, + ): NavRoute { val builder = Builder(parts, reservedNamesCheck = reservedNamesCheck) builder.init() return builder.build() @@ -96,7 +98,7 @@ data class NavRoute constructor( internal constructor(graphName: String, pathName: String, reservedNamesCheck: Boolean) : this( emptyList(), - reservedNamesCheck = reservedNamesCheck + reservedNamesCheck = reservedNamesCheck, ) { graphName(graphName) path(pathName) @@ -125,8 +127,8 @@ data class NavRoute constructor( } private fun ensureNameNotEmpty(name: String) { - if (name.isEmpty()) { - throw IllegalArgumentException("Name must not be empty") + require(name.isNotEmpty()) { + "Name must not be empty" } } @@ -155,13 +157,15 @@ data class NavRoute constructor( * * @param graphName Name of the graph the builder will be initialized with */ -fun navRoute(graphName: String, init: NavRoute.Builder.() -> Unit = {}): NavRoute = - navRoute(graphName = graphName, reservedNamesCheck = true, init = init) +fun navRoute( + graphName: String, + init: NavRoute.Builder.() -> Unit = {}, +): NavRoute = navRoute(graphName = graphName, reservedNamesCheck = true, init = init) internal fun navRoute( graphName: String, reservedNamesCheck: Boolean = true, - init: NavRoute.Builder.() -> Unit = {} + init: NavRoute.Builder.() -> Unit = {}, ): NavRoute { val builder = NavRoute.Builder(graphName = graphName, reservedNamesCheck = reservedNamesCheck) builder.init() @@ -174,14 +178,17 @@ internal fun navRoute( * @param graphName Name of the graph the builder will be initialized with * @param path Path to initialize the builder with */ -fun navRoute(graphName: String, path: String, init: NavRoute.Builder.() -> Unit = {}): NavRoute = - navRoute(graphName = graphName, path = path, reservedNamesCheck = true, init = init) +fun navRoute( + graphName: String, + path: String, + init: NavRoute.Builder.() -> Unit = {}, +): NavRoute = navRoute(graphName = graphName, path = path, reservedNamesCheck = true, init = init) internal fun navRoute( graphName: String, path: String, reservedNamesCheck: Boolean = true, - init: NavRoute.Builder.() -> Unit = {} + init: NavRoute.Builder.() -> Unit = {}, ): NavRoute { val builder = NavRoute.Builder(graphName = graphName, pathName = path, reservedNamesCheck = reservedNamesCheck) builder.init() diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoutePart.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoutePart.kt index f103672..0362713 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoutePart.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavRoutePart.kt @@ -6,14 +6,12 @@ import com.adamkobus.compose.navigation.ComposeNavigation * Used to declare apart of [ScreenDestination]'s route.. */ sealed class NavRoutePart { - /** * Declares a path of the route that contains name of a [NavGraph] * * @param name Name of a [NavGraph] */ class GraphName internal constructor(val name: String, reservedNamesCheck: Boolean = true) : NavRoutePart() { - /** * @param name Name of a [NavGraph] */ @@ -51,7 +49,6 @@ sealed class NavRoutePart { * @param name will become part of the final route without any modification */ class Path internal constructor(val name: String, reservedNamesCheck: Boolean) : NavRoutePart() { - /** * @param name will become part of the final route without any modification */ @@ -89,7 +86,6 @@ sealed class NavRoutePart { * @param paramName name by which this param can be later obtained from [NavStackEntry] */ class Param internal constructor(val paramName: String, reservedNamesCheck: Boolean) : NavRoutePart() { - /** * @param paramName name by which this param can be later obtained from [NavStackEntry] */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavStackEntry.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavStackEntry.kt index c7601cc..fc0fe6c 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavStackEntry.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavStackEntry.kt @@ -15,7 +15,7 @@ import com.adamkobus.compose.navigation.error.NavArgumentMissingError */ data class NavStackEntry( val destination: NavDestination, - val arguments: Map + val arguments: Map, ) { /** * Returns a String representation of [NavStackEntry] @@ -47,7 +47,7 @@ data class NavStackEntry( return stringValue.toInt() } catch (e: NumberFormatException) { throw NavArgumentFormatInvalidError( - "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Int" + "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Int", ) } } @@ -65,7 +65,7 @@ data class NavStackEntry( return stringValue.toLong() } catch (e: NumberFormatException) { throw NavArgumentFormatInvalidError( - "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Long" + "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Long", ) } } @@ -83,7 +83,7 @@ data class NavStackEntry( return stringValue.toFloat() } catch (e: NumberFormatException) { throw NavArgumentFormatInvalidError( - "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Float" + "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Float", ) } } @@ -101,7 +101,7 @@ data class NavStackEntry( return stringValue.toDouble() } catch (e: NumberFormatException) { throw NavArgumentFormatInvalidError( - "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Double" + "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Double", ) } } @@ -118,7 +118,7 @@ data class NavStackEntry( "true" -> true "false" -> false else -> throw NavArgumentFormatInvalidError( - "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Boolean" + "Value '$stringValue' of argument '$key' in destination '${this.destination}' could not be parsed to Boolean", ) } } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavState.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavState.kt index eb6a49f..9df3d9f 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavState.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/NavState.kt @@ -8,7 +8,7 @@ import com.adamkobus.compose.navigation.NavigationId * @param controllersState Each [NavControllerState] represents the back stack state of tracked NavHost. */ data class NavState( - val controllersState: List + val controllersState: List, ) { /** * Checks if provided destination is currently in back stack of any of the tracked controllers @@ -51,7 +51,7 @@ data class NavState( data class NavControllerState( val navId: NavigationId, val currentDestination: NavStackEntry?, - val backStack: List + val backStack: List, ) { /** * Checks if provided destination is currently in back stack diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/PopDestination.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/PopDestination.kt index 94a54b7..a08ddd0 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/PopDestination.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/PopDestination.kt @@ -7,9 +7,8 @@ import com.adamkobus.compose.navigation.action.PopAction */ data class PopDestination( override val graph: NavGraph, - override val route: NavRoute = navRoute(graph.name, path = "__back__", reservedNamesCheck = false) + override val route: NavRoute = navRoute(graph.name, path = "__back__", reservedNamesCheck = false), ) : INavDestination { - /** * @return formatted string representation of [PopDestination] */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/ScreenDestination.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/ScreenDestination.kt index 0e3e7c4..961fb44 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/ScreenDestination.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/ScreenDestination.kt @@ -8,9 +8,8 @@ package com.adamkobus.compose.navigation.destination */ open class ScreenDestination( override val graph: NavGraph, - override val route: NavRoute + override val route: NavRoute, ) : NavDestination { - /** * Creates a new [ScreenDestination] with a route that is a continuation of this destination's [route] */ @@ -49,7 +48,7 @@ internal fun screenDestination( graph: NavGraph, pathName: String, reservedNameCheck: Boolean = true, - init: NavRoute.Builder.() -> Unit = {} + init: NavRoute.Builder.() -> Unit = {}, ): ScreenDestination { val route = navRoute(graphName = graph.name, path = pathName, reservedNamesCheck = reservedNameCheck, init) return ScreenDestination(graph, route) diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownDestination.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownDestination.kt index 13724bc..8fd9e98 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownDestination.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownDestination.kt @@ -8,7 +8,7 @@ import com.adamkobus.compose.navigation.NavigationStateSource * @param path Raw path string that was encountered by [NavigationStateSource] */ data class UnknownDestination internal constructor( - val path: String + val path: String, ) : NavDestination { /** * Fixed value - [UnknownGraph] diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownGraph.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownGraph.kt index 3e9e2c3..6715285 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownGraph.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/destination/UnknownGraph.kt @@ -6,7 +6,6 @@ import com.adamkobus.compose.navigation.NavigationStateSource * Any destination that is not recognized by [NavigationStateSource] is assigned to this graph. */ object UnknownGraph : NavGraph("__unknown__", reservedNameCheck = false) { - /** * [UnknownGraph] has fixed startDestination with the same name as the name of the graph. */ diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/ext/NavGraphBuilderExt.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/ext/NavGraphBuilderExt.kt index 7f55b88..969e471 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/ext/NavGraphBuilderExt.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/ext/NavGraphBuilderExt.kt @@ -12,7 +12,9 @@ import androidx.navigation.NamedNavArgument import androidx.navigation.NavBackStackEntry import androidx.navigation.NavDeepLink import androidx.navigation.NavGraphBuilder +import androidx.navigation.compose.composable import androidx.navigation.compose.dialog +import androidx.navigation.compose.navigation import com.adamkobus.compose.navigation.ComposeNavigation import com.adamkobus.compose.navigation.destination.DialogDestination import com.adamkobus.compose.navigation.destination.NavGraph @@ -20,8 +22,6 @@ import com.adamkobus.compose.navigation.destination.NavStackEntry import com.adamkobus.compose.navigation.destination.ScreenDestination import com.adamkobus.compose.navigation.model.toNavStackEntry import com.adamkobus.compose.navigation.ui.LocalNavDestination -import com.google.accompanist.navigation.animation.composable -import com.google.accompanist.navigation.animation.navigation /** * @see [navigation] @@ -34,7 +34,7 @@ fun NavGraphBuilder.composableNavigation( exitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)? = null, popEnterTransition: (AnimatedContentTransitionScope.() -> EnterTransition?)? = enterTransition, popExitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)? = exitTransition, - builder: NavGraphBuilder.() -> Unit + builder: NavGraphBuilder.() -> Unit, ) { ComposeNavigation.getKnownDestinationsSource().addToKnownDestinations(graph) @@ -45,7 +45,7 @@ fun NavGraphBuilder.composableNavigation( exitTransition = exitTransition, popEnterTransition = popEnterTransition, popExitTransition = popExitTransition, - builder = builder + builder = builder, ) } @@ -62,7 +62,7 @@ fun NavGraphBuilder.composableDestination( exitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)? = null, popEnterTransition: (AnimatedContentTransitionScope.() -> EnterTransition?)? = enterTransition, popExitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)? = exitTransition, - content: @Composable AnimatedVisibilityScope.(NavStackEntry) -> Unit + content: @Composable AnimatedVisibilityScope.(NavStackEntry) -> Unit, ) { ComposeNavigation.getKnownDestinationsSource().addToKnownDestinations(destination) @@ -78,7 +78,7 @@ fun NavGraphBuilder.composableDestination( CompositionLocalProvider(LocalNavDestination provides destination) { content(backStackEntry.toNavStackEntry()) } - } + }, ) } @@ -90,7 +90,7 @@ fun NavGraphBuilder.composableDialog( arguments: List = emptyList(), deepLinks: List = emptyList(), dialogProperties: DialogProperties = DialogProperties(), - content: @Composable (NavStackEntry) -> Unit + content: @Composable (NavStackEntry) -> Unit, ) { ComposeNavigation.getKnownDestinationsSource().addToKnownDestinations(destination) @@ -103,6 +103,6 @@ fun NavGraphBuilder.composableDialog( CompositionLocalProvider(LocalNavDestination provides destination) { content(backStackEntry.toNavStackEntry()) } - } + }, ) } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntent.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntent.kt index ecb1ce5..91c180b 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntent.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntent.kt @@ -26,7 +26,7 @@ data class NavIntent( val origin: NavDestination? = null, val popOptions: NavOptions? = null, val navigationId: NavigationId? = null, - private val arguments: MutableMap = mutableMapOf() + private val arguments: MutableMap = mutableMapOf(), ) { /** * Creates a copy of [NavIntent] with [pair] added to its arguments @@ -36,13 +36,18 @@ data class NavIntent( /** * Creates a copy of [NavIntent] with [pair] added to its arguments */ - operator fun plus(pair: Pair): NavIntent = copy( - arguments = arguments.toMutableMap().also { - it[pair.first] = pair.second - } - ) + operator fun plus(pair: Pair): NavIntent = + copy( + arguments = + arguments.toMutableMap().also { + it[pair.first] = pair.second + }, + ) - fun addArgument(key: String, value: Any) { + fun addArgument( + key: String, + value: Any, + ) { arguments[key] = value } @@ -100,7 +105,7 @@ data class NavIntent( internal fun navIntent( name: String, sourceDestination: NavDestination, - reservedNameCheck: Boolean = true + reservedNameCheck: Boolean = true, ): NavIntent { if (reservedNameCheck) { ComposeNavigation.getReservedNamesHandler().checkIntentName(name) diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentHistory.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentHistory.kt index e60d7e0..6e60114 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentHistory.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentHistory.kt @@ -26,11 +26,11 @@ internal class NavIntentHistory(startingIntent: NavIntent) { fun popNode(intent: NavIntent) { if (nodes.last() == intent) { - nodes.removeLast() + nodes.removeAt(nodes.lastIndex) } else { throw IllegalStateException( "Last node is different from the one that should be removed. " + - "Current last: ${nodes.last()} | node to remove $intent" + "Current last: ${nodes.last()} | node to remove $intent", ) } } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManager.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManager.kt index 32c16f5..ec11f2f 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManager.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManager.kt @@ -5,14 +5,16 @@ import com.adamkobus.compose.navigation.action.NavAction import com.adamkobus.compose.navigation.destination.NavState internal class NavIntentResolvingManager { - private val resolvers = mutableListOf() fun register(resolvers: Collection) { this.resolvers.addAll(resolvers) } - suspend fun resolve(intent: NavIntent, navState: NavState): NavAction? { + suspend fun resolve( + intent: NavIntent, + navState: NavState, + ): NavAction? { val history = NavIntentHistory(intent) val result = getNextResult(intent, navState, history) return if (result is ResolveResult.Action) { @@ -22,7 +24,11 @@ internal class NavIntentResolvingManager { } } - private suspend fun getNextResult(intent: NavIntent, navState: NavState, history: NavIntentHistory): ResolveResult { + private suspend fun getNextResult( + intent: NavIntent, + navState: NavState, + history: NavIntentHistory, + ): ResolveResult { resolvers.forEach { val resolverResult = it.resolve(intent, navState) if (resolverResult is ResolveResult.Action) { diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/ResolveResult.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/ResolveResult.kt index c058e06..35eef38 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/intent/ResolveResult.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/intent/ResolveResult.kt @@ -7,7 +7,6 @@ import com.adamkobus.compose.navigation.action.NavAction * Produced as a result of [NavIntent] processing by [NavIntentResolver]s */ sealed class ResolveResult { - /** * Indicates that [NavIntent] was resolved to the [action] * diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLogger.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLogger.kt index 7d68e85..72e18e1 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLogger.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLogger.kt @@ -9,7 +9,6 @@ import com.adamkobus.compose.navigation.ComposeNavigation * You can provide your own implementation via [ComposeNavigation.setLogger] */ interface NavLogger { - /** * Used to log details about navigation actions processing, i.e. when processing of the new actions has started and finished */ @@ -18,7 +17,10 @@ interface NavLogger { /** * Used to log details about navigation actions processing, i.e. when processing of the new actions has started and finished */ - fun v(error: Throwable, message: String) + fun v( + error: Throwable, + message: String, + ) /** * Used to log current destination changes @@ -28,7 +30,10 @@ interface NavLogger { /** * Used to log current destination changes */ - fun d(error: Throwable, message: String) + fun d( + error: Throwable, + message: String, + ) /** * Used to log warnings, i.e. about intents or actions that were discarded @@ -38,7 +43,10 @@ interface NavLogger { /** * Used to log warnings, i.e. about intents or actions that were discarded */ - fun w(error: Throwable, message: String) + fun w( + error: Throwable, + message: String, + ) /** * Used to log unexpected errors @@ -48,7 +56,10 @@ interface NavLogger { /** * Used to log unexpected errors */ - fun e(error: Throwable, message: String) + fun e( + error: Throwable, + message: String, + ) /** * When set, then logger should log only the messages with matching or higher importance than [level]. @@ -57,7 +68,9 @@ interface NavLogger { * @see [android.util.Log] * @see [NavLogLevel] */ - fun setLogLevel(@NavLogLevel level: Int) + fun setLogLevel( + @NavLogLevel level: Int, + ) companion object { /** diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLoggerImpl.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLoggerImpl.kt index d7af31a..33e3cad 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLoggerImpl.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/logger/NavLoggerImpl.kt @@ -4,7 +4,6 @@ import android.util.Log import com.adamkobus.compose.navigation.ComposeNavigation internal object NavLoggerImpl : NavLogger { - private const val TAG = "Navigation" private var logLevel: Int = ComposeNavigation.DEFAULT_LOG_LEVEL @@ -15,7 +14,10 @@ internal object NavLoggerImpl : NavLogger { } } - override fun v(error: Throwable, message: String) { + override fun v( + error: Throwable, + message: String, + ) { if (canLog(Log.VERBOSE)) { Log.v(TAG, message, error) } @@ -27,7 +29,10 @@ internal object NavLoggerImpl : NavLogger { } } - override fun d(error: Throwable, message: String) { + override fun d( + error: Throwable, + message: String, + ) { if (canLog(Log.DEBUG)) { Log.d(TAG, message, error) } @@ -39,7 +44,10 @@ internal object NavLoggerImpl : NavLogger { } } - override fun w(error: Throwable, message: String) { + override fun w( + error: Throwable, + message: String, + ) { if (canLog(Log.WARN)) { Log.w(TAG, message, error) } @@ -51,7 +59,10 @@ internal object NavLoggerImpl : NavLogger { } } - override fun e(error: Throwable, message: String) { + override fun e( + error: Throwable, + message: String, + ) { if (canLog(Log.ERROR)) { Log.e(TAG, message, error) } @@ -61,5 +72,7 @@ internal object NavLoggerImpl : NavLogger { logLevel = level } - private fun canLog(@NavLogLevel level: Int) = level >= logLevel + private fun canLog( + @NavLogLevel level: Int, + ) = level >= logLevel } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ActionConsumer.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ActionConsumer.kt index 158cb38..e5b495a 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ActionConsumer.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ActionConsumer.kt @@ -2,5 +2,6 @@ package com.adamkobus.compose.navigation.model internal interface ActionConsumer { val supportedGraphsRoutes: List + suspend fun awaitUntilReady() } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/KnownDestinationsSource.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/KnownDestinationsSource.kt index c673ef6..4720028 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/KnownDestinationsSource.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/KnownDestinationsSource.kt @@ -9,7 +9,6 @@ import com.adamkobus.compose.navigation.destination.NavStackEntry import com.adamkobus.compose.navigation.destination.UnknownDestination internal class KnownDestinationsSource { - private val knownDestinations = mutableMapOf() internal fun addToKnownDestinations(destination: INavDestination) { @@ -20,7 +19,10 @@ internal class KnownDestinationsSource { } } - private fun addKnownDestination(route: String, destination: NavDestination) { + private fun addKnownDestination( + route: String, + destination: NavDestination, + ) { synchronized(knownDestinations) { knownDestinations.putIfAbsent(route, destination) } @@ -38,16 +40,19 @@ internal class KnownDestinationsSource { } internal fun NavBackStackEntry.toNavStackEntry( - knownDestinationsSource: KnownDestinationsSource = ComposeNavigation.getKnownDestinationsSource() + knownDestinationsSource: KnownDestinationsSource = ComposeNavigation.getKnownDestinationsSource(), ): NavStackEntry { val destination = knownDestinationsSource.resolveNavBackStackEntryToDestination(this) return NavStackEntry( destination = destination, - arguments = buildArguments(destination, this.arguments) + arguments = buildArguments(destination, this.arguments), ) } -private fun buildArguments(destination: NavDestination, arguments: Bundle?): Map = +private fun buildArguments( + destination: NavDestination, + arguments: Bundle?, +): Map = destination.route.paramNames.associateWith { arguments?.getString(it)!! } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavDelegate.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavDelegate.kt index 60aa68f..49abc63 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavDelegate.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavDelegate.kt @@ -6,8 +6,19 @@ import kotlinx.coroutines.flow.Flow internal interface NavDelegate { fun onActionCompletedWithoutBackStackUpdate(actionConsumer: ActionConsumer) - fun onBackStackEntryUpdated(actionConsumer: ActionConsumer, entry: NavBackStackEntry?, backQueue: List) - fun register(actionConsumer: ActionConsumer, supportedGraphsRoutes: List): Flow + + fun onBackStackEntryUpdated( + actionConsumer: ActionConsumer, + entry: NavBackStackEntry?, + backQueue: List, + ) + + fun register( + actionConsumer: ActionConsumer, + supportedGraphsRoutes: List, + ): Flow + fun unregister(actionConsumer: ActionConsumer) + fun onBackStackCleared(actionConsumer: ActionConsumer) } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGatekeeper.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGatekeeper.kt index 531c2e5..b5735c6 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGatekeeper.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGatekeeper.kt @@ -6,14 +6,17 @@ import com.adamkobus.compose.navigation.action.NavAction import com.adamkobus.compose.navigation.destination.NavState internal class NavGatekeeper( - private val initialVerifiers: Set = emptySet() + private val initialVerifiers: Set = emptySet(), ) { + private val verifiers = + mutableListOf().apply { + addAll(initialVerifiers) + } - private val verifiers = mutableListOf().apply { - addAll(initialVerifiers) - } - - fun isNavActionAllowed(navState: NavState, action: NavAction): NavActionVerifier? { + fun isNavActionAllowed( + navState: NavState, + action: NavAction, + ): NavActionVerifier? { synchronized(verifiers) { verifiers.forEach { if (it.isNavActionAllowed(navState, action) == VerifyResult.Discard) { diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGraphNamesExtractor.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGraphNamesExtractor.kt index 8782035..2dfe00c 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGraphNamesExtractor.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavGraphNamesExtractor.kt @@ -7,8 +7,11 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.NavHostController internal object NavGraphNamesExtractor { - - fun extractGraphNames(controller: NavHostController, startRoute: String, init: NavGraphBuilder.() -> Unit): List { + fun extractGraphNames( + controller: NavHostController, + startRoute: String, + init: NavGraphBuilder.() -> Unit, + ): List { val navGraphBuilder = NavGraphBuilder(controller.navigatorProvider, startRoute, null) val nodes = navGraphBuilder.apply(init).build().nodes val graphNames = mutableListOf() @@ -16,7 +19,10 @@ internal object NavGraphNamesExtractor { return graphNames } - private fun addGraphNames(nodes: SparseArrayCompat, graphNames: MutableList) { + private fun addGraphNames( + nodes: SparseArrayCompat, + graphNames: MutableList, + ) { for (i in 0 until nodes.size()) { val node = nodes.get(nodes.keyAt(i)) node?.route diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavStateManager.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavStateManager.kt index a2d0db5..9ff3b7b 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavStateManager.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavStateManager.kt @@ -15,7 +15,6 @@ import kotlinx.coroutines.flow.StateFlow * It depends on NavComposable to work properly. */ internal class NavStateManager : NavigationStateSource { - private val _navState = MutableStateFlow(NavState(emptyList())) override val navState: NavState get() = _navState.value @@ -25,15 +24,20 @@ internal class NavStateManager : NavigationStateSource { private val logger: NavLogger get() = ComposeNavigation.getLogger() - internal fun onBackStackUpdated(navigationId: NavigationId, entry: NavBackStackEntry?, backQueue: List) { - val backStack = backQueue.mapNotNull { - if (it.destination.id == 0 && it.destination.route == null) { - // this is the app's root graph that is not part of the navigation tree - null - } else { - it.toNavStackEntry() + internal fun onBackStackUpdated( + navigationId: NavigationId, + entry: NavBackStackEntry?, + backQueue: List, + ) { + val backStack = + backQueue.mapNotNull { + if (it.destination.id == 0 && it.destination.route == null) { + // this is the app's root graph that is not part of the navigation tree + null + } else { + it.toNavStackEntry() + } } - } updateCurrentDestination(NavControllerState(navigationId, entry?.toNavStackEntry(), backStack)) } @@ -45,15 +49,16 @@ internal class NavStateManager : NavigationStateSource { } logger.d("[${controllerState.navId}] Current destination changed to $controllerState") if (existing != null) { - _navState.value = NavState( - _navState.value.controllersState.map { - if (it.navId == controllerState.navId) { - controllerState - } else { - it - } - } - ) + _navState.value = + NavState( + _navState.value.controllersState.map { + if (it.navId == controllerState.navId) { + controllerState + } else { + it + } + }, + ) } else { _navState.value = NavState(_navState.value.controllersState + controllerState) } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationConsumerImpl.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationConsumerImpl.kt index 6f02a0e..1ad8a7f 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationConsumerImpl.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationConsumerImpl.kt @@ -9,7 +9,6 @@ import com.adamkobus.compose.navigation.intent.NavIntent import kotlinx.coroutines.CompletableDeferred internal class NavigationConsumerImpl : NavigationConsumer { - private val navProcessor get() = ComposeNavigation.getNavProcessor() diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationProcessor.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationProcessor.kt index bc72f2f..70b3f21 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationProcessor.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/NavigationProcessor.kt @@ -27,7 +27,7 @@ internal class NavigationProcessor( private val navIntentResolver: NavIntentResolvingManager, private val navGatekeeper: NavGatekeeper, private val loggerProvider: Provider, - private val timeoutProvider: Provider + private val timeoutProvider: Provider, ) { private val navState: NavState get() = stateManager.navState @@ -52,36 +52,44 @@ internal class NavigationProcessor( fun getDispatcher(navigationId: NavigationId): PendingActionDispatcher { synchronized(dispatchers) { return dispatchers.find { it.navigationId == navigationId } ?: run { - val dispatcher = PendingActionDispatcher( - navigationId = navigationId, - loggerProvider = loggerProvider, - timeoutProvider = timeoutProvider, - mainDispatcher = mainDispatcher, - stateManager = stateManager - ) + val dispatcher = + PendingActionDispatcher( + navigationId = navigationId, + loggerProvider = loggerProvider, + timeoutProvider = timeoutProvider, + mainDispatcher = mainDispatcher, + stateManager = stateManager, + ) dispatchers.add(dispatcher) dispatcher } } } - fun postNavAction(navAction: NavAction, onTaskCompleted: CompletableDeferred? = null) { + fun postNavAction( + navAction: NavAction, + onTaskCompleted: CompletableDeferred? = null, + ) { scope.launch { actionBuffer.emit(ProcessorTask.Action(navAction, onTaskCompleted)) } } - fun postNavIntent(intent: NavIntent, onTaskCompleted: CompletableDeferred? = null) { + fun postNavIntent( + intent: NavIntent, + onTaskCompleted: CompletableDeferred? = null, + ) { scope.launch { actionBuffer.emit(ProcessorTask.Intent(intent, onTaskCompleted)) } } private suspend fun processTask(task: ProcessorTask) { - val result = when (task) { - is ProcessorTask.Action -> processAction(task.navAction) - is ProcessorTask.Intent -> processIntent(task.navIntent) - } + val result = + when (task) { + is ProcessorTask.Action -> processAction(task.navAction) + is ProcessorTask.Intent -> processIntent(task.navIntent) + } task.onTaskCompleted?.complete(result) } @@ -109,9 +117,10 @@ internal class NavigationProcessor( return NavigationResult.Discarded(DiscardReason.NotDelivered) } - val readyDispatchers = dispatchers.filter { - it.awaitUntilReady() - } + val readyDispatchers = + dispatchers.filter { + it.awaitUntilReady() + } val rejectingVerifier = navGatekeeper.isNavActionAllowed(navState, action) if (rejectingVerifier != null) { @@ -119,9 +128,10 @@ internal class NavigationProcessor( return NavigationResult.Discarded(DiscardReason.RejectedByVerifier(rejectingVerifier)) } - val suitableDispatchers = readyDispatchers.filter { - isDispatcherSuitableForAction(it, action) - } + val suitableDispatchers = + readyDispatchers.filter { + isDispatcherSuitableForAction(it, action) + } if (suitableDispatchers.isEmpty()) { logger.v("$logPrefix There is no NavHost suitable for action: $action") @@ -133,24 +143,25 @@ internal class NavigationProcessor( suitableDispatchers.map { Pair(it, it.dispatchAction(action)) }.forEach { (dispatcher, deferredResult) -> - val mappedResult = when (deferredResult.await()) { - DispatchResult.Success -> { - logger.v("$logPrefix Action $action accepted by dispatcher $dispatcher") - NavigationResult.Accepted - } - DispatchResult.Timeout -> { - logger.e("$logPrefix Timeout when trying to deliver action $action to $dispatcher") - NavigationResult.Discarded(DiscardReason.Timeout) - } - DispatchResult.NotDelivered -> { - logger.w("$logPrefix Failed to deliver action $action to $dispatcher") - NavigationResult.Discarded(DiscardReason.NotDelivered) + val mappedResult = + when (deferredResult.await()) { + DispatchResult.Success -> { + logger.v("$logPrefix Action $action accepted by dispatcher $dispatcher") + NavigationResult.Accepted + } + DispatchResult.Timeout -> { + logger.e("$logPrefix Timeout when trying to deliver action $action to $dispatcher") + NavigationResult.Discarded(DiscardReason.Timeout) + } + DispatchResult.NotDelivered -> { + logger.w("$logPrefix Failed to deliver action $action to $dispatcher") + NavigationResult.Discarded(DiscardReason.NotDelivered) + } + DispatchResult.WrongNavHost -> { + logger.v("$logPrefix Action cannot be processed by nav host $dispatcher: $action") + NavigationResult.Discarded(DiscardReason.NotDelivered) + } } - DispatchResult.WrongNavHost -> { - logger.v("$logPrefix Action cannot be processed by nav host $dispatcher: $action") - NavigationResult.Discarded(DiscardReason.NotDelivered) - } - } if (result !is NavigationResult.Accepted) { result = mappedResult } @@ -158,7 +169,10 @@ internal class NavigationProcessor( return result } - private suspend fun isDispatcherSuitableForAction(dispatcher: PendingActionDispatcher, action: NavAction): Boolean { + private suspend fun isDispatcherSuitableForAction( + dispatcher: PendingActionDispatcher, + action: NavAction, + ): Boolean { val supportedGraphs = dispatcher.getSupportedGraphRoutes() ?: return false return if (action is NavigateAction || action is PopUpToAction) { action.toDestination.graph.serializedRoute in supportedGraphs diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/PendingActionDispatcher.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/PendingActionDispatcher.kt index ad80cbf..c6f49ce 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/PendingActionDispatcher.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/PendingActionDispatcher.kt @@ -20,7 +20,7 @@ internal class PendingActionDispatcher( private val mainDispatcher: CoroutineDispatcher, private val loggerProvider: Provider, private val timeoutProvider: Provider, - private val stateManager: NavStateManager + private val stateManager: NavStateManager, ) : NavDelegate { private val actionDispatchTimeoutMs: Long get() = timeoutProvider.provide() @@ -36,7 +36,7 @@ internal class PendingActionDispatcher( override fun onBackStackEntryUpdated( actionConsumer: ActionConsumer, entry: NavBackStackEntry?, - backQueue: List + backQueue: List, ) { if (actionConsumer == consumer?.owner) { stateManager.onBackStackUpdated(navigationId, entry, backQueue) @@ -57,18 +57,22 @@ internal class PendingActionDispatcher( } } - override fun register(actionConsumer: ActionConsumer, supportedGraphsRoutes: List): Flow { + override fun register( + actionConsumer: ActionConsumer, + supportedGraphsRoutes: List, + ): Flow { consumer?.let { unregister(it.owner) } logger.v("$logPrefix Registering action consumer: $actionConsumer") val flow = MutableSharedFlow() - consumer = PendingActionConsumer( - actionConsumer, - flow, - CoroutineScope(this.mainDispatcher + SupervisorJob()), - supportedGraphsRoutes - ) + consumer = + PendingActionConsumer( + actionConsumer, + flow, + CoroutineScope(this.mainDispatcher + SupervisorJob()), + supportedGraphsRoutes, + ) return flow } @@ -110,24 +114,28 @@ internal class PendingActionDispatcher( complete(DispatchResult.WrongNavHost) } - suspend fun getSupportedGraphRoutes(): List? = - getReadyConsumer()?.supportedGraphsRoutes + suspend fun getSupportedGraphRoutes(): List? = getReadyConsumer()?.supportedGraphsRoutes - private suspend fun dispatchToConsumer(action: NavAction, consumer: PendingActionConsumer): CompletableDeferred { + private suspend fun dispatchToConsumer( + action: NavAction, + consumer: PendingActionConsumer, + ): CompletableDeferred { val ret = CompletableDeferred() onActionPerformed = ret var job: Job? = null - job = consumer.scope.launch { - timeoutJob = consumer.scope.launch { - delay(actionDispatchTimeoutMs) - job?.cancel() - if (ret == onActionPerformed) { - completeAction(DispatchResult.Timeout) - } + job = + consumer.scope.launch { + timeoutJob = + consumer.scope.launch { + delay(actionDispatchTimeoutMs) + job?.cancel() + if (ret == onActionPerformed) { + completeAction(DispatchResult.Timeout) + } + } + consumer.owner.awaitUntilReady() + consumer.consumerFlow.emit(action) } - consumer.owner.awaitUntilReady() - consumer.consumerFlow.emit(action) - } return ret } @@ -147,7 +155,7 @@ private data class PendingActionConsumer( val owner: ActionConsumer, val consumerFlow: MutableSharedFlow, val scope: CoroutineScope, - val supportedGraphsRoutes: List + val supportedGraphsRoutes: List, ) { override fun toString(): String { return owner.toString() @@ -158,5 +166,5 @@ internal enum class DispatchResult { WrongNavHost, NotDelivered, Timeout, - Success + Success, } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorInitializedState.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorInitializedState.kt index 9369693..0b3e6e1 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorInitializedState.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorInitializedState.kt @@ -3,7 +3,6 @@ package com.adamkobus.compose.navigation.model import kotlinx.coroutines.CompletableDeferred internal class ProcessorInitializedState { - private var state: State = State.Unregistered private var initializedDeferred: CompletableDeferred = CompletableDeferred() @@ -33,6 +32,6 @@ internal class ProcessorInitializedState { private enum class State { Registered, - Unregistered + Unregistered, } } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorTask.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorTask.kt index c2ec700..81b3945 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorTask.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ProcessorTask.kt @@ -6,7 +6,6 @@ import com.adamkobus.compose.navigation.intent.NavIntent import kotlinx.coroutines.CompletableDeferred internal sealed class ProcessorTask(val onTaskCompleted: CompletableDeferred?) { - class Action(val navAction: NavAction, onTaskCompleted: CompletableDeferred?) : ProcessorTask(onTaskCompleted) { override fun equals(other: Any?): Boolean { return other is Action && other.navAction == navAction diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ReservedNamesHandler.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ReservedNamesHandler.kt index 0772d30..8b26464 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/model/ReservedNamesHandler.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/model/ReservedNamesHandler.kt @@ -3,14 +3,13 @@ package com.adamkobus.compose.navigation.model import com.adamkobus.compose.navigation.error.ReservedNameError internal class ReservedNamesHandler { - internal var enabled = true fun checkGraphName(graphName: String) { if (enabled && graphName.startsWith(RESERVED_NAME_PREFIX)) { throw ReservedNameError( "Graph names starting with $RESERVED_NAME_PREFIX are reserved " + - "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()" + "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()", ) } } @@ -19,7 +18,7 @@ internal class ReservedNamesHandler { if (enabled && pathName.startsWith(RESERVED_NAME_PREFIX)) { throw ReservedNameError( "Path names starting with $RESERVED_NAME_PREFIX are reserved " + - "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()" + "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()", ) } } @@ -28,7 +27,7 @@ internal class ReservedNamesHandler { if (enabled && paramName.startsWith(RESERVED_NAME_PREFIX)) { throw ReservedNameError( "Param names starting with $RESERVED_NAME_PREFIX are reserved " + - "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()" + "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()", ) } } @@ -37,7 +36,7 @@ internal class ReservedNamesHandler { if (enabled && name.startsWith(RESERVED_NAME_PREFIX)) { throw ReservedNameError( "Intent names starting with $RESERVED_NAME_PREFIX are reserved " + - "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()" + "for internal usage. You can disable this with ComposeNavigation.disableRestrictedNamesCheck()", ) } } diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposable.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposable.kt index 43b6dd8..05f2de1 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposable.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposable.kt @@ -1,5 +1,6 @@ package com.adamkobus.compose.navigation.ui +import android.annotation.SuppressLint import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.State @@ -20,7 +21,7 @@ import com.adamkobus.compose.navigation.NavigationId fun NavComposable( navController: NavHostController, observedGraphs: List = emptyList(), - navigationId: NavigationId + navigationId: NavigationId, ) { val vm: NavComposableVM = viewModel(key = navController.toString()) vm.viewParam.bind(NavComposableParam(navigationId = navigationId, graphs = observedGraphs)) @@ -31,18 +32,19 @@ fun NavComposable( @Composable private fun NavComposableInner( navController: NavHostController, - vm: NavComposableVM + vm: NavComposableVM, ) { val backStackState = navController.currentBackStackEntryAsState() CurrentBackStackEntryUpdater(navController, vm, backStackState) PendingActionProcessor(navController, vm) } +@SuppressLint("RestrictedApi") @Composable private fun CurrentBackStackEntryUpdater( navController: NavHostController, vm: NavComposableVM, - backStackState: State + backStackState: State, ) { val currentBackStackEntry = backStackState.value val queue = navController.currentBackStack.collectAsState().value @@ -54,7 +56,10 @@ private fun CurrentBackStackEntryUpdater( } @Composable -private fun PendingActionProcessor(navController: NavHostController, vm: NavComposableVM) { +private fun PendingActionProcessor( + navController: NavHostController, + vm: NavComposableVM, +) { val pendingAction = vm.pendingActionState.value LaunchedEffect(key1 = pendingAction) { if (pendingAction is PendingActionState.Present) { @@ -66,5 +71,5 @@ private fun PendingActionProcessor(navController: NavHostController, vm: NavComp private data class BackStackEntryUpdateState( val currentBackStackEntry: NavBackStackEntry?, - val queue: List + val queue: List, ) diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableState.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableState.kt index 7df737e..ffdb256 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableState.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableState.kt @@ -3,5 +3,5 @@ package com.adamkobus.compose.navigation.ui import androidx.compose.runtime.State internal data class NavComposableState( - val isInitialized: State + val isInitialized: State, ) diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableVM.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableVM.kt index f8ea758..f2557b1 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableVM.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/NavComposableVM.kt @@ -18,7 +18,6 @@ import kotlinx.coroutines.launch @OptIn(ExperimentalCoroutinesApi::class) internal class NavComposableVM : ViewModel(), ActionConsumer { - val viewParam = ViewParam() private val logger: NavLogger @@ -74,7 +73,10 @@ internal class NavComposableVM : ViewModel(), ActionConsumer { pendingActionState.value = PendingActionState.Missing } - fun processBackStackEntry(entry: NavBackStackEntry?, backQueue: List) { + fun processBackStackEntry( + entry: NavBackStackEntry?, + backQueue: List, + ) { navDelegate?.onBackStackEntryUpdated(this@NavComposableVM, entry, backQueue) if (entry != null) { loadingCompletable?.let { @@ -94,5 +96,5 @@ internal class NavComposableVM : ViewModel(), ActionConsumer { internal data class NavComposableParam( val navigationId: NavigationId, - val graphs: List + val graphs: List, ) diff --git a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/PendingActionState.kt b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/PendingActionState.kt index 8c15ab2..b46cc2f 100644 --- a/composenav/src/main/java/com/adamkobus/compose/navigation/ui/PendingActionState.kt +++ b/composenav/src/main/java/com/adamkobus/compose/navigation/ui/PendingActionState.kt @@ -4,7 +4,6 @@ import com.adamkobus.compose.navigation.action.NavAction import kotlinx.coroutines.CompletableDeferred internal sealed class PendingActionState { - object Missing : PendingActionState() class Present(val action: NavAction, private val completable: CompletableDeferred) : PendingActionState() { diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/ComposeNavigationTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/ComposeNavigationTest.kt index 6806ad3..e815a8d 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/ComposeNavigationTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/ComposeNavigationTest.kt @@ -5,7 +5,6 @@ import org.junit.After import org.junit.Test class ComposeNavigationTest { - @After fun cleanUp() { ComposeNavigation.reset() diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/action/NavigateActionTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/action/NavigateActionTest.kt index 549989c..b1d7ad4 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/action/NavigateActionTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/action/NavigateActionTest.kt @@ -11,7 +11,6 @@ import org.junit.Before import org.junit.Test class NavigateActionTest { - private val controller: NavHostController = mockk() private val fromDestination: NavDestination = mockk() private val toDestination: NavDestination = mockk() diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/GlobalGraphTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/GlobalGraphTest.kt index 6a7c314..5585168 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/GlobalGraphTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/GlobalGraphTest.kt @@ -4,7 +4,6 @@ import org.junit.Assert.assertEquals import org.junit.Test class GlobalGraphTest { - @Test fun `WHEN startDestination THEN proper destination is returned`() { assertEquals("__global__/__root__", GlobalGraph.startDestination().route.buildRoute()) diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRoutePartTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRoutePartTest.kt index 1b9ccd6..0f1e562 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRoutePartTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRoutePartTest.kt @@ -5,7 +5,6 @@ import junit.framework.TestCase.assertEquals import org.junit.Test class NavRoutePartTest { - @Test(expected = ReservedNameError::class) fun `GIVEN reserved graph name WHEN GraphName THEN ReservedNameError is thrown`() { NavRoutePart.GraphName("__reserved") diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRouteTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRouteTest.kt index d9b694d..6bc6361 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRouteTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavRouteTest.kt @@ -5,7 +5,6 @@ import org.junit.Assert.assertEquals import org.junit.Test class NavRouteTest { - @Test fun `GIVEN route defined WHEN buildRoute THEN proper route is returned`() { // given @@ -21,11 +20,12 @@ class NavRouteTest { @Test fun `GIVEN route with params defined WHEN buildRoute THEN proper route is returned`() { // given - val testSubject = navRoute("testGraph", "testPath") { - param("param1") - path("foobar") - param("secondParam") - } + val testSubject = + navRoute("testGraph", "testPath") { + param("param1") + path("foobar") + param("secondParam") + } // when val obtained = testSubject.buildRoute() @@ -37,9 +37,10 @@ class NavRouteTest { @Test fun `GIVEN route defined WHEN next THEN properly initialized route builder is returned`() { // given - val testSubject = navRoute("testGraph", "testPath").next { - param("param") - } + val testSubject = + navRoute("testGraph", "testPath").next { + param("param") + } // when val obtained = testSubject.buildRoute() @@ -63,11 +64,12 @@ class NavRouteTest { @Test fun `GIVEN route with params WHEN buildPath THEN proper path is returned`() { // given - val testSubject = navRoute("testGraph", "testPath") { - param("param1") - path("foobar") - param("secondParam") - } + val testSubject = + navRoute("testGraph", "testPath") { + param("param1") + path("foobar") + param("secondParam") + } // when val obtained = testSubject.buildPath("aaa", "bbb") @@ -79,11 +81,12 @@ class NavRouteTest { @Test(expected = IllegalArgumentException::class) fun `GIVEN providing too few params WHEN buildPath THEN IllegalArgumentException is thrown`() { // given - val testSubject = navRoute("testGraph", "testPath") { - param("param1") - path("foobar") - param("secondParam") - } + val testSubject = + navRoute("testGraph", "testPath") { + param("param1") + path("foobar") + param("secondParam") + } // when testSubject.buildPath("aaa") @@ -92,11 +95,12 @@ class NavRouteTest { @Test(expected = IllegalArgumentException::class) fun `GIVEN providing too many params WHEN buildPath THEN IllegalArgumentException is thrown`() { // given - val testSubject = navRoute("testGraph", "testPath") { - param("param1") - path("foobar") - param("secondParam") - } + val testSubject = + navRoute("testGraph", "testPath") { + param("param1") + path("foobar") + param("secondParam") + } // when testSubject.buildPath("aaa", "bbb", "ccc") diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavStackEntryTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavStackEntryTest.kt index 9dddaa9..ba72524 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavStackEntryTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/NavStackEntryTest.kt @@ -10,16 +10,16 @@ import org.junit.Before import org.junit.Test class NavStackEntryTest { - private val destination: NavDestination = mockk() - private val arguments = mutableMapOf( - "intArg" to "10", - "longArg" to "100000000", - "stringArg" to "asdf", - "floatArg" to "0.5", - "doubleArg" to "0.123", - "booleanArg" to "true" - ) + private val arguments = + mutableMapOf( + "intArg" to "10", + "longArg" to "100000000", + "stringArg" to "asdf", + "floatArg" to "0.5", + "doubleArg" to "0.123", + "booleanArg" to "true", + ) private val testSubject = NavStackEntry(destination, arguments) @@ -40,9 +40,10 @@ class NavStackEntryTest { @Test fun `GIVEN String argument is missing WHEN getString THEN NavArgumentMissingError is thrown`() { // when - val error = assertThrows(NavArgumentMissingError::class.java) { - testSubject.getString("missing") - } + val error = + assertThrows(NavArgumentMissingError::class.java) { + testSubject.getString("missing") + } // then assertEquals("Destination 'destinationString' did not receive value for argument with key 'missing'", error.message) @@ -60,9 +61,10 @@ class NavStackEntryTest { @Test fun `GIVEN Long argument is missing WHEN getLong THEN NavArgumentMissingError is thrown`() { // when - val error = assertThrows(NavArgumentMissingError::class.java) { - testSubject.getLong("missing") - } + val error = + assertThrows(NavArgumentMissingError::class.java) { + testSubject.getLong("missing") + } // then assertEquals("Destination 'destinationString' did not receive value for argument with key 'missing'", error.message) @@ -71,14 +73,15 @@ class NavStackEntryTest { @Test fun `GIVEN Reading non-numeric argument WHEN getLong THEN NavArgumentFormatInvalidError is thrown`() { // when - val error = assertThrows(NavArgumentFormatInvalidError::class.java) { - testSubject.getLong("stringArg") - } + val error = + assertThrows(NavArgumentFormatInvalidError::class.java) { + testSubject.getLong("stringArg") + } // then assertEquals( "Value 'asdf' of argument 'stringArg' in destination 'destinationString' could not be parsed to Long", - error.message + error.message, ) } @@ -94,9 +97,10 @@ class NavStackEntryTest { @Test fun `GIVEN Int argument is missing WHEN getInt THEN NavArgumentMissingError is thrown`() { // when - val error = assertThrows(NavArgumentMissingError::class.java) { - testSubject.getInt("missing") - } + val error = + assertThrows(NavArgumentMissingError::class.java) { + testSubject.getInt("missing") + } // then assertEquals("Destination 'destinationString' did not receive value for argument with key 'missing'", error.message) @@ -105,14 +109,15 @@ class NavStackEntryTest { @Test fun `GIVEN Reading non-numeric argument WHEN getInt THEN NavArgumentFormatInvalidError is thrown`() { // when - val error = assertThrows(NavArgumentFormatInvalidError::class.java) { - testSubject.getInt("stringArg") - } + val error = + assertThrows(NavArgumentFormatInvalidError::class.java) { + testSubject.getInt("stringArg") + } // then assertEquals( "Value 'asdf' of argument 'stringArg' in destination 'destinationString' could not be parsed to Int", - error.message + error.message, ) } @@ -128,9 +133,10 @@ class NavStackEntryTest { @Test fun `GIVEN Float argument is missing WHEN getFloat THEN NavArgumentMissingError is thrown`() { // when - val error = assertThrows(NavArgumentMissingError::class.java) { - testSubject.getFloat("missing") - } + val error = + assertThrows(NavArgumentMissingError::class.java) { + testSubject.getFloat("missing") + } // then assertEquals("Destination 'destinationString' did not receive value for argument with key 'missing'", error.message) @@ -139,14 +145,15 @@ class NavStackEntryTest { @Test fun `GIVEN Reading non-numeric argument WHEN getFloat THEN NavArgumentFormatInvalidError is thrown`() { // when - val error = assertThrows(NavArgumentFormatInvalidError::class.java) { - testSubject.getFloat("stringArg") - } + val error = + assertThrows(NavArgumentFormatInvalidError::class.java) { + testSubject.getFloat("stringArg") + } // then assertEquals( "Value 'asdf' of argument 'stringArg' in destination 'destinationString' could not be parsed to Float", - error.message + error.message, ) } @@ -162,9 +169,10 @@ class NavStackEntryTest { @Test fun `GIVEN Double argument is missing WHEN getDouble THEN NavArgumentMissingError is thrown`() { // when - val error = assertThrows(NavArgumentMissingError::class.java) { - testSubject.getDouble("missing") - } + val error = + assertThrows(NavArgumentMissingError::class.java) { + testSubject.getDouble("missing") + } // then assertEquals("Destination 'destinationString' did not receive value for argument with key 'missing'", error.message) @@ -173,14 +181,15 @@ class NavStackEntryTest { @Test fun `GIVEN Reading non-numeric argument WHEN getDouble THEN NavArgumentFormatInvalidError is thrown`() { // when - val error = assertThrows(NavArgumentFormatInvalidError::class.java) { - testSubject.getDouble("stringArg") - } + val error = + assertThrows(NavArgumentFormatInvalidError::class.java) { + testSubject.getDouble("stringArg") + } // then assertEquals( "Value 'asdf' of argument 'stringArg' in destination 'destinationString' could not be parsed to Double", - error.message + error.message, ) } @@ -196,9 +205,10 @@ class NavStackEntryTest { @Test fun `GIVEN Boolean argument is missing WHEN getDouble THEN NavArgumentMissingError is thrown`() { // when - val error = assertThrows(NavArgumentMissingError::class.java) { - testSubject.getBoolean("missing") - } + val error = + assertThrows(NavArgumentMissingError::class.java) { + testSubject.getBoolean("missing") + } // then assertEquals("Destination 'destinationString' did not receive value for argument with key 'missing'", error.message) @@ -207,14 +217,15 @@ class NavStackEntryTest { @Test fun `GIVEN Reading non-boolean argument WHEN getDouble THEN NavArgumentFormatInvalidError is thrown`() { // when - val error = assertThrows(NavArgumentFormatInvalidError::class.java) { - testSubject.getBoolean("stringArg") - } + val error = + assertThrows(NavArgumentFormatInvalidError::class.java) { + testSubject.getBoolean("stringArg") + } // then assertEquals( "Value 'asdf' of argument 'stringArg' in destination 'destinationString' could not be parsed to Boolean", - error.message + error.message, ) } } diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/ScreenDestinationTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/ScreenDestinationTest.kt index b486a79..6ffab67 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/destination/ScreenDestinationTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/destination/ScreenDestinationTest.kt @@ -6,7 +6,6 @@ import junit.framework.TestCase.assertEquals import org.junit.Test class ScreenDestinationTest { - private val graph: NavGraph = mockk() @Test diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentHistoryTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentHistoryTest.kt index aaa57e5..66b47da 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentHistoryTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentHistoryTest.kt @@ -6,15 +6,15 @@ import org.junit.Assert.assertThrows import org.junit.Test class NavIntentHistoryTest { - private val testSubject = NavIntentHistory(INITIAL_ACTION) @Test fun `GIVEN only single node preset WHEN adding intent with same name THEN NavIntentCycleDetectedError thrown`() { // when - val error = assertThrows(NavIntentCycleDetectedError::class.java) { - testSubject.addNode(NavIntent("initial")) - } + val error = + assertThrows(NavIntentCycleDetectedError::class.java) { + testSubject.addNode(NavIntent("initial")) + } // then assertEquals("initial -> initial", error.message) @@ -23,11 +23,12 @@ class NavIntentHistoryTest { @Test fun `GIVEN multiple nodes preset WHEN adding node creates cycle THEN NavIntentCycleDetectedError thrown`() { // when - val error = assertThrows(NavIntentCycleDetectedError::class.java) { - testSubject.addNode(NavIntent("second")) - testSubject.addNode(NavIntent("third")) - testSubject.addNode(NavIntent("second")) - } + val error = + assertThrows(NavIntentCycleDetectedError::class.java) { + testSubject.addNode(NavIntent("second")) + testSubject.addNode(NavIntent("third")) + testSubject.addNode(NavIntent("second")) + } // then assertEquals("initial -> second -> third -> second", error.message) diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManagerTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManagerTest.kt index 5933cd2..f866acc 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManagerTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentResolvingManagerTest.kt @@ -17,7 +17,6 @@ import org.junit.Test @OptIn(ExperimentalCoroutinesApi::class) class NavIntentResolvingManagerTest { - private val actionProducingResolver: NavIntentResolver = mockk() private val intentProducingResolver: NavIntentResolver = mockk() private val cycleProducingResolver: NavIntentResolver = mockk() @@ -38,29 +37,31 @@ class NavIntentResolvingManagerTest { } } coEvery { intentProducingResolver.resolve(capture(slot), any()) } coAnswers { - val mapped = if (slot.captured == firstIntent) { - secondIntent - } else if (slot.captured == secondIntent) { - thirdIntent - } else if (slot.captured == thirdIntent) { - actionProducingIntent - } else { - null - } + val mapped = + if (slot.captured == firstIntent) { + secondIntent + } else if (slot.captured == secondIntent) { + thirdIntent + } else if (slot.captured == thirdIntent) { + actionProducingIntent + } else { + null + } mapped?.let { ResolveResult.Intent(it) } ?: ResolveResult.None } coEvery { cycleProducingResolver.resolve(capture(slot), any()) } coAnswers { - val mapped = if (slot.captured == firstIntent) { - secondIntent - } else if (slot.captured == secondIntent) { - thirdIntent - } else if (slot.captured == thirdIntent) { - firstIntent - } else { - null - } + val mapped = + if (slot.captured == firstIntent) { + secondIntent + } else if (slot.captured == secondIntent) { + thirdIntent + } else if (slot.captured == thirdIntent) { + firstIntent + } else { + null + } mapped?.let { ResolveResult.Intent(it) } ?: ResolveResult.None @@ -68,79 +69,86 @@ class NavIntentResolvingManagerTest { } @Test - fun `GIVEN only one resolver registered WHEN resolve intent that directly produces action THEN action is returned`() = runTest { - // given - testSubject.register(listOf(actionProducingResolver)) + fun `GIVEN only one resolver registered WHEN resolve intent that directly produces action THEN action is returned`() = + runTest { + // given + testSubject.register(listOf(actionProducingResolver)) - // when - val obtained = testSubject.resolve(actionProducingIntent, navState) + // when + val obtained = testSubject.resolve(actionProducingIntent, navState) - // then - assertEquals(producedAction, obtained) - } + // then + assertEquals(producedAction, obtained) + } @Test - fun `GIVEN multiple resolvers registered WHEN resolve intent that directly produces action THEN action is returned`() = runTest { - // given - testSubject.register(listOf(intentProducingResolver, actionProducingResolver)) + fun `GIVEN multiple resolvers registered WHEN resolve intent that directly produces action THEN action is returned`() = + runTest { + // given + testSubject.register(listOf(intentProducingResolver, actionProducingResolver)) - // when - val obtained = testSubject.resolve(actionProducingIntent, navState) + // when + val obtained = testSubject.resolve(actionProducingIntent, navState) - // then - assertEquals(producedAction, obtained) - } + // then + assertEquals(producedAction, obtained) + } @Test - fun `GIVEN unknown intent WHEN resolve THEN null is returned`() = runTest { - // given - testSubject.register(listOf(intentProducingResolver, actionProducingResolver)) + fun `GIVEN unknown intent WHEN resolve THEN null is returned`() = + runTest { + // given + testSubject.register(listOf(intentProducingResolver, actionProducingResolver)) - // when - val obtained = testSubject.resolve(unknownIntent, navState) + // when + val obtained = testSubject.resolve(unknownIntent, navState) - // then - assertNull(obtained) - } + // then + assertNull(obtained) + } @Test - fun `GIVEN finding actions requires multiple resolves WHEN resolve THEN action is returned`() = runTest { - // given - testSubject.register(listOf(intentProducingResolver, actionProducingResolver)) + fun `GIVEN finding actions requires multiple resolves WHEN resolve THEN action is returned`() = + runTest { + // given + testSubject.register(listOf(intentProducingResolver, actionProducingResolver)) - // when - val obtained = testSubject.resolve(firstIntent, navState) + // when + val obtained = testSubject.resolve(firstIntent, navState) - // then - assertEquals(producedAction, obtained) - } + // then + assertEquals(producedAction, obtained) + } @Test(expected = NavIntentCycleDetectedError::class) - fun `GIVEN resolver produces cycle WHEN resolve THEN NavIntentCycleDetectedError thrown`() = runTest { - // given - testSubject.register(listOf(cycleProducingResolver)) + fun `GIVEN resolver produces cycle WHEN resolve THEN NavIntentCycleDetectedError thrown`() = + runTest { + // given + testSubject.register(listOf(cycleProducingResolver)) - // when - testSubject.resolve(firstIntent, navState) - } + // when + testSubject.resolve(firstIntent, navState) + } @Test(expected = NavIntentMappingTooDeepError::class) - fun `GIVEN too many mappings required WHEN resolve THEN NavIntentMappingTooDeepError thrown`() = runTest { - // given - val firstIntent = createChain(51) + fun `GIVEN too many mappings required WHEN resolve THEN NavIntentMappingTooDeepError thrown`() = + runTest { + // given + val firstIntent = createChain(51) - // when - testSubject.resolve(firstIntent, navState) - } + // when + testSubject.resolve(firstIntent, navState) + } @Test - fun `GIVEN mappings number just at the depth limit WHEN resolve THEN no error`() = runTest { - // given - val firstIntent = createChain(50) + fun `GIVEN mappings number just at the depth limit WHEN resolve THEN no error`() = + runTest { + // given + val firstIntent = createChain(50) - // when - testSubject.resolve(firstIntent, navState) - } + // when + testSubject.resolve(firstIntent, navState) + } private fun createChain(depth: Int): NavIntent { val firstIntent = NavIntent("0") diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentTest.kt index d3c2b04..69bc4ab 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/intent/NavIntentTest.kt @@ -4,7 +4,6 @@ import junit.framework.TestCase.assertEquals import org.junit.Test class NavIntentTest { - @Test fun `GIVEN nav intent has argument WHEN get THEN argument value is returned`() { // given diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/model/NavGatekeeperTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/model/NavGatekeeperTest.kt index 9b7882b..330caba 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/model/NavGatekeeperTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/model/NavGatekeeperTest.kt @@ -11,7 +11,6 @@ import junit.framework.TestCase.assertNull import org.junit.Test class NavGatekeeperTest { - @Test fun `GIVEN at least one verifier returns false WHEN isNavActionAllowed THEN returns false`() { // given diff --git a/composenav/src/test/java/com/adamkobus/compose/navigation/model/ReservedNamesHandlerTest.kt b/composenav/src/test/java/com/adamkobus/compose/navigation/model/ReservedNamesHandlerTest.kt index 7abe508..f624a24 100644 --- a/composenav/src/test/java/com/adamkobus/compose/navigation/model/ReservedNamesHandlerTest.kt +++ b/composenav/src/test/java/com/adamkobus/compose/navigation/model/ReservedNamesHandlerTest.kt @@ -5,7 +5,6 @@ import junit.framework.TestCase.assertTrue import org.junit.Test class ReservedNamesHandlerTest { - private val testSubject = ReservedNamesHandler() @Test diff --git a/demo-common-ui/build.gradle b/demo-common-ui/build.gradle index fd02d04..427b5c3 100644 --- a/demo-common-ui/build.gradle +++ b/demo-common-ui/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -15,24 +14,27 @@ dependencies { api project(':demo-core') api project(':composenav') - api Lib.AndroidX.Core - api Lib.AndroidX.Appcompat - api Lib.Kotlin.Coroutines - api Lib.AdamKobus.LifecycleAwareViewModel + api libs.androidx.core + api libs.androidx.appcompat + + api libs.kotlin.coroutines + api libs.ak.lifecycle.vm // hilt - implementation Lib.Google.Hilt - api Lib.Google.HiltNavigationCompose - kapt Lib.Google.HiltCompiler + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler // compose - api Lib.Compose.Ui - api Lib.Compose.Activity - api Lib.Compose.Material - api Lib.Compose.ToolingPreview - debugApi Lib.Compose.UiTooling + api platform(libs.compose.bom) + api libs.compose.ui + api libs.compose.activity + api libs.compose.material + api libs.compose.material3 + api libs.compose.tooling.preview + api libs.compose.hilt + debugApi libs.compose.tooling.ui // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/DemoAppBackground.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/DemoAppBackground.kt index 8c5772b..212c730 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/DemoAppBackground.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/DemoAppBackground.kt @@ -5,9 +5,9 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.material.LocalContentColor -import androidx.compose.material.MaterialTheme -import androidx.compose.material.contentColorFor +import androidx.compose.material3.LocalContentColor +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.contentColorFor import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier @@ -17,16 +17,17 @@ import com.adamkobus.compose.navigation.demo.ui.appbar.AppBarHeight @Composable fun DemoAppBackground( usesTopBar: Boolean = false, - content: @Composable BoxScope.() -> Unit + content: @Composable BoxScope.() -> Unit, ) { Box( - modifier = Modifier + modifier = + Modifier .fillMaxSize() - .background(MaterialTheme.colors.background) - .padding(top = if (usesTopBar) AppBarHeight else 0.dp) + .background(MaterialTheme.colorScheme.background) + .padding(top = if (usesTopBar) AppBarHeight else 0.dp), ) { CompositionLocalProvider( - LocalContentColor provides contentColorFor(backgroundColor = MaterialTheme.colors.background) + LocalContentColor provides contentColorFor(backgroundColor = MaterialTheme.colorScheme.background), ) { content() } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/Paddings.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/Paddings.kt index 7104586..9386e4e 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/Paddings.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/Paddings.kt @@ -8,10 +8,11 @@ object Paddings { val CardPadding = 14.dp val TabHostSpacing = 64.dp - val ScreenWithTabHostInsets = PaddingValues( - top = Screen, - start = Screen, - end = Screen, - bottom = TabHostSpacing - ) + val ScreenWithTabHostInsets = + PaddingValues( + top = Screen, + start = Screen, + end = Screen, + bottom = TabHostSpacing, + ) } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/PreviewComponent.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/PreviewComponent.kt index 7902db0..1804a30 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/PreviewComponent.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/PreviewComponent.kt @@ -1,13 +1,13 @@ package com.adamkobus.compose.navigation.demo.ui -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Surface +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import com.adamkobus.compose.navigation.demo.ui.theme.DemoTheme @Composable fun PreviewComponent(content: @Composable () -> Unit) { DemoTheme { - Surface(color = MaterialTheme.colors.background, content = content) + Surface(color = MaterialTheme.colorScheme.background, content = content) } } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBar.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBar.kt index 3208c93..a084542 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBar.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBar.kt @@ -17,15 +17,14 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.material.AppBarDefaults import androidx.compose.material.ContentAlpha -import androidx.compose.material.Icon -import androidx.compose.material.IconButton import androidx.compose.material.LocalContentAlpha -import androidx.compose.material.MaterialTheme -import androidx.compose.material.ProvideTextStyle -import androidx.compose.material.Surface -import androidx.compose.material.Text -import androidx.compose.material.contentColorFor -import androidx.compose.material.primarySurface +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ProvideTextStyle +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.material3.contentColorFor import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Alignment @@ -48,30 +47,31 @@ fun AnimatedAppBar() { @Composable private fun AnimatedAppBarContent( appBarState: AnimatedAppBarState, - backgroundColor: Color = MaterialTheme.colors.primarySurface, + backgroundColor: Color = MaterialTheme.colorScheme.primaryContainer, contentColor: Color = contentColorFor(backgroundColor), elevation: Dp = AppBarDefaults.TopAppBarElevation, contentPadding: PaddingValues = AppBarDefaults.ContentPadding, shape: Shape = RectangleShape, - height: Dp = AppBarHeight + height: Dp = AppBarHeight, ) { val targetBackground = animateColorAsState(targetValue = if (appBarState.isAnyContentAvailable) backgroundColor else Color.Transparent) val targetElevation = animateDpAsState(targetValue = if (appBarState.isAnyContentAvailable) elevation else 0.dp) Surface( color = targetBackground.value, contentColor = contentColor, - elevation = targetElevation.value, + shadowElevation = targetElevation.value, shape = shape, - modifier = Modifier + modifier = + Modifier .fillMaxWidth() - .height(height) + .height(height), ) { CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) { Box( Modifier .fillMaxSize() .padding(contentPadding), - contentAlignment = Alignment.CenterStart + contentAlignment = Alignment.CenterStart, ) { AnimatedAppBarInnerContent(appBarState) } @@ -84,14 +84,15 @@ private fun AnimatedAppBarInnerContent(appBarState: AnimatedAppBarState) { val titlePosition = animateDpAsState(targetValue = if (appBarState.iconState != null) TitleIconOffset else TitleNoIconOffset) Box( modifier = Modifier.fillMaxHeight(), - contentAlignment = Alignment.CenterStart + contentAlignment = Alignment.CenterStart, ) { IconContent(appBarState.iconState) Row( - modifier = Modifier + modifier = + Modifier .fillMaxSize() .padding(start = titlePosition.value), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { Box(modifier = Modifier.weight(1f)) { TitleContent(appBarState.titleState) @@ -103,9 +104,9 @@ private fun AnimatedAppBarInnerContent(appBarState: AnimatedAppBarState) { @Composable private fun TitleContent(titleState: AppBarTitleState?) { - ProvideTextStyle(value = MaterialTheme.typography.h6) { + ProvideTextStyle(value = MaterialTheme.typography.titleMedium) { CompositionLocalProvider( - LocalContentAlpha provides ContentAlpha.high + LocalContentAlpha provides ContentAlpha.high, ) { Crossfade(targetState = titleState?.getText() ?: "", modifier = Modifier.fillMaxWidth()) { text -> Text(text = text, modifier = Modifier.fillMaxWidth()) @@ -127,7 +128,7 @@ private fun IconContent(iconState: AppBarIconState?) { } else { Row(TitleIconModifier, verticalAlignment = Alignment.CenterVertically) { CompositionLocalProvider( - LocalContentAlpha provides ContentAlpha.high + LocalContentAlpha provides ContentAlpha.high, ) { AnimatedAppBarIcon(iconStateInner, onClick = onClickWrapper) } @@ -138,12 +139,15 @@ private fun IconContent(iconState: AppBarIconState?) { @OptIn(ExperimentalAnimationApi::class) @Composable -private fun ActionButtons(actionsList: List, clickable: Boolean) { +private fun ActionButtons( + actionsList: List, + clickable: Boolean, +) { CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) { Row( modifier = Modifier.fillMaxHeight(), horizontalArrangement = Arrangement.End, - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { actionsList.forEachIndexed { index, item -> val onClickWrapper = { @@ -160,14 +164,20 @@ private fun ActionButtons(actionsList: List, clickable: Boole } @Composable -fun ActionButtonContent(item: AppBarActionState, onClick: () -> Unit) { +fun ActionButtonContent( + item: AppBarActionState, + onClick: () -> Unit, +) { IconButton(onClick = onClick) { Icon(imageVector = item.icon, contentDescription = stringResource(id = item.contentDescriptionResId)) } } @Composable -private fun AnimatedAppBarIcon(iconState: AppBarIconState, onClick: () -> Unit) { +private fun AnimatedAppBarIcon( + iconState: AppBarIconState, + onClick: () -> Unit, +) { IconButton(onClick = onClick) { Icon(iconState.icon, iconState.contentDescriptionResId?.let { stringResource(id = it) }) } @@ -177,12 +187,14 @@ val AppBarHeight = 56.dp private val AppBarHorizontalPadding = 4.dp -private val TitleInsetWithoutIcon = Modifier - .width(16.dp - AppBarHorizontalPadding) +private val TitleInsetWithoutIcon = + Modifier + .width(16.dp - AppBarHorizontalPadding) -private val TitleIconModifier = Modifier - .fillMaxHeight() - .width(72.dp - AppBarHorizontalPadding) +private val TitleIconModifier = + Modifier + .fillMaxHeight() + .width(72.dp - AppBarHorizontalPadding) private val TitleNoIconOffset = 12.dp private val TitleIconOffset = 68.dp diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarDefaults.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarDefaults.kt index fac1a87..cf55834 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarDefaults.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarDefaults.kt @@ -1,5 +1,5 @@ package com.adamkobus.compose.navigation.demo.ui.appbar object AnimatedAppBarDefaults { - const val DefaultStyle = 0 + const val DEFAULT_STYLE = 0 } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarState.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarState.kt index 4191ae2..c460de8 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarState.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarState.kt @@ -2,28 +2,28 @@ package com.adamkobus.compose.navigation.demo.ui.appbar import androidx.annotation.StringRes import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.filled.Settings import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource -import com.adamkobus.compose.navigation.demo.ui.appbar.AnimatedAppBarDefaults.DefaultStyle +import com.adamkobus.compose.navigation.demo.ui.appbar.AnimatedAppBarDefaults.DEFAULT_STYLE import com.adamkobus.compose.navigation.demo.ui.common.R data class AnimatedAppBarState( val titleState: AppBarTitleState? = null, val iconState: AppBarIconState? = null, val actionsState: List = emptyList(), - val searchState: AppBarSearchState = AppBarSearchState() + val searchState: AppBarSearchState = AppBarSearchState(), ) { val isAnyContentAvailable: Boolean get() = titleState != null || iconState != null || actionsState.isNotEmpty() || searchState.isSearchEnabled } data class AppBarTitleState( - val style: Int = DefaultStyle, + val style: Int = DEFAULT_STYLE, @StringRes private val titleResId: Int? = null, - private val title: String? = null + private val title: String? = null, ) { override fun equals(other: Any?): Boolean { return other is AppBarTitleState && other.style == style && other.titleResId == titleResId && other.title == title @@ -46,7 +46,7 @@ class AppBarIconState( @StringRes val contentDescriptionResId: Int?, val onClick: (() -> Unit) = {}, val iconId: Int = nextIconId, - val style: Int = AnimatedAppBarDefaults.DefaultStyle + val style: Int = AnimatedAppBarDefaults.DEFAULT_STYLE, ) { override fun equals(other: Any?): Boolean { return other is AppBarIconState && other.iconId == iconId @@ -65,7 +65,11 @@ class AppBarIconState( } fun back(onClick: () -> Unit): AppBarIconState = - AppBarIconState(icon = Icons.Filled.ArrowBack, onClick = onClick, contentDescriptionResId = R.string.accessibility_back) + AppBarIconState( + icon = Icons.AutoMirrored.Filled.ArrowBack, + onClick = onClick, + contentDescriptionResId = R.string.accessibility_back, + ) } } @@ -73,9 +77,8 @@ class AppBarActionState( val actionId: Int = nextActionId, val icon: ImageVector, @StringRes val contentDescriptionResId: Int, - val onClick: (() -> Unit) + val onClick: (() -> Unit), ) { - override fun equals(other: Any?): Boolean { return other is AppBarActionState && other.actionId == actionId } @@ -100,5 +103,5 @@ class AppBarActionState( data class AppBarSearchState( val isSearchEnabled: Boolean = false, val currentText: String = "", - val onQueryChanged: ((String) -> Unit)? = null + val onQueryChanged: ((String) -> Unit)? = null, ) diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarVM.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarVM.kt index 2ea199d..a349725 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarVM.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/appbar/AnimatedAppBarVM.kt @@ -6,7 +6,7 @@ import javax.inject.Inject @HiltViewModel class AnimatedAppBarVM @Inject constructor( - appBarStateSource: AppBarStateSource + appBarStateSource: AppBarStateSource, ) : ViewModel() { val appBarState = appBarStateSource.appBarState } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModule.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModule.kt index 45b1d33..f17abdf 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModule.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModule.kt @@ -10,7 +10,6 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) @Module(includes = [NavModuleInternalBinds::class]) object NavModule { - @Provides fun provideNavigationStateSource(): NavigationStateSource = ComposeNavigation.getNavigationStateSource() } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModuleInternalBinds.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModuleInternalBinds.kt index adea43d..d0b6d8d 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModuleInternalBinds.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/NavModuleInternalBinds.kt @@ -11,7 +11,6 @@ import dagger.multibindings.IntoSet @InstallIn(SingletonComponent::class) @Module internal interface NavModuleInternalBinds { - @Binds @IntoSet fun providesStubNavGraphApplier(impl: StubNavGraphApplier): NavGraphApplier diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/UiModule.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/UiModule.kt index b564a71..dbd6951 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/UiModule.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/di/UiModule.kt @@ -11,7 +11,6 @@ import dagger.multibindings.IntoSet @InstallIn(SingletonComponent::class) @Module interface UiModule { - @Binds @IntoSet fun bindsAppBarOverlayProvider(impl: AppBarOverlayProvider): OverlayProvider diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/ext/LifecycleEventExt.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/ext/LifecycleEventExt.kt index f9e6edc..155218a 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/ext/LifecycleEventExt.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/ext/LifecycleEventExt.kt @@ -2,7 +2,10 @@ package com.adamkobus.compose.navigation.demo.ui.ext import androidx.lifecycle.Lifecycle -fun Lifecycle.Event.onStartStop(onStart: () -> Unit, onStop: () -> Unit) { +fun Lifecycle.Event.onStartStop( + onStart: () -> Unit, + onStop: () -> Unit, +) { if (this == Lifecycle.Event.ON_START) { onStart() } else if (this == Lifecycle.Event.ON_STOP) { diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/loading/LoadingScreen.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/loading/LoadingScreen.kt index 48a1511..b6a16f4 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/loading/LoadingScreen.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/loading/LoadingScreen.kt @@ -2,7 +2,7 @@ package com.adamkobus.compose.navigation.demo.ui.loading import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material.CircularProgressIndicator +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/Actions.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/Actions.kt index 3db647e..a0ffe72 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/Actions.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/Actions.kt @@ -6,10 +6,11 @@ import com.adamkobus.compose.navigation.action.navActionOptions sealed class FromSplash(action: NavAction) : NavActionWrapper(action) { object ToWelcome : FromSplash( - AppGraph.SplashScreen goTo OnBoardingGraph withOptions navActionOptions { - popUpTo(AppRootGraph) - launchSingleTop = true - } + AppGraph.SplashScreen goTo OnBoardingGraph withOptions + navActionOptions { + popUpTo(AppRootGraph) + launchSingleTop = true + }, ) } @@ -19,22 +20,24 @@ sealed class FromWelcome(action: NavAction) : NavActionWrapper(action) { .setNavOptions { popUpTo(AppRootGraph) launchSingleTop = true - } + }, ) object ToDogsList : FromWelcome( - OnBoardingGraph.WelcomeScreen goTo DogsBrowserGraph withOptions navActionOptions { - popUpTo(AppRootGraph) - launchSingleTop = true - } + OnBoardingGraph.WelcomeScreen goTo DogsBrowserGraph withOptions + navActionOptions { + popUpTo(AppRootGraph) + launchSingleTop = true + }, ) } sealed class FromCatsList(action: NavAction) : NavActionWrapper(action) { class ToCatDetails(catId: Int) : FromCatsList( - CatsBrowserGraph.CatsList goTo CatsBrowserGraph.CatDetails arg catId withOptions navActionOptions { - popUpTo(CatsBrowserGraph.CatsList) - } + CatsBrowserGraph.CatsList goTo CatsBrowserGraph.CatDetails arg catId withOptions + navActionOptions { + popUpTo(CatsBrowserGraph.CatsList) + }, ) object ToSettings : FromCatsList(CatsBrowserGraph.CatsList goTo SettingsGraph) @@ -46,12 +49,15 @@ sealed class FromCatDetails(action: NavAction) : NavActionWrapper(action) { sealed class FromDogsList(action: NavAction) : NavActionWrapper(action) { class ToDogDetails(dogId: Int) : FromDogsList(DogsBrowserGraph.DogsList goTo DogsBrowserGraph.DogDetails arg dogId) + object ToSettings : FromDogsList(DogsBrowserGraph.DogsList goTo SettingsGraph) } sealed class FromDogDetails(action: NavAction) : NavActionWrapper(action) { object Back : FromDogDetails(DogsBrowserGraph.DogDetails.pop()) + object ToDemoDialog : FromDogDetails(DogsBrowserGraph.DogDetails goTo DogsBrowserGraph.DemoDialog) + class ToGallery(dogId: Int) : FromDogDetails(DogsBrowserGraph.DogDetails goTo DogsBrowserGraph.DogGallery arg dogId) } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/ApplyNavGraphsTask.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/ApplyNavGraphsTask.kt index 99884f1..06d790a 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/ApplyNavGraphsTask.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/ApplyNavGraphsTask.kt @@ -5,7 +5,7 @@ import androidx.navigation.NavGraphBuilder import javax.inject.Inject class ApplyNavGraphsTask @Inject constructor( - private val graphs: Set<@JvmSuppressWildcards NavGraphApplier> + private val graphs: Set<@JvmSuppressWildcards NavGraphApplier>, ) { @OptIn(ExperimentalAnimationApi::class) fun apply(builder: NavGraphBuilder) { diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/CatsBrowserGraph.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/CatsBrowserGraph.kt index 76ea0f2..c126107 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/CatsBrowserGraph.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/CatsBrowserGraph.kt @@ -10,9 +10,10 @@ object CatsBrowserGraph : NavGraph("cats") { override fun startDestination(): ScreenDestination = CatsList val CatsList = screenDestination("catsList") - val CatDetails = CatsList.next { - param(PARAM_CAT_ID) - } + val CatDetails = + CatsList.next { + param(PARAM_CAT_ID) + } } fun NavStackEntry.catId() = getInt(CatsBrowserGraph.PARAM_CAT_ID) diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/DogsBrowserGraph.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/DogsBrowserGraph.kt index c2df379..8f0d707 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/DogsBrowserGraph.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/nav/DogsBrowserGraph.kt @@ -10,13 +10,15 @@ object DogsBrowserGraph : NavGraph("dogs") { override fun startDestination(): ScreenDestination = DogsList val DogsList = screenDestination("dogsList") - val DogDetails = DogsList.next { - param(PARAM_DOG_ID) - } + val DogDetails = + DogsList.next { + param(PARAM_DOG_ID) + } val DemoDialog = dialogDestination("demoDialog") - val DogGallery = DogDetails.next { - path("gallery") - } + val DogGallery = + DogDetails.next { + path("gallery") + } } fun NavStackEntry.dogId() = getInt(DogsBrowserGraph.PARAM_DOG_ID) diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppBarOverlayProvider.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppBarOverlayProvider.kt index 7788f78..bce785c 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppBarOverlayProvider.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppBarOverlayProvider.kt @@ -7,9 +7,10 @@ import javax.inject.Inject class AppBarOverlayProvider @Inject constructor() : OverlayProvider { @Composable - override fun provideOverlay(): @Composable BoxScope.() -> Unit = { - AnimatedAppBar() - } + override fun provideOverlay(): @Composable BoxScope.() -> Unit = + { + AnimatedAppBar() + } override val priority: Int get() = PRIORITY diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppOverlays.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppOverlays.kt index daa24cc..40fde1b 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppOverlays.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/overlay/AppOverlays.kt @@ -3,7 +3,7 @@ package com.adamkobus.compose.navigation.demo.ui.overlay import javax.inject.Inject class AppOverlays @Inject constructor( - private val providersSet: Set<@JvmSuppressWildcards OverlayProvider> + private val providersSet: Set<@JvmSuppressWildcards OverlayProvider>, ) { val providers: List get() = providersSet.sortedBy { it.priority } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/DemoTheme.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/DemoTheme.kt index 92560c4..c56a00f 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/DemoTheme.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/DemoTheme.kt @@ -2,8 +2,8 @@ package com.adamkobus.compose.navigation.demo.ui.theme -import androidx.compose.material.MaterialTheme -import androidx.compose.material.lightColors +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color @@ -13,21 +13,22 @@ private val Primary = Color(0xFF35B6B6) private val PrimaryVariant = Color(0xFF5CD1D1) private val Background = Color(0xFFEEEEEE) -private val DemoPalette = lightColors( - primary = Primary, - primaryVariant = PrimaryVariant, - onPrimary = Color.Black, - secondary = Teal200, - surface = Color.White, - background = Background -) +private val DemoPalette = + lightColorScheme( + primary = Primary, + primaryContainer = PrimaryVariant, + onPrimary = Color.Black, + secondary = Teal200, + surface = Color.White, + background = Background, + ) @Composable fun DemoTheme(content: @Composable () -> Unit) { MaterialTheme( - colors = DemoPalette, + colorScheme = DemoPalette, typography = Typography, shapes = Shapes, - content = content + content = content, ) } diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Shape.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Shape.kt index b305b42..f266ebd 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Shape.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Shape.kt @@ -1,11 +1,12 @@ package com.adamkobus.compose.navigation.demo.ui.theme import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Shapes +import androidx.compose.material3.Shapes import androidx.compose.ui.unit.dp -internal val Shapes = Shapes( - small = RoundedCornerShape(4.dp), - medium = RoundedCornerShape(4.dp), - large = RoundedCornerShape(0.dp) -) +internal val Shapes = + Shapes( + small = RoundedCornerShape(4.dp), + medium = RoundedCornerShape(4.dp), + large = RoundedCornerShape(0.dp), + ) diff --git a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Type.kt b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Type.kt index 8c2a957..73e0f2f 100644 --- a/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Type.kt +++ b/demo-common-ui/src/main/java/com/adamkobus/compose/navigation/demo/ui/theme/Type.kt @@ -1,20 +1,23 @@ package com.adamkobus.compose.navigation.demo.ui.theme -import androidx.compose.material.Typography +import androidx.compose.material3.Typography import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp -internal val Typography = Typography( - body1 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 16.sp - ), - h2 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.SemiBold, - fontSize = 24.sp +internal val Typography = + Typography( + bodyLarge = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + ), + titleMedium = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.SemiBold, + fontSize = 24.sp, + ), ) -) diff --git a/demo-core/build.gradle b/demo-core/build.gradle index 1f1454b..88e35ba 100644 --- a/demo-core/build.gradle +++ b/demo-core/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -12,16 +11,18 @@ android { } dependencies { - api Lib.AndroidX.Core - api Lib.AndroidX.Appcompat - api Lib.Kotlin.Coroutines + api libs.androidx.core + api libs.androidx.appcompat + api libs.kotlin.coroutines // hilt - implementation Lib.Google.Hilt - api Lib.Google.HiltNavigationCompose - kapt Lib.Google.HiltCompiler + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler + + // compose + api libs.compose.hilt // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } diff --git a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/CatInfo.kt b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/CatInfo.kt index 5af1f87..575bfd9 100644 --- a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/CatInfo.kt +++ b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/CatInfo.kt @@ -2,5 +2,5 @@ package com.adamkobus.compose.navigation.democore.data data class CatInfo( val id: Int, - val name: String + val name: String, ) diff --git a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/DogInfo.kt b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/DogInfo.kt index 495e137..fb3bc82 100644 --- a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/DogInfo.kt +++ b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/data/DogInfo.kt @@ -2,5 +2,5 @@ package com.adamkobus.compose.navigation.democore.data data class DogInfo( val id: Int, - val name: String + val name: String, ) diff --git a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/CatsSource.kt b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/CatsSource.kt index 12c7c4e..03ce2af 100644 --- a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/CatsSource.kt +++ b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/CatsSource.kt @@ -19,15 +19,14 @@ class CatsSource @Inject constructor() { suspend fun getCat(id: Int): CatInfo { delay(MOCK_DELAY) - if (Random.nextBoolean()) { - return data.value.find { it.id == id } ?: throw IllegalArgumentException("Cat with id $id does not exist") - } else { - throw IllegalArgumentException("Failed to load cat info for id $id") + val isSuccess = Random.nextBoolean() + require(isSuccess) { + "Failed to load cat info for id $id" } + return data.value.find { it.id == id } ?: throw IllegalArgumentException("Cat with id $id does not exist") } - private fun createData() = - generateSequence(0) { it + 1 }.take(MOCKED_DATA_SIZE).map { CatInfo(it, "Cat $it") }.toList() + private fun createData() = generateSequence(0) { it + 1 }.take(MOCKED_DATA_SIZE).map { CatInfo(it, "Cat $it") }.toList() companion object { private const val MOCK_DELAY = 500L diff --git a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/DogsSource.kt b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/DogsSource.kt index 855d2b6..9cfe471 100644 --- a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/DogsSource.kt +++ b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/model/DogsSource.kt @@ -21,8 +21,7 @@ class DogsSource @Inject constructor() { return data.value.find { it.id == id } ?: throw IllegalArgumentException("Dog with id $id does not exist") } - private fun createData() = - generateSequence(0) { it + 1 }.take(MOCKED_DATA_SIZE).map { DogInfo(it, "Dog $it") }.toList() + private fun createData() = generateSequence(0) { it + 1 }.take(MOCKED_DATA_SIZE).map { DogInfo(it, "Dog $it") }.toList() companion object { private const val MOCK_DELAY = 500L diff --git a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/util/AsyncData.kt b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/util/AsyncData.kt index 08139b9..da9c586 100644 --- a/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/util/AsyncData.kt +++ b/demo-core/src/main/java/com/adamkobus/compose/navigation/democore/util/AsyncData.kt @@ -2,6 +2,8 @@ package com.adamkobus.compose.navigation.democore.util sealed class AsyncData { class Loading : AsyncData() + class Present(val data: T) : AsyncData() + class Missing(val error: E? = null) : AsyncData() } diff --git a/demo-devmenu/build.gradle b/demo-devmenu/build.gradle index d49faf3..7ca1c99 100644 --- a/demo-devmenu/build.gradle +++ b/demo-devmenu/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -14,14 +13,11 @@ android { dependencies { implementation project(':demo-common-ui') - // compose - implementation Lib.Accompanist.NavigationAnimation - // hilt - implementation Lib.Google.Hilt - kapt Lib.Google.HiltCompiler + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/di/DevMenuModuleInternalBinds.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/di/DevMenuModuleInternalBinds.kt index 45963ab..494c28f 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/di/DevMenuModuleInternalBinds.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/di/DevMenuModuleInternalBinds.kt @@ -14,7 +14,6 @@ import dagger.multibindings.IntoSet @InstallIn(SingletonComponent::class) @Module internal interface DevMenuModuleInternalBinds { - @Binds @IntoSet fun bindsDevMenuNavIntentResolver(impl: DevMenuNavIntentResolver): NavIntentResolver diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuNavIntentResolver.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuNavIntentResolver.kt index 716e0b6..2d02f34 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuNavIntentResolver.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuNavIntentResolver.kt @@ -9,14 +9,20 @@ import com.adamkobus.compose.navigation.intent.ResolveResult import javax.inject.Inject internal class DevMenuNavIntentResolver @Inject constructor() : NavIntentResolver { - override suspend fun resolve(intent: NavIntent, navState: NavState): ResolveResult = + override suspend fun resolve( + intent: NavIntent, + navState: NavState, + ): ResolveResult = when (intent.name) { DemoIntents.OPEN_DEV_MENU -> openDevMenu(intent, navState) DemoIntents.CLOSE_DEV_MENU -> closeDevMenu(navState) else -> ResolveResult.None } - private fun openDevMenu(intent: NavIntent, navState: NavState): ResolveResult { + private fun openDevMenu( + intent: NavIntent, + navState: NavState, + ): ResolveResult { if (navState.isInBackStack(DevMenuRootGraph)) return ResolveResult.None return intent.navigationId?.let { @@ -24,9 +30,11 @@ internal class DevMenuNavIntentResolver @Inject constructor() : NavIntentResolve }?.takeIf { !it.isInBackStack(DevMenuRootGraph) }?.currentDestination?.destination?.let { - val action = it goTo DevMenuRootGraph withOptions navActionOptions { - launchSingleTop = true - } + val action = + it goTo DevMenuRootGraph withOptions + navActionOptions { + launchSingleTop = true + } return action.asResult() } ?: ResolveResult.None } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuRootGraph.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuRootGraph.kt index db2cf31..52dfb0b 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuRootGraph.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/DevMenuRootGraph.kt @@ -8,7 +8,6 @@ import com.adamkobus.compose.navigation.ext.composableDestination import com.adamkobus.compose.navigation.ext.composableNavigation internal object DevMenuRootGraph : NavGraph("devMenuRoot") { - override fun startDestination() = Root val Root = screenDestination("root") diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuInfoGraph.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuInfoGraph.kt index 60266a6..77c2424 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuInfoGraph.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuInfoGraph.kt @@ -8,7 +8,6 @@ import com.adamkobus.compose.navigation.ext.composableDestination import com.adamkobus.compose.navigation.ext.composableNavigation internal object DevMenuInfoGraph : NavGraph("devMenuInfo") { - override fun startDestination() = Home val Home = screenDestination("home") diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuSettingsGraph.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuSettingsGraph.kt index f362ddd..a368d0d 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuSettingsGraph.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuSettingsGraph.kt @@ -8,7 +8,6 @@ import com.adamkobus.compose.navigation.ext.composableDestination import com.adamkobus.compose.navigation.ext.composableNavigation internal object DevMenuSettingsGraph : NavGraph("devMenuSettings") { - override fun startDestination() = Home val Home = screenDestination("home") diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuTabHostIntentResolver.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuTabHostIntentResolver.kt index 79159c3..bb34d10 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuTabHostIntentResolver.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/nav/tabhost/DevMenuTabHostIntentResolver.kt @@ -6,10 +6,11 @@ import com.adamkobus.compose.navigation.demo.devmenu.nav.DevMenuGraph import javax.inject.Inject internal class DevMenuTabHostIntentResolver @Inject constructor() : TabBarIntentResolver( - tabsMapping = mapOf( + tabsMapping = + mapOf( DevMenuTabHostIntents.OpenInfo.name to DevMenuInfoGraph, - DevMenuTabHostIntents.OpenSettings.name to DevMenuSettingsGraph + DevMenuTabHostIntents.OpenSettings.name to DevMenuSettingsGraph, ), tabStateSavingBehaviour = TabStateSavingBehaviour.SAVE_ALL, - tabsRootGraph = DevMenuGraph + tabsRootGraph = DevMenuGraph, ) diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/theme/DevMenuTheme.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/theme/DevMenuTheme.kt index 0630f2b..06fe833 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/theme/DevMenuTheme.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/theme/DevMenuTheme.kt @@ -1,10 +1,10 @@ package com.adamkobus.compose.navigation.demo.devmenu.theme import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Shapes -import androidx.compose.material.Typography -import androidx.compose.material.darkColors +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Shapes +import androidx.compose.material3.Typography +import androidx.compose.material3.darkColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.TextStyle @@ -13,43 +13,48 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -private val DevMenuColors = darkColors( - primary = Color.DarkGray, - primaryVariant = Color.DarkGray, - onPrimary = Color.White, - secondary = Color.DarkGray, - onSecondary = Color.White, - surface = Color.DarkGray, - onSurface = Color.White, - background = Color.DarkGray, - onBackground = Color.White -) +private val DevMenuColors = + darkColorScheme( + primary = Color.DarkGray, + primaryContainer = Color.DarkGray, + onPrimary = Color.White, + secondary = Color.DarkGray, + onSecondary = Color.White, + surface = Color.DarkGray, + onSurface = Color.White, + background = Color.DarkGray, + onBackground = Color.White, + ) -private val Shapes = Shapes( - small = RoundedCornerShape(4.dp), - medium = RoundedCornerShape(4.dp), - large = RoundedCornerShape(0.dp) -) +private val Shapes = + Shapes( + small = RoundedCornerShape(4.dp), + medium = RoundedCornerShape(4.dp), + large = RoundedCornerShape(0.dp), + ) -private val Typography = Typography( - body1 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 16.sp - ), - h2 = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.SemiBold, - fontSize = 24.sp +private val Typography = + Typography( + bodyLarge = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + ), + titleMedium = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.SemiBold, + fontSize = 24.sp, + ), ) -) @Composable internal fun DevMenuTheme(content: @Composable () -> Unit) { MaterialTheme( - colors = DevMenuColors, + colorScheme = DevMenuColors, typography = Typography, shapes = Shapes, - content = content + content = content, ) } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/DevMenuPaddings.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/DevMenuPaddings.kt index 17ba502..9f2feab 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/DevMenuPaddings.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/DevMenuPaddings.kt @@ -7,10 +7,11 @@ internal object DevMenuPaddings { val Screen = 16.dp val TabHostSpacing = 64.dp - val InsetsWithTabHost = PaddingValues( - start = Screen, - end = Screen, - top = Screen, - bottom = TabHostSpacing - ) + val InsetsWithTabHost = + PaddingValues( + start = Screen, + end = Screen, + top = Screen, + bottom = TabHostSpacing, + ) } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/info/home/InfoHome.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/info/home/InfoHome.kt index 441cb4d..bd30ac5 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/info/home/InfoHome.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/info/home/InfoHome.kt @@ -2,7 +2,7 @@ package com.adamkobus.compose.navigation.demo.devmenu.ui.info.home import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding -import androidx.compose.material.Text +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.adamkobus.compose.navigation.demo.devmenu.ui.DevMenuPaddings diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRoot.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRoot.kt index 89b0900..9b545ec 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRoot.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRoot.kt @@ -8,6 +8,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController +import androidx.navigation.compose.rememberNavController import com.adamkobus.compose.navigation.ComposeNavHost import com.adamkobus.compose.navigation.demo.devmenu.nav.DevMenuGraph import com.adamkobus.compose.navigation.demo.devmenu.nav.DevMenuNavId @@ -16,14 +17,13 @@ import com.adamkobus.compose.navigation.demo.devmenu.theme.DevMenuTheme import com.adamkobus.compose.navigation.demo.devmenu.ui.tabhost.DevMenuTabHost import com.adamkobus.compose.navigation.demo.ui.DemoAppBackground import com.adamkobus.compose.navigation.demo.ui.LifecycleAwareComponent -import com.google.accompanist.navigation.animation.rememberAnimatedNavController @OptIn(ExperimentalAnimationApi::class) @Composable internal fun DevMenuRoot() { val vm: DevMenuRootVM = hiltViewModel() LifecycleAwareComponent(observer = vm) - val controller = rememberAnimatedNavController() + val controller = rememberNavController() DevMenuRootContent(controller = controller) BackHandler(onBack = vm.interactions.onBackPressed) } @@ -36,14 +36,15 @@ private fun DevMenuRootContent(controller: NavHostController) { ComposeNavHost( startGraph = DevMenuGraph, controller = controller, - navigationId = DevMenuNavId + navigationId = DevMenuNavId, ) { devMenuGraph() } DevMenuTabHost( - modifier = Modifier + modifier = + Modifier .align(Alignment.BottomCenter) - .fillMaxWidth() + .fillMaxWidth(), ) } } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootInteractions.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootInteractions.kt index 4fe1116..8f88929 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootInteractions.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootInteractions.kt @@ -1,5 +1,5 @@ package com.adamkobus.compose.navigation.demo.devmenu.ui.root internal data class DevMenuRootInteractions( - val onBackPressed: () -> Unit + val onBackPressed: () -> Unit, ) diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootVM.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootVM.kt index 5e43507..4fa6885 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootVM.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/root/DevMenuRootVM.kt @@ -12,14 +12,14 @@ import javax.inject.Inject @HiltViewModel internal class DevMenuRootVM @Inject constructor( private val appBarStateSource: AppBarStateSource, - private val navigationConsumer: NavigationConsumer + private val navigationConsumer: NavigationConsumer, ) : LifecycleAwareViewModel() { - - val interactions = DevMenuRootInteractions( - onBackPressed = { - navigationConsumer.offer(NavIntent(DemoIntents.CLOSE_DEV_MENU)) - } - ) + val interactions = + DevMenuRootInteractions( + onBackPressed = { + navigationConsumer.offer(NavIntent(DemoIntents.CLOSE_DEV_MENU)) + }, + ) init { runOnStart { diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHome.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHome.kt index 324a1c9..5cc9c3b 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHome.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHome.kt @@ -5,8 +5,8 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.material.Button -import androidx.compose.material.Text +import androidx.compose.material3.Button +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @@ -21,19 +21,18 @@ internal fun SettingsHome() { } @Composable -private fun SettingsHomeContent( - interactions: SettingsHomeInteractions = SettingsHomeInteractions.STUB -) { +private fun SettingsHomeContent(interactions: SettingsHomeInteractions = SettingsHomeInteractions.STUB) { DemoAppBackground { Column(modifier = Modifier.padding(DevMenuPaddings.InsetsWithTabHost)) { Text( - text = "Button below will invoke intent that will be translated into action that has " + - "different source and target nav controllers, but action will still succeed" + text = + "Button below will invoke intent that will be translated into action that has " + + "different source and target nav controllers, but action will still succeed", ) Spacer(modifier = Modifier.height(60.dp)) Button( onClick = interactions.onRestartAppClicked, - modifier = Modifier.fillMaxWidth() + modifier = Modifier.fillMaxWidth(), ) { Text(text = "Restart app") } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeInteractions.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeInteractions.kt index 98369d4..590aeaf 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeInteractions.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeInteractions.kt @@ -1,11 +1,12 @@ package com.adamkobus.compose.navigation.demo.devmenu.ui.settings.home internal data class SettingsHomeInteractions( - val onRestartAppClicked: () -> Unit + val onRestartAppClicked: () -> Unit, ) { companion object { - val STUB = SettingsHomeInteractions( - onRestartAppClicked = {} - ) + val STUB = + SettingsHomeInteractions( + onRestartAppClicked = {}, + ) } } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeVM.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeVM.kt index 478237d..ecc78f6 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeVM.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/settings/home/SettingsHomeVM.kt @@ -9,12 +9,12 @@ import javax.inject.Inject @HiltViewModel internal class SettingsHomeVM @Inject constructor( - private val navigationConsumer: NavigationConsumer + private val navigationConsumer: NavigationConsumer, ) : LifecycleAwareViewModel() { - - val interactions = SettingsHomeInteractions( - onRestartAppClicked = { - navigationConsumer.offer(DemoIntents.restartApp(origin = DevMenuSettingsGraph.Home)) - } - ) + val interactions = + SettingsHomeInteractions( + onRestartAppClicked = { + navigationConsumer.offer(DemoIntents.restartApp(origin = DevMenuSettingsGraph.Home)) + }, + ) } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabData.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabData.kt index 7a4db43..b21085e 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabData.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabData.kt @@ -5,10 +5,8 @@ import androidx.annotation.StringRes internal data class DevMenuTabData( val index: Int, - @DrawableRes val iconResId: Int, - @StringRes - val titleResId: Int + val titleResId: Int, ) diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHost.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHost.kt index f0884a3..718d2ec 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHost.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHost.kt @@ -3,10 +3,10 @@ package com.adamkobus.compose.navigation.demo.devmenu.ui.tabhost import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material.Icon -import androidx.compose.material.LeadingIconTab -import androidx.compose.material.TabRow -import androidx.compose.material.Text +import androidx.compose.material3.Icon +import androidx.compose.material3.LeadingIconTab +import androidx.compose.material3.TabRow +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier @@ -29,7 +29,7 @@ internal fun DevMenuTabHost(modifier: Modifier) { private fun DevMenuTabHostContent( modifier: Modifier, state: DevMenuTabHostState = DevMenuTabHostState.stub(), - interactions: DevMenuTabHostInteractions = DevMenuTabHostInteractions.STUB + interactions: DevMenuTabHostInteractions = DevMenuTabHostInteractions.STUB, ) { Box(modifier = modifier) { Crossfade(targetState = state.isVisible.value) { renderedIsVisible -> @@ -47,19 +47,22 @@ private fun EmptyTabHost() { } @Composable -private fun TabHost(state: DevMenuTabHostState, onTabSelected: (DevMenuTabData) -> Unit) { +private fun TabHost( + state: DevMenuTabHostState, + onTabSelected: (DevMenuTabData) -> Unit, +) { val selectedIndex = state.selectedIndex.value val items = state.tabs.value val scope = rememberCoroutineScope() TabRow( - selectedTabIndex = selectedIndex + selectedTabIndex = selectedIndex, ) { items.forEachIndexed { index, tab -> LeadingIconTab( icon = { Icon( painter = painterResource(id = tab.iconResId), - contentDescription = null + contentDescription = null, ) }, text = { @@ -70,7 +73,7 @@ private fun TabHost(state: DevMenuTabHostState, onTabSelected: (DevMenuTabData) scope.launch { onTabSelected(tab) } - } + }, ) } } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostInteractions.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostInteractions.kt index 980a590..a4c4ef0 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostInteractions.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostInteractions.kt @@ -1,11 +1,12 @@ package com.adamkobus.compose.navigation.demo.devmenu.ui.tabhost internal data class DevMenuTabHostInteractions( - val onTabSelected: (DevMenuTabData) -> Unit + val onTabSelected: (DevMenuTabData) -> Unit, ) { companion object { - val STUB = DevMenuTabHostInteractions( - onTabSelected = {} - ) + val STUB = + DevMenuTabHostInteractions( + onTabSelected = {}, + ) } } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostState.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostState.kt index 3bc163e..5ddf99a 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostState.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostState.kt @@ -6,20 +6,21 @@ import androidx.compose.runtime.mutableStateOf internal data class DevMenuTabHostState( val isVisible: State, val tabs: State>, - val selectedIndex: State + val selectedIndex: State, ) { companion object { fun stub( isVisible: Boolean = true, - tabs: List = listOf( - DevMenuTabs.Info, - DevMenuTabs.Settings - ), - selectedIndex: Int = 0 + tabs: List = + listOf( + DevMenuTabs.Info, + DevMenuTabs.Settings, + ), + selectedIndex: Int = 0, ) = DevMenuTabHostState( isVisible = mutableStateOf(isVisible), tabs = mutableStateOf(tabs), - selectedIndex = mutableStateOf(selectedIndex) + selectedIndex = mutableStateOf(selectedIndex), ) } } diff --git a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostVM.kt b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostVM.kt index a4fd3b4..838e6d2 100644 --- a/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostVM.kt +++ b/demo-devmenu/src/main/java/com/adamkobus/compose/navigation/demo/devmenu/ui/tabhost/DevMenuTabHostVM.kt @@ -15,28 +15,30 @@ import javax.inject.Inject @HiltViewModel internal class DevMenuTabHostVM @Inject constructor( private val navigationStateSource: NavigationStateSource, - private val navigationConsumer: NavigationConsumer + private val navigationConsumer: NavigationConsumer, ) : LifecycleAwareViewModel() { - private val isVisible = mutableStateOf(false) private val selectedIndex = mutableStateOf(0) - private val tabs = mutableStateOf( - listOf( - DevMenuTabs.Info, - DevMenuTabs.Settings + private val tabs = + mutableStateOf( + listOf( + DevMenuTabs.Info, + DevMenuTabs.Settings, + ), + ) + val state = + DevMenuTabHostState( + tabs = tabs, + isVisible = isVisible, + selectedIndex = selectedIndex, ) - ) - val state = DevMenuTabHostState( - tabs = tabs, - isVisible = isVisible, - selectedIndex = selectedIndex - ) - val interactions = DevMenuTabHostInteractions( - onTabSelected = { - processTabSelection(it) - } - ) + val interactions = + DevMenuTabHostInteractions( + onTabSelected = { + processTabSelection(it) + }, + ) init { runOnStart { diff --git a/demo-ui-cats-browser/build.gradle b/demo-ui-cats-browser/build.gradle index 642b254..d9e99e3 100644 --- a/demo-ui-cats-browser/build.gradle +++ b/demo-ui-cats-browser/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -15,10 +14,10 @@ dependencies { implementation project(':demo-common-ui') // hilt - implementation Lib.Google.Hilt - kapt Lib.Google.HiltCompiler + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } diff --git a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreen.kt b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreen.kt index 42c1f52..96b9040 100644 --- a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreen.kt +++ b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreen.kt @@ -6,8 +6,8 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -46,13 +46,14 @@ private fun CatDetailsScreenContent(screenState: CatDetailsScreenState) { @Composable private fun CatDetails(catInfo: CatInfo) { Column(modifier = Modifier.padding(Paddings.Screen)) { - Text(text = catInfo.name, style = MaterialTheme.typography.h2) + Text(text = catInfo.name, style = MaterialTheme.typography.titleMedium) Spacer(modifier = Modifier.height(24.dp)) val currentDestination = LocalNavDestination.current val isCatDetails = currentDestination == CatsBrowserGraph.CatDetails Text( - text = "Current destination: $currentDestination\n" + - "isCatDetailsDestination: $isCatDetails" + text = + "Current destination: $currentDestination\n" + + "isCatDetailsDestination: $isCatDetails", ) } } @@ -60,10 +61,11 @@ private fun CatDetails(catInfo: CatInfo) { @Composable private fun CatError() { Box( - modifier = Modifier + modifier = + Modifier .fillMaxSize() - .padding(Paddings.Screen) + .padding(Paddings.Screen), ) { - Text(text = stringResource(id = R.string.cat_details_error), style = MaterialTheme.typography.h2, color = Color.Red) + Text(text = stringResource(id = R.string.cat_details_error), style = MaterialTheme.typography.titleMedium, color = Color.Red) } } diff --git a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenState.kt b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenState.kt index c28fccd..031b1b8 100644 --- a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenState.kt +++ b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenState.kt @@ -5,5 +5,5 @@ import com.adamkobus.compose.navigation.democore.data.CatInfo import com.adamkobus.compose.navigation.democore.util.AsyncData data class CatDetailsScreenState( - val catInfo: State> + val catInfo: State>, ) diff --git a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenVM.kt b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenVM.kt index a16fe3b..b75f319 100644 --- a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenVM.kt +++ b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catdetails/CatDetailsScreenVM.kt @@ -22,20 +22,21 @@ import javax.inject.Inject class CatDetailsScreenVM @Inject constructor( private val catsSource: CatsSource, private val navigationConsumer: NavigationConsumer, - private val appBarStateSource: AppBarStateSource + private val appBarStateSource: AppBarStateSource, ) : LifecycleAwareViewModel() { - val catIdParam = ViewParam() private val catInfo = mutableStateOf>(AsyncData.Loading()) - val screenState = CatDetailsScreenState( - catInfo = catInfo - ) + val screenState = + CatDetailsScreenState( + catInfo = catInfo, + ) - private val appBarState = AnimatedAppBarState( - titleState = AppBarTitleState(titleResId = R.string.cat_details_title), - iconState = AppBarIconState.back { onBackPressed() } - ) + private val appBarState = + AnimatedAppBarState( + titleState = AppBarTitleState(titleResId = R.string.cat_details_title), + iconState = AppBarIconState.back { onBackPressed() }, + ) private fun onBackPressed() { navigationConsumer.offer(CatsBrowserGraph.CatDetails.pop()) diff --git a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListInteractions.kt b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListInteractions.kt index da4964b..9d1c224 100644 --- a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListInteractions.kt +++ b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListInteractions.kt @@ -3,5 +3,5 @@ package com.adamkobus.compose.navigation.demo.ui.catslist import com.adamkobus.compose.navigation.democore.data.CatInfo data class CatsListInteractions( - val onCatListItemSelected: (CatInfo) -> Unit = {} + val onCatListItemSelected: (CatInfo) -> Unit = {}, ) diff --git a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreen.kt b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreen.kt index 70b0c9f..fb3501e 100644 --- a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreen.kt +++ b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreen.kt @@ -8,8 +8,9 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.material.Card -import androidx.compose.material.Text +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @@ -32,7 +33,7 @@ fun CatsListScreen() { @Composable private fun CatsListScreenContent( state: CatsListScreenState, - interactions: CatsListInteractions + interactions: CatsListInteractions, ) { when (state.isLoading.value) { true -> LoadingScreen() @@ -43,13 +44,13 @@ private fun CatsListScreenContent( @Composable private fun CatsListContent( state: CatsListScreenState, - onCatListItemSelected: (CatInfo) -> Unit + onCatListItemSelected: (CatInfo) -> Unit, ) { val data = state.catsList.value LazyColumn( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(10.dp), - contentPadding = Paddings.ScreenWithTabHostInsets + contentPadding = Paddings.ScreenWithTabHostInsets, ) { items(data, key = { it.id }) { catInfo -> CatListItem(catInfo = catInfo, onCatListItemSelected) @@ -58,14 +59,18 @@ private fun CatsListContent( } @Composable -private fun CatListItem(catInfo: CatInfo, onCatListItemSelected: (CatInfo) -> Unit) { +private fun CatListItem( + catInfo: CatInfo, + onCatListItemSelected: (CatInfo) -> Unit, +) { Card( - modifier = Modifier + modifier = + Modifier .fillMaxWidth() .clickable { onCatListItemSelected(catInfo) }, - elevation = 4.dp + elevation = CardDefaults.elevatedCardElevation(), ) { Column(modifier = Modifier.padding(Paddings.CardPadding)) { Text(text = catInfo.name) diff --git a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenState.kt b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenState.kt index e3ed205..a0bd287 100644 --- a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenState.kt +++ b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenState.kt @@ -5,5 +5,5 @@ import com.adamkobus.compose.navigation.democore.data.CatInfo data class CatsListScreenState( val isLoading: State, - val catsList: State> + val catsList: State>, ) diff --git a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenVM.kt b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenVM.kt index b0389bd..dfe72f8 100644 --- a/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenVM.kt +++ b/demo-ui-cats-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/catslist/CatsListScreenVM.kt @@ -20,31 +20,34 @@ import javax.inject.Inject class CatsListScreenVM @Inject constructor( private val navigationConsumer: NavigationConsumer, private val appBarStateSource: AppBarStateSource, - private val catsSource: CatsSource + private val catsSource: CatsSource, ) : LifecycleAwareViewModel() { - private val isLoading = mutableStateOf(true) private val catsList = mutableStateOf>(emptyList()) - val screenState = CatsListScreenState( - isLoading = isLoading, - catsList = catsList - ) + val screenState = + CatsListScreenState( + isLoading = isLoading, + catsList = catsList, + ) - val interactions = CatsListInteractions( - onCatListItemSelected = { - navigationConsumer.offer(FromCatsList.ToCatDetails(it.id)) - } - ) + val interactions = + CatsListInteractions( + onCatListItemSelected = { + navigationConsumer.offer(FromCatsList.ToCatDetails(it.id)) + }, + ) - private val settingsAction = AppBarActionState.settings { - viewModelScope.launch { - navigationConsumer.offer(FromCatsList.ToSettings) + private val settingsAction = + AppBarActionState.settings { + viewModelScope.launch { + navigationConsumer.offer(FromCatsList.ToSettings) + } } - } - private val appBarState = AnimatedAppBarState( - titleState = AppBarTitleState(titleResId = R.string.cats_list_title), - actionsState = listOf(settingsAction) - ) + private val appBarState = + AnimatedAppBarState( + titleState = AppBarTitleState(titleResId = R.string.cats_list_title), + actionsState = listOf(settingsAction), + ) init { runOnStart { diff --git a/demo-ui-dogs-browser/build.gradle b/demo-ui-dogs-browser/build.gradle index c394161..208bd71 100644 --- a/demo-ui-dogs-browser/build.gradle +++ b/demo-ui-dogs-browser/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -15,10 +14,10 @@ dependencies { implementation project(':demo-common-ui') // hilt - implementation Lib.Google.Hilt - kapt Lib.Google.HiltCompiler + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialog.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialog.kt index 79c3f79..da8df42 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialog.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialog.kt @@ -7,9 +7,9 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.widthIn -import androidx.compose.material.Button -import androidx.compose.material.Card -import androidx.compose.material.Text +import androidx.compose.material3.Button +import androidx.compose.material3.Card +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -31,7 +31,7 @@ fun DemoDialog() { private fun DemoDialogContent(onCancelClicked: () -> Unit) { Box( modifier = Modifier.padding(vertical = Paddings.Screen), - contentAlignment = Alignment.Center + contentAlignment = Alignment.Center, ) { Card(modifier = Modifier.widthIn(0.dp, 350.dp)) { DialogCardContent(onCancelClicked) @@ -42,9 +42,10 @@ private fun DemoDialogContent(onCancelClicked: () -> Unit) { @Composable private fun DialogCardContent(onCancelClicked: () -> Unit) { Column( - modifier = Modifier + modifier = + Modifier .fillMaxWidth() - .padding(Paddings.Screen) + .padding(Paddings.Screen), ) { Text(text = stringResource(id = R.string.demo_dialog_text)) Spacer(modifier = Modifier.height(24.dp)) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogInteractions.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogInteractions.kt index 64f7c05..88c952a 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogInteractions.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogInteractions.kt @@ -1,5 +1,5 @@ package com.adamkobus.compose.navigation.demo.ui.demodialog data class DemoDialogInteractions( - val onCancelClicked: () -> Unit = {} + val onCancelClicked: () -> Unit = {}, ) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogVM.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogVM.kt index e4be3b9..2f2ab94 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogVM.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/demodialog/DemoDialogVM.kt @@ -10,14 +10,14 @@ import javax.inject.Inject @HiltViewModel class DemoDialogVM @Inject constructor( - private val navigationConsumer: NavigationConsumer + private val navigationConsumer: NavigationConsumer, ) : ViewModel() { - - val interactions = DemoDialogInteractions( - onCancelClicked = { - viewModelScope.launch { - navigationConsumer.offer(FromDemoDialog.Dismiss) - } - } - ) + val interactions = + DemoDialogInteractions( + onCancelClicked = { + viewModelScope.launch { + navigationConsumer.offer(FromDemoDialog.Dismiss) + } + }, + ) } diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreen.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreen.kt index 5c1a403..2f58b02 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreen.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreen.kt @@ -7,9 +7,9 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.material.Button -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -35,7 +35,7 @@ fun DogDetailsScreen(dogId: Int) { @Composable private fun DogDetailsScreenContent( screenState: DogDetailsScreenState, - interactions: DogDetailsScreenInteractions + interactions: DogDetailsScreenInteractions, ) { DemoAppBackground(usesTopBar = true) { when (val dogInfo = screenState.dogInfo.value) { @@ -47,9 +47,12 @@ private fun DogDetailsScreenContent( } @Composable -private fun DogDetails(dogInfo: DogInfo, interactions: DogDetailsScreenInteractions) { +private fun DogDetails( + dogInfo: DogInfo, + interactions: DogDetailsScreenInteractions, +) { Column(modifier = Modifier.padding(Paddings.Screen)) { - Text(text = dogInfo.name, style = MaterialTheme.typography.h2) + Text(text = dogInfo.name, style = MaterialTheme.typography.titleMedium) Spacer(modifier = Modifier.height(60.dp)) Button(onClick = interactions.onOpenDialogClicked, modifier = Modifier.fillMaxWidth()) { Text(text = stringResource(id = R.string.dog_details_open_dialog_button)) @@ -64,10 +67,11 @@ private fun DogDetails(dogInfo: DogInfo, interactions: DogDetailsScreenInteracti @Composable private fun DogError() { Box( - modifier = Modifier + modifier = + Modifier .fillMaxSize() - .padding(Paddings.Screen) + .padding(Paddings.Screen), ) { - Text(text = stringResource(id = R.string.dog_details_error), style = MaterialTheme.typography.h2, color = Color.Red) + Text(text = stringResource(id = R.string.dog_details_error), style = MaterialTheme.typography.titleMedium, color = Color.Red) } } diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenInteractions.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenInteractions.kt index 4b7998c..1231740 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenInteractions.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenInteractions.kt @@ -2,5 +2,5 @@ package com.adamkobus.compose.navigation.demo.ui.dogdetails data class DogDetailsScreenInteractions( val onOpenDialogClicked: () -> Unit = {}, - val onOpenGalleryClicked: () -> Unit = {} + val onOpenGalleryClicked: () -> Unit = {}, ) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenState.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenState.kt index 7c0e469..9d1b335 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenState.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenState.kt @@ -5,5 +5,5 @@ import com.adamkobus.compose.navigation.democore.data.DogInfo import com.adamkobus.compose.navigation.democore.util.AsyncData data class DogDetailsScreenState( - val dogInfo: State> + val dogInfo: State>, ) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenVM.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenVM.kt index 8ac7985..426fafc 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenVM.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogdetails/DogDetailsScreenVM.kt @@ -24,34 +24,36 @@ import javax.inject.Inject class DogDetailsScreenVM @Inject constructor( private val dogsSource: DogsSource, private val appBarStateSource: AppBarStateSource, - private val navigationConsumer: NavigationConsumer + private val navigationConsumer: NavigationConsumer, ) : LifecycleAwareViewModel() { - val dogIdParam = ViewParam() private val dogInfo = mutableStateOf>(AsyncData.Loading()) - val screenState = DogDetailsScreenState( - dogInfo = dogInfo - ) + val screenState = + DogDetailsScreenState( + dogInfo = dogInfo, + ) - val interactions = DogDetailsScreenInteractions( - onOpenDialogClicked = { - viewModelScope.launch { - navigationConsumer.offer(FromDogDetails.ToDemoDialog) - } - }, - onOpenGalleryClicked = { - viewModelScope.launch { - val id = dogIdParam.observe().first() - navigationConsumer.offer(FromDogDetails.ToGallery(id)) - } - } - ) + val interactions = + DogDetailsScreenInteractions( + onOpenDialogClicked = { + viewModelScope.launch { + navigationConsumer.offer(FromDogDetails.ToDemoDialog) + } + }, + onOpenGalleryClicked = { + viewModelScope.launch { + val id = dogIdParam.observe().first() + navigationConsumer.offer(FromDogDetails.ToGallery(id)) + } + }, + ) - private val appBarState = AnimatedAppBarState( - titleState = AppBarTitleState(titleResId = R.string.dog_details_title), - iconState = AppBarIconState.back { onBackPressed() } - ) + private val appBarState = + AnimatedAppBarState( + titleState = AppBarTitleState(titleResId = R.string.dog_details_title), + iconState = AppBarIconState.back { onBackPressed() }, + ) private fun onBackPressed() { navigationConsumer.offer(DogsBrowserGraph.DogDetails.pop()) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreen.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreen.kt index eb417ce..e3fd13d 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreen.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreen.kt @@ -3,8 +3,8 @@ package com.adamkobus.compose.navigation.demo.ui.doggallery import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.material.Button -import androidx.compose.material.Text +import androidx.compose.material3.Button +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -33,9 +33,10 @@ private fun DogGalleryScreenContent(interactions: DogGalleryScreenInteractions) @Composable fun InnerContent(interactions: DogGalleryScreenInteractions) { Box( - modifier = Modifier + modifier = + Modifier .fillMaxSize() - .padding(Paddings.ScreenWithTabHostInsets) + .padding(Paddings.ScreenWithTabHostInsets), ) { Button(onClick = interactions.onBackToListClicked, modifier = Modifier.align(Alignment.BottomCenter)) { Text(text = stringResource(id = R.string.dog_gallery_back_to_list_button)) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenInteractions.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenInteractions.kt index 3e97817..f07d4c2 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenInteractions.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenInteractions.kt @@ -1,5 +1,5 @@ package com.adamkobus.compose.navigation.demo.ui.doggallery data class DogGalleryScreenInteractions( - val onBackToListClicked: () -> Unit + val onBackToListClicked: () -> Unit, ) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenVM.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenVM.kt index 4338044..8d93c80 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenVM.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/doggallery/DogGalleryScreenVM.kt @@ -18,21 +18,22 @@ import javax.inject.Inject @HiltViewModel class DogGalleryScreenVM @Inject constructor( private val navigationConsumer: NavigationConsumer, - private val topBarState: AppBarStateSource + private val topBarState: AppBarStateSource, ) : LifecycleAwareViewModel() { - val dogId = ViewParam() - private val appBarState = AnimatedAppBarState( - titleState = AppBarTitleState(titleResId = R.string.dog_gallery_title), - iconState = AppBarIconState.back { onBackPressed() } - ) + private val appBarState = + AnimatedAppBarState( + titleState = AppBarTitleState(titleResId = R.string.dog_gallery_title), + iconState = AppBarIconState.back { onBackPressed() }, + ) - val interactions = DogGalleryScreenInteractions( - onBackToListClicked = { - navigationConsumer.offer(FromDogsGallery.ToList) - } - ) + val interactions = + DogGalleryScreenInteractions( + onBackToListClicked = { + navigationConsumer.offer(FromDogsGallery.ToList) + }, + ) init { runOnStart { diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListInteractions.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListInteractions.kt index dda19f5..7ba9fe6 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListInteractions.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListInteractions.kt @@ -3,5 +3,5 @@ package com.adamkobus.compose.navigation.demo.ui.dogslist import com.adamkobus.compose.navigation.democore.data.DogInfo data class DogsListInteractions( - val onDogsItemSelected: (DogInfo) -> Unit = {} + val onDogsItemSelected: (DogInfo) -> Unit = {}, ) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreen.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreen.kt index 04a93f3..257d9a4 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreen.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreen.kt @@ -8,8 +8,9 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.material.Card -import androidx.compose.material.Text +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @@ -33,7 +34,7 @@ fun DogsListScreen() { @Composable private fun DogsListScreenContent( state: DogsListScreenState, - interactions: DogsListInteractions + interactions: DogsListInteractions, ) { when (state.isLoading.value) { true -> LoadingScreen() @@ -42,12 +43,15 @@ private fun DogsListScreenContent( } @Composable -private fun DogsListContent(state: DogsListScreenState, onDogsItemSelected: (DogInfo) -> Unit) { +private fun DogsListContent( + state: DogsListScreenState, + onDogsItemSelected: (DogInfo) -> Unit, +) { val data = state.dogsList.value LazyColumn( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.spacedBy(10.dp), - contentPadding = Paddings.ScreenWithTabHostInsets + contentPadding = Paddings.ScreenWithTabHostInsets, ) { items(data, key = { it.id }) { dogInfo -> DogListItem(dogInfo = dogInfo, onDogsItemSelected) @@ -56,14 +60,18 @@ private fun DogsListContent(state: DogsListScreenState, onDogsItemSelected: (Dog } @Composable -private fun DogListItem(dogInfo: DogInfo, onDogsItemSelected: (DogInfo) -> Unit) { +private fun DogListItem( + dogInfo: DogInfo, + onDogsItemSelected: (DogInfo) -> Unit, +) { Card( - modifier = Modifier + modifier = + Modifier .fillMaxWidth() .clickable { onDogsItemSelected(dogInfo) }, - elevation = Elevation.AppBar + elevation = CardDefaults.elevatedCardElevation(Elevation.AppBar), ) { Column(modifier = Modifier.padding(Paddings.CardPadding)) { Text(text = dogInfo.name) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenState.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenState.kt index 4c40fff..010c563 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenState.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenState.kt @@ -5,5 +5,5 @@ import com.adamkobus.compose.navigation.democore.data.DogInfo data class DogsListScreenState( val isLoading: State, - val dogsList: State> + val dogsList: State>, ) diff --git a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenVM.kt b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenVM.kt index df9fc78..5efb787 100644 --- a/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenVM.kt +++ b/demo-ui-dogs-browser/src/main/java/com/adamkobus/compose/navigation/demo/ui/dogslist/DogsListScreenVM.kt @@ -20,34 +20,37 @@ import javax.inject.Inject class DogsListScreenVM @Inject constructor( private val navigationConsumer: NavigationConsumer, private val appBarStateSource: AppBarStateSource, - private val dogsSource: DogsSource + private val dogsSource: DogsSource, ) : LifecycleAwareViewModel() { - private val isLoading = mutableStateOf(true) private val dogsList = mutableStateOf>(emptyList()) - val screenState = DogsListScreenState( - isLoading = isLoading, - dogsList = dogsList - ) + val screenState = + DogsListScreenState( + isLoading = isLoading, + dogsList = dogsList, + ) + + val interactions = + DogsListInteractions( + onDogsItemSelected = { + viewModelScope.launch { + navigationConsumer.offer(FromDogsList.ToDogDetails(it.id)) + } + }, + ) - val interactions = DogsListInteractions( - onDogsItemSelected = { + private val settingsAction = + AppBarActionState.settings { viewModelScope.launch { - navigationConsumer.offer(FromDogsList.ToDogDetails(it.id)) + navigationConsumer.offer(FromDogsList.ToSettings) } } - ) - - private val settingsAction = AppBarActionState.settings { - viewModelScope.launch { - navigationConsumer.offer(FromDogsList.ToSettings) - } - } - private val appBarState = AnimatedAppBarState( - titleState = AppBarTitleState(titleResId = R.string.dogs_list_title), - actionsState = listOf(settingsAction) - ) + private val appBarState = + AnimatedAppBarState( + titleState = AppBarTitleState(titleResId = R.string.dogs_list_title), + actionsState = listOf(settingsAction), + ) init { runOnStart { diff --git a/demo-ui-on-boarding/build.gradle b/demo-ui-on-boarding/build.gradle index 2f81219..e02a81d 100644 --- a/demo-ui-on-boarding/build.gradle +++ b/demo-ui-on-boarding/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -15,10 +14,10 @@ dependencies { implementation project(':demo-common-ui') // hilt - implementation Lib.Google.Hilt - kapt Lib.Google.HiltCompiler + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } diff --git a/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreen.kt b/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreen.kt index a8215f4..49bf8fe 100644 --- a/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreen.kt +++ b/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreen.kt @@ -7,9 +7,9 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.material.Button -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -33,17 +33,18 @@ fun WelcomeScreen() { fun WelcomeScreenContent(interactions: WelcomeScreenInteractions) { DemoAppBackground { Box( - modifier = Modifier + modifier = + Modifier .padding(Paddings.Screen) .fillMaxSize(), - contentAlignment = Alignment.Center + contentAlignment = Alignment.Center, ) { Column { Text( modifier = Modifier.fillMaxWidth(), text = stringResource(id = R.string.welcome_hi), textAlign = TextAlign.Center, - style = MaterialTheme.typography.h2 + style = MaterialTheme.typography.titleMedium, ) Spacer(modifier = Modifier.height(90.dp)) WelcomeScreenButton(stringResource(id = R.string.welcome_button_cats), onClick = interactions.onCatsSelected) @@ -55,7 +56,10 @@ fun WelcomeScreenContent(interactions: WelcomeScreenInteractions) { } @Composable -private fun WelcomeScreenButton(text: String, onClick: () -> Unit) { +private fun WelcomeScreenButton( + text: String, + onClick: () -> Unit, +) { Button(modifier = Modifier.fillMaxWidth(), onClick = onClick) { Text(text = text) } diff --git a/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenInteractions.kt b/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenInteractions.kt index 10d79cd..9b1a6e9 100644 --- a/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenInteractions.kt +++ b/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenInteractions.kt @@ -2,5 +2,5 @@ package com.adamkobus.compose.navigation.demo.ui.welcome data class WelcomeScreenInteractions( val onDogsSelected: () -> Unit = {}, - val onCatsSelected: () -> Unit = {} + val onCatsSelected: () -> Unit = {}, ) diff --git a/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenVM.kt b/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenVM.kt index ee413c6..c8d076b 100644 --- a/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenVM.kt +++ b/demo-ui-on-boarding/src/main/java/com/adamkobus/compose/navigation/demo/ui/welcome/WelcomeScreenVM.kt @@ -11,17 +11,17 @@ import javax.inject.Inject @HiltViewModel class WelcomeScreenVM @Inject constructor( private val navigationConsumer: NavigationConsumer, - private val appBarStateSource: AppBarStateSource + private val appBarStateSource: AppBarStateSource, ) : LifecycleAwareViewModel() { - - val interactions = WelcomeScreenInteractions( - onDogsSelected = { - navigationConsumer.offer(FromWelcome.ToDogsList) - }, - onCatsSelected = { - navigationConsumer.offer(FromWelcome.ToCatsList) - } - ) + val interactions = + WelcomeScreenInteractions( + onDogsSelected = { + navigationConsumer.offer(FromWelcome.ToDogsList) + }, + onCatsSelected = { + navigationConsumer.offer(FromWelcome.ToCatsList) + }, + ) private val appBatState = AnimatedAppBarState() diff --git a/demo-ui-settings/build.gradle b/demo-ui-settings/build.gradle index 2f38baa..03a318b 100644 --- a/demo-ui-settings/build.gradle +++ b/demo-ui-settings/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -15,10 +14,10 @@ dependencies { implementation project(':demo-common-ui') // hilt - implementation Lib.Google.Hilt - kapt Lib.Google.HiltCompiler + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } diff --git a/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/HomeScreenVM.kt b/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/HomeScreenVM.kt index b20f69b..22995e3 100644 --- a/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/HomeScreenVM.kt +++ b/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/HomeScreenVM.kt @@ -14,13 +14,13 @@ import javax.inject.Inject @HiltViewModel internal class HomeScreenVM @Inject constructor( private val navigationConsumer: NavigationConsumer, - private val appBarStateSource: AppBarStateSource + private val appBarStateSource: AppBarStateSource, ) : LifecycleAwareViewModel() { - - private val appBarState = AnimatedAppBarState( - titleState = AppBarTitleState(titleResId = R.string.settings_title), - iconState = AppBarIconState.back { onBackClicked() } - ) + private val appBarState = + AnimatedAppBarState( + titleState = AppBarTitleState(titleResId = R.string.settings_title), + iconState = AppBarIconState.back { onBackClicked() }, + ) init { runOnStart { diff --git a/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/SettingsHomeScreen.kt b/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/SettingsHomeScreen.kt index 7e15a9e..8e437d0 100644 --- a/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/SettingsHomeScreen.kt +++ b/demo-ui-settings/src/main/java/com/adamkobus/compose/navigation/demo/settings/ui/home/SettingsHomeScreen.kt @@ -5,8 +5,8 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -29,11 +29,12 @@ internal fun SettingsHomeScreen() { @Composable fun HomeScreenContent() { Column( - modifier = Modifier + modifier = + Modifier .fillMaxSize() - .padding(Paddings.Screen) + .padding(Paddings.Screen), ) { - Text(text = stringResource(id = R.string.settings_title), style = MaterialTheme.typography.h5) + Text(text = stringResource(id = R.string.settings_title), style = MaterialTheme.typography.titleSmall) Spacer(modifier = Modifier.height(30.dp)) Text(text = stringResource(id = R.string.settings_dev_menu_info)) } diff --git a/demo/build.gradle b/demo/build.gradle index 6ddb6f0..e97acc8 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,10 +1,9 @@ -import com.adamkobus.compose.navigation.Lib - plugins { - id 'com.android.application' - id 'kotlin-android' - id 'kotlin-kapt' - id 'dagger.hilt.android.plugin' + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.ksp) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.compose) } android { @@ -25,16 +24,13 @@ dependencies { debugImplementation project(':demo-devmenu') - implementation Lib.Google.Material + implementation libs.compose.material3 // hilt - implementation Lib.Google.Hilt - kapt Lib.Google.HiltCompiler - - // compose - implementation Lib.Accompanist.NavigationAnimation + implementation libs.google.hilt.core + ksp libs.google.hilt.compiler // testing - testImplementation Lib.Test.JUnit - testImplementation Lib.Test.Mockk + testImplementation libs.test.junit + testImplementation libs.test.mockk } \ No newline at end of file diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml index 84b31ec..e5bbe53 100644 --- a/demo/src/main/AndroidManifest.xml +++ b/demo/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ android:name=".MainActivity" android:exported="true" android:label="@string/app_name" - android:theme="@style/Theme.ComposeNavigation.NoActionBar"> + android:theme="@style/Theme.ComposeNavigation"> diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/app/DemoApp.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/app/DemoApp.kt index e51f35f..1c2b31c 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/app/DemoApp.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/app/DemoApp.kt @@ -10,7 +10,6 @@ import javax.inject.Inject @HiltAndroidApp class DemoApp : Application() { - @Inject lateinit var intentResolvers: Set<@JvmSuppressWildcards NavIntentResolver> diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/AppModuleBinds.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/AppModuleBinds.kt index de5fca1..14c8b99 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/AppModuleBinds.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/AppModuleBinds.kt @@ -17,7 +17,6 @@ import dagger.multibindings.IntoSet @InstallIn(SingletonComponent::class) @Module interface AppModuleBinds { - @Binds @IntoSet fun bindsAppNavActionVerifier(impl: AppNavActionVerifier): NavActionVerifier diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/NavigationModule.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/NavigationModule.kt index 39713a9..a9b029a 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/NavigationModule.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/di/NavigationModule.kt @@ -10,7 +10,6 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) @Module object NavigationModule { - @Provides fun providesNavigationConsumer(): NavigationConsumer = ComposeNavigation.getNavigationConsumer() } diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/AppNavActionVerifier.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/AppNavActionVerifier.kt index b7927f1..d553705 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/AppNavActionVerifier.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/AppNavActionVerifier.kt @@ -7,7 +7,10 @@ import com.adamkobus.compose.navigation.destination.GlobalGraph import com.adamkobus.compose.navigation.destination.NavState object AppNavActionVerifier : NavActionVerifier { - override fun isNavActionAllowed(navState: NavState, action: NavAction): VerifyResult { + override fun isNavActionAllowed( + navState: NavState, + action: NavAction, + ): VerifyResult { if (action.fromDestination.graph == GlobalGraph) return VerifyResult.Allow return if (navState.isCurrent(action.fromDestination)) { VerifyResult.Allow diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/RestartAppNavIntentResolver.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/RestartAppNavIntentResolver.kt index 6e10414..814ff01 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/RestartAppNavIntentResolver.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/RestartAppNavIntentResolver.kt @@ -10,11 +10,15 @@ import com.adamkobus.compose.navigation.intent.ResolveResult import javax.inject.Inject class RestartAppNavIntentResolver @Inject constructor() : NavIntentResolver { - override suspend fun resolve(intent: NavIntent, navState: NavState): ResolveResult = + override suspend fun resolve( + intent: NavIntent, + navState: NavState, + ): ResolveResult = intent.takeIf { it.name == DemoIntents.RESTART_APP }?.origin?.let { - val action = it.goTo(AppGraph.SplashScreen).setNavOptions { - popUpTo(AppRootGraph) - } + val action = + it.goTo(AppGraph.SplashScreen).setNavOptions { + popUpTo(AppRootGraph) + } action.asResult() } ?: ResolveResult.None } diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/tabhost/DemoTabBarIntentResolver.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/tabhost/DemoTabBarIntentResolver.kt index 848f56d..bea0fe6 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/tabhost/DemoTabBarIntentResolver.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/nav/tabhost/DemoTabBarIntentResolver.kt @@ -11,8 +11,8 @@ import javax.inject.Inject class DemoTabBarIntentResolver @Inject constructor() : TabBarIntentResolver( mapOf( DemoIntents.OpenDogsBrowser.name to DogsBrowserGraph, - DemoIntents.OpenCatsBrowser.name to CatsBrowserGraph + DemoIntents.OpenCatsBrowser.name to CatsBrowserGraph, ), AppRootGraph, - tabStateSavingBehaviour = TabStateSavingBehaviour.SAVE_START_DESTINATION + tabStateSavingBehaviour = TabStateSavingBehaviour.SAVE_START_DESTINATION, ) diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/DevMenuLauncherOverlayProvider.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/DevMenuLauncherOverlayProvider.kt index 665c3d8..86c07de 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/DevMenuLauncherOverlayProvider.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/DevMenuLauncherOverlayProvider.kt @@ -18,11 +18,11 @@ import com.adamkobus.compose.navigation.intent.NavIntent import javax.inject.Inject class DevMenuLauncherOverlayProvider @Inject constructor() : OverlayProvider { - @Composable - override fun provideOverlay(): @Composable BoxScope.() -> Unit = { - Launcher() - } + override fun provideOverlay(): @Composable BoxScope.() -> Unit = + { + Launcher() + } override val priority: Int get() = PRIORITY @@ -35,7 +35,8 @@ class DevMenuLauncherOverlayProvider @Inject constructor() : OverlayProvider { @Composable private fun BoxScope.Launcher() { Box( - modifier = Modifier + modifier = + Modifier .height(56.dp) .fillMaxWidth(LAUNCHER_WIDTH_FACTOR) .align(Alignment.TopCenter) @@ -45,9 +46,9 @@ private fun BoxScope.Launcher() { ComposeNavigation .getNavigationConsumer() .offer(NavIntent(DemoIntents.OPEN_DEV_MENU, navigationId = DemoNavigationId)) - } + }, ) - } + }, ) } diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRoot.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRoot.kt index a1539c2..af56ded 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRoot.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRoot.kt @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.hilt.navigation.compose.hiltViewModel +import androidx.navigation.compose.rememberNavController import com.adamkobus.compose.navigation.ComposeNavHost import com.adamkobus.compose.navigation.demo.nav.appGraph import com.adamkobus.compose.navigation.demo.nav.onBoardingGraph @@ -16,19 +17,18 @@ import com.adamkobus.compose.navigation.demo.ui.nav.AppRootGraph import com.adamkobus.compose.navigation.demo.ui.nav.DemoNavigationId import com.adamkobus.compose.navigation.demo.ui.overlay.AppOverlays import com.adamkobus.compose.navigation.ext.composableNavigation -import com.google.accompanist.navigation.animation.rememberAnimatedNavController @OptIn(ExperimentalAnimationApi::class) @Composable fun DemoAppRoot() { val vm = hiltViewModel() - val controller = rememberAnimatedNavController() + val controller = rememberNavController() Box(modifier = Modifier.fillMaxSize()) { ComposeNavHost( startGraph = AppRootGraph, controller = controller, navigationId = DemoNavigationId, - modifier = Modifier.fillMaxSize() + modifier = Modifier.fillMaxSize(), ) { composableNavigation(AppRootGraph) { appGraph() diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRootVM.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRootVM.kt index dee7697..29905ab 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRootVM.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/app/DemoAppRootVM.kt @@ -9,5 +9,5 @@ import javax.inject.Inject @HiltViewModel class DemoAppRootVM @Inject constructor( val overlays: AppOverlays, - val applyNavGraphsTask: ApplyNavGraphsTask + val applyNavGraphsTask: ApplyNavGraphsTask, ) : ViewModel() diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/splash/SplashScreenVM.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/splash/SplashScreenVM.kt index e359e45..a588a2f 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/splash/SplashScreenVM.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/splash/SplashScreenVM.kt @@ -15,9 +15,8 @@ import javax.inject.Inject @HiltViewModel class SplashScreenVM @Inject constructor( private val navigationConsumer: NavigationConsumer, - private val appBarStateSource: AppBarStateSource + private val appBarStateSource: AppBarStateSource, ) : LifecycleAwareViewModel() { - private val appBarState = AnimatedAppBarState() init { diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabData.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabData.kt index 1521ad2..0655221 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabData.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabData.kt @@ -7,7 +7,6 @@ data class DemoTabData( val index: Int, @DrawableRes val iconResId: Int, - @StringRes - val titleResId: Int + val titleResId: Int, ) diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsInteractions.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsInteractions.kt index f86759b..736c46b 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsInteractions.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsInteractions.kt @@ -1,5 +1,5 @@ package com.adamkobus.compose.navigation.demo.ui.tabhost data class DemoTabsInteractions( - val onTabSelected: (DemoTabData) -> Unit + val onTabSelected: (DemoTabData) -> Unit, ) diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigation.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigation.kt index 4a10df5..61175b2 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigation.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigation.kt @@ -3,10 +3,10 @@ package com.adamkobus.compose.navigation.demo.ui.tabhost import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material.Icon -import androidx.compose.material.LeadingIconTab -import androidx.compose.material.TabRow -import androidx.compose.material.Text +import androidx.compose.material3.Icon +import androidx.compose.material3.LeadingIconTab +import androidx.compose.material3.TabRow +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier @@ -25,7 +25,7 @@ fun DemoTabsNavigation(modifier: Modifier = Modifier) { DemoTabsNavigationContent( state, interactions = interactions, - modifier = modifier + modifier = modifier, ) } @@ -33,7 +33,7 @@ fun DemoTabsNavigation(modifier: Modifier = Modifier) { private fun DemoTabsNavigationContent( state: DemoTabsNavigationState, interactions: DemoTabsInteractions, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { Box(modifier = modifier) { Crossfade(targetState = state.tabHostType.value) { renderedState -> @@ -51,17 +51,20 @@ fun EmptyTabHost() { } @Composable -fun AnimalsTabHost(state: AnimalsTabHostState, onTabSelected: (DemoTabData) -> Unit) { +fun AnimalsTabHost( + state: AnimalsTabHostState, + onTabSelected: (DemoTabData) -> Unit, +) { val scope = rememberCoroutineScope() TabRow( - selectedTabIndex = state.selectedIndex + selectedTabIndex = state.selectedIndex, ) { state.items.forEachIndexed { index, tab -> LeadingIconTab( icon = { Icon( painter = painterResource(id = tab.iconResId), - contentDescription = null + contentDescription = null, ) }, text = { @@ -72,7 +75,7 @@ fun AnimalsTabHost(state: AnimalsTabHostState, onTabSelected: (DemoTabData) -> U scope.launch { onTabSelected(tab) } - } + }, ) } } diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationOverlayProvider.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationOverlayProvider.kt index f2250c1..efe9168 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationOverlayProvider.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationOverlayProvider.kt @@ -8,11 +8,11 @@ import com.adamkobus.compose.navigation.demo.ui.overlay.OverlayProvider import javax.inject.Inject class DemoTabsNavigationOverlayProvider @Inject constructor() : OverlayProvider { - @Composable - override fun provideOverlay(): @Composable BoxScope.() -> Unit = { - DemoTabsNavigation(modifier = Modifier.align(Alignment.BottomCenter)) - } + override fun provideOverlay(): @Composable BoxScope.() -> Unit = + { + DemoTabsNavigation(modifier = Modifier.align(Alignment.BottomCenter)) + } override val priority: Int = PRIORITY diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationState.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationState.kt index a21117c..cf470dd 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationState.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationState.kt @@ -4,15 +4,15 @@ import androidx.compose.runtime.State data class DemoTabsNavigationState( val tabHostType: State, - val animalsTabHostState: State + val animalsTabHostState: State, ) data class AnimalsTabHostState( val items: List, - val selectedIndex: Int + val selectedIndex: Int, ) enum class TabHostType { NONE, - ANIMALS + ANIMALS, } diff --git a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationVM.kt b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationVM.kt index 08278df..f8e181f 100644 --- a/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationVM.kt +++ b/demo/src/main/java/com/adamkobus/compose/navigation/demo/ui/tabhost/DemoTabsNavigationVM.kt @@ -17,32 +17,35 @@ import javax.inject.Inject @HiltViewModel class DemoTabsNavigationVM @Inject constructor( private val navigationStateSource: NavigationStateSource, - private val navigationConsumer: NavigationConsumer + private val navigationConsumer: NavigationConsumer, ) : LifecycleAwareViewModel() { - private val currentTabHostType = mutableStateOf(TabHostType.NONE) - private val animalsTabHostState = mutableStateOf( - AnimalsTabHostState( - items = listOf( - DemoTabs.Dogs, - DemoTabs.Cats - ).sortedBy { it.index }, - selectedIndex = 0 + private val animalsTabHostState = + mutableStateOf( + AnimalsTabHostState( + items = + listOf( + DemoTabs.Dogs, + DemoTabs.Cats, + ).sortedBy { it.index }, + selectedIndex = 0, + ), ) - ) - val screenState = DemoTabsNavigationState( - tabHostType = currentTabHostType, - animalsTabHostState = animalsTabHostState - ) + val screenState = + DemoTabsNavigationState( + tabHostType = currentTabHostType, + animalsTabHostState = animalsTabHostState, + ) - val interactions = DemoTabsInteractions( - onTabSelected = { - viewModelScope.launch { - processTabSelection(it) - } - } - ) + val interactions = + DemoTabsInteractions( + onTabSelected = { + viewModelScope.launch { + processTabSelection(it) + } + }, + ) init { runOnStart { @@ -86,11 +89,12 @@ class DemoTabsNavigationVM @Inject constructor( companion object { private val CATS_DESTINATIONS = listOf(CatsBrowserGraph.CatsList, CatsBrowserGraph.CatDetails) - private val DOGS_DESTINATIONS = listOf( - DogsBrowserGraph.DogDetails, - DogsBrowserGraph.DogsList, - DogsBrowserGraph.DemoDialog, - DogsBrowserGraph.DogGallery - ) + private val DOGS_DESTINATIONS = + listOf( + DogsBrowserGraph.DogDetails, + DogsBrowserGraph.DogsList, + DogsBrowserGraph.DemoDialog, + DogsBrowserGraph.DogGallery, + ) } } diff --git a/demo/src/main/res/values/themes.xml b/demo/src/main/res/values/themes.xml index 148d817..a66c519 100644 --- a/demo/src/main/res/values/themes.xml +++ b/demo/src/main/res/values/themes.xml @@ -1,25 +1,4 @@ - - - - - - - - \ No newline at end of file +