소스 검색

Replace ThemeCheckableUtils with common lib utils

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 년 전
부모
커밋
46fef5c883

+ 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:2fa8334415c4289228e650d6a70cb1c70746c28e'
+    implementation 'com.github.nextcloud.android-common:ui:05edc813295567d24ea468ac1b32c3ab1e950dfb'
 }
 
 configurations.all {

+ 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.ThemeCheckableUtils
 import com.owncloud.android.utils.theme.ThemeColorUtils
 import com.owncloud.android.utils.theme.ThemeDrawableUtils
 import com.owncloud.android.utils.theme.ThemeMenuUtils
@@ -99,12 +98,6 @@ internal abstract class ThemeModule {
             return ThemeTextInputUtils()
         }
 
-        @Provides
-        @Singleton
-        fun themeCheckableUtils(): ThemeCheckableUtils {
-            return ThemeCheckableUtils()
-        }
-
         @Provides
         @Singleton
         fun themeAvatarUtils(): ThemeAvatarUtils {

+ 2 - 5
app/src/main/java/com/owncloud/android/ui/dialog/ConflictsResolveDialog.java

@@ -39,7 +39,6 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.adapter.LocalFileListAdapter;
 import com.owncloud.android.utils.DisplayUtils;
-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.newm3.ViewThemeUtils;
@@ -75,7 +74,6 @@ public class ConflictsResolveDialog extends DialogFragment implements Injectable
     @Inject ThemeColorUtils themeColorUtils;
     @Inject ThemeDrawableUtils themeDrawableUtils;
     @Inject ViewThemeUtils viewThemeUtils;
-    @Inject ThemeCheckableUtils themeCheckableUtils;
 
     private static final String KEY_NEW_FILE = "file";
     private static final String KEY_EXISTING_FILE = "ocfile";
@@ -160,9 +158,8 @@ public class ConflictsResolveDialog extends DialogFragment implements Injectable
         // Inflate the layout for the dialog
         binding = ConflictResolveDialogBinding.inflate(requireActivity().getLayoutInflater());
 
-        themeCheckableUtils.tintCheckbox(themeColorUtils.primaryColor(getContext()),
-                                         binding.newCheckbox,
-                                         binding.existingCheckbox);
+        viewThemeUtils.platform.themeCheckbox(binding.newCheckbox);
+        viewThemeUtils.platform.themeCheckbox(binding.existingCheckbox);
 
         // Build the dialog
         AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());

+ 9 - 26
app/src/main/java/com/owncloud/android/ui/dialog/SyncedFolderPreferencesDialogFragment.java

@@ -24,7 +24,6 @@ import android.app.Activity;
 import android.app.Dialog;
 import android.content.DialogInterface;
 import android.content.Intent;
-import android.graphics.Color;
 import android.graphics.Typeface;
 import android.os.Bundle;
 import android.text.TextUtils;
@@ -47,8 +46,6 @@ import com.owncloud.android.ui.activity.UploadFilesActivity;
 import com.owncloud.android.ui.dialog.parcel.SyncedFolderParcelable;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.FileStorageUtils;
-import com.owncloud.android.utils.theme.ThemeCheckableUtils;
-import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.io.File;
@@ -81,8 +78,6 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment implem
     private final static float alphaEnabled = 1.0f;
     private final static float alphaDisabled = 0.7f;
 
-    @Inject ThemeColorUtils themeColorUtils;
-    @Inject ThemeCheckableUtils themeCheckableUtils;
     @Inject ViewThemeUtils viewThemeUtils;
 
     protected View mView;
@@ -161,8 +156,6 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment implem
      * @param view the parent view
      */
     private void setupDialogElements(View view) {
-        int accentColor = themeColorUtils.primaryAccentColor(getContext());
-
         if (mSyncedFolder.getType().getId() > MediaFolderType.CUSTOM.getId()) {
             // hide local folder chooser and delete for non-custom folders
             view.findViewById(R.id.local_folder_container).setVisibility(View.GONE);
@@ -187,7 +180,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment implem
 
         // find/saves UI elements
         mEnabledSwitch = view.findViewById(R.id.sync_enabled);
-        themeCheckableUtils.tintSwitch(mEnabledSwitch, themeColorUtils);
+        viewThemeUtils.androidx.colorSwitchCompat(mEnabledSwitch);
 
         mLocalFolderPath = view.findViewById(R.id.synced_folders_settings_local_folder_path);
 
@@ -203,11 +196,10 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment implem
         mUploadUseSubfoldersCheckbox = view.findViewById(
             R.id.setting_instant_upload_path_use_subfolders_checkbox);
 
-        themeCheckableUtils.tintCheckbox(accentColor,
-                                         mUploadOnWifiCheckbox,
-                                         mUploadOnChargingCheckbox,
-                                         mUploadExistingCheckbox,
-                                         mUploadUseSubfoldersCheckbox);
+        viewThemeUtils.platform.themeCheckbox(mUploadOnWifiCheckbox,
+                                              mUploadOnChargingCheckbox,
+                                              mUploadExistingCheckbox,
+                                              mUploadUseSubfoldersCheckbox);
 
         mUploadBehaviorSummary = view.findViewById(R.id.setting_instant_behaviour_summary);
 
@@ -361,19 +353,10 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment implem
         view.findViewById(R.id.setting_instant_name_collision_policy_container).setEnabled(enable);
         view.findViewById(R.id.setting_instant_name_collision_policy_container).setAlpha(alpha);
 
-        if (enable) {
-            themeCheckableUtils.tintCheckbox(themeColorUtils.primaryAccentColor(getContext()),
-                                             mUploadOnWifiCheckbox,
-                                             mUploadOnChargingCheckbox,
-                                             mUploadExistingCheckbox,
-                                             mUploadUseSubfoldersCheckbox);
-        } else {
-            themeCheckableUtils.tintCheckbox(Color.GRAY,
-                                             mUploadOnWifiCheckbox,
-                                             mUploadOnChargingCheckbox,
-                                             mUploadExistingCheckbox,
-                                             mUploadUseSubfoldersCheckbox);
-        }
+        mUploadOnWifiCheckbox.setEnabled(enable);
+        mUploadOnChargingCheckbox.setEnabled(enable);
+        mUploadExistingCheckbox.setEnabled(enable);
+        mUploadUseSubfoldersCheckbox.setEnabled(enable);
 
         checkWritableFolder();
     }

+ 3 - 5
app/src/main/java/com/owncloud/android/ui/fragment/contactsbackup/BackupFragment.java

@@ -52,7 +52,6 @@ import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.PermissionUtil;
-import com.owncloud.android.utils.theme.ThemeCheckableUtils;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 import com.owncloud.android.utils.theme.ThemeToolbarUtils;
 import com.owncloud.android.utils.theme.ThemeUtils;
@@ -93,7 +92,6 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
     @Inject ThemeColorUtils themeColorUtils;
     @Inject ThemeToolbarUtils themeToolbarUtils;
     @Inject ThemeUtils themeUtils;
-    @Inject ThemeCheckableUtils themeCheckableUtils;
 
     @Inject ArbitraryDataProvider arbitraryDataProvider;
     @Inject ViewThemeUtils viewThemeUtils;
@@ -163,9 +161,9 @@ public class BackupFragment extends FileFragment implements DatePickerDialog.OnD
         }
 
 
-        themeCheckableUtils.tintSwitch(binding.contacts, themeColorUtils);
-        themeCheckableUtils.tintSwitch(binding.calendar, themeColorUtils);
-        themeCheckableUtils.tintSwitch(binding.dailyBackup, themeColorUtils);
+        viewThemeUtils.androidx.colorSwitchCompat(binding.contacts);
+        viewThemeUtils.androidx.colorSwitchCompat(binding.calendar);
+        viewThemeUtils.androidx.colorSwitchCompat(binding.dailyBackup);
         binding.dailyBackup.setChecked(arbitraryDataProvider.getBooleanValue(user,
                                                                              PREFERENCE_CONTACTS_AUTOMATIC_BACKUP));
 

+ 0 - 77
app/src/main/java/com/owncloud/android/utils/theme/ThemeCheckableUtils.java

@@ -1,77 +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.res.ColorStateList;
-import android.graphics.Color;
-
-import com.owncloud.android.R;
-
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.appcompat.widget.AppCompatCheckBox;
-import androidx.appcompat.widget.SwitchCompat;
-import androidx.core.graphics.drawable.DrawableCompat;
-import androidx.core.widget.CompoundButtonCompat;
-
-/**
- * Utility class with methods for client side checkable theming.
- */
-public final class ThemeCheckableUtils {
-    public void tintCheckbox(int color, AppCompatCheckBox... checkBoxes) {
-        if (checkBoxes != null) {
-            for (AppCompatCheckBox checkBox : checkBoxes) {
-                CompoundButtonCompat.setButtonTintList(checkBox, new ColorStateList(
-                    new int[][]{
-                        new int[]{-android.R.attr.state_checked},
-                        new int[]{android.R.attr.state_checked},
-                    },
-                    new int[]{
-                        Color.GRAY,
-                        color
-                    }
-                ));
-            }
-        }
-    }
-
-    public void tintSwitch(SwitchCompat switchView, ThemeColorUtils themeColorUtils) {
-        int trackColor = switchView.getContext().getResources().getColor(R.color.grey_200);
-        ColorStateList thumbColorStateList;
-        ColorStateList trackColorStateList;
-        int thumbColor = themeColorUtils.primaryAccentColor(switchView.getContext());
-        if (themeColorUtils.darkTheme(switchView.getContext()) &&
-            AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
-            thumbColor = Color.WHITE;
-            trackColor = Color.DKGRAY;
-        }
-        thumbColorStateList = new ColorStateList(
-            new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
-            new int[]{thumbColor, switchView.getContext().getResources().getColor(R.color.switch_thumb_color_unchecked)});
-        trackColorStateList = new ColorStateList(
-            new int[][]{new int[]{android.R.attr.state_checked},
-                new int[]{}},
-            new int[]{trackColor, trackColor});
-        DrawableCompat.setTintList(switchView.getThumbDrawable(), thumbColorStateList);
-        DrawableCompat.setTintList(switchView.getTrackDrawable(), trackColorStateList);
-    }
-}