Avoid setting invalid states to bottom sheet callback

This commit is contained in:
Stypox 2022-08-24 16:03:15 +02:00
parent 500acce178
commit ca0f56eea8
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 16 additions and 4 deletions

View File

@ -180,6 +180,8 @@ public final class VideoDetailFragment
@State @State
int bottomSheetState = BottomSheetBehavior.STATE_EXPANDED; int bottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
@State @State
int lastStableBottomSheetState = BottomSheetBehavior.STATE_EXPANDED;
@State
protected boolean autoPlayEnabled = true; protected boolean autoPlayEnabled = true;
@Nullable @Nullable
@ -269,7 +271,7 @@ public final class VideoDetailFragment
public static VideoDetailFragment getInstanceInCollapsedState() { public static VideoDetailFragment getInstanceInCollapsedState() {
final VideoDetailFragment instance = new VideoDetailFragment(); final VideoDetailFragment instance = new VideoDetailFragment();
instance.bottomSheetState = BottomSheetBehavior.STATE_COLLAPSED; instance.updateBottomSheetState(BottomSheetBehavior.STATE_COLLAPSED);
return instance; return instance;
} }
@ -1170,7 +1172,7 @@ public final class VideoDetailFragment
// doesn't tell which state it was settling to, and thus the bottom sheet settles to // doesn't tell which state it was settling to, and thus the bottom sheet settles to
// STATE_COLLAPSED. This can be solved by manually setting the state that will be // STATE_COLLAPSED. This can be solved by manually setting the state that will be
// restored (i.e. bottomSheetState) to STATE_EXPANDED. // restored (i.e. bottomSheetState) to STATE_EXPANDED.
bottomSheetState = BottomSheetBehavior.STATE_EXPANDED; updateBottomSheetState(BottomSheetBehavior.STATE_EXPANDED);
// toggle landscape in order to open directly in fullscreen // toggle landscape in order to open directly in fullscreen
onScreenRotationButtonClicked(); onScreenRotationButtonClicked();
} }
@ -2284,7 +2286,9 @@ public final class VideoDetailFragment
final FrameLayout bottomSheetLayout = activity.findViewById(R.id.fragment_player_holder); final FrameLayout bottomSheetLayout = activity.findViewById(R.id.fragment_player_holder);
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout); bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout);
bottomSheetBehavior.setState(bottomSheetState); bottomSheetBehavior.setState(lastStableBottomSheetState);
updateBottomSheetState(lastStableBottomSheetState);
final int peekHeight = getResources().getDimensionPixelSize(R.dimen.mini_player_height); final int peekHeight = getResources().getDimensionPixelSize(R.dimen.mini_player_height);
if (bottomSheetState != BottomSheetBehavior.STATE_HIDDEN) { if (bottomSheetState != BottomSheetBehavior.STATE_HIDDEN) {
manageSpaceAtTheBottom(false); manageSpaceAtTheBottom(false);
@ -2300,7 +2304,7 @@ public final class VideoDetailFragment
bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() { bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override @Override
public void onStateChanged(@NonNull final View bottomSheet, final int newState) { public void onStateChanged(@NonNull final View bottomSheet, final int newState) {
bottomSheetState = newState; updateBottomSheetState(newState);
switch (newState) { switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN: case BottomSheetBehavior.STATE_HIDDEN:
@ -2441,4 +2445,12 @@ public final class VideoDetailFragment
return player.UIs().get(VideoPlayerUi.class) return player.UIs().get(VideoPlayerUi.class)
.map(playerUi -> playerUi.getBinding().getRoot()); .map(playerUi -> playerUi.getBinding().getRoot());
} }
private void updateBottomSheetState(final int newState) {
bottomSheetState = newState;
if (newState != BottomSheetBehavior.STATE_DRAGGING
&& newState != BottomSheetBehavior.STATE_SETTLING) {
lastStableBottomSheetState = newState;
}
}
} }