Browse Source

Handle null bottomSheetBehavior

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
90aa9bb954
  1. 9
      app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java

9
app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java

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

Loading…
Cancel
Save