Skip to content

Commit 99dc9e5

Browse files
adding safeargs for parsing in types of data
1 parent d268242 commit 99dc9e5

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ apply plugin: 'kotlin-android'
2020

2121
apply plugin: 'kotlin-kapt'
2222
apply plugin: 'kotlin-android-extensions'
23+
apply plugin: 'androidx.navigation.safeargs'
24+
2325

2426
android {
2527
compileSdkVersion 28

app/src/main/java/com/example/android/navigation/GameFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ class GameFragment : Fragment() {
9999
binding.invalidateAll()
100100
} else {
101101
// We've won! Navigate to the gameWonFragment.
102-
view.findNavController().navigate(R.id.action_gameFragment_to_gameWonFragment)
102+
view.findNavController().navigate(GameFragmentDirections.actionGameFragmentToGameWonFragment(numQuestions, questionIndex))
103103
}
104104
} else {
105-
view.findNavController().navigate(R.id.action_gameFragment_to_gameOverFragment2)
105+
// We've lost! Navigate to the gameLostFragment
106+
view.findNavController().navigate(GameFragmentDirections.actionGameFragmentToGameOverFragment2())
106107
}
107108
}
108109
}

app/src/main/res/navigation/navigation.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
android:id="@+id/action_gameWonFragment_to_gameFragment"
4848
app:destination="@id/gameFragment"
4949
app:popUpTo="@id/gameFragment" />
50+
<argument
51+
android:name="numQuestions"
52+
app:argType="integer" />
53+
<argument
54+
android:name="numCorrect"
55+
app:argType="integer" />
5056
</fragment>
5157
<fragment
5258
android:id="@+id/aboutFragment"

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ buildscript {
3131
dependencies {
3232
classpath 'com.android.tools.build:gradle:3.3.0'
3333
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"
34+
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
3435

3536
// NOTE: Do not place your application dependencies here; they belong
3637
// in the individual module build.gradle files

0 commit comments

Comments
 (0)