1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-16 11:47:29 +00:00

Handle some 'may be null' warnings

This commit is contained in:
Ammar Githam 2021-01-08 22:27:52 +09:00
parent 404747fedc
commit 92d8163c7b

View File

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