Skip to content

Commit ef214f2

Browse files
Add default tab selection screen
1 parent c685368 commit ef214f2

File tree

4 files changed

+184
-29
lines changed

4 files changed

+184
-29
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/onboarding/OnboardingActivity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public void onPageSelected(int position) {
4646
Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + currentPosition);
4747
if (fragment instanceof ThemeFragment) {
4848
((ThemeFragment) fragment).saveSelection();
49+
} else if (fragment instanceof StartPageFragment) {
50+
((StartPageFragment) fragment).saveSelection();
4951
} else if (fragment instanceof DataFragment) {
5052
((DataFragment) fragment).saveSelection();
5153
}
@@ -98,6 +100,8 @@ public void onTabReselected(TabLayout.Tab tab) {
98100
Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + current);
99101
if (fragment instanceof ThemeFragment) {
100102
((ThemeFragment) fragment).saveSelection();
103+
} else if (fragment instanceof StartPageFragment) {
104+
((StartPageFragment) fragment).saveSelection();
101105
} else if (fragment instanceof DataFragment) {
102106
((DataFragment) fragment).saveSelection();
103107
}
@@ -140,6 +144,8 @@ public Fragment createFragment(int position) {
140144
case 0:
141145
return new ThemeFragment();
142146
case 1:
147+
return new StartPageFragment();
148+
case 2:
143149
return new DataFragment();
144150
default:
145151
return new DoneFragment();
@@ -148,7 +154,7 @@ public Fragment createFragment(int position) {
148154

149155
@Override
150156
public int getItemCount() {
151-
return 3;
157+
return 4;
152158
}
153159
}
154160
}

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/onboarding/StartPageFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
2929
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
3030
super.onViewCreated(view, savedInstanceState);
3131
viewModel = new ViewModelProvider(requireActivity()).get(OnboardingViewModel.class);
32+
33+
binding.cardHome.setOnClickListener(v -> binding.radioHome.setChecked(true));
34+
binding.cardAndroidStudio.setOnClickListener(v -> binding.radioAndroidStudio.setChecked(true));
35+
binding.cardAbout.setOnClickListener(v -> binding.radioAbout.setChecked(true));
3236
}
3337

3438
public void saveSelection() {
Lines changed: 169 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,200 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
2+
<ScrollView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
46
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
7+
android:layout_height="match_parent"
8+
android:fillViewport="true">
69

7-
<LinearLayout
10+
<androidx.constraintlayout.widget.ConstraintLayout
811
android:layout_width="match_parent"
912
android:layout_height="wrap_content"
10-
android:orientation="vertical"
1113
android:padding="24dp">
1214

13-
<com.google.android.material.card.MaterialCardView
14-
android:layout_width="match_parent"
15+
<!-- Main Title -->
16+
<com.google.android.material.textview.MaterialTextView
17+
android:id="@+id/title"
18+
android:layout_width="wrap_content"
1519
android:layout_height="wrap_content"
16-
android:padding="16dp"
17-
app:cardElevation="0dp">
20+
android:text="@string/default_tab"
21+
android:textAppearance="?attr/textAppearanceHeadlineMedium"
22+
app:layout_constraintTop_toTopOf="parent"
23+
app:layout_constraintStart_toStartOf="parent"
24+
app:layout_constraintEnd_toEndOf="parent" />
1825

19-
<LinearLayout
26+
<!-- Subtitle/Description -->
27+
<com.google.android.material.textview.MaterialTextView
28+
android:id="@+id/description"
29+
android:layout_width="0dp"
30+
android:layout_height="wrap_content"
31+
android:layout_marginTop="8dp"
32+
android:text="@string/default_tab_description"
33+
android:textAppearance="?attr/textAppearanceBodyMedium"
34+
android:textColor="?attr/colorOnSurfaceVariant"
35+
app:layout_constraintTop_toBottomOf="@id/title"
36+
app:layout_constraintStart_toStartOf="parent"
37+
app:layout_constraintEnd_toEndOf="parent"/>
38+
39+
<!-- RadioGroup manages the selection logic for the cards -->
40+
<RadioGroup
41+
android:id="@+id/start_page_group"
42+
android:layout_width="0dp"
43+
android:layout_height="wrap_content"
44+
android:layout_marginTop="32dp"
45+
android:orientation="vertical"
46+
app:layout_constraintTop_toBottomOf="@id/description"
47+
app:layout_constraintStart_toStartOf="parent"
48+
app:layout_constraintEnd_toEndOf="parent">
49+
50+
<!-- Home Card -->
51+
<com.google.android.material.card.MaterialCardView
52+
android:id="@+id/card_home"
2053
android:layout_width="match_parent"
2154
android:layout_height="wrap_content"
22-
android:orientation="vertical">
55+
app:cardElevation="0dp">
2356

24-
<com.google.android.material.textview.MaterialTextView
25-
style="@style/TextAppearance.Material3.TitleLarge"
26-
android:layout_width="wrap_content"
57+
<LinearLayout
58+
android:layout_width="match_parent"
2759
android:layout_height="wrap_content"
28-
android:layout_marginBottom="16dp"
29-
android:text="@string/default_tab" />
60+
android:orientation="horizontal"
61+
android:gravity="center_vertical"
62+
android:padding="16dp">
3063

31-
<RadioGroup
32-
android:id="@+id/start_page_group"
33-
android:layout_width="match_parent"
34-
android:layout_height="wrap_content">
64+
<ImageView
65+
android:layout_width="24dp"
66+
android:layout_height="24dp"
67+
android:src="@drawable/ic_home"
68+
android:contentDescription="@string/home"/>
69+
70+
<LinearLayout
71+
android:layout_width="0dp"
72+
android:layout_height="wrap_content"
73+
android:layout_marginStart="16dp"
74+
android:layout_weight="1"
75+
android:orientation="vertical">
76+
77+
<com.google.android.material.textview.MaterialTextView
78+
android:layout_width="wrap_content"
79+
android:layout_height="wrap_content"
80+
android:text="@string/home"
81+
android:textAppearance="?attr/textAppearanceBodyLarge"/>
82+
83+
<com.google.android.material.textview.MaterialTextView
84+
android:layout_width="wrap_content"
85+
android:layout_height="wrap_content"
86+
android:text="@string/home_description"
87+
android:textAppearance="?attr/textAppearanceBodySmall"
88+
android:textColor="?attr/colorOnSurfaceVariant"/>
89+
</LinearLayout>
3590

3691
<com.google.android.material.radiobutton.MaterialRadioButton
3792
android:id="@+id/radio_home"
3893
android:layout_width="wrap_content"
3994
android:layout_height="wrap_content"
40-
android:checked="true"
41-
android:text="@string/home" />
95+
android:checked="true"/>
96+
</LinearLayout>
97+
</com.google.android.material.card.MaterialCardView>
98+
99+
<!-- Android Studio Card -->
100+
<com.google.android.material.card.MaterialCardView
101+
android:id="@+id/card_android_studio"
102+
android:layout_width="match_parent"
103+
android:layout_height="wrap_content"
104+
android:layout_marginTop="16dp"
105+
app:cardElevation="0dp">
106+
107+
<LinearLayout
108+
android:layout_width="match_parent"
109+
android:layout_height="wrap_content"
110+
android:orientation="horizontal"
111+
android:gravity="center_vertical"
112+
android:padding="16dp">
113+
114+
<ImageView
115+
android:layout_width="24dp"
116+
android:layout_height="24dp"
117+
android:src="@drawable/ic_android"
118+
android:contentDescription="@string/android_studio"/>
119+
120+
<LinearLayout
121+
android:layout_width="0dp"
122+
android:layout_height="wrap_content"
123+
android:layout_marginStart="16dp"
124+
android:layout_weight="1"
125+
android:orientation="vertical">
126+
127+
<com.google.android.material.textview.MaterialTextView
128+
android:layout_width="wrap_content"
129+
android:layout_height="wrap_content"
130+
android:text="@string/android_studio"
131+
android:textAppearance="?attr/textAppearanceBodyLarge"/>
132+
133+
<com.google.android.material.textview.MaterialTextView
134+
android:layout_width="wrap_content"
135+
android:layout_height="wrap_content"
136+
android:text="@string/android_studio_description"
137+
android:textAppearance="?attr/textAppearanceBodySmall"
138+
android:textColor="?attr/colorOnSurfaceVariant"/>
139+
</LinearLayout>
42140

43141
<com.google.android.material.radiobutton.MaterialRadioButton
44142
android:id="@+id/radio_android_studio"
45143
android:layout_width="wrap_content"
144+
android:layout_height="wrap_content"/>
145+
</LinearLayout>
146+
</com.google.android.material.card.MaterialCardView>
147+
148+
<!-- About Card -->
149+
<com.google.android.material.card.MaterialCardView
150+
android:id="@+id/card_about"
151+
android:layout_width="match_parent"
152+
android:layout_height="wrap_content"
153+
android:layout_marginTop="16dp"
154+
app:cardElevation="0dp">
155+
156+
<LinearLayout
157+
android:layout_width="match_parent"
158+
android:layout_height="wrap_content"
159+
android:orientation="horizontal"
160+
android:gravity="center_vertical"
161+
android:padding="16dp">
162+
163+
<ImageView
164+
android:layout_width="24dp"
165+
android:layout_height="24dp"
166+
android:src="@drawable/ic_about"
167+
android:contentDescription="@string/about"/>
168+
169+
<LinearLayout
170+
android:layout_width="0dp"
46171
android:layout_height="wrap_content"
47-
android:text="@string/android_studio" />
172+
android:layout_marginStart="16dp"
173+
android:layout_weight="1"
174+
android:orientation="vertical">
175+
176+
<com.google.android.material.textview.MaterialTextView
177+
android:layout_width="wrap_content"
178+
android:layout_height="wrap_content"
179+
android:text="@string/about"
180+
android:textAppearance="?attr/textAppearanceBodyLarge"/>
181+
182+
<com.google.android.material.textview.MaterialTextView
183+
android:layout_width="wrap_content"
184+
android:layout_height="wrap_content"
185+
android:text="@string/about_description"
186+
android:textAppearance="?attr/textAppearanceBodySmall"
187+
android:textColor="?attr/colorOnSurfaceVariant"/>
188+
</LinearLayout>
48189

49190
<com.google.android.material.radiobutton.MaterialRadioButton
50191
android:id="@+id/radio_about"
51192
android:layout_width="wrap_content"
52-
android:layout_height="wrap_content"
53-
android:text="@string/about" />
54-
</RadioGroup>
55-
</LinearLayout>
56-
</com.google.android.material.card.MaterialCardView>
193+
android:layout_height="wrap_content"/>
194+
</LinearLayout>
195+
</com.google.android.material.card.MaterialCardView>
196+
197+
</RadioGroup>
57198

58-
</LinearLayout>
199+
</androidx.constraintlayout.widget.ConstraintLayout>
59200
</ScrollView>

app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@
254254
<string name="dark_mode">Dark mode</string>
255255
<string name="auto_battery_mode">Auto battery dark mode</string>
256256
<string name="default_tab">Default tab</string>
257+
<string name="default_tab_description">Select which tab opens when the app starts.</string>
258+
<string name="home_description">Latest tutorials and updates.</string>
259+
<string name="android_studio_description">Tools and tips for Android Studio.</string>
260+
<string name="about_description">Information about this app.</string>
257261
<string name="bottom_navigation_bar_labels">Bottom navigation bar labels</string>
258262
<string name="labeled">Labeled</string>
259263
<string name="selected">Selected %1$s</string>

0 commit comments

Comments
 (0)