From 82e960d9fe5ee53916ee0d113283278f37729f47 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Thu, 19 Nov 2020 01:51:08 +0900 Subject: [PATCH] Fix item decoration add/remove logic and one null check --- .../instagrabber/customviews/PostsRecyclerView.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java index aee8930f..0524cff7 100644 --- a/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java +++ b/app/src/main/java/awais/instagrabber/customviews/PostsRecyclerView.java @@ -216,6 +216,7 @@ public class PostsRecyclerView extends RecyclerView { if (progressPercent != 100) continue; final String url = progress.getString(DownloadWorker.URL); final List feedModels = feedViewModel.getList().getValue(); + if (feedModels == null) continue; for (int i = 0; i < feedModels.size(); i++) { final FeedModel feedModel = feedModels.get(i); final List displayUrls = getDisplayUrl(feedModel); @@ -254,10 +255,15 @@ public class PostsRecyclerView extends RecyclerView { post(() -> { TransitionManager.beginDelayedTransition(this, transition); feedAdapter.notifyDataSetChanged(); + final int itemDecorationCount = getItemDecorationCount(); if (!layoutPreferences.getHasGap()) { - removeItemDecoration(gridSpacingItemDecoration); + if (itemDecorationCount == 1) { + removeItemDecoration(gridSpacingItemDecoration); + } } else { - addItemDecoration(gridSpacingItemDecoration); + if (itemDecorationCount == 0) { + addItemDecoration(gridSpacingItemDecoration); + } } if (layoutPreferences.getType() == PostsLayoutPreferences.PostsLayoutType.LINEAR) { if (layoutManager.getSpanCount() != 1) {