Fixed NPEs related to bottom sheet

This commit is contained in:
ByteHamster 2020-10-26 10:56:27 +01:00
parent 342ad86467
commit fc54186373
2 changed files with 9 additions and 1 deletions

View File

@ -166,6 +166,9 @@ public class MainActivity extends CastEnabledActivity {
public void onSlide(@NonNull View view, float slideOffset) {
AudioPlayerFragment audioPlayer = (AudioPlayerFragment) getSupportFragmentManager()
.findFragmentByTag(AudioPlayerFragment.TAG);
if (audioPlayer == null) {
return;
}
float condensedSlideOffset = Math.max(0.0f, Math.min(0.2f, slideOffset - 0.2f)) / 0.2f;
audioPlayer.getExternalPlayerHolder().setAlpha(1 - condensedSlideOffset);
audioPlayer.getExternalPlayerHolder().setVisibility(

View File

@ -135,7 +135,12 @@ public class AudioPlayerFragment extends Fragment implements
pager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
pager.post(() -> ((MainActivity) getActivity()).getBottomSheet().updateScrollingChild());
pager.post(() -> {
if (getActivity() != null) {
// By the time this is posted, the activity might be closed again.
((MainActivity) getActivity()).getBottomSheet().updateScrollingChild();
}
});
}
});
pageIndicator = root.findViewById(R.id.page_indicator);