Selaa lähdekoodia

Replace ThemeFabUtils and ThemeLayoutUtils with common library utils

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 vuotta sitten
vanhempi
commit
22dc29ce43

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

@@ -26,8 +26,6 @@ import com.owncloud.android.utils.theme.ThemeAvatarUtils
 import com.owncloud.android.utils.theme.ThemeCheckableUtils
 import com.owncloud.android.utils.theme.ThemeColorUtils
 import com.owncloud.android.utils.theme.ThemeDrawableUtils
-import com.owncloud.android.utils.theme.ThemeFabUtils
-import com.owncloud.android.utils.theme.ThemeLayoutUtils
 import com.owncloud.android.utils.theme.ThemeMenuUtils
 import com.owncloud.android.utils.theme.ThemeSnackbarUtils
 import com.owncloud.android.utils.theme.ThemeTextInputUtils
@@ -55,18 +53,6 @@ internal abstract class ThemeModule {
             return ThemeColorUtils()
         }
 
-        @Provides
-        @Singleton
-        fun themeFabUtils(themeColorUtils: ThemeColorUtils?, themeDrawableUtils: ThemeDrawableUtils?): ThemeFabUtils {
-            return ThemeFabUtils(themeColorUtils, themeDrawableUtils)
-        }
-
-        @Provides
-        @Singleton
-        fun themeLayoutUtils(themeColorUtils: ThemeColorUtils?): ThemeLayoutUtils {
-            return ThemeLayoutUtils(themeColorUtils)
-        }
-
         @Provides
         @Singleton
         fun themeToolbarUtils(

+ 3 - 1
app/src/main/java/com/owncloud/android/ui/activities/ActivitiesActivity.java

@@ -41,6 +41,7 @@ import com.owncloud.android.ui.interfaces.ActivityListInterface;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
 import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.util.List;
 
@@ -70,6 +71,7 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
     @Inject ActivitiesRepository activitiesRepository;
     @Inject FilesRepository filesRepository;
     @Inject ClientFactory clientFactory;
+    @Inject ViewThemeUtils viewThemeUtils;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -84,7 +86,7 @@ public class ActivitiesActivity extends DrawerActivity implements ActivityListIn
         // setup toolbar
         setupToolbar();
 
-        themeLayoutUtils.colorSwipeRefreshLayout(this, binding.swipeContainingList);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingList);
 
         // setup drawer
         setupDrawer(R.id.nav_activity);

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

@@ -100,8 +100,8 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio
 
         updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_notifications));
 
-        themeLayoutUtils.colorSwipeRefreshLayout(this, binding.swipeContainingList);
-        themeLayoutUtils.colorSwipeRefreshLayout(this, binding.swipeContainingEmpty);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingList);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingEmpty);
 
         // setup drawer
         setupDrawer(R.id.nav_notifications);

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

@@ -44,10 +44,8 @@ import com.nextcloud.client.di.Injectable;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
-
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.ThemeDrawableUtils;
-import com.owncloud.android.utils.theme.ThemeLayoutUtils;
 import com.owncloud.android.utils.theme.ThemeToolbarUtils;
 import com.owncloud.android.utils.theme.ThemeUtils;
 
@@ -81,7 +79,6 @@ public abstract class ToolbarActivity extends BaseActivity implements Injectable
     private boolean isHomeSearchToolbarShow = false;
 
     @Inject public ThemeColorUtils themeColorUtils;
-    @Inject public ThemeLayoutUtils themeLayoutUtils;
     @Inject public ThemeToolbarUtils themeToolbarUtils;
     @Inject public ThemeUtils themeUtils;
     @Inject public ThemeDrawableUtils themeDrawableUtils;

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java

@@ -171,7 +171,7 @@ public class UploadListActivity extends FileActivity {
         binding.list.setLayoutManager(lm);
         binding.list.setAdapter(uploadListAdapter);
 
-        themeLayoutUtils.colorSwipeRefreshLayout(this, swipeListRefreshLayout);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(swipeListRefreshLayout);
         swipeListRefreshLayout.setOnRefreshListener(this::refresh);
 
         loadItems();

+ 4 - 3
app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -70,8 +70,8 @@ import com.owncloud.android.ui.adapter.OCFileListAdapter;
 import com.owncloud.android.ui.events.SearchEvent;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.ThemeDrawableUtils;
-import com.owncloud.android.utils.theme.ThemeLayoutUtils;
 import com.owncloud.android.utils.theme.ThemeToolbarUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import org.greenrobot.eventbus.EventBus;
 
@@ -117,9 +117,10 @@ public class ExtendedListFragment extends Fragment implements
     @Inject AppPreferences preferences;
     @Inject UserAccountManager accountManager;
     @Inject ThemeColorUtils themeColorUtils;
-    @Inject ThemeLayoutUtils themeLayoutUtils;
     @Inject ThemeToolbarUtils themeToolbarUtils;
     @Inject ThemeDrawableUtils themeDrawableUtils;
+    @Inject ViewThemeUtils viewThemeUtils;
+
     private ScaleGestureDetector mScaleGestureDetector;
     protected SwipeRefreshLayout mRefreshListLayout;
     protected MaterialButton mSortButton;
@@ -347,7 +348,7 @@ public class ExtendedListFragment extends Fragment implements
 
         // Pull-down to refresh layout
         mRefreshListLayout = binding.swipeContainingList;
-        themeLayoutUtils.colorSwipeRefreshLayout(getContext(), mRefreshListLayout);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(mRefreshListLayout);
         mRefreshListLayout.setOnRefreshListener(this);
 
         mSortButton = getActivity().findViewById(R.id.sort_button);

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

@@ -61,9 +61,9 @@ import com.owncloud.android.ui.interfaces.VersionListInterface;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.ThemeDrawableUtils;
-import com.owncloud.android.utils.theme.ThemeLayoutUtils;
 import com.owncloud.android.utils.theme.ThemeTextInputUtils;
 import com.owncloud.android.utils.theme.ThemeToolbarUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import org.apache.commons.httpclient.HttpStatus;
 import org.greenrobot.eventbus.EventBus;
@@ -115,10 +115,10 @@ public class FileDetailActivitiesFragment extends Fragment implements
     @Inject ClientFactory clientFactory;
     @Inject ContentResolver contentResolver;
     @Inject ThemeColorUtils themeColorUtils;
-    @Inject ThemeLayoutUtils themeLayoutUtils;
     @Inject ThemeToolbarUtils themeToolbarUtils;
     @Inject ThemeDrawableUtils themeDrawableUtils;
     @Inject ThemeTextInputUtils themeTextInputUtils;
+    @Inject ViewThemeUtils viewThemeUtils;
 
     public static FileDetailActivitiesFragment newInstance(OCFile file, User user) {
         FileDetailActivitiesFragment fragment = new FileDetailActivitiesFragment();
@@ -151,8 +151,8 @@ public class FileDetailActivitiesFragment extends Fragment implements
 
         setupView();
 
-        themeLayoutUtils.colorSwipeRefreshLayout(getContext(), binding.swipeContainingEmpty);
-        themeLayoutUtils.colorSwipeRefreshLayout(getContext(), binding.swipeContainingList);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingEmpty);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingList);
 
         fetchAndSetData(-1);
 

+ 1 - 3
app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -73,7 +73,6 @@ import com.owncloud.android.ui.events.FavoriteEvent;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
-import com.owncloud.android.utils.theme.ThemeLayoutUtils;
 import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import org.greenrobot.eventbus.EventBus;
@@ -117,7 +116,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
     @Inject ClientFactory clientFactory;
     @Inject FileDataStorageManager storageManager;
     @Inject ThemeColorUtils themeColorUtils;
-    @Inject ThemeLayoutUtils themeLayoutUtils;
     @Inject ViewThemeUtils viewThemeUtils;
     @Inject BackgroundJobManager backgroundJobManager;
 
@@ -257,7 +255,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
         binding.tabLayout.removeAllTabs();
 
         binding.tabLayout.addTab(binding.tabLayout.newTab().setText(R.string.drawer_item_activities).setIcon(R.drawable.ic_activity));
-        themeLayoutUtils.colorTabLayout(getContext().getApplicationContext(), binding.tabLayout);
+        viewThemeUtils.material.themeTabLayoutOnSurface(binding.tabLayout);
 
         if (!getFile().isEncrypted()) {
             binding.tabLayout.addTab(binding.tabLayout.newTab().setText(R.string.share_dialog_title).setIcon(R.drawable.shared_via_users));

+ 5 - 3
app/src/main/java/com/owncloud/android/ui/preview/PreviewTextStringFragment.java

@@ -38,7 +38,7 @@ import com.owncloud.android.R;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.theme.ThemeFabUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import javax.inject.Inject;
 
@@ -50,7 +50,7 @@ public class PreviewTextStringFragment extends PreviewTextFragment {
     private static final String EXTRA_FILE = "FILE";
 
     @Inject UserAccountManager accountManager;
-    @Inject ThemeFabUtils themeFabUtils;
+    @Inject ViewThemeUtils viewThemeUtils;
 
     /**
      * Creates an empty fragment for previews.
@@ -100,7 +100,9 @@ public class PreviewTextStringFragment extends PreviewTextFragment {
         fabMain.setVisibility(View.VISIBLE);
         fabMain.setEnabled(true);
         fabMain.setOnClickListener(v -> edit());
-        themeFabUtils.colorFloatingActionButton(fabMain, R.drawable.ic_edit, requireContext());
+
+        fabMain.setImageResource(R.drawable.ic_edit);
+        viewThemeUtils.material.themeFAB(fabMain);
 
         return view;
     }

+ 4 - 1
app/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.java

@@ -49,6 +49,7 @@ import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
 import com.owncloud.android.ui.interfaces.TrashbinActivityInterface;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.FileSortOrder;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.util.List;
 
@@ -73,6 +74,8 @@ public class TrashbinActivity extends DrawerActivity implements
     @Inject AppPreferences preferences;
     @Inject CurrentAccountProvider accountProvider;
     @Inject ClientFactory clientFactory;
+    @Inject ViewThemeUtils viewThemeUtils;
+
     private TrashbinListAdapter trashbinListAdapter;
 
     @VisibleForTesting
@@ -149,7 +152,7 @@ public class TrashbinActivity extends DrawerActivity implements
         recyclerView.setHasFooter(true);
         recyclerView.setLayoutManager(new LinearLayoutManager(this));
 
-        themeLayoutUtils.colorSwipeRefreshLayout(this, binding.swipeContainingList);
+        viewThemeUtils.androidx.themeSwipeRefreshLayout(binding.swipeContainingList);
         binding.swipeContainingList.setOnRefreshListener(this::loadFolder);
 
         findViewById(R.id.sort_button).setOnClickListener(l ->

+ 0 - 73
app/src/main/java/com/owncloud/android/utils/theme/ThemeFabUtils.java

@@ -1,73 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * @author Andy Scherzinger
- * Copyright (C) 2017 Tobias Kaminsky
- * Copyright (C) 2017 Nextcloud GmbH
- * Copyright (C) 2018 Andy Scherzinger
- *
- * 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.content.Context;
-import android.content.res.ColorStateList;
-
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
-
-import androidx.annotation.DrawableRes;
-
-/**
- * Utility class with methods for client side FAB theming.
- */
-public class ThemeFabUtils {
-    private final ThemeColorUtils themeColorUtils;
-    private final ThemeDrawableUtils themeDrawableUtils;
-
-    public ThemeFabUtils(ThemeColorUtils themeColorUtils,
-                         ThemeDrawableUtils themeDrawableUtils) {
-        this.themeColorUtils = themeColorUtils;
-        this.themeDrawableUtils = themeDrawableUtils;
-    }
-
-    public void colorFloatingActionButton(FloatingActionButton button,
-                                          @DrawableRes int drawable,
-                                          Context context) {
-        int primaryColor = themeColorUtils.primaryColor(null, true, false, context);
-
-        colorFloatingActionButton(button, context, primaryColor);
-        button.setImageDrawable(themeDrawableUtils.tintDrawable(drawable,
-                                                                themeColorUtils.getColorForPrimary(primaryColor,
-                                                                                                   context)));
-    }
-
-    public void colorFloatingActionButton(FloatingActionButton button,
-                                          Context context) {
-        colorFloatingActionButton(button,
-                                  context,
-                                  themeColorUtils.primaryColor(null, true, false, context));
-    }
-
-    public void colorFloatingActionButton(FloatingActionButton button,
-                                          Context context,
-                                          int primaryColor) {
-        colorFloatingActionButton(button, primaryColor, themeColorUtils.calculateDarkColor(primaryColor, context));
-    }
-
-    public void colorFloatingActionButton(FloatingActionButton button, int backgroundColor, int rippleColor) {
-        button.setBackgroundTintList(ColorStateList.valueOf(backgroundColor));
-        button.setRippleColor(rippleColor);
-    }
-}

+ 0 - 73
app/src/main/java/com/owncloud/android/utils/theme/ThemeLayoutUtils.java

@@ -1,73 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Tobias Kaminsky
- * @author Andy Scherzinger
- * Copyright (C) 2017 Tobias Kaminsky
- * Copyright (C) 2017 Nextcloud GmbH
- * Copyright (C) 2018 Andy Scherzinger
- *
- * 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.content.Context;
-import android.content.res.ColorStateList;
-import android.graphics.Color;
-
-import com.google.android.material.tabs.TabLayout;
-import com.owncloud.android.R;
-
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
-
-/**
- * Utility class with methods for client side checkable theming.
- */
-public class ThemeLayoutUtils {
-    private final ThemeColorUtils themeColorUtils;
-
-    public ThemeLayoutUtils(ThemeColorUtils themeColorUtils) {
-        this.themeColorUtils = themeColorUtils;
-    }
-
-    public void colorSwipeRefreshLayout(Context context,
-                                        SwipeRefreshLayout swipeRefreshLayout) {
-        int primaryColor = themeColorUtils.primaryColor(context);
-        int darkColor = themeColorUtils.primaryDarkColor(context);
-        int accentColor = themeColorUtils.primaryAccentColor(context);
-
-        swipeRefreshLayout.setColorSchemeColors(accentColor, primaryColor, darkColor);
-        swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.bg_elevation_one);
-    }
-
-    public void colorTabLayout(Context context, TabLayout tabLayout) {
-        int primaryColor = themeColorUtils.primaryColor(context, true);
-        int textColor = context.getResources().getColor(R.color.text_color);
-        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
-        tabLayout.setSelectedTabIndicatorColor(primaryColor);
-        tabLayout.setTabTextColors(textColor, primaryColor);
-        tabLayout.setTabIconTint(new ColorStateList(
-            new int[][]{
-                new int[]{android.R.attr.state_selected},
-                new int[]{android.R.attr.state_enabled},
-                new int[]{-android.R.attr.state_enabled}
-            },
-            new int[]{
-                primaryColor,
-                textColor,
-                Color.GRAY
-            }
-        ));
-    }
-}