Skip to content

Commit 92f1ae3

Browse files
author
Mihai-Cristian Condrea
committed
Refactor EdgeToEdgeDelegate to simplify inset application
The `applyInsetsAsPadding` method in `EdgeToEdgeDelegate.java` was refactored. The boolean parameters `applyStart` and `applyEnd` were removed, simplifying the logic to always apply left and right insets. Calls to this method were updated accordingly. Additionally, added `@NonNull` annotations to `onViewAttachedToWindow` and `onViewDetachedFromWindow` method parameters. Marked some deprecated API calls with `FIXME` comments.
1 parent 65b20a5 commit 92f1ae3

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/utils/EdgeToEdgeDelegate.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public static void apply(Activity activity, View view) {
2525
view,
2626
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(),
2727
true,
28-
true,
29-
true,
3028
true
3129
);
3230
}
@@ -37,16 +35,12 @@ public static void applyBottomBar(Activity activity, View container, View bottom
3735
container,
3836
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(),
3937
true,
40-
true,
41-
true,
4238
false
4339
);
4440
applyInsetsAsPadding(
4541
bottomNavigationView,
4642
WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(),
47-
true,
4843
false,
49-
true,
5044
true
5145
);
5246
}
@@ -59,8 +53,8 @@ private static void enableEdgeToEdge(Activity activity) {
5953
}
6054

6155
private static void applyInsetsAsPadding(View view, int insetTypes,
62-
boolean applyStart, boolean applyTop,
63-
boolean applyEnd, boolean applyBottom) {
56+
boolean applyTop,
57+
boolean applyBottom) {
6458
if (view == null) {
6559
return;
6660
}
@@ -83,12 +77,12 @@ private static void applyInsetsAsPadding(View view, int insetTypes,
8377
InsetsPadding padding = basePadding;
8478
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
8579
Insets insets = windowInsets.getInsets(insetTypes);
86-
int start = applyStart ? insets.left : 0;
80+
int start = insets.left;
8781
int top = applyTop ? insets.top : 0;
88-
int end = applyEnd ? insets.right : 0;
82+
int end = insets.right;
8983
int bottom = applyBottom ? insets.bottom : 0;
9084

91-
ViewCompat.setPaddingRelative(
85+
ViewCompat.setPaddingRelative( // FIXME: 'setPaddingRelative(android.view.@org.jspecify.annotations.NonNull View, int, int, int, int)' is deprecated
9286
v,
9387
padding.start + start,
9488
padding.top + top,
@@ -102,18 +96,18 @@ private static void applyInsetsAsPadding(View view, int insetTypes,
10296
}
10397

10498
private static void requestApplyInsetsWhenAttached(@NonNull View view) {
105-
if (ViewCompat.isAttachedToWindow(view)) {
99+
if (ViewCompat.isAttachedToWindow(view)) { // FIXME: 'isAttachedToWindow(android.view.@org.jspecify.annotations.NonNull View)' is deprecated
106100
ViewCompat.requestApplyInsets(view);
107101
} else {
108102
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
109103
@Override
110-
public void onViewAttachedToWindow(View v) {
104+
public void onViewAttachedToWindow(@NonNull View v) {
111105
v.removeOnAttachStateChangeListener(this);
112106
ViewCompat.requestApplyInsets(v);
113107
}
114108

115109
@Override
116-
public void onViewDetachedFromWindow(View v) {
110+
public void onViewDetachedFromWindow(@NonNull View v) {
117111
// No-op
118112
}
119113
});

0 commit comments

Comments
 (0)