Skip to content

Commit c2fcaf1

Browse files
update gradle version to 4.2.0-alpha14
1 parent 4fa0440 commit c2fcaf1

File tree

16 files changed

+228
-52
lines changed

16 files changed

+228
-52
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Tutorials for learning Navigation Components starting with simple set up, contin
1111
* Nested navigation with a NavHostFragment and back press handled with OnBackPressedCallback
1212
* [Tutorial1-3Navigation-NestedNavHost](https://github.com/SmartToolFactory/NavigationComponents-Tutorials/tree/master/Tutorial1-3Navigation-NestedNavHost)
1313

14-
* Set navigation with toolbar, navigationview and use top menu buttons to navigate
14+
* Set navigation with toolbar, NavigationView and use top menu buttons to navigate
1515
* [Tutorial4-1NavigationUI-NavigationView](https://github.com/SmartToolFactory/NavigationComponents-Tutorials/tree/master/Tutorial4-1NavigationUI-NavigationView)
1616

1717
* BottomNavigationView with simple navigation
@@ -26,7 +26,7 @@ Tutorials for learning Navigation Components starting with simple set up, contin
2626
* ViewPager2 inside a fragment with single navigation graph, navigates from the fragment ViewPager2 is in to next one
2727
* [Tutorial6-0NavigationUI-ViewPager2](https://github.com/SmartToolFactory/NavigationComponents-Tutorials/tree/master/Tutorial6-0NavigationUI-ViewPager2)
2828

29-
* Same tutorial as the previos one but data binding used this time to examine and solve memory leaks due to data binding
29+
* Same tutorial as the previous one but data binding used this time to examine and solve memory leaks due to data binding
3030
* [Tutorial6-1NavigationUI-ViewPager2](https://github.com/SmartToolFactory/NavigationComponents-Tutorials/tree/master/Tutorial6-1NavigationUI-ViewPager2)
3131

3232
* ViewPager2 navigation with each page has it's own back stack or fragment that wraps/contains NavHostFragment
@@ -771,7 +771,7 @@ If ```BottomNavigationView``` extension is used with ```DynamicNavHostFragment`
771771
772772
Also, since extension is not used, observe that not getting **MEMORY LEAK** that was present in Tutorial7-3
773773
774-
### TodDos:
774+
### ToDos:
775775
- [ ] Use nav graph ViewModel by navGraphViewModels, couldn't find it yet
776776
- [ ] Solve ```setFragmentResultListener``` issue to get result from a framgent on back press, and use instead of savedStateHandle
777777
- [ ] Use saveStateHandle or save fragment state in Tutorial 8-2 when ViewPager2 moves away from viewPort

Tutorial0-0MaterialDesign/src/main/java/com/smarttoolfactory/tutorial0_materialdesign/MainActivity.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,12 @@ class MainActivity : AppCompatActivity(), BaseAdapter.OnRecyclerViewItemClickLis
8181
setOnItemClickListener(this@MainActivity)
8282
}
8383
}
84-
8584
}
8685

8786
@Override
8887
override fun onItemClicked(view: View, position: Int) {
89-
90-
9188
Intent(this@MainActivity, activityClassModels[position].clazz).also {
9289
startActivity(it)
9390
}
94-
9591
}
9692
}

Tutorial2-1Navigation-PassData/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ android {
4343
dependencies {
4444
implementation fileTree(dir: 'libs', include: ['*.jar'])
4545
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
46-
implementation 'androidx.appcompat:appcompat:1.0.2'
47-
implementation 'androidx.core:core-ktx:1.0.2'
48-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
46+
implementation 'androidx.appcompat:appcompat:1.2.0'
47+
implementation 'androidx.core:core-ktx:1.3.2'
48+
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
4949

5050
//Navigation
5151
implementation "androidx.navigation:navigation-fragment-ktx:$rootProject.navigationVersion"

Tutorial7-3BNV-ViewPager2-FragmentToolbar-MixedNavigation/src/main/java/com/smarttoolfactory/tutorial7_3bnv_viewpager2_fragmenttoolbar_mixednavigation/fragment/main/MainFragment.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class MainFragment : BaseDataBindingFragment<FragmentMainBinding>() {
4545

4646
val bottomNavigationView = dataBinding!!.bottomNav
4747

48-
4948
val navGraphIds = listOf(
5049
R.navigation.nav_graph_view_pager,
5150
R.navigation.nav_graph_dashboard,

Tutorial8-1DynamicFeatures-Navigation/src/main/res/navigation/nav_graph_dashboard.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
android:id="@+id/dashboardFragment3"
3030
android:name="com.smarttoolfactory.tutorial8_1dynamicfeatures_navigation.fragment.blankfragment.DashboardFragment3"
3131
android:label="DashboardFragment3"
32-
tools:layout="@layout/fragment_dashboard3" >
32+
tools:layout="@layout/fragment_dashboard3">
3333
<action
3434
android:id="@+id/action_dashboardFragment3_to_dashboardFragment1"
3535
app:destination="@id/dashboardFragment1"

Tutorial8-1DynamicFeatures-Navigation/src/main/res/navigation/nav_graph_notification.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
android:id="@+id/nav_graph_favorites"
4848
android:name="com.smarttoolfactory.favorites"
4949
app:graphResName="nav_graph_favorites"
50-
app:moduleName="favorites" >
50+
app:moduleName="favorites">
5151
<argument
5252
android:name="count"
53-
app:argType="integer"
54-
android:defaultValue="0" />
53+
android:defaultValue="0"
54+
app:argType="integer" />
5555
</include-dynamic>
5656
</navigation>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,76 @@
11
package com.smarttoolfactory.tutorial8_2dynamicfeatures_complexarchitecture.fragment.blankfragment
22

33

4+
import android.os.Bundle
5+
import android.view.*
6+
import android.widget.Toast
7+
import androidx.navigation.fragment.findNavController
8+
import androidx.navigation.ui.AppBarConfiguration
9+
import androidx.navigation.ui.setupWithNavController
10+
import com.google.android.material.appbar.AppBarLayout
11+
import com.smarttoolfactory.tutorial8_2dynamicfeatures_complexarchitecture.MainActivity
412
import com.smarttoolfactory.tutorial8_2dynamicfeatures_complexarchitecture.R
513
import com.smarttoolfactory.tutorial8_2dynamicfeatures_complexarchitecture.databinding.FragmentLogin2Binding
614

7-
815
class LoginFragment2 : BaseDataBindingFragment<FragmentLogin2Binding>() {
16+
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
setHasOptionsMenu(true)
19+
super.onCreate(savedInstanceState)
20+
}
21+
22+
override fun onCreateView(
23+
inflater: LayoutInflater,
24+
container: ViewGroup?,
25+
savedInstanceState: Bundle?
26+
): View? {
27+
setHasOptionsMenu(true)
28+
return super.onCreateView(inflater, container, savedInstanceState)
29+
}
30+
31+
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
32+
Toast.makeText(requireContext(), "FragementA onCreateOptionsMenu()", Toast.LENGTH_SHORT).show()
33+
34+
inflater.inflate(R.menu.menu_login_detail, menu)
35+
super.onCreateOptionsMenu(menu,inflater)
36+
}
37+
38+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39+
super.onViewCreated(view, savedInstanceState)
40+
val toolbar = dataBinding!!. toolbar
41+
val appBarConfig = AppBarConfiguration(findNavController().graph)
42+
toolbar.setupWithNavController(findNavController(), appBarConfig)
43+
44+
// Alternative 1 for setting Fragment Toolbar Options menu
45+
// (requireActivity() as? MainActivity)?.setSupportActionBar(toolbar)
46+
47+
48+
// Alternative 2 for setting Fragment Toolbar Options menu
49+
toolbar.inflateMenu(R.menu.menu_login_detail)
50+
toolbar.setOnMenuItemClickListener {
51+
Toast.makeText(requireContext(), "item: $it", Toast.LENGTH_SHORT).show()
52+
true
53+
}
54+
55+
val appbarLayout = dataBinding!!.appbar
56+
val collapsingToolbarLayout = dataBinding!!.collapsingToolbarLayout
57+
58+
var isShow = true
59+
var scrollRange = -1
60+
appbarLayout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { barLayout, verticalOffset ->
61+
if (scrollRange == -1){
62+
scrollRange = barLayout?.totalScrollRange!!
63+
}
64+
if (scrollRange + verticalOffset == 0){
65+
collapsingToolbarLayout.title = "Title Collapse"
66+
isShow = true
67+
} else if (isShow){
68+
collapsingToolbarLayout.title = " " //careful there should a space between double quote otherwise it wont work
69+
isShow = false
70+
}
71+
})
72+
73+
}
74+
975
override fun getLayoutRes(): Int = R.layout.fragment_login2
1076
}

Tutorial8-2DynamicFeatures-ComplexArchitecture/src/main/java/com/smarttoolfactory/tutorial8_2dynamicfeatures_complexarchitecture/fragment/navhost/NavHostContainerFragment.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import androidx.fragment.app.Fragment
1010
import androidx.fragment.app.FragmentFactory
1111
import androidx.fragment.app.activityViewModels
1212
import androidx.navigation.NavController
13-
import androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment
1413
import androidx.navigation.fragment.NavHostFragment
1514
import com.smarttoolfactory.tutorial8_2dynamicfeatures_complexarchitecture.fragment.factory.NavHostFragmentFactory
1615
import com.smarttoolfactory.tutorial8_2dynamicfeatures_complexarchitecture.util.Event
@@ -32,7 +31,27 @@ class NavHostContainerFragment() : Fragment() {
3231
private var layoutRes: Int = -1
3332

3433
/**
35-
* Id of [NavHostFragment] or [DynamicNavHostFragment]
34+
* Id of [NavHostFragment] inside layout specified with [layoutRes]. A layout
35+
* for instance is like the snippet below
36+
*
37+
* ```
38+
* <SomeLayout>
39+
* <androidx.fragment.app.FragmentContainerView
40+
* android:id="@+id/nested_nav_host_fragment"
41+
* android:name="androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment"
42+
* app:defaultNavHost="true"
43+
* app:navGraph="@navigation/nav_graph_x"/>
44+
*</SomeLayout>
45+
* ```
46+
*
47+
* and instantiate a fragment from this layout
48+
* ```
49+
* NavHostContainerFragment.newInstance(
50+
* R.layout.fragment_SOME_FRAGMENT,
51+
* R.id.nested_nav_host_fragment)
52+
* ```
53+
* name of this layout is [layoutRes], id in layout snippet is [navHostFragmentId]
54+
*
3655
*/
3756
private var navHostFragmentId: Int = -1
3857

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
10+
</vector>
Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,86 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout>
3-
<androidx.constraintlayout.widget.ConstraintLayout
4-
xmlns:android="http://schemas.android.com/apk/res/android"
5-
xmlns:tools="http://schemas.android.com/tools"
6-
xmlns:app="http://schemas.android.com/apk/res-auto"
2+
3+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools">
6+
7+
8+
<androidx.coordinatorlayout.widget.CoordinatorLayout
9+
android:id="@+id/coordinatorLayout"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
tools:context=".MainActivity">
13+
14+
<com.google.android.material.appbar.AppBarLayout
15+
android:id="@+id/appbar"
716
android:layout_width="match_parent"
8-
android:background="#795548"
9-
android:layout_height="match_parent"
10-
android:id="@+id/fragment_layout">
17+
android:fitsSystemWindows="true"
18+
android:layout_height="wrap_content"
19+
android:theme="@style/ThemeOverlay.MaterialComponents.ActionBar">
1120

12-
<TextView
13-
android:text="Logged In"
14-
android:textSize="32sp"
15-
android:textColor="#fff"
16-
android:layout_width="wrap_content"
21+
<com.google.android.material.appbar.CollapsingToolbarLayout
22+
android:id="@+id/collapsingToolbarLayout"
23+
android:layout_width="match_parent"
1724
android:layout_height="wrap_content"
18-
android:id="@+id/tvTitle"
19-
app:layout_constraintHorizontal_bias="0.5"
20-
app:layout_constraintStart_toStartOf="parent"
21-
app:layout_constraintEnd_toEndOf="parent"
22-
app:layout_constraintTop_toTopOf="parent"
23-
app:layout_constraintBottom_toBottomOf="parent"/>
24-
25-
</androidx.constraintlayout.widget.ConstraintLayout>
25+
app:contentScrim="#ccc"
26+
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
27+
app:statusBarScrim="@android:color/transparent">
28+
29+
<ImageView
30+
android:id="@+id/ivLogo"
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
android:scaleType="centerCrop"
34+
android:src="@drawable/avatar_1_raster" />
35+
36+
<androidx.appcompat.widget.Toolbar
37+
android:id="@+id/toolbar"
38+
android:layout_width="match_parent"
39+
android:layout_height="?attr/actionBarSize"
40+
app:layout_collapseMode="pin"
41+
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
42+
43+
</com.google.android.material.appbar.CollapsingToolbarLayout>
44+
45+
</com.google.android.material.appbar.AppBarLayout>
46+
47+
48+
<androidx.core.widget.NestedScrollView
49+
android:layout_width="match_parent"
50+
android:layout_height="match_parent"
51+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
52+
53+
<androidx.constraintlayout.widget.ConstraintLayout
54+
android:id="@+id/fragment_layout"
55+
android:layout_width="match_parent"
56+
android:layout_height="match_parent"
57+
android:background="#795548">
58+
59+
<TextView
60+
android:id="@+id/tvTitle"
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:text="Logged In"
64+
android:textColor="#fff"
65+
android:textSize="32sp"
66+
app:layout_constraintBottom_toBottomOf="parent"
67+
app:layout_constraintEnd_toEndOf="parent"
68+
app:layout_constraintHorizontal_bias="0.5"
69+
app:layout_constraintStart_toStartOf="parent"
70+
app:layout_constraintTop_toTopOf="parent"
71+
app:layout_constraintVertical_bias="0.050000012" />
72+
73+
<View
74+
android:layout_width="match_parent"
75+
android:layout_height="2000dp"
76+
app:layout_constraintEnd_toEndOf="parent"
77+
app:layout_constraintStart_toStartOf="parent"
78+
app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
79+
80+
</androidx.constraintlayout.widget.ConstraintLayout>
81+
82+
</androidx.core.widget.NestedScrollView>
83+
84+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
85+
2686
</layout>

0 commit comments

Comments
 (0)