From 1ba3f4f745d4bc9fe54e744841066c39e2a57593 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Wed, 3 Apr 2019 19:26:35 +0200 Subject: [PATCH] Add icons with favicon dominant color for drawer feeds items --- .../com/readrops/app/utils/DrawerManager.java | 16 ++++++++++++++++ .../main/java/com/readrops/app/utils/Utils.java | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/src/main/java/com/readrops/app/utils/DrawerManager.java b/app/src/main/java/com/readrops/app/utils/DrawerManager.java index f2e8010e..52d3ad1a 100644 --- a/app/src/main/java/com/readrops/app/utils/DrawerManager.java +++ b/app/src/main/java/com/readrops/app/utils/DrawerManager.java @@ -1,6 +1,14 @@ package com.readrops.app.utils; import android.content.Context; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.graphics.drawable.ShapeDrawable; +import android.graphics.drawable.shapes.OvalShape; +import android.graphics.drawable.shapes.Shape; +import android.support.annotation.ColorInt; import com.mikepenz.materialdrawer.Drawer; import com.mikepenz.materialdrawer.model.DividerDrawerItem; @@ -16,6 +24,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static com.readrops.app.utils.Utils.drawableWithColor; + public class DrawerManager { public static final int ARTICLES_ITEM_ID = 1; @@ -43,8 +53,11 @@ public class DrawerManager { List secondaryDrawerItems = new ArrayList<>(); for (Feed feed : folderListMap.get(folder)) { + int color = feed.getTextColor(); + SecondaryDrawerItem secondaryDrawerItem = new SecondaryDrawerItem() .withName(feed.getName()) + .withIcon(color != 0 ? drawableWithColor(color) : drawableWithColor(context.getResources().getColor(R.color.colorPrimary))) .withIdentifier(feed.getId()); secondaryDrawerItems.add(secondaryDrawerItem); @@ -56,8 +69,11 @@ public class DrawerManager { } } else { // no folder case, items to add after the folders for (Feed feed : folderListMap.get(folder)) { + int color = feed.getTextColor(); + SecondaryDrawerItem primaryDrawerItem = new SecondaryDrawerItem() .withName(feed.getName()) + .withIcon(color != 0 ? drawableWithColor(color) : drawableWithColor(context.getResources().getColor(R.color.colorPrimary))) .withIdentifier(feed.getId()); feedsWithoutFolder.add(primaryDrawerItem); diff --git a/app/src/main/java/com/readrops/app/utils/Utils.java b/app/src/main/java/com/readrops/app/utils/Utils.java index 1ee4d579..2575ff78 100644 --- a/app/src/main/java/com/readrops/app/utils/Utils.java +++ b/app/src/main/java/com/readrops/app/utils/Utils.java @@ -9,6 +9,8 @@ import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; +import android.graphics.drawable.ShapeDrawable; +import android.graphics.drawable.shapes.OvalShape; import android.os.Handler; import android.os.Looper; import android.support.annotation.ColorInt; @@ -88,4 +90,14 @@ public final class Utils { drawable.mutate().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)); } + public static Drawable drawableWithColor(@ColorInt int color) { + ShapeDrawable drawable = new ShapeDrawable(new OvalShape()); + drawable.setIntrinsicWidth(50); + drawable.setIntrinsicHeight(50); + + drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN)); + + return drawable; + } + }