Skip to content

Commit 281bacf

Browse files
authored
Add Android Navigation Components library and setup
1 parent d6d571d commit 281bacf

9 files changed

Lines changed: 41 additions & 10 deletions

File tree

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ It helps you to create a well configured Android starter application with the mo
1616
6. Create your application class which extends `BaseApplication` in `:app` module, implement abstract methods and add to `AndroidManifest.xml` file.
1717
7. Specify your retrofit base URL in `NetworkModule.kt` file.
1818
8. Start to design your main layout xml file `fragment_main.xml` and fragment class.
19+
9. Specify your `MainFragment.kt` name in navigation graph xml file.
1920
9. That's all. Start your app development journey now 🎉.
2021

2122
## Good Practices

app/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
plugins {
22
id("com.android.application")
3+
commonPlugins.forEach { id(it) }
4+
id("androidx.navigation.safeargs.kotlin")
35
}
46

57
//apply(from = "../dependencies.gradle.kts")
6-
importCommonPlugins()
78
configAndroid()
89
importCommonDependencies()
910

@@ -15,4 +16,6 @@ android {
1516

1617
dependencies {
1718
implementation(project(":base"))
19+
implementation(Dependencies.Navigation.fragmentKtx)
20+
implementation(Dependencies.Navigation.uiKtx)
1821
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<FrameLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/fragmentContainer"
5+
android:name="androidx.navigation.fragment.NavHostFragment"
46
android:layout_width="match_parent"
57
android:layout_height="match_parent"
6-
android:id="@+id/fragmentContainer"/>
8+
app:defaultNavHost="true"
9+
app:navGraph="@navigation/nav_graph"/>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/nav_graph"
6+
app:startDestination="@id/fragmentMain">
7+
<!-- TODO: 7. Add your content fragment and set navigation name -->
8+
<fragment
9+
android:id="@+id/fragmentMain"
10+
tools:layout="@layout/fragment_main"
11+
/>
12+
</navigation>

base/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
22
id("com.android.library")
3+
commonPlugins.forEach { id(it) }
34
}
45

5-
importCommonPlugins()
66
configAndroid()
77
importCommonDependencies()
88

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildscript {
99
dependencies {
1010
classpath(Dependencies.androidGradlePlugin)
1111
classpath(Dependencies.Kotlin.gradlePlugin)
12+
classpath(Dependencies.Navigation.safeArgs)
1213
// NOTE: Do not place your application dependencies here; they belong
1314
// in the individual module build.gradle files
1415
}

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ object Dependencies {
6666
const val rxJava2 =
6767
"androidx.paging:paging-rxjava2:${Versions.ArchitectureComponents.paging}"
6868
}
69-
}
7069

71-
fun Project.importCommonPlugins() {
72-
plugins.apply("kotlin-android")
73-
plugins.apply("kotlin-android-extensions")
74-
plugins.apply("kotlin-kapt")
70+
object Navigation {
71+
const val fragmentKtx =
72+
"androidx.navigation:navigation-fragment-ktx:${Versions.ArchitectureComponents.navigation}"
73+
const val uiKtx =
74+
"androidx.navigation:navigation-fragment-ktx:${Versions.ArchitectureComponents.navigation}"
75+
const val safeArgs =
76+
"androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.ArchitectureComponents.navigation}"
77+
}
7578
}
7679

80+
val commonPlugins = arrayOf("kotlin-android", "kotlin-android-extensions", "kotlin-kapt")
81+
7782
// apply common plugin
7883
fun Project.importCommonDependencies() {
7984
dependencies {

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ object Versions {
3939
const val lifecycle = "2.1.0"
4040
const val paging = "2.1.2"
4141
const val room = "2.2.5"
42+
const val navigation = "2.3.0"
4243
}
4344

4445
}

0 commit comments

Comments
 (0)