Merge pull request #4604 from ByteHamster/fix-npe-bottomsheet

Fixed NPEs in bottom sheet
This commit is contained in:
ByteHamster 2020-10-26 11:11:00 +01:00 committed by GitHub
commit 73bae55022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);