浏览代码

Replace ThemeMenuUtils with common library utils

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 年之前
父节点
当前提交
8a31f9b8f7

+ 1 - 1
app/build.gradle

@@ -355,7 +355,7 @@ dependencies {
     gplayImplementation "com.google.firebase:firebase-messaging:23.0.7"
 
     // TODO change back to tag before merging
-    implementation 'com.github.nextcloud.android-common:ui:cbcc747'
+    implementation 'com.github.nextcloud.android-common:ui:f02df7f'
 }
 
 configurations.all {

+ 0 - 7
app/src/main/java/com/nextcloud/client/di/ThemeModule.kt

@@ -25,7 +25,6 @@ import com.nextcloud.android.common.ui.theme.MaterialSchemes
 import com.owncloud.android.utils.theme.ThemeAvatarUtils
 import com.owncloud.android.utils.theme.ThemeColorUtils
 import com.owncloud.android.utils.theme.ThemeDrawableUtils
-import com.owncloud.android.utils.theme.ThemeMenuUtils
 import com.owncloud.android.utils.theme.ThemeSnackbarUtils
 import com.owncloud.android.utils.theme.ThemeTextUtils
 import com.owncloud.android.utils.theme.ThemeToolbarUtils
@@ -74,12 +73,6 @@ internal abstract class ThemeModule {
             return ThemeUtils()
         }
 
-        @Provides
-        @Singleton
-        fun themeMenuUtils(): ThemeMenuUtils {
-            return ThemeMenuUtils()
-        }
-
         @Provides
         @Singleton
         fun themeSnackbarUtils(): ThemeSnackbarUtils {

+ 4 - 10
app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -113,7 +113,6 @@ import com.owncloud.android.utils.svg.SVGorImage;
 import com.owncloud.android.utils.svg.SvgOrImageBitmapTranscoder;
 import com.owncloud.android.utils.svg.SvgOrImageDecoder;
 import com.owncloud.android.utils.theme.CapabilityUtils;
-import com.owncloud.android.utils.theme.ThemeMenuUtils;
 import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import org.greenrobot.eventbus.EventBus;
@@ -210,9 +209,6 @@ public abstract class DrawerActivity extends ToolbarActivity
     @Inject
     ClientFactory clientFactory;
 
-    @Inject
-    ThemeMenuUtils themeMenuUtils;
-
     @Inject
     ViewThemeUtils viewThemeUtils;
 
@@ -790,8 +786,6 @@ public abstract class DrawerActivity extends ToolbarActivity
         if (mNavigationView != null && mNavigationView.getMenu().findItem(menuItemId) != null) {
             mCheckedMenuItem = menuItemId;
             MenuItem currentItem = mNavigationView.getMenu().findItem(menuItemId);
-            int drawerColor = getResources().getColor(R.color.drawer_text_color);
-            int activeColor = themeColorUtils.primaryColor(null, true, true, this);
 
             currentItem.setChecked(true);
 
@@ -800,11 +794,11 @@ public abstract class DrawerActivity extends ToolbarActivity
                 MenuItem menuItem = mNavigationView.getMenu().getItem(i);
                 if (menuItem.getIcon() != null) {
                     if (menuItem == currentItem) {
-                        themeDrawableUtils.tintDrawable(currentItem.getIcon(), activeColor);
-                        themeMenuUtils.tintMenuItemText(currentItem, activeColor);
+                        viewThemeUtils.platform.colorMenuItemIconActive(this, menuItem);
+                        viewThemeUtils.platform.colorMenuItemTextActive(this, menuItem);
                     } else {
-                        themeDrawableUtils.tintDrawable(menuItem.getIcon(), drawerColor);
-                        themeMenuUtils.tintMenuItemText(menuItem, drawerColor);
+                        viewThemeUtils.platform.colorToolbarMenuIcon(this, menuItem);
+                        viewThemeUtils.platform.colorMenuItemText(this, menuItem);
                     }
                 }
             }

+ 1 - 4
app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java

@@ -47,7 +47,6 @@ import com.owncloud.android.ui.adapter.GalleryAdapter;
 import com.owncloud.android.ui.asynctasks.GallerySearchTask;
 import com.owncloud.android.ui.events.ChangeMenuEvent;
 import com.owncloud.android.ui.fragment.util.GalleryFastScrollViewHelper;
-import com.owncloud.android.utils.theme.ThemeMenuUtils;
 
 import javax.inject.Inject;
 
@@ -74,7 +73,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
     private OCFile remoteFile;
     private GalleryFragmentBottomSheetDialog galleryFragmentBottomSheetDialog;
 
-    @Inject ThemeMenuUtils themeMenuUtils;
     @Inject FileDataStorageManager fileDataStorageManager;
 
     @Override
@@ -252,8 +250,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
         MenuItem menuItem = menu.findItem(R.id.action_three_dot_icon);
 
         if (menuItem != null) {
-            themeMenuUtils.tintMenuIcon(menuItem,
-                                        themeColorUtils.appBarPrimaryFontColor(requireContext()));
+            viewThemeUtils.platform.colorMenuItemText(requireContext(), menuItem);
         }
 
     }

+ 0 - 65
app/src/main/java/com/owncloud/android/utils/theme/ThemeMenuUtils.java

@@ -1,65 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * @author Andy Scherzinger
- * @author TSI-mc
- * Copyright (C) 2017 Tobias Kaminsky
- * Copyright (C) 2017 Nextcloud GmbH
- * Copyright (C) 2018 Andy Scherzinger
- * Copyright (C) 2022 TSI-mc
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package com.owncloud.android.utils.theme;
-
-import android.graphics.drawable.Drawable;
-import android.text.Spannable;
-import android.text.SpannableString;
-import android.text.style.ForegroundColorSpan;
-import android.view.MenuItem;
-
-import androidx.annotation.NonNull;
-import androidx.core.graphics.drawable.DrawableCompat;
-
-/**
- * Utility class with methods for client side checkable theming.
- */
-public final class ThemeMenuUtils {
-    /**
-     * Will change a menu item text tint
-     *
-     * @param item  the menu item object
-     * @param color the wanted color (as resource or color)
-     */
-    public void tintMenuItemText(MenuItem item, int color) {
-        SpannableString newItemTitle = new SpannableString(item.getTitle());
-        newItemTitle.setSpan(new ForegroundColorSpan(color), 0, newItemTitle.length(),
-                             Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
-        item.setTitle(newItemTitle);
-    }
-
-    /**
-     * tinting menu item color
-     *
-     * @param item    the menu item object
-     * @param color   the color wanted as a color resource
-     */
-    public void tintMenuIcon(@NonNull MenuItem item, int color) {
-        Drawable normalDrawable = item.getIcon();
-        Drawable wrapDrawable = DrawableCompat.wrap(normalDrawable);
-        DrawableCompat.setTint(wrapDrawable, color);
-        item.setIcon(wrapDrawable);
-    }
-}