From 1c1e5f0654304a8bcb7361f3092e822d9f953c66 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:54:38 +0900 Subject: [PATCH] Null check. Fixes https://github.com/austinhuang0131/barinsta/issues/991 --- .../fragments/StoryListViewerFragment.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java index ee997c86..73efea84 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java @@ -24,6 +24,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import awais.instagrabber.R; @@ -98,8 +99,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr final Context context = getContext(); Toast.makeText(context, R.string.empty_list, Toast.LENGTH_SHORT).show(); } catch (Exception ignored) {} - } - else { + } else { endCursor = result.getNextCursor(); final List models = archivesViewModel.getList().getValue(); final List modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); @@ -198,7 +198,13 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr adapter = new FeedStoriesListAdapter(clickListener); binding.rvStories.setLayoutManager(layoutManager); binding.rvStories.setAdapter(adapter); - feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList); + feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), list -> { + if (list == null) { + adapter.submitList(Collections.emptyList()); + return; + } + adapter.submitList(list); + }); } else { if (actionBar != null) actionBar.setTitle(R.string.action_archive); final RecyclerLazyLoader lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {