Skip to content

Commit

Permalink
Organize navigation between modules through common navigation module
Browse files Browse the repository at this point in the history
  • Loading branch information
PStrelchenko committed Aug 16, 2020
1 parent 1bcbb70 commit 4933a9d
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 34 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/build.gradle.kts
Expand Up @@ -63,6 +63,9 @@ dependencies {
implementation(Libs.ui.adapterDelegateKotlinDsl)
implementation(Libs.ui.adapterDelegateKotlinDslLayoutContainer)

// Core modules
implementation(project(":common-navigation"))

// Feature modules
implementation(project(":company"))
implementation(project(":vacancy"))
Expand Down
1 change: 1 addition & 0 deletions core/common-navigation/.gitignore
@@ -0,0 +1 @@
/build
44 changes: 44 additions & 0 deletions core/common-navigation/build.gradle.kts
@@ -0,0 +1,44 @@
plugins {
id("com.android.library")
kotlin("android")
id("androidx.navigation.safeargs.kotlin")
}

repositories {
jcenter()
google()
}

android {
compileSdkVersion(Versions.compileSdkVersion)
buildToolsVersion = Versions.buildToolsVersion

defaultConfig {
minSdkVersion(Versions.minSdkVersion)
targetSdkVersion(Versions.targetSdkVersion)

versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
// Navigation
compileOnly(Libs.jetpack.navigationComponentFragmentKtx)
}
Empty file.
21 changes: 21 additions & 0 deletions core/common-navigation/proguard-rules.pro
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
5 changes: 5 additions & 0 deletions core/common-navigation/src/main/AndroidManifest.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aaglobal.jnc_playground.common_navigation">

</manifest>
Expand Up @@ -7,8 +7,7 @@

<fragment
android:id="@+id/SplashFragment"
android:name="com.aaglobal.jnc_playground.ui.splash.SplashFragment"
tools:layout="@layout/fragment_splash">
android:name="com.aaglobal.jnc_playground.ui.splash.SplashFragment">

<action
android:id="@+id/action__SplashFragment__to__MainFragment"
Expand All @@ -26,8 +25,7 @@

<fragment
android:id="@+id/MainFragment"
android:name="com.aaglobal.jnc_playground.ui.main.MainFragment"
tools:layout="@layout/fragment_main">
android:name="com.aaglobal.jnc_playground.ui.main.MainFragment">

<action
android:id="@+id/action__MainFragment__to__AuthFlow"
Expand Down
Expand Up @@ -8,8 +8,7 @@
<fragment
android:id="@+id/StartAuthFragment"
android:name="com.aaglobal.jnc_playground.ui.auth.StartAuthFragment"
android:label="Start auth"
tools:layout="@layout/fragment_start_auth">
android:label="Start auth">

<argument
android:name="isFromSplashScreen"
Expand All @@ -26,7 +25,6 @@
<fragment
android:id="@+id/FinishAuthFragment"
android:name="com.aaglobal.jnc_playground.ui.auth.FinishAuthFragment"
android:label="Finish auth"
tools:layout="@layout/fragment_finish_auth" />
android:label="Finish auth" />

</navigation>
Expand Up @@ -5,14 +5,11 @@
android:id="@+id/company_flow__nav_graph"
app:startDestination="@id/CompanyFragment">

<!-- Even :common-navigation doesn't know anything about
fragments and destinations, it can build graph -->
<fragment
android:id="@+id/CompanyFragment"
android:name="com.aaglobal.jnc_playground.company.CompanyFragment"
android:label="@string/fragment_company__title"
tools:layout="@layout/fragment_company">

<!-- Define deep link for other features -->
<deepLink app:uri="companyflow://company" />
android:name="com.aaglobal.jnc_playground.company.CompanyFragment">

<action
android:id="@+id/action__CompanyFragment__to__CompanyDetailsFragment"
Expand All @@ -22,9 +19,7 @@

<fragment
android:id="@+id/CompanyDetailsFragment"
android:name="com.aaglobal.jnc_playground.company.CompanyDetailsFragment"
android:label="@string/fragment_company_details__title"
tools:layout="@layout/fragment_company_details">
android:name="com.aaglobal.jnc_playground.company.CompanyDetailsFragment">

<!-- We can use this action for back navigation, but it seems that it is -->
<!-- not semantically right to use "navigate" word when you return to some screen -->
Expand Down
Expand Up @@ -7,8 +7,7 @@

<fragment
android:id="@+id/FavoritesContainerFragment"
android:name="com.aaglobal.jnc_playground.ui.tabs.favorites.FavoritesContainerFragment"
tools:layout="@layout/fragment_favorites_container">
android:name="com.aaglobal.jnc_playground.ui.tabs.favorites.FavoritesContainerFragment">

<action
android:id="@+id/action__FavoritesContainerFragment__to__VacancyFragment"
Expand Down
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/menu__profile"
app:startDestination="@id/ProfileContainerFragment">

<fragment
android:id="@+id/ProfileContainerFragment"
android:name="com.aaglobal.jnc_playground.ui.tabs.profile.ProfileContainerFragment"
tools:layout="@layout/fragment_profile_container" />
android:name="com.aaglobal.jnc_playground.ui.tabs.profile.ProfileContainerFragment" />

</navigation>
Expand Up @@ -7,8 +7,7 @@

<fragment
android:id="@+id/ResponsesContainerFragment"
android:name="com.aaglobal.jnc_playground.ui.tabs.responses.ResponsesContainerFragment"
tools:layout="@layout/fragment_responses_container">
android:name="com.aaglobal.jnc_playground.ui.tabs.responses.ResponsesContainerFragment">

<action
android:id="@+id/action__ResponsesContainerFragment__to__CompanyFlow"
Expand Down
Expand Up @@ -7,8 +7,7 @@

<fragment
android:id="@+id/SearchContainerFragment"
android:name="com.aaglobal.jnc_playground.ui.tabs.search.SearchContainerFragment"
tools:layout="@layout/fragment_search_container">
android:name="com.aaglobal.jnc_playground.ui.tabs.search.SearchContainerFragment">

<action
android:id="@+id/action__SearchContainerFragment__to__CompanyFlow"
Expand Down
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/vacancy_nav_graph"
app:startDestination="@id/VacancyFragment">

<fragment
android:id="@+id/VacancyFragment"
android:name="com.aaglobal.jnc_playground.vacancy.VacancyFragment"
android:label="Fragment vacancy"
tools:layout="@layout/fragment_vacancy">
android:label="Fragment vacancy">

<argument
android:name="vacancyId"
Expand All @@ -23,6 +21,12 @@
android:id="@+id/action__VacancyFragment__to__VacancyFragment"
app:destination="@id/VacancyFragment" />

<action
android:id="@+id/action__VacancyFragment__to__CompanyFlow"
app:destination="@id/company_flow__nav_graph" />

</fragment>

<include app:graph="@navigation/company_flow__nav_graph" />

</navigation>
3 changes: 3 additions & 0 deletions features/company/build.gradle.kts
Expand Up @@ -43,6 +43,9 @@ androidExtensions {
}

dependencies {
// Core modules
implementation(project(":common-navigation"))

// Kotlin
compileOnly(Libs.kotlin)

Expand Down
5 changes: 3 additions & 2 deletions features/vacancy/build.gradle.kts
Expand Up @@ -44,6 +44,9 @@ androidExtensions {
}

dependencies {
// Core modules
implementation(project(":common-navigation"))

// Kotlin
compileOnly(Libs.kotlin)

Expand All @@ -58,6 +61,4 @@ dependencies {
// Navigation
compileOnly(Libs.jetpack.navigationComponentFragmentKtx)
compileOnly(Libs.jetpack.navigationComponentUiKtx)
compileOnly(Libs.ui.adapterDelegateKotlinDsl)
compileOnly(Libs.ui.adapterDelegateKotlinDslLayoutContainer)
}
Expand Up @@ -36,9 +36,7 @@ class VacancyFragment : Fragment(R.layout.fragment_vacancy) {
}

fragment_vacancy__button__open_company_flow.setOnClickListener {
// Navigation through deep link
val companyFlowUri = "companyflow://company".toUri()
findNavController().navigate(companyFlowUri)
findNavController().navigate(R.id.action__VacancyFragment__to__CompanyFlow)
}
}

Expand Down
5 changes: 5 additions & 0 deletions settings.gradle.kts
@@ -1,6 +1,11 @@
// Application modules
include(":app")

// Core modules
include(":common-navigation")

project(":common-navigation").projectDir = File(settingsDir, "core/common-navigation")

// Feature modules
include(":company")
include(":vacancy")
Expand Down

0 comments on commit 4933a9d

Please sign in to comment.