From ae79a35d010124d5eee3153d776d8294d6fb9953 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 17 Mar 2021 00:54:43 +0900 Subject: [PATCH] Null check palette object. Should fix https://github.com/austinhuang0131/barinsta/issues/567 --- .../viewholder/TopicClusterViewHolder.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/TopicClusterViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/TopicClusterViewHolder.java index e3e7f281..86b0d35b 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/TopicClusterViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/TopicClusterViewHolder.java @@ -81,16 +81,18 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder { } if (bitmap != null) { Palette.from(bitmap).generate(p -> { - final Palette.Swatch swatch = p.getDominantSwatch(); final Resources resources = itemView.getResources(); int titleTextColor = resources.getColor(R.color.white); - if (swatch != null) { - backgroundColor.set(swatch.getRgb()); - GradientDrawable gd = new GradientDrawable( - GradientDrawable.Orientation.TOP_BOTTOM, - new int[]{Color.TRANSPARENT, backgroundColor.get()}); - titleTextColor = swatch.getTitleTextColor(); - binding.background.setBackground(gd); + if (p != null) { + final Palette.Swatch swatch = p.getDominantSwatch(); + if (swatch != null) { + backgroundColor.set(swatch.getRgb()); + GradientDrawable gd = new GradientDrawable( + GradientDrawable.Orientation.TOP_BOTTOM, + new int[]{Color.TRANSPARENT, backgroundColor.get()}); + titleTextColor = swatch.getTitleTextColor(); + binding.background.setBackground(gd); + } } titleColor.set(titleTextColor); binding.title.setTextColor(titleTextColor); @@ -127,8 +129,8 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder { // binding.title.setTransitionName("title-" + topicCluster.getId()); binding.cover.setTransitionName("cover-" + topicCluster.getId()); final String thumbUrl = ResponseBodyUtils.getThumbUrl(topicCluster.getCoverMedias() == null - ? topicCluster.getCoverMedia() - : topicCluster.getCoverMedias().get(0)); + ? topicCluster.getCoverMedia() + : topicCluster.getCoverMedias().get(0)); if (thumbUrl == null) { binding.cover.setImageURI((String) null); } else {