Browse Source

Handle some 'may be null' warnings

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
92d8163c7b
  1. 27
      app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java

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

@ -64,7 +64,6 @@ import java.io.Serializable;
import java.util.List; import java.util.List;
import awais.instagrabber.R; import awais.instagrabber.R;
import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.adapters.SliderCallbackAdapter; import awais.instagrabber.adapters.SliderCallbackAdapter;
import awais.instagrabber.adapters.SliderItemsAdapter; import awais.instagrabber.adapters.SliderItemsAdapter;
import awais.instagrabber.adapters.viewholder.SliderVideoViewHolder; import awais.instagrabber.adapters.viewholder.SliderVideoViewHolder;
@ -228,7 +227,6 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
public void onCreate(@Nullable final Bundle savedInstanceState) { public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.PostViewV2Style); setStyle(DialogFragment.STYLE_NO_FRAME, R.style.PostViewV2Style);
final MainActivity fragmentActivity = (MainActivity) getActivity();
mediaService = MediaService.getInstance(); mediaService = MediaService.getInstance();
final Bundle arguments = getArguments(); final Bundle arguments = getArguments();
if (arguments == null) return; if (arguments == null) return;
@ -241,7 +239,6 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
return; return;
} }
feedModel = (Media) feedModelSerializable; feedModel = (Media) feedModelSerializable;
if (feedModel == null) return;
if (feedModel.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) { if (feedModel.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) {
sliderPosition = arguments.getInt(ARG_SLIDER_POSITION, 0); sliderPosition = arguments.getInt(ARG_SLIDER_POSITION, 0);
} }
@ -700,8 +697,9 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
binding.title.setOnClickListener(v -> navigateToProfile("@" + profileModel.getUsername())); binding.title.setOnClickListener(v -> navigateToProfile("@" + profileModel.getUsername()));
binding.righttitle.setOnClickListener(v -> navigateToProfile("@" + profileModel.getUsername())); binding.righttitle.setOnClickListener(v -> navigateToProfile("@" + profileModel.getUsername()));
final Location location = feedModel.getLocation(); final Location location = feedModel.getLocation();
final String locationName = location != null ? location.getName() : "";
if (!TextUtils.isEmpty(locationName)) {
if (location != null) {
final String locationName = location.getName();
if (TextUtils.isEmpty(locationName)) return;
binding.subtitle.setText(locationName); binding.subtitle.setText(locationName);
binding.subtitle.setVisibility(View.VISIBLE); binding.subtitle.setVisibility(View.VISIBLE);
binding.subtitle.setOnClickListener(v -> { binding.subtitle.setOnClickListener(v -> {
@ -737,11 +735,13 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
.setView(input) .setView(input)
.setPositiveButton(R.string.confirm, (d, w) -> { .setPositiveButton(R.string.confirm, (d, w) -> {
binding.editCaption.setVisibility(View.GONE); binding.editCaption.setVisibility(View.GONE);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(COOKIE);
if (csrfToken != null) {
mediaService.editCaption( mediaService.editCaption(
feedModel.getPk(), feedModel.getPk(),
userId, userId,
input.getText().toString(), input.getText().toString(),
CookieUtils.getCsrfTokenFromCookie(COOKIE),
csrfToken,
new ServiceCallback<Boolean>() { new ServiceCallback<Boolean>() {
@Override @Override
public void onSuccess(final Boolean result) { public void onSuccess(final Boolean result) {
@ -759,6 +759,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
binding.editCaption.setVisibility(View.VISIBLE); binding.editCaption.setVisibility(View.VISIBLE);
} }
}); });
}
}) })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show(); .show();
@ -798,9 +799,11 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) return; if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) return;
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}); });
if (caption.getPk() <= 0)
if (caption != null) {
if (caption.getPk() <= 0) {
binding.translateTitle.setVisibility(View.GONE); binding.translateTitle.setVisibility(View.GONE);
else binding.translateTitle.setOnClickListener(v -> {
} else {
binding.translateTitle.setOnClickListener(v -> {
mediaService.translate(String.valueOf(caption.getPk()), "1", new ServiceCallback<String>() { mediaService.translate(String.valueOf(caption.getPk()), "1", new ServiceCallback<String>() {
@Override @Override
public void onSuccess(final String result) { public void onSuccess(final String result) {
@ -820,6 +823,8 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
} }
}); });
}); });
}
}
binding.captionToggle.setOnClickListener(v -> { binding.captionToggle.setOnClickListener(v -> {
if (bottomSheetBehavior == null) return; if (bottomSheetBehavior == null) return;
switch (bottomSheetBehavior.getState()) { switch (bottomSheetBehavior.getState()) {
@ -1136,6 +1141,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
videoUrl = videoVersion.getUrl(); videoUrl = videoVersion.getUrl();
} }
} }
if (videoUrl != null) {
videoPlayerViewHelper = new VideoPlayerViewHelper( videoPlayerViewHelper = new VideoPlayerViewHelper(
binding.getRoot().getContext(), binding.getRoot().getContext(),
binding.videoPost, binding.videoPost,
@ -1147,6 +1153,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
binding.playerControls, binding.playerControls,
videoPlayerCallback); videoPlayerCallback);
} }
}
private void enablePlayerControls(final boolean enable) { private void enablePlayerControls(final boolean enable) {
video = enable; video = enable;
@ -1175,7 +1182,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
hideCaption(); hideCaption();
// previously invisible view // previously invisible view
View view = binding.playerControls.getRoot(); View view = binding.playerControls.getRoot();
if (view != null && view.getVisibility() == View.VISIBLE) {
if (view.getVisibility() == View.VISIBLE) {
return; return;
} }
if (!ViewCompat.isAttachedToWindow(view)) { if (!ViewCompat.isAttachedToWindow(view)) {
@ -1202,7 +1209,7 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
private void hidePlayerControls() { private void hidePlayerControls() {
// previously visible view // previously visible view
final View view = binding.playerControls.getRoot(); final View view = binding.playerControls.getRoot();
if (view != null && view.getVisibility() == View.GONE) {
if (view.getVisibility() == View.GONE) {
return; return;
} }
if (!ViewCompat.isAttachedToWindow(view)) { if (!ViewCompat.isAttachedToWindow(view)) {

Loading…
Cancel
Save