From 643454c1d75726c5c1166fe51bddecfd68d0d74c Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 22 Jun 2020 17:41:27 +0200 Subject: [PATCH] proper coloring of drawer items in black/white edge case scenarios Signed-off-by: Andy Scherzinger --- .../android/ui/activity/DrawerActivity.java | 2 +- .../owncloud/android/utils/ThemeUtils.java | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index b176c4e454..fd1746a5f6 100644 --- a/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -703,7 +703,7 @@ public abstract class DrawerActivity extends ToolbarActivity mCheckedMenuItem = menuItemId; MenuItem currentItem = mNavigationView.getMenu().findItem(menuItemId); int drawerColor = getResources().getColor(R.color.drawer_text_color); - int activeColor = ThemeUtils.elementColor(this); + int activeColor = ThemeUtils.primaryColor(null, true, true, this); currentItem.setChecked(true); diff --git a/src/main/java/com/owncloud/android/utils/ThemeUtils.java b/src/main/java/com/owncloud/android/utils/ThemeUtils.java index 0c4e49cc03..217c427fd6 100644 --- a/src/main/java/com/owncloud/android/utils/ThemeUtils.java +++ b/src/main/java/com/owncloud/android/utils/ThemeUtils.java @@ -133,6 +133,24 @@ public final class ThemeUtils { } public static int primaryColor(Account account, boolean replaceEdgeColors, Context context) { + return primaryColor(account, replaceEdgeColors, false, context); + } + + /** + * return the primary color defined in the server-side theming respecting Android dark/light theming and edge case + * scenarios including drawer menu. + * + * @param account the Nextcloud user + * @param replaceEdgeColors flag if edge case color scenarios should be handled + * @param replaceEdgeColorsByInvertedColor flag in edge case handling should be done via color inversion + * (black/white) + * @param context the context (needed to load client-side colors) + * @return the color + */ + public static int primaryColor(Account account, + boolean replaceEdgeColors, + boolean replaceEdgeColorsByInvertedColor, + Context context) { if (context == null) { return Color.GRAY; } @@ -142,13 +160,21 @@ public final class ThemeUtils { if (replaceEdgeColors) { if (isDarkModeActive(context)) { if (Color.BLACK == color) { - return getNeutralGrey(context); + if (replaceEdgeColorsByInvertedColor) { + return Color.WHITE; + } else { + return getNeutralGrey(context); + } } else { return color; } } else { if (Color.WHITE == color) { - return getNeutralGrey(context); + if (replaceEdgeColorsByInvertedColor) { + return Color.BLACK; + } else { + return getNeutralGrey(context); + } } else { return color; }