mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-02-08 00:25:41 +00:00
Use ViewCompat.setOnApplyWindowInsetsListener in MainActivity on Android 15+. Remove Immersive Interface option on Android 15+.
This commit is contained in:
@ -68,7 +68,7 @@ dependencies {
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.activity:activity:1.9.0'
|
||||
implementation 'androidx.activity:activity:1.10.1'
|
||||
implementation 'androidx.core:core-ktx:1.16.0'
|
||||
def lifecycleVersion = "2.7.0"
|
||||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
|
||||
@ -90,6 +90,7 @@ dependencies {
|
||||
implementation 'androidx.viewpager2:viewpager2:1.1.0'
|
||||
implementation 'androidx.work:work-runtime:2.9.0'
|
||||
implementation 'com.google.android.material:material:1.14.0-alpha01'
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-beta01"
|
||||
|
||||
/** ExoPlayer **/
|
||||
def media3_version = "1.4.0-alpha02"
|
||||
|
||||
@ -111,8 +111,8 @@ public abstract class BaseActivity extends AppCompatActivity implements CustomFo
|
||||
|
||||
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||||
int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
|
||||
immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true);
|
||||
immersiveInterface = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) || Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM;
|
||||
if (immersiveInterface && config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
immersiveInterface = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMMERSIVE_INTERFACE_IN_LANDSCAPE_MODE, false);
|
||||
}
|
||||
|
||||
@ -13,11 +13,13 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
@ -32,7 +34,12 @@ import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.splashscreen.SplashScreen;
|
||||
import androidx.core.view.OnApplyWindowInsetsListener;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@ -253,20 +260,70 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else {
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||
}
|
||||
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 (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()
|
||||
);
|
||||
|
||||
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.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(params.getMarginStart() + allInsets.left);
|
||||
params.setMarginEnd(params.getMarginEnd() + allInsets.right);
|
||||
toolbar.setLayoutParams(params);
|
||||
|
||||
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);
|
||||
}
|
||||
binding.navDrawerRecyclerViewMainActivity.setPadding(0, 0, 0, navBarHeight);
|
||||
}
|
||||
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());
|
||||
|
||||
@ -26,7 +26,7 @@ public class InterfacePreferenceFragment extends CustomFontPreferenceFragmentCom
|
||||
SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
|
||||
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
|
||||
|
||||
if (immersiveInterfaceEntryPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
if (immersiveInterfaceEntryPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
immersiveInterfaceEntryPreference.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user