Просмотр исходного кода

proper coloring of drawer items in black/white edge case scenarios

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 4 лет назад
Родитель
Сommit
643454c1d7

+ 1 - 1
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);
 

+ 28 - 2
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;
                     }