Explorar o código

proper toolbar theming ignoring dark/light theme for toolbar colors

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger %!s(int64=5) %!d(string=hai) anos
pai
achega
27e6c7b205

+ 3 - 0
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -288,6 +288,9 @@ public abstract class DrawerActivity extends ToolbarActivity
             }
         };
 
+        // proper coloring of drawer menu icon
+        mDrawerToggle.getDrawerArrowDrawable().setColor(ThemeUtils.toolbarTextColor(this));
+
         // Set the drawer toggle as the DrawerListener
         mDrawerLayout.addDrawerListener(mDrawerToggle);
         mDrawerToggle.setDrawerIndicatorEnabled(true);

+ 2 - 2
src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java

@@ -751,8 +751,8 @@ public class SettingsActivity extends ThemedPreferenceActivity
             actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor(this)));
 
             Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back);
-            actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(this,
-                                                                                                   !ThemeUtils.darkTheme(this))));
+            actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow,
+                                                                   ThemeUtils.toolbarTextColor(this)));
         }
 
         Window window = getWindow();

+ 3 - 3
src/main/java/com/owncloud/android/ui/activity/ToolbarActivity.java

@@ -65,7 +65,7 @@ public abstract class ToolbarActivity extends BaseActivity {
      */
     protected void setupToolbar(boolean useBackgroundImage) {
         int primaryColor = ThemeUtils.primaryColor(this, false);
-        int fontColor = ThemeUtils.fontColor(this, !ThemeUtils.darkTheme(getApplicationContext()));
+        int toolbarTextColor = ThemeUtils.toolbarTextColor(this);
 
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
@@ -86,11 +86,11 @@ public abstract class ToolbarActivity extends BaseActivity {
         ThemeUtils.colorStatusBar(this, primaryColor);
 
         if (toolbar.getOverflowIcon() != null) {
-            ThemeUtils.tintDrawable(toolbar.getOverflowIcon(), fontColor);
+            ThemeUtils.tintDrawable(toolbar.getOverflowIcon(), toolbarTextColor);
         }
 
         if (toolbar.getNavigationIcon() != null) {
-            ThemeUtils.tintDrawable(toolbar.getNavigationIcon(), fontColor);
+            ThemeUtils.tintDrawable(toolbar.getNavigationIcon(), toolbarTextColor);
         }
 
         if (!useBackgroundImage) {

+ 10 - 3
src/main/java/com/owncloud/android/utils/ThemeUtils.java

@@ -188,8 +188,11 @@ public final class ThemeUtils {
     }
 
     /**
+     * returns the font color based on the server side theming and uses black/white as a fallback based on replaceWhite.
+     *
+     * @param context the context
+     * @param replaceWhite FLAG to return white/black if server side color isn't available
      * @return int font color to use
-     * adapted from https://github.com/nextcloud/server/blob/master/apps/theming/lib/Util.php#L90-L102
      */
     public static int fontColor(Context context, boolean replaceWhite) {
         if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
@@ -200,6 +203,10 @@ public final class ThemeUtils {
             }
         }
 
+        return toolbarTextColor(context);
+    }
+
+    public static int toolbarTextColor(Context context) {
         try {
             return Color.parseColor(getCapability(context).getServerTextColor());
         } catch (Exception e) {
@@ -249,7 +256,7 @@ public final class ThemeUtils {
                 actionBar.setTitle(title);
             } else {
                 Spannable text = new SpannableString(title);
-                text.setSpan(new ForegroundColorSpan(fontColor(context, !darkTheme(context))),
+                text.setSpan(new ForegroundColorSpan(toolbarTextColor(context)),
                              0,
                              text.length(),
                              Spannable.SPAN_INCLUSIVE_INCLUSIVE);
@@ -612,7 +619,7 @@ public final class ThemeUtils {
             drawable, Context context) {
         button.setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.primaryColor(context)));
         button.setRippleColor(ThemeUtils.primaryDarkColor(context));
-        button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.fontColor(context)));
+        button.setImageDrawable(ThemeUtils.tintDrawable(drawable, ThemeUtils.toolbarTextColor(context)));
     }
 
     private static OCCapability getCapability(Context context) {