From 627b1bfe76d5e36c612bef599ceec430e12c1b3b Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Sun, 18 Apr 2021 16:46:36 +0900 Subject: [PATCH] Null check and fragment manager check. Fixes https://github.com/austinhuang0131/barinsta/issues/1116 --- .codebeatsettings | 5 +++++ .../fragments/StoryListViewerFragment.java | 12 +++++++++--- .../instagrabber/fragments/main/ProfileFragment.java | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .codebeatsettings diff --git a/.codebeatsettings b/.codebeatsettings new file mode 100644 index 00000000..32a4ee3d --- /dev/null +++ b/.codebeatsettings @@ -0,0 +1,5 @@ +{ + "JAVA": { + "TOO_MANY_IVARS": [8, 10, 20, 30] + } +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java index 73efea84..f4bf129a 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java @@ -51,12 +51,15 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr private AppCompatActivity fragmentActivity; private FragmentStoryListViewerBinding binding; private SwipeRefreshLayout root; - private boolean shouldRefresh = true, firstRefresh = true; + private boolean shouldRefresh = true; + private boolean firstRefresh = true; private FeedStoriesViewModel feedStoriesViewModel; private ArchivesViewModel archivesViewModel; private StoriesService storiesService; private Context context; - private String type, currentQuery, endCursor = null; + private String type; + private String currentQuery; + private String endCursor = null; private FeedStoriesListAdapter adapter; private MenuItem menuSearch; @@ -226,7 +229,10 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr binding.swipeRefreshLayout.setRefreshing(true); if (type.equals("feed") && firstRefresh) { binding.swipeRefreshLayout.setRefreshing(false); - adapter.submitList(feedStoriesViewModel.getList().getValue()); + final List value = feedStoriesViewModel.getList().getValue(); + if (value != null) { + adapter.submitList(value); + } firstRefresh = false; } else if (type.equals("feed")) { storiesService.getFeedStories(new ServiceCallback>() { diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index cc2ce13a..15181356 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -264,7 +264,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe postViewV2Fragment.dismiss(); binding.postsRecyclerView.refresh(); }); - postViewV2Fragment.show(getChildFragmentManager(), "post_view"); + final FragmentManager fragmentManager = getChildFragmentManager(); + if (fragmentManager.isDestroyed() || fragmentManager.isStateSaved()) return; + postViewV2Fragment.show(fragmentManager, "post_view"); } }; private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() {