From 578161d604fb452830f0675ad0504260b5d3cf24 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 8 Feb 2023 17:57:50 +0100 Subject: [PATCH] Some fixes --- .../client/entities/app/BottomMenu.java | 2 +- .../mastodon/ui/drawer/StatusAdapter.java | 24 +++++++++++-------- .../timeline/FragmentMastodonTimeline.java | 8 ++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BottomMenu.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BottomMenu.java index 17861797a..30ee41209 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BottomMenu.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/BottomMenu.java @@ -111,7 +111,7 @@ public class BottomMenu implements Serializable { } public static ItemMenuType getType(BottomMenu bottomMenu, int position) { - if (bottomMenu == null || bottomMenu.bottom_menu == null || bottomMenu.bottom_menu.size() < position) { + if (bottomMenu == null || bottomMenu.bottom_menu == null || bottomMenu.bottom_menu.size() <= position) { return null; } return bottomMenu.bottom_menu.get(position).item_menu_type; diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index f34d4484d..81c8defa3 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -2777,16 +2777,20 @@ public class StatusAdapter extends RecyclerView.Adapter context.startActivity(intent, options.toBundle()); }); holder.bindingArt.artMedia.setOnClickListener(v -> { - Intent mediaIntent = new Intent(context, MediaActivity.class); - Bundle b = new Bundle(); - b.putInt(Helper.ARG_MEDIA_POSITION, 1); - ArrayList attachments = new ArrayList<>(); - attachments.add(status.art_attachment); - b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments); - mediaIntent.putExtras(b); - ActivityOptionsCompat options = ActivityOptionsCompat - .makeSceneTransitionAnimation((Activity) context, holder.bindingArt.artMedia, status.art_attachment.url); - context.startActivity(mediaIntent, options.toBundle()); + if (status.art_attachment != null) { + Intent mediaIntent = new Intent(context, MediaActivity.class); + Bundle b = new Bundle(); + b.putInt(Helper.ARG_MEDIA_POSITION, 1); + ArrayList attachments = new ArrayList<>(); + attachments.add(status.art_attachment); + b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments); + mediaIntent.putExtras(b); + ActivityOptionsCompat options = ActivityOptionsCompat + .makeSceneTransitionAnimation((Activity) context, holder.bindingArt.artMedia, status.art_attachment.url); + context.startActivity(mediaIntent, options.toBundle()); + } else { + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + } }); holder.bindingArt.bottomBanner.setOnClickListener(v -> { Intent intent = new Intent(context, ContextActivity.class); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java index 90d19b418..3aa67d366 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -753,7 +753,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. * @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll */ private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) { - if (binding == null || getActivity() == null || !isAdded()) { + if (binding == null || !isAdded() || getActivity() == null) { return; } //Initialize with default params @@ -964,7 +964,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. * @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll */ private void route(DIRECTION direction, boolean fetchingMissing, Status statusToUpdate) { - if (binding == null || getActivity() == null || !isAdded()) { + if (binding == null || !isAdded() || getActivity() == null) { return; } // --- HOME TIMELINE --- @@ -1083,7 +1083,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. initializeStatusesCommonView(otherStatuses); })); } else { - Toasty.error(requireActivity(), getString(R.string.toast_fetch_error), Toasty.LENGTH_LONG).show(); + if (isAdded() && !requireActivity().isFinishing()) { + Toasty.error(requireActivity(), getString(R.string.toast_fetch_error), Toasty.LENGTH_LONG).show(); + } } } });