ViewCompat.setOnApplyWindowInsetsListener in CommentFilterUsageListingActivity.

This commit is contained in:
Docile-Alligator
2025-06-16 18:29:57 -04:00
parent 0d208e4f92
commit bbd3001dbf
2 changed files with 70 additions and 31 deletions

View File

@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
@ -69,44 +68,42 @@ public class CommentFilterPreferenceActivity extends BaseActivity {
applyCustomTheme();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (isImmersiveInterface()) {
if (isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(binding.appbarLayoutCommentFilterPreferenceActivity);
}
if (isImmersiveInterface()) {
ViewCompat.setOnApplyWindowInsetsListener(binding.getRoot(), new OnApplyWindowInsetsListener() {
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
Insets allInsets = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
| WindowInsetsCompat.Type.displayCutout()
);
ViewCompat.setOnApplyWindowInsetsListener(binding.getRoot(), new OnApplyWindowInsetsListener() {
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
Insets allInsets = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
| WindowInsetsCompat.Type.displayCutout()
);
setMargins(binding.toolbarCommentFilterPreferenceActivity,
allInsets.left,
allInsets.top,
allInsets.right,
BaseActivity.IGNORE_MARGIN);
setMargins(binding.toolbarCommentFilterPreferenceActivity,
allInsets.left,
allInsets.top,
allInsets.right,
BaseActivity.IGNORE_MARGIN);
binding.recyclerViewCommentFilterPreferenceActivity.setPadding(
allInsets.left,
0,
allInsets.right,
allInsets.bottom
);
binding.recyclerViewCommentFilterPreferenceActivity.setPadding(
allInsets.left,
0,
allInsets.right,
allInsets.bottom
);
setMargins(binding.fabCommentFilterPreferenceActivity,
BaseActivity.IGNORE_MARGIN,
BaseActivity.IGNORE_MARGIN,
(int) Utils.convertDpToPixel(16, CommentFilterPreferenceActivity.this) + allInsets.right,
(int) Utils.convertDpToPixel(16, CommentFilterPreferenceActivity.this) + allInsets.bottom);
setMargins(binding.fabCommentFilterPreferenceActivity,
BaseActivity.IGNORE_MARGIN,
BaseActivity.IGNORE_MARGIN,
(int) Utils.convertDpToPixel(16, CommentFilterPreferenceActivity.this) + allInsets.right,
(int) Utils.convertDpToPixel(16, CommentFilterPreferenceActivity.this) + allInsets.bottom);
return WindowInsetsCompat.CONSUMED;
}
});
}
return WindowInsetsCompat.CONSUMED;
}
});
}
setSupportActionBar(binding.toolbarCommentFilterPreferenceActivity);

View File

@ -9,6 +9,10 @@ import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.OnApplyWindowInsetsListener;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -67,6 +71,44 @@ public class CommentFilterUsageListingActivity extends BaseActivity {
applyCustomTheme();
if (isImmersiveInterface()) {
if (isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(binding.appbarLayoutCommentFilterUsageListingActivity);
}
ViewCompat.setOnApplyWindowInsetsListener(binding.getRoot(), new OnApplyWindowInsetsListener() {
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
Insets allInsets = insets.getInsets(
WindowInsetsCompat.Type.systemBars()
| WindowInsetsCompat.Type.displayCutout()
);
setMargins(binding.toolbarCommentFilterUsageListingActivity,
allInsets.left,
allInsets.top,
allInsets.right,
BaseActivity.IGNORE_MARGIN);
binding.recyclerViewCommentFilterUsageListingActivity.setPadding(
allInsets.left,
0,
allInsets.right,
allInsets.bottom
);
setMargins(binding.fabCommentFilterUsageListingActivity,
BaseActivity.IGNORE_MARGIN,
BaseActivity.IGNORE_MARGIN,
(int) Utils.convertDpToPixel(16, CommentFilterUsageListingActivity.this) + allInsets.right,
(int) Utils.convertDpToPixel(16, CommentFilterUsageListingActivity.this) + allInsets.bottom);
return WindowInsetsCompat.CONSUMED;
}
});
}
setSupportActionBar(binding.toolbarCommentFilterUsageListingActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);