Merge pull request #6263 from ByteHamster/screen-insets
Use exactly those insets that we mark as consumed
This commit is contained in:
commit
cf057acdf7
|
@ -90,6 +90,7 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
private LockableBottomSheetBehavior sheetBehavior;
|
private LockableBottomSheetBehavior sheetBehavior;
|
||||||
private RecyclerView.RecycledViewPool recycledViewPool = new RecyclerView.RecycledViewPool();
|
private RecyclerView.RecycledViewPool recycledViewPool = new RecyclerView.RecycledViewPool();
|
||||||
private int lastTheme = 0;
|
private int lastTheme = 0;
|
||||||
|
private Insets navigationBarInsets = Insets.NONE;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Intent getIntentToOpenFeed(@NonNull Context context, long feedId) {
|
public static Intent getIntentToOpenFeed(@NonNull Context context, long feedId) {
|
||||||
|
@ -116,10 +117,13 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
setNavDrawerSize();
|
setNavDrawerSize();
|
||||||
|
|
||||||
// Consume navigation bar insets - we apply them in setPlayerVisible()
|
// Consume navigation bar insets - we apply them in setPlayerVisible()
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main_view), (v, insets) ->
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main_view), (v, insets) -> {
|
||||||
new WindowInsetsCompat.Builder(insets)
|
navigationBarInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars());
|
||||||
|
updateInsets();
|
||||||
|
return new WindowInsetsCompat.Builder(insets)
|
||||||
.setInsets(WindowInsetsCompat.Type.navigationBars(), Insets.NONE)
|
.setInsets(WindowInsetsCompat.Type.navigationBars(), Insets.NONE)
|
||||||
.build());
|
.build();
|
||||||
|
});
|
||||||
|
|
||||||
final FragmentManager fm = getSupportFragmentManager();
|
final FragmentManager fm = getSupportFragmentManager();
|
||||||
if (fm.findFragmentByTag(MAIN_FRAGMENT_TAG) == null) {
|
if (fm.findFragmentByTag(MAIN_FRAGMENT_TAG) == null) {
|
||||||
|
@ -160,8 +164,7 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
int playerHeight = (int) getResources().getDimension(R.dimen.external_player_height);
|
updateInsets();
|
||||||
sheetBehavior.setPeekHeight(playerHeight + getBottomInset());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,9 +256,10 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
return sheetBehavior;
|
return sheetBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getBottomInset() {
|
private void updateInsets() {
|
||||||
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(getWindow().getDecorView());
|
setPlayerVisible(findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE);
|
||||||
return insets == null ? 0 : insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom;
|
int playerHeight = (int) getResources().getDimension(R.dimen.external_player_height);
|
||||||
|
sheetBehavior.setPeekHeight(playerHeight + navigationBarInsets.bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerVisible(boolean visible) {
|
public void setPlayerVisible(boolean visible) {
|
||||||
|
@ -268,7 +272,8 @@ public class MainActivity extends CastEnabledActivity {
|
||||||
FragmentContainerView mainView = findViewById(R.id.main_view);
|
FragmentContainerView mainView = findViewById(R.id.main_view);
|
||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mainView.getLayoutParams();
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mainView.getLayoutParams();
|
||||||
int externalPlayerHeight = (int) getResources().getDimension(R.dimen.external_player_height);
|
int externalPlayerHeight = (int) getResources().getDimension(R.dimen.external_player_height);
|
||||||
params.setMargins(0, 0, 0, getBottomInset() + (visible ? externalPlayerHeight : 0));
|
params.setMargins(navigationBarInsets.left, 0, navigationBarInsets.right,
|
||||||
|
navigationBarInsets.bottom + (visible ? externalPlayerHeight : 0));
|
||||||
mainView.setLayoutParams(params);
|
mainView.setLayoutParams(params);
|
||||||
findViewById(R.id.audioplayerFragment).setVisibility(visible ? View.VISIBLE : View.GONE);
|
findViewById(R.id.audioplayerFragment).setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue