From b8ad359997c9b32725a74fb12f6cc55f8c997de1 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 12 Jul 2021 22:44:22 +0900 Subject: [PATCH] Null check. Fixes austinhuang0131/barinsta#1598 --- .../viewholder/TopicClusterViewHolder.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 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 809e09b1..4097d114 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/TopicClusterViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/TopicClusterViewHolder.java @@ -130,9 +130,7 @@ public class TopicClusterViewHolder extends RecyclerView.ViewHolder { } // binding.title.setTransitionName("title-" + topicCluster.getCollectionId()); binding.cover.setTransitionName("cover-" + topicCluster.getCollectionId()); - final String thumbUrl = ResponseBodyUtils.getThumbUrl(topicCluster.getCoverMediaList() == null - ? topicCluster.getCoverMedia() - : topicCluster.getCoverMediaList().get(0)); + final String thumbUrl = ResponseBodyUtils.getThumbUrl(topicCluster.getCoverMediaList().get(0)); if (thumbUrl == null) { binding.cover.setImageURI((String) null); } else { @@ -150,16 +148,19 @@ 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);