Skip to content

Commit fee79ab

Browse files
Refactor icon frame handling in preferences
This commit removes the explicit `iconFrame` `FrameLayout` from `item_preference.xml` and updates the logic in `AndroidStudioFragment.java` and `SettingsFragment.java` to directly manage the visibility of the icon `ImageView`. - In `AndroidStudioFragment.java`, removed references and visibility updates for `iconFrame`. - In `SettingsFragment.java`, updated `syncAccessoryVisibility` to set the visibility of the icon directly instead of its parent `iconFrame`. - In `item_preference.xml`, removed the `FrameLayout` with ID `@android:id/icon_frame` and moved its layout attributes to the `ShapeableImageView` with ID `@android:id/icon`.
1 parent 3654f45 commit fee79ab

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/android/AndroidStudioFragment.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ static class LessonHolder extends RecyclerView.ViewHolder {
430430
final MaterialTextView summary;
431431
final FrameLayout widgetFrame;
432432
final MaterialButton externalButton;
433-
final FrameLayout iconFrame;
434433

435434
LessonHolder(@NonNull View itemView) {
436435
super(itemView);
@@ -439,7 +438,6 @@ static class LessonHolder extends RecyclerView.ViewHolder {
439438
title = itemView.findViewById(android.R.id.title);
440439
summary = itemView.findViewById(android.R.id.summary);
441440
widgetFrame = itemView.findViewById(android.R.id.widget_frame);
442-
iconFrame = itemView.findViewById(android.R.id.icon_frame);
443441
LayoutInflater.from(itemView.getContext())
444442
.inflate(R.layout.item_preference_widget_open_in_new, widgetFrame, true);
445443
externalButton = widgetFrame.findViewById(R.id.open_in_new);
@@ -449,14 +447,8 @@ void bind(Lesson lesson, boolean first, boolean last) {
449447
if (lesson.iconRes != 0) {
450448
icon.setImageResource(lesson.iconRes);
451449
icon.setVisibility(View.VISIBLE);
452-
if (iconFrame != null) {
453-
iconFrame.setVisibility(View.VISIBLE);
454-
}
455450
} else {
456451
icon.setVisibility(View.GONE);
457-
if (iconFrame != null) {
458-
iconFrame.setVisibility(View.GONE);
459-
}
460452
}
461453
title.setText(lesson.title);
462454
if (lesson.summary != null) {

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/settings/SettingsFragment.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,9 @@ private void applyRoundedCorners(@NonNull MaterialCardView card, boolean first,
317317

318318
private void syncAccessoryVisibility(@NonNull View itemView) {
319319
View icon = itemView.findViewById(android.R.id.icon);
320-
View iconFrame = itemView.findViewById(android.R.id.icon_frame);
321-
if (iconFrame != null) {
322-
boolean showIcon = icon != null && icon.getVisibility() == View.VISIBLE;
323-
iconFrame.setVisibility(showIcon ? View.VISIBLE : View.GONE);
320+
boolean showIcon = icon != null && icon.getVisibility() == View.VISIBLE;
321+
if (icon != null) {
322+
icon.setVisibility(showIcon ? View.VISIBLE : View.GONE);
324323
}
325324
View widgetFrame = itemView.findViewById(android.R.id.widget_frame);
326325
if (widgetFrame instanceof ViewGroup) {

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,18 @@
1717
android:orientation="horizontal"
1818
android:padding="12dp">
1919

20-
<FrameLayout
21-
android:id="@android:id/icon_frame"
22-
android:layout_width="wrap_content"
23-
android:layout_height="wrap_content"
24-
android:layout_gravity="center_vertical"
20+
<com.google.android.material.imageview.ShapeableImageView
21+
android:id="@android:id/icon"
22+
android:layout_width="36dp"
23+
android:layout_height="36dp"
2524
android:layout_marginEnd="16dp"
25+
android:background="?attr/colorPrimaryContainer"
26+
android:contentDescription="@null"
27+
android:scaleType="centerCrop"
2628
android:visibility="gone"
27-
tools:visibility="visible">
28-
29-
<com.google.android.material.imageview.ShapeableImageView
30-
android:id="@android:id/icon"
31-
android:layout_width="36dp"
32-
android:layout_height="36dp"
33-
android:background="?attr/colorPrimaryContainer"
34-
android:contentDescription="@null"
35-
android:scaleType="centerCrop"
36-
android:visibility="gone"
37-
app:contentPadding="6dp"
38-
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Full"
39-
tools:visibility="visible" />
40-
</FrameLayout>
29+
app:contentPadding="6dp"
30+
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Full"
31+
tools:visibility="visible" />
4132

4233
<androidx.appcompat.widget.LinearLayoutCompat
4334
android:layout_width="0dp"

0 commit comments

Comments
 (0)