Skip to content

Commit 41ebce7

Browse files
Finish Tutorial 6-4, and pop inclusive back navigation to last fragments of ViewPager2
1 parent f7e16ad commit 41ebce7

File tree

154 files changed

+1559
-1227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+1559
-1227
lines changed

Tutorial6-1NavigationUI-ViewPager2/src/main/java/com/smarttoolfactory/tutorial6_1navigationui_viewpager2/adapter/ChildFragmentStateAdapter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.smarttoolfactory.tutorial6_1navigationui_viewpager2.blankfragment.Hom
88
/**
99
* Passing [Fragment] as parameter let's this adapter to use childFragmentManager
1010
*/
11-
class ChildFragmentStateAdapter(private val fragment: Fragment) :
11+
class ChildFragmentStateAdapter(fragment: Fragment) :
1212
FragmentStateAdapter(fragment) {
1313

1414
override fun getItemCount(): Int = 2

Tutorial6-1NavigationUI-ViewPager2/src/main/res/layout/activity_main.xml

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto">
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
44

55
<androidx.coordinatorlayout.widget.CoordinatorLayout
6-
android:layout_width="match_parent"
7-
android:layout_height="match_parent">
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent">
88

99

1010
<com.google.android.material.appbar.AppBarLayout
11-
android:id="@+id/appbar"
12-
android:layout_width="match_parent"
13-
android:layout_height="wrap_content"
14-
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
11+
android:id="@+id/appbar"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
1515

1616
<androidx.appcompat.widget.Toolbar
17-
android:id="@+id/toolbar"
18-
android:layout_width="match_parent"
19-
android:layout_height="?attr/actionBarSize"
20-
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar" />
17+
android:id="@+id/toolbar"
18+
android:layout_width="match_parent"
19+
android:layout_height="?attr/actionBarSize"
20+
app:popupTheme="@style/ThemeOverlay.AppCompat.ActionBar" />
2121

2222
</com.google.android.material.appbar.AppBarLayout>
2323

2424
<androidx.constraintlayout.widget.ConstraintLayout
25-
android:layout_width="match_parent"
26-
android:layout_height="match_parent"
27-
app:layout_behavior="@string/appbar_scrolling_view_behavior">
25+
android:layout_width="match_parent"
26+
android:layout_height="match_parent"
27+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
2828

2929
<fragment
30-
android:id="@+id/nav_host_fragment"
31-
android:name="androidx.navigation.fragment.NavHostFragment"
32-
android:layout_width="0dp"
33-
android:layout_height="0dp"
34-
app:layout_constraintLeft_toLeftOf="parent"
35-
app:layout_constraintRight_toRightOf="parent"
36-
app:layout_constraintTop_toTopOf="parent"
37-
app:layout_constraintBottom_toBottomOf="parent"
38-
39-
app:defaultNavHost="true"
40-
app:navGraph="@navigation/nav_graph"/>
30+
android:id="@+id/nav_host_fragment"
31+
android:name="androidx.navigation.fragment.NavHostFragment"
32+
android:layout_width="0dp"
33+
android:layout_height="0dp"
34+
app:layout_constraintBottom_toBottomOf="parent"
35+
app:layout_constraintLeft_toLeftOf="parent"
36+
app:layout_constraintRight_toRightOf="parent"
37+
app:layout_constraintTop_toTopOf="parent"
38+
39+
app:defaultNavHost="true"
40+
app:navGraph="@navigation/nav_graph"/>
4141

4242
</androidx.constraintlayout.widget.ConstraintLayout>
4343

Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:tools="http://schemas.android.com/tools"
5-
xmlns:app="http://schemas.android.com/apk/res-auto"
6-
android:layout_width="match_parent"
7-
android:background="#A1887F"
8-
android:layout_height="match_parent"
9-
android:id="@+id/fragment_layout">
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/fragment_layout"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:background="#A1887F">
108

119
<TextView
12-
android:text="Camera Fragment"
13-
android:textSize="32sp"
14-
android:textColor="#fff"
15-
android:layout_width="wrap_content"
16-
android:layout_height="wrap_content"
17-
android:id="@+id/tvTitle"
18-
app:layout_constraintHorizontal_bias="0.5"
19-
app:layout_constraintStart_toStartOf="parent"
20-
app:layout_constraintEnd_toEndOf="parent"
21-
app:layout_constraintTop_toTopOf="parent"
22-
app:layout_constraintBottom_toBottomOf="parent"/>
10+
android:id="@+id/tvTitle"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="Camera Fragment"
14+
android:textColor="#fff"
15+
android:textSize="32sp"
16+
app:layout_constraintBottom_toBottomOf="parent"
17+
app:layout_constraintEnd_toEndOf="parent"
18+
app:layout_constraintHorizontal_bias="0.5"
19+
app:layout_constraintStart_toStartOf="parent"
20+
app:layout_constraintTop_toTopOf="parent" />
2321

2422
</androidx.constraintlayout.widget.ConstraintLayout>

Tutorial6-1NavigationUI-ViewPager2/src/main/res/layout/fragment_dashboard1.xml

+80-83
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,105 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout xmlns:tools="http://schemas.android.com/tools"
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
xmlns:app="http://schemas.android.com/apk/res-auto">
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
54

65
<androidx.constraintlayout.widget.ConstraintLayout
7-
android:id="@+id/fragment_layout"
8-
android:layout_width="match_parent"
9-
android:layout_height="match_parent"
10-
android:background="#1976D2">
6+
android:id="@+id/fragment_layout"
7+
android:layout_width="match_parent"
8+
android:layout_height="match_parent"
9+
android:background="#1976D2">
1110

1211
<Switch
13-
android:id="@+id/switch1"
14-
android:layout_width="wrap_content"
15-
android:layout_height="wrap_content"
16-
android:layout_marginTop="32dp"
17-
android:layout_marginEnd="32dp"
18-
android:text="Switch"
19-
app:layout_constraintEnd_toEndOf="parent"
20-
app:layout_constraintTop_toTopOf="parent" />
12+
android:id="@+id/switch1"
13+
android:layout_width="wrap_content"
14+
android:layout_height="wrap_content"
15+
android:layout_marginTop="32dp"
16+
android:layout_marginEnd="32dp"
17+
android:text="Switch"
18+
app:layout_constraintEnd_toEndOf="parent"
19+
app:layout_constraintTop_toTopOf="parent" />
2120

2221
<CheckBox
23-
android:id="@+id/checkBox"
24-
android:layout_width="wrap_content"
25-
android:layout_height="wrap_content"
26-
android:layout_marginTop="32dp"
27-
android:text="CheckBox"
28-
app:layout_constraintEnd_toEndOf="@+id/switch1"
29-
app:layout_constraintTop_toBottomOf="@+id/switch1" />
22+
android:id="@+id/checkBox"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:layout_marginTop="32dp"
26+
android:text="CheckBox"
27+
app:layout_constraintEnd_toEndOf="@+id/switch1"
28+
app:layout_constraintTop_toBottomOf="@+id/switch1" />
3029

3130
<ToggleButton
32-
android:id="@+id/toggleButton"
33-
android:layout_width="wrap_content"
34-
android:layout_height="wrap_content"
35-
android:layout_marginTop="32dp"
36-
android:text="ToggleButton"
37-
app:layout_constraintEnd_toEndOf="@+id/checkBox"
38-
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
31+
android:id="@+id/toggleButton"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:layout_marginTop="32dp"
35+
android:text="ToggleButton"
36+
app:layout_constraintEnd_toEndOf="@+id/checkBox"
37+
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
3938

4039

4140
<EditText
42-
android:id="@+id/editText"
43-
android:layout_width="wrap_content"
44-
android:layout_height="wrap_content"
45-
android:layout_marginStart="32dp"
46-
android:hint="Enter text"
47-
app:layout_constraintStart_toStartOf="parent"
48-
app:layout_constraintTop_toTopOf="@+id/switch1" />
41+
android:id="@+id/editText"
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:layout_marginStart="32dp"
45+
android:hint="Enter text"
46+
app:layout_constraintStart_toStartOf="parent"
47+
app:layout_constraintTop_toTopOf="@+id/switch1" />
4948

5049
<SeekBar
51-
android:id="@+id/seekBar"
52-
android:layout_width="0dp"
53-
app:layout_constraintWidth_percent=".3"
54-
android:layout_height="wrap_content"
55-
android:layout_marginTop="32dp"
56-
app:layout_constraintStart_toStartOf="@+id/editText"
57-
app:layout_constraintTop_toBottomOf="@+id/editText" />
50+
android:id="@+id/seekBar"
51+
android:layout_width="0dp"
52+
android:layout_height="wrap_content"
53+
android:layout_marginTop="32dp"
54+
app:layout_constraintStart_toStartOf="@+id/editText"
55+
app:layout_constraintTop_toBottomOf="@+id/editText"
56+
app:layout_constraintWidth_percent=".3" />
5857

5958
<TextView
60-
android:id="@+id/tvLifeCycle"
61-
android:layout_width="wrap_content"
62-
android:layout_height="wrap_content"
63-
android:text="TextView"
64-
android:textColor="#fff"
65-
app:layout_constraintBottom_toBottomOf="parent"
66-
app:layout_constraintEnd_toEndOf="parent"
67-
app:layout_constraintStart_toStartOf="parent"
68-
app:layout_constraintTop_toTopOf="parent"
69-
app:layout_constraintVertical_bias="0.35" />
59+
android:id="@+id/tvLifeCycle"
60+
android:layout_width="wrap_content"
61+
android:layout_height="wrap_content"
62+
android:text="TextView"
63+
android:textColor="#fff"
64+
app:layout_constraintBottom_toBottomOf="parent"
65+
app:layout_constraintEnd_toEndOf="parent"
66+
app:layout_constraintStart_toStartOf="parent"
67+
app:layout_constraintTop_toTopOf="parent"
68+
app:layout_constraintVertical_bias="0.35" />
7069

7170
<TextView
72-
android:id="@+id/tvTitle"
73-
android:layout_width="wrap_content"
74-
android:layout_height="wrap_content"
75-
android:text="Dashboard Fragment1"
76-
android:textColor="#fff"
77-
android:textSize="32sp"
78-
app:layout_constraintBottom_toBottomOf="parent"
79-
app:layout_constraintEnd_toEndOf="parent"
80-
app:layout_constraintHorizontal_bias="0.5"
81-
app:layout_constraintStart_toStartOf="parent"
82-
app:layout_constraintTop_toBottomOf="@+id/tvLifeCycle"
83-
app:layout_constraintVertical_bias="0.3" />
71+
android:id="@+id/tvTitle"
72+
android:layout_width="wrap_content"
73+
android:layout_height="wrap_content"
74+
android:text="Dashboard Fragment1"
75+
android:textColor="#fff"
76+
android:textSize="32sp"
77+
app:layout_constraintBottom_toBottomOf="parent"
78+
app:layout_constraintEnd_toEndOf="parent"
79+
app:layout_constraintHorizontal_bias="0.5"
80+
app:layout_constraintStart_toStartOf="parent"
81+
app:layout_constraintTop_toBottomOf="@+id/tvLifeCycle"
82+
app:layout_constraintVertical_bias="0.3" />
8483

8584
<androidx.appcompat.widget.AppCompatButton
86-
android:id="@+id/btnIncrease"
87-
android:layout_width="wrap_content"
88-
android:layout_height="wrap_content"
89-
android:layout_marginTop="32dp"
90-
android:text="Count++"
91-
app:layout_constraintEnd_toEndOf="parent"
92-
app:layout_constraintStart_toStartOf="parent"
93-
app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
85+
android:id="@+id/btnIncrease"
86+
android:layout_width="wrap_content"
87+
android:layout_height="wrap_content"
88+
android:layout_marginTop="32dp"
89+
android:text="Count++"
90+
app:layout_constraintEnd_toEndOf="parent"
91+
app:layout_constraintStart_toStartOf="parent"
92+
app:layout_constraintTop_toBottomOf="@+id/tvTitle" />
9493

9594
<androidx.appcompat.widget.AppCompatButton
96-
android:id="@+id/btnNextPage"
97-
android:layout_width="wrap_content"
98-
android:layout_height="wrap_content"
99-
android:text="Next Page"
100-
app:layout_constraintBottom_toBottomOf="parent"
101-
app:layout_constraintEnd_toEndOf="parent"
102-
app:layout_constraintStart_toStartOf="parent"
103-
app:layout_constraintTop_toBottomOf="@+id/btnIncrease" />
104-
105-
95+
android:id="@+id/btnNextPage"
96+
android:layout_width="wrap_content"
97+
android:layout_height="wrap_content"
98+
android:text="Next Page"
99+
app:layout_constraintBottom_toBottomOf="parent"
100+
app:layout_constraintEnd_toEndOf="parent"
101+
app:layout_constraintStart_toStartOf="parent"
102+
app:layout_constraintTop_toBottomOf="@+id/btnIncrease" />
106103

107104

108105
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)