refactor/fix: renamed method name to be more descriptive and manually collapse bottomSheet on device state change

This commit is contained in:
antonio 2023-12-12 21:28:02 +01:00
parent 5bbab10485
commit 06f4898892
2 changed files with 10 additions and 4 deletions

View file

@ -94,7 +94,7 @@ public class MainActivity extends BaseActivity {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
collapseBottomSheet(); collapseBottomSheetDelayed();
else else
super.onBackPressed(); super.onBackPressed();
} }
@ -118,7 +118,7 @@ public class MainActivity extends BaseActivity {
bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallback); bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallback);
fragmentManager.beginTransaction().replace(R.id.player_bottom_sheet, new PlayerBottomSheetFragment(), "PlayerBottomSheet").commit(); fragmentManager.beginTransaction().replace(R.id.player_bottom_sheet, new PlayerBottomSheetFragment(), "PlayerBottomSheet").commit();
setBottomSheetInPeek(mainViewModel.isQueueLoaded()); checkBottomSheetAfterStateChanged();
} }
public void setBottomSheetInPeek(Boolean isVisible) { public void setBottomSheetInPeek(Boolean isVisible) {
@ -137,7 +137,13 @@ public class MainActivity extends BaseActivity {
} }
} }
public void collapseBottomSheet() { private void checkBottomSheetAfterStateChanged() {
final Handler handler = new Handler();
final Runnable runnable = () -> setBottomSheetInPeek(mainViewModel.isQueueLoaded());
handler.postDelayed(runnable, 100);
}
public void collapseBottomSheetDelayed() {
final Handler handler = new Handler(); final Handler handler = new Handler();
final Runnable runnable = () -> bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); final Runnable runnable = () -> bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
handler.postDelayed(runnable, 100); handler.postDelayed(runnable, 100);

View file

@ -296,7 +296,7 @@ public class PlayerControllerFragment extends Fragment {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(Constants.ARTIST_OBJECT, artist); bundle.putParcelable(Constants.ARTIST_OBJECT, artist);
NavHostFragment.findNavController(this).navigate(R.id.artistPageFragment, bundle); NavHostFragment.findNavController(this).navigate(R.id.artistPageFragment, bundle);
activity.collapseBottomSheet(); activity.collapseBottomSheetDelayed();
}); });
} }
}); });