mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-03-07 00:08:12 +00:00
ViewCompat.setOnApplyWindowInsetsListener in PostFragment. Fix ViewCompat.setOnApplyWindowInsetsListener in MainActivity.
This commit is contained in:
@ -81,7 +81,7 @@ dependencies {
|
||||
implementation "androidx.paging:paging-runtime:$pagingVersion"
|
||||
implementation "androidx.paging:paging-guava:$pagingVersion"
|
||||
implementation 'androidx.preference:preference:1.2.1'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.3.2'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.4.0'
|
||||
def roomVersion = "2.6.1"
|
||||
implementation "androidx.room:room-runtime:$roomVersion"
|
||||
annotationProcessor "androidx.room:room-compiler:$roomVersion"
|
||||
|
||||
@ -261,80 +261,91 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
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()
|
||||
);
|
||||
|
||||
if (navigationWrapper.navigationRailView == null) {
|
||||
if (navigationWrapper.bottomAppBar.getVisibility() != View.VISIBLE) {
|
||||
ViewGroup.MarginLayoutParams fabParams = (ViewGroup.MarginLayoutParams)
|
||||
navigationWrapper.floatingActionButton.getLayoutParams();
|
||||
fabParams.bottomMargin = (int) Utils.convertDpToPixel(16, MainActivity.this) + allInsets.bottom;
|
||||
navigationWrapper.floatingActionButton.setLayoutParams(fabParams);
|
||||
} else {
|
||||
ViewGroup.MarginLayoutParams fabParams = (ViewGroup.MarginLayoutParams)
|
||||
navigationWrapper.floatingActionButton.getLayoutParams();
|
||||
fabParams.bottomMargin = allInsets.bottom;
|
||||
navigationWrapper.floatingActionButton.setLayoutParams(fabParams);
|
||||
}
|
||||
if (navigationWrapper.navigationRailView == null) {
|
||||
if (navigationWrapper.bottomAppBar.getVisibility() != View.VISIBLE) {
|
||||
ViewGroup.MarginLayoutParams fabParams = (ViewGroup.MarginLayoutParams)
|
||||
navigationWrapper.floatingActionButton.getLayoutParams();
|
||||
fabParams.bottomMargin = (int) Utils.convertDpToPixel(16, MainActivity.this) + allInsets.bottom;
|
||||
fabParams.rightMargin = (int) Utils.convertDpToPixel(16, MainActivity.this) + allInsets.right;
|
||||
navigationWrapper.floatingActionButton.setLayoutParams(fabParams);
|
||||
} else {
|
||||
ViewGroup.MarginLayoutParams fabParams = (ViewGroup.MarginLayoutParams)
|
||||
navigationWrapper.floatingActionButton.getLayoutParams();
|
||||
fabParams.bottomMargin = allInsets.bottom;
|
||||
navigationWrapper.floatingActionButton.setLayoutParams(fabParams);
|
||||
}
|
||||
} else {
|
||||
if (navigationWrapper.navigationRailView.getVisibility() != View.VISIBLE) {
|
||||
ViewGroup.MarginLayoutParams fabParams = (ViewGroup.MarginLayoutParams)
|
||||
navigationWrapper.floatingActionButton.getLayoutParams();
|
||||
fabParams.bottomMargin = (int) Utils.convertDpToPixel(16, MainActivity.this) + allInsets.bottom;
|
||||
fabParams.rightMargin = (int) Utils.convertDpToPixel(16, MainActivity.this) + allInsets.right;
|
||||
navigationWrapper.floatingActionButton.setLayoutParams(fabParams);
|
||||
|
||||
binding.includedAppBar.viewPagerMainActivity.setPadding(allInsets.left, 0, allInsets.right, 0);
|
||||
} else {
|
||||
ViewGroup.MarginLayoutParams navRailParams = (ViewGroup.MarginLayoutParams)
|
||||
navigationWrapper.navigationRailView.getLayoutParams();
|
||||
navRailParams.bottomMargin = allInsets.bottom;
|
||||
navRailParams.setMarginStart(allInsets.left);
|
||||
navigationWrapper.navigationRailView.setLayoutParams(navRailParams);
|
||||
navigationWrapper.navigationRailView.setFitsSystemWindows(false);
|
||||
navigationWrapper.navigationRailView.setPadding(0, 0, 0, 0);
|
||||
|
||||
binding.includedAppBar.viewPagerMainActivity.setPadding(0, 0, allInsets.right, 0);
|
||||
}
|
||||
|
||||
if (navigationWrapper.bottomAppBar != null) {
|
||||
navigationWrapper.linearLayoutBottomAppBar.setPadding(
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingLeft(),
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingTop(),
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingRight(),
|
||||
allInsets.bottom
|
||||
);
|
||||
}
|
||||
|
||||
binding.navDrawerRecyclerViewMainActivity.setPadding(
|
||||
0, 0, 0, allInsets.bottom
|
||||
);
|
||||
|
||||
View toolbar = binding.includedAppBar.toolbar;
|
||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
||||
params.topMargin = allInsets.top;
|
||||
params.setMarginStart(allInsets.left);
|
||||
params.setMarginEnd(allInsets.right);
|
||||
toolbar.setLayoutParams(params);
|
||||
|
||||
binding.includedAppBar.tabLayoutMainActivity.setPadding(
|
||||
allInsets.left, 0, allInsets.right, 0
|
||||
);
|
||||
|
||||
return WindowInsetsCompat.CONSUMED;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
adjustToolbar(binding.includedAppBar.toolbar);
|
||||
|
||||
int navBarHeight = getNavBarHeight();
|
||||
if (navBarHeight > 0) {
|
||||
if (navigationWrapper.navigationRailView == null) {
|
||||
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) navigationWrapper.floatingActionButton.getLayoutParams();
|
||||
params.bottomMargin += navBarHeight;
|
||||
navigationWrapper.floatingActionButton.setLayoutParams(params);
|
||||
}
|
||||
if (navigationWrapper.bottomAppBar != null) {
|
||||
navigationWrapper.linearLayoutBottomAppBar.setPadding(navigationWrapper.linearLayoutBottomAppBar.getPaddingLeft(),
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingTop(), navigationWrapper.linearLayoutBottomAppBar.getPaddingRight(), navBarHeight);
|
||||
navigationWrapper.linearLayoutBottomAppBar.setPadding(
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingLeft(),
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingTop(),
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingRight(),
|
||||
allInsets.bottom
|
||||
);
|
||||
}
|
||||
binding.navDrawerRecyclerViewMainActivity.setPadding(0, 0, 0, navBarHeight);
|
||||
|
||||
View toolbar = binding.includedAppBar.toolbar;
|
||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
||||
params.topMargin = allInsets.top;
|
||||
params.setMarginStart(allInsets.left);
|
||||
params.setMarginEnd(allInsets.right);
|
||||
toolbar.setLayoutParams(params);
|
||||
|
||||
ViewGroup.MarginLayoutParams navRailParams = (ViewGroup.MarginLayoutParams)
|
||||
binding.includedAppBar.tabLayoutMainActivity.getLayoutParams();
|
||||
navRailParams.setMarginStart(allInsets.left);
|
||||
navRailParams.setMarginEnd(allInsets.right);
|
||||
binding.includedAppBar.tabLayoutMainActivity.setLayoutParams(navRailParams);
|
||||
|
||||
return WindowInsetsCompat.CONSUMED;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/*adjustToolbar(binding.includedAppBar.toolbar);
|
||||
|
||||
int navBarHeight = getNavBarHeight();
|
||||
if (navBarHeight > 0) {
|
||||
if (navigationWrapper.navigationRailView == null) {
|
||||
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) navigationWrapper.floatingActionButton.getLayoutParams();
|
||||
params.bottomMargin += navBarHeight;
|
||||
navigationWrapper.floatingActionButton.setLayoutParams(params);
|
||||
}
|
||||
if (navigationWrapper.bottomAppBar != null) {
|
||||
navigationWrapper.linearLayoutBottomAppBar.setPadding(navigationWrapper.linearLayoutBottomAppBar.getPaddingLeft(),
|
||||
navigationWrapper.linearLayoutBottomAppBar.getPaddingTop(), navigationWrapper.linearLayoutBottomAppBar.getPaddingRight(), navBarHeight);
|
||||
}
|
||||
binding.navDrawerRecyclerViewMainActivity.setPadding(0, 0, 0, navBarHeight);
|
||||
}*/
|
||||
} else {
|
||||
binding.drawerLayout.setStatusBarBackgroundColor(mCustomThemeWrapper.getColorPrimaryDark());
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import static ml.docilealligator.infinityforreddit.videoautoplay.media.PlaybackI
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
@ -18,6 +17,10 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
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 androidx.paging.LoadState;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -45,7 +48,6 @@ import ml.docilealligator.infinityforreddit.account.Account;
|
||||
import ml.docilealligator.infinityforreddit.activities.AccountPostsActivity;
|
||||
import ml.docilealligator.infinityforreddit.activities.AccountSavedThingActivity;
|
||||
import ml.docilealligator.infinityforreddit.activities.ActivityToolbarInterface;
|
||||
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
|
||||
import ml.docilealligator.infinityforreddit.activities.CustomizePostFilterActivity;
|
||||
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
|
||||
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
|
||||
@ -188,14 +190,21 @@ public class PostFragment extends PostFragmentBase implements FragmentCommunicat
|
||||
|
||||
Resources resources = getResources();
|
||||
|
||||
if ((activity != null && activity.isImmersiveInterface())) {
|
||||
binding.recyclerViewPostFragment.setPadding(0, 0, 0, ((BaseActivity) activity).getNavBarHeight());
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
|
||||
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (navBarResourceId > 0) {
|
||||
binding.recyclerViewPostFragment.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
|
||||
}
|
||||
if (activity.isImmersiveInterface()) {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(activity.getWindow().getDecorView(), new OnApplyWindowInsetsListener() {
|
||||
@NonNull
|
||||
@Override
|
||||
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
|
||||
Insets allInsets = insets.getInsets(
|
||||
WindowInsetsCompat.Type.systemBars()
|
||||
| WindowInsetsCompat.Type.displayCutout()
|
||||
);
|
||||
binding.recyclerViewPostFragment.setPadding(
|
||||
0, 0, 0, allInsets.bottom
|
||||
);
|
||||
return insets;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
binding.swipeRefreshLayoutPostFragment.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
|
||||
|
||||
Reference in New Issue
Block a user