Kaynağa Gözat

Replace ThemeBarUtils with common themeutils

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 yıl önce
ebeveyn
işleme
f16f9400ed

+ 1 - 1
app/build.gradle

@@ -354,7 +354,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:feature/more-theming-files-SNAPSHOT'
+    implementation 'com.github.nextcloud.android-common:ui:9bad101de67c312731b7f170b23a4e4cf81633a6'
 }
 
 configurations.all {

+ 1 - 0
app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java

@@ -145,6 +145,7 @@ public class UserAccountManagerImpl implements UserAccountManager {
     @Override
     @Nullable
     public Account getCurrentAccount() {
+        Log_OC.d(TAG, "getCurrentAccount"); // TODO debug only, remove
         Account[] ocAccounts = getAccounts();
         Account defaultAccount = null;
 

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

@@ -23,7 +23,6 @@ package com.nextcloud.client.di
 import android.content.Context
 import com.nextcloud.android.common.ui.theme.MaterialSchemes
 import com.owncloud.android.utils.theme.ThemeAvatarUtils
-import com.owncloud.android.utils.theme.ThemeBarUtils
 import com.owncloud.android.utils.theme.ThemeButtonUtils
 import com.owncloud.android.utils.theme.ThemeCheckableUtils
 import com.owncloud.android.utils.theme.ThemeColorUtils
@@ -115,12 +114,6 @@ internal abstract class ThemeModule {
             return ThemeButtonUtils()
         }
 
-        @Provides
-        @Singleton
-        fun themeBarUtils(): ThemeBarUtils {
-            return ThemeBarUtils()
-        }
-
         @Provides
         @Singleton
         fun themeTextInputUtils(): ThemeTextInputUtils {

+ 4 - 3
app/src/main/java/com/nextcloud/client/logger/ui/LogsActivity.kt

@@ -33,7 +33,7 @@ import com.nextcloud.client.di.ViewModelFactory
 import com.owncloud.android.R
 import com.owncloud.android.databinding.LogsActivityBinding
 import com.owncloud.android.ui.activity.ToolbarActivity
-import com.owncloud.android.utils.theme.ThemeBarUtils
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils
 import javax.inject.Inject
 
 class LogsActivity : ToolbarActivity() {
@@ -42,7 +42,8 @@ class LogsActivity : ToolbarActivity() {
     protected lateinit var viewModelFactory: ViewModelFactory
 
     @Inject
-    protected lateinit var themeBarUtils: ThemeBarUtils
+    lateinit var viewThemeUtils: ViewThemeUtils
+
     private lateinit var vm: LogsViewModel
     private lateinit var binding: LogsActivityBinding
     private lateinit var logsAdapter: LogsAdapter
@@ -67,7 +68,7 @@ class LogsActivity : ToolbarActivity() {
         }
 
         findViewById<ProgressBar>(R.id.logs_loading_progress).apply {
-            themeBarUtils.themeProgressBar(context, this, themeColorUtils)
+            viewThemeUtils.platform.themeHorizontalProgressBar(this)
         }
 
         logsAdapter = LogsAdapter(this)

+ 4 - 4
app/src/main/java/com/owncloud/android/media/MediaControlView.java

@@ -41,8 +41,8 @@ import android.widget.TextView;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.utils.theme.ThemeBarUtils;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.util.Formatter;
 import java.util.Locale;
@@ -74,7 +74,7 @@ public class MediaControlView extends FrameLayout implements OnClickListener, On
     @Inject
     ThemeColorUtils themeColorUtils;
     @Inject
-    ThemeBarUtils themeBarUtils;
+    ViewThemeUtils viewThemeUtils;
 
 
     public MediaControlView(Context context,
@@ -137,10 +137,10 @@ public class MediaControlView extends FrameLayout implements OnClickListener, On
         if (progressBar != null) {
             if (progressBar instanceof SeekBar) {
                 SeekBar seeker = (SeekBar) progressBar;
-                themeBarUtils.colorHorizontalSeekBar(seeker, getContext(), themeColorUtils);
+                viewThemeUtils.platform.themeHorizontalSeekBar(seeker);
                 seeker.setOnSeekBarChangeListener(this);
             } else {
-                themeBarUtils.colorHorizontalProgressBar(progressBar, themeColorUtils.primaryAccentColor(getContext()));
+                viewThemeUtils.platform.themeHorizontalProgressBar(progressBar);
             }
             progressBar.setMax(1000);
         }

+ 7 - 6
app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -113,8 +113,8 @@ 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.ThemeBarUtils;
 import com.owncloud.android.utils.theme.ThemeMenuUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
@@ -214,7 +214,7 @@ public abstract class DrawerActivity extends ToolbarActivity
     ThemeMenuUtils themeMenuUtils;
 
     @Inject
-    ThemeBarUtils themeBarUtils;
+    ViewThemeUtils viewThemeUtils;
 
     /**
      * Initializes the drawer, its content and highlights the menu item with the given id. This method needs to be
@@ -300,7 +300,7 @@ public abstract class DrawerActivity extends ToolbarActivity
         mQuotaProgressBar = (ProgressBar) findQuotaViewById(R.id.drawer_quota_ProgressBar);
         mQuotaTextPercentage = (TextView) findQuotaViewById(R.id.drawer_quota_percentage);
         mQuotaTextLink = (TextView) findQuotaViewById(R.id.drawer_quota_link);
-        themeBarUtils.colorProgressBar(mQuotaProgressBar, themeColorUtils.primaryColor(this));
+        viewThemeUtils.platform.themeHorizontalProgressBar(mQuotaProgressBar);
     }
 
     public void updateHeader() {
@@ -702,9 +702,10 @@ public abstract class DrawerActivity extends ToolbarActivity
 
         mQuotaProgressBar.setProgress(relative);
 
-        themeBarUtils.colorProgressBar(mQuotaProgressBar, DisplayUtils.getRelativeInfoColor(this,
-                                                                                            relative,
-                                                                                            themeColorUtils));
+        final int color = DisplayUtils.getRelativeInfoColor(this,
+                                                                        relative,
+                                                                        themeColorUtils);
+        viewThemeUtils.platform.themeHorizontalProgressBar(mQuotaProgressBar, color);
 
         updateQuotaLink();
         showQuota(true);

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

@@ -56,6 +56,7 @@ import com.owncloud.android.operations.CheckCurrentCredentialsOperation;
 import com.owncloud.android.ui.adapter.UploadListAdapter;
 import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
 import com.owncloud.android.utils.FilesSyncHelper;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import javax.inject.Inject;
 
@@ -99,6 +100,9 @@ public class UploadListActivity extends FileActivity {
     @Inject
     LocalBroadcastManager localBroadcastManager;
 
+    @Inject
+    ViewThemeUtils viewThemeUtils;
+
     private UploadListLayoutBinding binding;
 
     public static Intent createIntent(OCFile file, User user, Integer flag, Context context) {
@@ -157,7 +161,7 @@ public class UploadListActivity extends FileActivity {
                                                   clock,
                                                   themeColorUtils,
                                                   themeDrawableUtils,
-                                                  themeBarUtils);
+                                                  viewThemeUtils);
 
         final GridLayoutManager lm = new GridLayoutManager(this, 1);
         uploadListAdapter.setLayoutManager(lm);

+ 5 - 7
app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

@@ -24,7 +24,6 @@
 
 package com.owncloud.android.ui.adapter;
 
-import android.accounts.Account;
 import android.content.ActivityNotFoundException;
 import android.content.Context;
 import android.content.Intent;
@@ -65,9 +64,9 @@ import com.owncloud.android.ui.activity.ConflictsResolveActivity;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimeTypeUtil;
-import com.owncloud.android.utils.theme.ThemeBarUtils;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.ThemeDrawableUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.io.File;
 import java.util.Arrays;
@@ -92,7 +91,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
     private boolean showUser;
     private ThemeColorUtils themeColorUtils;
     private ThemeDrawableUtils themeDrawableUtils;
-    private ThemeBarUtils themeBarUtils;
+    private final  ViewThemeUtils viewThemeUtils;
 
     @Override
     public int getSectionCount() {
@@ -174,7 +173,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                              final Clock clock,
                              final ThemeColorUtils themeColorUtils,
                              final ThemeDrawableUtils themeDrawableUtils,
-                             final ThemeBarUtils themeBarUtils) {
+                             final ViewThemeUtils viewThemeUtils) {
         Log_OC.d(TAG, "UploadListAdapter");
         this.parentActivity = fileActivity;
         this.uploadsStorageManager = uploadsStorageManager;
@@ -185,7 +184,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
         this.clock = clock;
         this.themeColorUtils = themeColorUtils;
         this.themeDrawableUtils = themeDrawableUtils;
-        this.themeBarUtils = themeBarUtils;
+        this.viewThemeUtils = viewThemeUtils;
 
         uploadGroups = new UploadGroup[3];
 
@@ -280,8 +279,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
         String status = getStatusText(item);
         switch (item.getUploadStatus()) {
             case UPLOAD_IN_PROGRESS:
-                themeBarUtils.colorHorizontalProgressBar(itemViewHolder.binding.uploadProgressBar,
-                                                         themeColorUtils.primaryAccentColor(parentActivity));
+                viewThemeUtils.platform.themeHorizontalProgressBar(itemViewHolder.binding.uploadProgressBar);
                 itemViewHolder.binding.uploadProgressBar.setProgress(0);
                 itemViewHolder.binding.uploadProgressBar.setVisibility(View.VISIBLE);
 

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

@@ -72,9 +72,9 @@ import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
 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.ThemeBarUtils;
 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;
 import org.greenrobot.eventbus.Subscribe;
@@ -118,7 +118,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
     @Inject FileDataStorageManager storageManager;
     @Inject ThemeColorUtils themeColorUtils;
     @Inject ThemeLayoutUtils themeLayoutUtils;
-    @Inject ThemeBarUtils themeBarUtils;
+    @Inject ViewThemeUtils viewThemeUtils;
     @Inject BackgroundJobManager backgroundJobManager;
 
     /**
@@ -233,7 +233,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
     @Override
     public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
         if (getFile() != null && user != null) {
-            themeBarUtils.colorHorizontalProgressBar(binding.progressBar, themeColorUtils.primaryAccentColor(getContext()));
+            viewThemeUtils.platform.themeHorizontalProgressBar(binding.progressBar);
             progressListener = new ProgressListener(binding.progressBar);
             binding.cancelBtn.setOnClickListener(this);
             binding.favorite.setOnClickListener(this);

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

@@ -34,8 +34,8 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.fragment.FileFragment;
-import com.owncloud.android.utils.theme.ThemeBarUtils;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.lang.ref.WeakReference;
 
@@ -63,7 +63,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
     private User user;
 
     @Inject ThemeColorUtils themeColorUtils;
-    @Inject ThemeBarUtils themeBarUtils;
+    @Inject ViewThemeUtils viewThemeUtils;
     public ProgressListener mProgressListener;
     private boolean mListening;
 
@@ -145,7 +145,7 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
         mView = inflater.inflate(R.layout.file_download_fragment, container, false);
 
         ProgressBar progressBar = mView.findViewById(R.id.progressBar);
-        themeBarUtils.colorHorizontalProgressBar(progressBar, themeColorUtils.primaryAccentColor(getContext()));
+        viewThemeUtils.platform.themeHorizontalProgressBar(progressBar);
         mProgressListener = new ProgressListener(progressBar);
 
         (mView.findViewById(R.id.cancelBtn)).setOnClickListener(this);

+ 0 - 3
app/src/main/java/com/owncloud/android/utils/theme/CapabilityUtils.java

@@ -34,9 +34,6 @@ import com.owncloud.android.lib.resources.status.OCCapability;
 import java.util.HashMap;
 import java.util.Map;
 
-/**
- * Utility class with methods for client side button theming.
- */
 public final class CapabilityUtils {
     private static final Map<String, OCCapability> cachedCapabilities = new HashMap<>();
 

+ 0 - 79
app/src/main/java/com/owncloud/android/utils/theme/ThemeBarUtils.java

@@ -1,79 +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.PorterDuff;
-import android.widget.ProgressBar;
-import android.widget.SeekBar;
-
-import androidx.annotation.ColorInt;
-
-/**
- * Utility class with methods for client side button theming.
- */
-public final class ThemeBarUtils {
-    /**
-     * sets the coloring of the given progress bar to given color.
-     *
-     * @param progressBar the progress bar to be colored
-     * @param color       the color to be used
-     */
-    public void colorHorizontalProgressBar(ProgressBar progressBar, @ColorInt int color) {
-        if (progressBar != null) {
-            progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
-            progressBar.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
-        }
-    }
-
-    /**
-     * sets the coloring of the given progress bar's progress to given color.
-     *
-     * @param progressBar the progress bar to be colored
-     * @param color       the color to be used
-     */
-    public void colorProgressBar(ProgressBar progressBar, @ColorInt int color) {
-        if (progressBar != null) {
-            progressBar.setProgressTintList(ColorStateList.valueOf(color));
-        }
-    }
-
-    /**
-     * sets the coloring of the given seek bar to color_accent.
-     *
-     * @param seekBar the seek bar to be colored
-     */
-    public void colorHorizontalSeekBar(SeekBar seekBar, Context context, ThemeColorUtils themeColorUtils) {
-        int color = themeColorUtils.primaryAccentColor(context);
-
-        colorHorizontalProgressBar(seekBar, color);
-        seekBar.getThumb().setColorFilter(color, PorterDuff.Mode.SRC_IN);
-    }
-
-    public void themeProgressBar(Context context, ProgressBar progressBar, ThemeColorUtils themeColorUtils) {
-        // TODO harmonize methods
-        int color = themeColorUtils.primaryAccentColor(context);
-        progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
-    }
-}

+ 1 - 0
app/src/main/java/com/owncloud/android/utils/theme/ThemeColorUtils.java

@@ -40,6 +40,7 @@ import static com.owncloud.android.utils.theme.CapabilityUtils.getCapability;
 /**
  * Utility class with methods for theming related.
  */
+@Deprecated
 public class ThemeColorUtils {
 
     private static final int INDEX_LUMINATION = 2;

+ 11 - 5
app/src/main/java/com/owncloud/android/utils/theme/newm3/ViewThemeUtils.kt

@@ -21,6 +21,7 @@
 
 package com.owncloud.android.utils.theme.newm3
 
+import com.nextcloud.android.common.ui.color.ColorUtil
 import com.nextcloud.android.common.ui.theme.MaterialSchemes
 import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
 import com.nextcloud.android.common.ui.theme.utils.AndroidViewThemeUtils
@@ -32,12 +33,17 @@ import javax.inject.Inject
 @Suppress("TooManyFunctions")
 class ViewThemeUtils @Inject constructor(
     schemes: MaterialSchemes,
+    colorUtil: ColorUtil
+) : ViewThemeUtilsBase(schemes) {
     @JvmField
-    val platform: AndroidViewThemeUtils,
+    val platform = AndroidViewThemeUtils(schemes, colorUtil)
+
     @JvmField
-    val material: MaterialViewThemeUtils,
+    val material = MaterialViewThemeUtils(schemes, colorUtil)
+
     @JvmField
-    val androidx: AndroidXViewThemeUtils,
+    val androidx = AndroidXViewThemeUtils(schemes)
+
     @JvmField
-    val dialog: DialogViewThemeUtils
-) : ViewThemeUtilsBase(schemes)
+    val dialog = DialogViewThemeUtils(schemes)
+}