Skip to content

Commit ae68787

Browse files
null safety and also used to enforce arguments. not to handle overhead
1 parent d8cee78 commit ae68787

File tree

6 files changed

+28
-46
lines changed

6 files changed

+28
-46
lines changed

app/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ android {
4949

5050
dependencies {
5151
implementation fileTree(include: ['*.jar'], dir: 'libs')
52+
5253
// Kotlin
5354
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version_kotlin"
5455

@@ -60,7 +61,8 @@ dependencies {
6061

6162
// Material Design
6263
implementation "com.google.android.material:material:$version_material"
63-
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
64-
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
65-
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
64+
65+
// Navigation
66+
implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation"
67+
implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation"
6668
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class GameOverFragment : Fragment() {
3131
// Inflate the layout for this fragment
3232
val binding: FragmentGameOverBinding = DataBindingUtil.inflate(
3333
inflater, R.layout.fragment_game_over, container, false)
34-
binding.tryAgainButton.setOnClickListener { view : View ->
35-
view.findNavController().navigate(R.id.action_gameOverFragment2_to_gameFragment)
34+
binding.tryAgainButton.setOnClickListener { view: View ->
35+
view.findNavController().navigate(GameOverFragmentDirections.actionGameOverFragment2ToGameFragment())
3636
}
3737
return binding.root
3838
}
39-
}
39+
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ class GameWonFragment : Fragment() {
3434
// Inflate the layout for this fragment
3535
val binding: FragmentGameWonBinding = DataBindingUtil.inflate(
3636
inflater, R.layout.fragment_game_won, container, false)
37-
binding.nextMatchButton.setOnClickListener{view: View ->
38-
view.findNavController().navigate(GameFragmentDirections.actionGameFragmentToGameWonFragment(numQuestions, questionIndex))
39-
37+
binding.nextMatchButton.setOnClickListener { view: View ->
38+
view.findNavController().navigate(
39+
GameWonFragmentDirections.actionGameWonFragmentToGameFragment())
4040
}
41-
val args = GameWonFragmentArgs.fromBundle(arguments!!)
42-
Toast.makeText(context, "NumCorrect: ${args.numCorrect}, NumQuestions: ${args.numQuestions}", Toast.LENGTH_LONG).show()
41+
var args = GameWonFragmentArgs.fromBundle(arguments!!)
42+
Toast.makeText(context,
43+
"NumCorrect: ${args.numCorrect}, NumQuestions: ${args.numQuestions}",
44+
Toast.LENGTH_LONG).show()
4345
return binding.root
4446
}
4547
}

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,25 @@ import com.example.android.navigation.databinding.FragmentTitleBinding
1515
* A simple [Fragment] subclass.
1616
*/
1717
class TitleFragment : Fragment() {
18-
1918
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
2019
savedInstanceState: Bundle?): View? {
21-
// create a binding object and then inflate it in a layout using LayoutInflater
22-
val binding : FragmentTitleBinding = DataBindingUtil.inflate(
20+
val binding: FragmentTitleBinding = DataBindingUtil.inflate(
2321
inflater, R.layout.fragment_title, container, false)
24-
// navigation controller from the navigation host fragment being attached to a button it generates an callable action from one fragment to the other
25-
binding.playButton.setOnClickListener(
26-
Navigation.createNavigateOnClickListener(R.id.action_titleFragment_to_gameFragment)
27-
)
28-
// set the activity to have an instance of the menu before you override its functions. (Has two functions)
29-
setHasOptionsMenu(true)
30-
return binding.root
22+
binding.playButton.setOnClickListener { v: View ->
23+
v.findNavController().navigate(TitleFragmentDirections.actionTitleFragmentToGameFragment())
3124
}
25+
setHasOptionsMenu(true)
26+
return binding.root
27+
}
3228

33-
// create a new menu resource
3429
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
3530
super.onCreateOptionsMenu(menu, inflater)
3631
inflater?.inflate(R.menu.overflow_menu, menu)
3732
}
38-
// override on options selected
33+
3934
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
4035
return NavigationUI.onNavDestinationSelected(item!!,
41-
view!!.findNavController())
42-
// override the Navigation.onOptionsItemSelected method when it fails to find a view and set the item selected as the navigation
36+
view!!.findNavController())
4337
|| super.onOptionsItemSelected(item)
4438
}
45-
}
39+
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ buildscript {
2929
jcenter()
3030
}
3131
dependencies {
32-
classpath 'com.android.tools.build:gradle:3.3.0'
32+
classpath 'com.android.tools.build:gradle:3.6.3'
3333
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"
3434
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
3535

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
1-
#
2-
# Copyright 2018, The Android Open Source Project
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
7-
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
15-
#
16-
17-
#Tue Apr 17 15:14:16 PDT 2018
1+
#Fri May 01 10:29:28 EAT 2020
182
distributionBase=GRADLE_USER_HOME
193
distributionPath=wrapper/dists
204
zipStoreBase=GRADLE_USER_HOME
21-
zipStorePath=wrapper/dists
22-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
235
android.databinding.enableV2=true
6+
zipStorePath=wrapper/dists
7+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 commit comments

Comments
 (0)