1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-16 19:57:31 +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 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 (location != null) {
if (!TextUtils.isEmpty(locationName)) { 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,28 +735,31 @@ 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);
mediaService.editCaption( final String csrfToken = CookieUtils.getCsrfTokenFromCookie(COOKIE);
feedModel.getPk(), if (csrfToken != null) {
userId, mediaService.editCaption(
input.getText().toString(), feedModel.getPk(),
CookieUtils.getCsrfTokenFromCookie(COOKIE), userId,
new ServiceCallback<Boolean>() { input.getText().toString(),
@Override csrfToken,
public void onSuccess(final Boolean result) { new ServiceCallback<Boolean>() {
binding.editCaption.setVisibility(View.VISIBLE); @Override
if (result) { public void onSuccess(final Boolean result) {
feedModel.setPostCaption(input.getText().toString()); binding.editCaption.setVisibility(View.VISIBLE);
binding.caption.setText(input.getText().toString()); if (result) {
} else Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); feedModel.setPostCaption(input.getText().toString());
} binding.caption.setText(input.getText().toString());
} else Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
}
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error editing caption", t); Log.e(TAG, "Error editing caption", t);
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
binding.editCaption.setVisibility(View.VISIBLE); binding.editCaption.setVisibility(View.VISIBLE);
} }
}); });
}
}) })
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show(); .show();
@ -798,28 +799,32 @@ 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) {
binding.translateTitle.setVisibility(View.GONE); if (caption.getPk() <= 0) {
else binding.translateTitle.setOnClickListener(v -> { binding.translateTitle.setVisibility(View.GONE);
mediaService.translate(String.valueOf(caption.getPk()), "1", new ServiceCallback<String>() { } else {
@Override binding.translateTitle.setOnClickListener(v -> {
public void onSuccess(final String result) { mediaService.translate(String.valueOf(caption.getPk()), "1", new ServiceCallback<String>() {
if (TextUtils.isEmpty(result)) { @Override
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); public void onSuccess(final String result) {
return; if (TextUtils.isEmpty(result)) {
} Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
binding.translateTitle.setOnClickListener(null); return;
binding.translatedCaption.setVisibility(View.VISIBLE); }
binding.translatedCaption.setText(result); binding.translateTitle.setOnClickListener(null);
} binding.translatedCaption.setVisibility(View.VISIBLE);
binding.translatedCaption.setText(result);
}
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
Log.e(TAG, "Error translating comment", t); Log.e(TAG, "Error translating comment", t);
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
} }
}); });
}); });
}
}
binding.captionToggle.setOnClickListener(v -> { binding.captionToggle.setOnClickListener(v -> {
if (bottomSheetBehavior == null) return; if (bottomSheetBehavior == null) return;
switch (bottomSheetBehavior.getState()) { switch (bottomSheetBehavior.getState()) {
@ -1136,16 +1141,18 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment {
videoUrl = videoVersion.getUrl(); videoUrl = videoVersion.getUrl();
} }
} }
videoPlayerViewHelper = new VideoPlayerViewHelper( if (videoUrl != null) {
binding.getRoot().getContext(), videoPlayerViewHelper = new VideoPlayerViewHelper(
binding.videoPost, binding.getRoot().getContext(),
videoUrl, binding.videoPost,
vol, videoUrl,
aspectRatio, vol,
ResponseBodyUtils.getThumbUrl(feedModel), aspectRatio,
true, ResponseBodyUtils.getThumbUrl(feedModel),
binding.playerControls, true,
videoPlayerCallback); binding.playerControls,
videoPlayerCallback);
}
} }
private void enablePlayerControls(final boolean enable) { private void enablePlayerControls(final boolean 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)) {