@@ -180,6 +180,8 @@ public final class VideoDetailFragment
180180 @ State
181181 int bottomSheetState = BottomSheetBehavior .STATE_EXPANDED ;
182182 @ State
183+ int lastStableBottomSheetState = BottomSheetBehavior .STATE_EXPANDED ;
184+ @ State
183185 protected boolean autoPlayEnabled = true ;
184186
185187 @ Nullable
@@ -269,7 +271,7 @@ public static VideoDetailFragment getInstance(final int serviceId,
269271
270272 public static VideoDetailFragment getInstanceInCollapsedState () {
271273 final VideoDetailFragment instance = new VideoDetailFragment ();
272- instance .bottomSheetState = BottomSheetBehavior .STATE_COLLAPSED ;
274+ instance .updateBottomSheetState ( BottomSheetBehavior .STATE_COLLAPSED ) ;
273275 return instance ;
274276 }
275277
@@ -1170,7 +1172,7 @@ public void openVideoPlayer(final boolean directlyFullscreenIfApplicable) {
11701172 // doesn't tell which state it was settling to, and thus the bottom sheet settles to
11711173 // STATE_COLLAPSED. This can be solved by manually setting the state that will be
11721174 // restored (i.e. bottomSheetState) to STATE_EXPANDED.
1173- bottomSheetState = BottomSheetBehavior .STATE_EXPANDED ;
1175+ updateBottomSheetState ( BottomSheetBehavior .STATE_EXPANDED ) ;
11741176 // toggle landscape in order to open directly in fullscreen
11751177 onScreenRotationButtonClicked ();
11761178 }
@@ -2284,7 +2286,9 @@ private void setupBottomPlayer() {
22842286
22852287 final FrameLayout bottomSheetLayout = activity .findViewById (R .id .fragment_player_holder );
22862288 bottomSheetBehavior = BottomSheetBehavior .from (bottomSheetLayout );
2287- bottomSheetBehavior .setState (bottomSheetState );
2289+ bottomSheetBehavior .setState (lastStableBottomSheetState );
2290+ updateBottomSheetState (lastStableBottomSheetState );
2291+
22882292 final int peekHeight = getResources ().getDimensionPixelSize (R .dimen .mini_player_height );
22892293 if (bottomSheetState != BottomSheetBehavior .STATE_HIDDEN ) {
22902294 manageSpaceAtTheBottom (false );
@@ -2300,7 +2304,7 @@ private void setupBottomPlayer() {
23002304 bottomSheetCallback = new BottomSheetBehavior .BottomSheetCallback () {
23012305 @ Override
23022306 public void onStateChanged (@ NonNull final View bottomSheet , final int newState ) {
2303- bottomSheetState = newState ;
2307+ updateBottomSheetState ( newState ) ;
23042308
23052309 switch (newState ) {
23062310 case BottomSheetBehavior .STATE_HIDDEN :
@@ -2441,4 +2445,12 @@ public Optional<View> getRoot() {
24412445 return player .UIs ().get (VideoPlayerUi .class )
24422446 .map (playerUi -> playerUi .getBinding ().getRoot ());
24432447 }
2448+
2449+ private void updateBottomSheetState (final int newState ) {
2450+ bottomSheetState = newState ;
2451+ if (newState != BottomSheetBehavior .STATE_DRAGGING
2452+ && newState != BottomSheetBehavior .STATE_SETTLING ) {
2453+ lastStableBottomSheetState = newState ;
2454+ }
2455+ }
24442456}
0 commit comments