Handle null bottomSheetBehavior

This commit is contained in:
Ammar Githam 2020-11-08 15:48:48 +09:00
parent 820a959196
commit 90aa9bb954
1 changed files with 12 additions and 5 deletions

View File

@ -373,7 +373,9 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
binding.sliderParent.setLayoutParams(new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
binding.sliderParent.requestLayout();
if (bottomSheetBehavior != null) {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
return;
}
if (destView == binding.videoPost.thumbnailParent) {
@ -382,9 +384,11 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
params.gravity = Gravity.CENTER;
binding.videoPost.thumbnailParent.setLayoutParams(params);
binding.videoPost.thumbnailParent.requestLayout();
if (bottomSheetBehavior != null) {
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
}
@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
@ -703,10 +707,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
}
});
binding.caption.setOnClickListener(v -> {
if (bottomSheetBehavior == null) return;
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) return;
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
});
binding.captionToggle.setOnClickListener(v -> {
if (bottomSheetBehavior == null) return;
switch (bottomSheetBehavior.getState()) {
case BottomSheetBehavior.STATE_HIDDEN:
binding.captionParent.fullScroll(ScrollView.FOCUS_UP); // reset scroll position
@ -734,6 +740,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
@Override
public void onGlobalLayout() {
binding.getRoot().getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (bottomSheetBehavior == null) return;
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
});
@ -762,7 +769,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
final int likesCount = (int) feedModel.getLikesCount();
final String likesString = getResources().getQuantityString(R.plurals.likes_count, likesCount, likesCount);
binding.likesCount.setText(likesString);
} catch (IllegalStateException e) {}
} catch (IllegalStateException ignored) {}
}
private void setupPostTypeLayout() {