Skip to content

Commit 31c0d53

Browse files
Add icons for data consent screen
1 parent e9a578d commit 31c0d53

File tree

8 files changed

+121
-46
lines changed

8 files changed

+121
-46
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
3131
super.onViewCreated(view, savedInstanceState);
3232
viewModel = new ViewModelProvider(requireActivity()).get(OnboardingViewModel.class);
3333

34-
binding.switchCrashlytics.setOnCheckedChangeListener((buttonView, isChecked) -> {
35-
binding.textDetails.setVisibility(isChecked ? View.VISIBLE : View.GONE);
36-
viewModel.setCrashlyticsEnabled(isChecked);
37-
});
34+
binding.switchCrashlytics.setOnCheckedChangeListener((buttonView, isChecked) ->
35+
viewModel.setCrashlyticsEnabled(isChecked));
3836

3937
binding.linkPrivacy.setOnClickListener(v -> {
4038
Intent intent = new Intent(Intent.ACTION_VIEW,

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,25 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
4444
super.onViewCreated(view, savedInstanceState);
4545
viewModel = new ViewModelProvider(requireActivity()).get(OnboardingViewModel.class);
4646

47-
// Assign unique IDs to each radio button for proper RadioGroup handling
4847
binding.optionFirst.radioButton.setId(View.generateViewId());
4948
binding.optionSecond.radioButton.setId(View.generateViewId());
5049
binding.optionThird.radioButton.setId(View.generateViewId());
5150

52-
// Default selection
53-
binding.optionFirst.radioButton.setChecked(true);
51+
selectOption(0);
5452

55-
binding.cardFirst.setOnClickListener(v -> binding.optionFirst.radioButton.setChecked(true));
56-
binding.cardSecond.setOnClickListener(v -> binding.optionSecond.radioButton.setChecked(true));
57-
binding.cardThird.setOnClickListener(v -> binding.optionThird.radioButton.setChecked(true));
53+
binding.cardFirst.setOnClickListener(v -> selectOption(0));
54+
binding.cardSecond.setOnClickListener(v -> selectOption(1));
55+
binding.cardThird.setOnClickListener(v -> selectOption(2));
56+
57+
binding.optionFirst.radioButton.setOnClickListener(v -> selectOption(0));
58+
binding.optionSecond.radioButton.setOnClickListener(v -> selectOption(1));
59+
binding.optionThird.radioButton.setOnClickListener(v -> selectOption(2));
60+
}
61+
62+
private void selectOption(int index) {
63+
binding.optionFirst.radioButton.setChecked(index == 0);
64+
binding.optionSecond.radioButton.setChecked(index == 1);
65+
binding.optionThird.radioButton.setChecked(index == 2);
5866
}
5967

6068
public void saveSelection() {

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,25 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
4444
super.onViewCreated(view, savedInstanceState);
4545
viewModel = new ViewModelProvider(requireActivity()).get(OnboardingViewModel.class);
4646

47-
// Assign unique IDs to each radio button
4847
binding.optionFirst.radioButton.setId(View.generateViewId());
4948
binding.optionSecond.radioButton.setId(View.generateViewId());
5049
binding.optionThird.radioButton.setId(View.generateViewId());
5150

52-
// Default selection
53-
binding.optionThird.radioButton.setChecked(true);
51+
selectOption(2);
5452

55-
binding.cardFirst.setOnClickListener(v -> binding.optionFirst.radioButton.setChecked(true));
56-
binding.cardSecond.setOnClickListener(v -> binding.optionSecond.radioButton.setChecked(true));
57-
binding.cardThird.setOnClickListener(v -> binding.optionThird.radioButton.setChecked(true));
53+
binding.cardFirst.setOnClickListener(v -> selectOption(0));
54+
binding.cardSecond.setOnClickListener(v -> selectOption(1));
55+
binding.cardThird.setOnClickListener(v -> selectOption(2));
56+
57+
binding.optionFirst.radioButton.setOnClickListener(v -> selectOption(0));
58+
binding.optionSecond.radioButton.setOnClickListener(v -> selectOption(1));
59+
binding.optionThird.radioButton.setOnClickListener(v -> selectOption(2));
60+
}
61+
62+
private void selectOption(int index) {
63+
binding.optionFirst.radioButton.setChecked(index == 0);
64+
binding.optionSecond.radioButton.setChecked(index == 1);
65+
binding.optionThird.radioButton.setChecked(index == 2);
5866
}
5967

6068
public void saveSelection() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
<path
7+
android:fillColor="?attr/colorOnSurface"
8+
android:pathData="M12 4l1.41 1.41L8.83 10H20v2H8.83l4.58 4.59L12 18l-8-8z"/>
9+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
<path
7+
android:fillColor="?attr/colorOnSurface"
8+
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12V5l-9,-4zM12,3.18l7,3.11v5.58c0,4.35 -3.06,8.52 -7,9.69 -3.94,-1.17 -7,-5.34 -7,-9.69V6.29l7,-3.11z"/>
9+
</vector>

app/src/main/res/layout/fragment_onboarding_data.xml

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
5+
android:layout_height="match_parent"
6+
android:background="?attr/colorSurfaceContainer">
67

78
<LinearLayout
89
android:layout_width="match_parent"
@@ -13,46 +14,86 @@
1314
<com.google.android.material.card.MaterialCardView
1415
android:layout_width="match_parent"
1516
android:layout_height="wrap_content"
16-
android:padding="16dp"
17+
app:cardCornerRadius="16dp"
1718
app:cardElevation="0dp">
1819

1920
<LinearLayout
2021
android:layout_width="match_parent"
2122
android:layout_height="wrap_content"
22-
android:orientation="vertical">
23+
android:orientation="vertical"
24+
android:padding="24dp">
2325

24-
<com.google.android.material.textview.MaterialTextView
25-
style="@style/TextAppearance.Material3.TitleLarge"
26-
android:layout_width="wrap_content"
27-
android:layout_height="wrap_content"
28-
android:layout_marginBottom="16dp"
29-
android:text="@string/onboarding_data_title" />
26+
<ImageView
27+
android:layout_width="64dp"
28+
android:layout_height="64dp"
29+
android:layout_gravity="center_horizontal"
30+
android:src="@drawable/ic_security"
31+
app:tint="?attr/colorPrimary"
32+
android:contentDescription="@string/privacy_icon" />
3033

31-
<com.google.android.material.switchmaterial.SwitchMaterial
32-
android:id="@+id/switchCrashlytics"
34+
<com.google.android.material.textview.MaterialTextView
35+
style="@style/TextAppearance.Material3.HeadlineSmall"
3336
android:layout_width="wrap_content"
3437
android:layout_height="wrap_content"
35-
android:text="@string/onboarding_data_toggle" />
38+
android:layout_gravity="center_horizontal"
39+
android:layout_marginTop="16dp"
40+
android:text="@string/onboarding_data_title"
41+
android:textAlignment="center" />
3642

3743
<com.google.android.material.textview.MaterialTextView
38-
android:id="@+id/textDetails"
3944
style="@style/TextAppearance.Material3.BodyMedium"
4045
android:layout_width="wrap_content"
4146
android:layout_height="wrap_content"
47+
android:layout_gravity="center_horizontal"
4248
android:layout_marginTop="8dp"
43-
android:text="@string/onboarding_data_active"
44-
android:visibility="gone" />
49+
android:text="@string/onboarding_data_subtitle"
50+
android:textAlignment="center"
51+
android:textColor="?attr/colorOnSurfaceVariant" />
4552

46-
<com.google.android.material.textview.MaterialTextView
47-
android:id="@+id/linkPrivacy"
48-
style="@style/TextAppearance.Material3.BodyMedium"
49-
android:layout_width="wrap_content"
53+
<com.google.android.material.materialswitch.MaterialSwitch
54+
android:id="@+id/switchCrashlytics"
55+
android:layout_width="match_parent"
5056
android:layout_height="wrap_content"
51-
android:layout_marginTop="16dp"
52-
android:text="@string/privacy_policy"
53-
android:textColor="?attr/colorPrimary" />
57+
android:layout_marginTop="24dp"
58+
android:text="@string/onboarding_data_toggle"
59+
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
5460

61+
<com.google.android.material.textview.MaterialTextView
62+
android:id="@+id/textDetails"
63+
style="@style/TextAppearance.Material3.BodySmall"
64+
android:layout_width="match_parent"
65+
android:layout_height="wrap_content"
66+
android:layout_marginTop="8dp"
67+
android:text="@string/onboarding_data_active"
68+
android:textColor="?attr/colorOnSurfaceVariant" />
5569
</LinearLayout>
5670
</com.google.android.material.card.MaterialCardView>
71+
72+
<LinearLayout
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content"
75+
android:orientation="horizontal"
76+
android:gravity="center_vertical"
77+
android:layout_marginTop="24dp">
78+
79+
<com.google.android.material.textview.MaterialTextView
80+
android:id="@+id/linkPrivacy"
81+
style="@style/TextAppearance.Material3.BodyMedium"
82+
android:layout_width="0dp"
83+
android:layout_height="wrap_content"
84+
android:layout_weight="1"
85+
android:text="@string/privacy_policy_link"
86+
android:textColor="?attr/colorPrimary"
87+
android:clickable="true"
88+
android:focusable="true" />
89+
90+
<ImageView
91+
android:layout_width="wrap_content"
92+
android:layout_height="wrap_content"
93+
android:src="@drawable/ic_arrow_forward"
94+
app:tint="?attr/colorPrimary"
95+
android:contentDescription="@string/arrow_icon" />
96+
</LinearLayout>
97+
5798
</LinearLayout>
5899
</ScrollView>

app/src/main/res/layout/item_onboarding_option.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
android:layout_height="wrap_content"
1414
android:padding="20dp">
1515

16-
<ImageView
16+
<androidx.appcompat.widget.AppCompatImageView
1717
android:id="@+id/icon"
1818
android:layout_width="24dp"
1919
android:layout_height="24dp"
@@ -24,7 +24,7 @@
2424
app:layout_constraintBottom_toBottomOf="parent"
2525
tools:src="@drawable/ic_theme"/>
2626

27-
<TextView
27+
<com.google.android.material.textview.MaterialTextView
2828
android:id="@+id/title_text"
2929
android:layout_width="0dp"
3030
android:layout_height="wrap_content"
@@ -36,7 +36,7 @@
3636
app:layout_constraintEnd_toStartOf="@id/radio_button"
3737
tools:text="Light mode"/>
3838

39-
<TextView
39+
<com.google.android.material.textview.MaterialTextView
4040
android:id="@+id/description_text"
4141
android:layout_width="0dp"
4242
android:layout_height="wrap_content"
@@ -52,8 +52,6 @@
5252
android:id="@+id/radio_button"
5353
android:layout_width="wrap_content"
5454
android:layout_height="wrap_content"
55-
android:clickable="false"
56-
android:focusable="false"
5755
app:layout_constraintEnd_toEndOf="parent"
5856
app:layout_constraintTop_toTopOf="parent"
5957
app:layout_constraintBottom_toBottomOf="parent"/>

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,13 @@
355355
<string name="follow_system_mode_description">Follows your device theme</string>
356356
<string name="theme_desc_use_system_or_override">Use the system theme or choose a custom one</string>
357357
<string name="auto_battery_mode_description">Switches to dark at night or when Battery Saver is on</string>
358-
<string name="onboarding_data_title">Help Us Improve</string>
359-
<string name="onboarding_data_toggle">Share anonymous usage and crash reports</string>
360-
<string name="onboarding_data_active">Reporting is enabled</string>
358+
<string name="onboarding_data_title">Help Us Improve Your Experience</string>
359+
<string name="onboarding_data_subtitle">Help us make the app better for you by sharing anonymous crash reports and usage statistics.</string>
360+
<string name="onboarding_data_toggle">Enable Crash Reporting</string>
361+
<string name="onboarding_data_active">By enabling this, you help us identify and fix bugs faster. We do not collect any personal information.</string>
362+
<string name="privacy_policy_link">Read our Privacy Policy</string>
363+
<string name="privacy_icon">Privacy Icon</string>
364+
<string name="arrow_icon">Arrow Icon</string>
361365
<string name="onboarding_done_title">You\'re All Set</string>
362366
<string name="onboarding_done_subtitle">Thanks for setting up your preferences. Enjoy the app.</string>
363367
<string name="summary_preference_permissions_access_notification_policy">Allows the app to access and modify the device\'s notification policy, controlling how and when notifications are displayed to the user and providing custom notification management features.</string>

0 commit comments

Comments
 (0)