瀏覽代碼

ThemeableSwitchPreference: use m3 utilities

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 年之前
父節點
當前提交
c1cb7e9430
共有 2 個文件被更改,包括 4 次插入34 次删除
  1. 1 1
      app/build.gradle
  2. 3 33
      app/src/main/java/com/owncloud/android/ui/ThemeableSwitchPreference.java

+ 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:1f2547e'
+    implementation 'com.github.nextcloud.android-common:ui:d2d5a96'
 }
 
 configurations.all {

+ 3 - 33
app/src/main/java/com/owncloud/android/ui/ThemeableSwitchPreference.java

@@ -21,8 +21,6 @@
 package com.owncloud.android.ui;
 
 import android.content.Context;
-import android.content.res.ColorStateList;
-import android.graphics.Color;
 import android.preference.SwitchPreference;
 import android.util.AttributeSet;
 import android.view.View;
@@ -30,14 +28,10 @@ import android.view.ViewGroup;
 import android.widget.Switch;
 
 import com.owncloud.android.MainApp;
-import com.owncloud.android.R;
-import com.owncloud.android.utils.theme.ThemeColorUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import javax.inject.Inject;
 
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.core.graphics.drawable.DrawableCompat;
-
 
 /**
  * Themeable switch preference TODO Migrate to androidx
@@ -45,7 +39,7 @@ import androidx.core.graphics.drawable.DrawableCompat;
 // TODO use ViewThemeUtils to theme SwitchPreference directly and remove this class
 public class ThemeableSwitchPreference extends SwitchPreference {
     @Inject
-    ThemeColorUtils themeColorUtils;
+    ViewThemeUtils viewThemeUtils;
 
     public ThemeableSwitchPreference(Context context) {
         super(context);
@@ -72,37 +66,13 @@ public class ThemeableSwitchPreference extends SwitchPreference {
     }
 
     private void findSwitch(ViewGroup viewGroup) {
-        ColorStateList thumbColorStateList = null;
-        ColorStateList trackColorStateList = null;
-
         for (int i = 0; i < viewGroup.getChildCount(); i++) {
             View child = viewGroup.getChildAt(i);
 
             if (child instanceof Switch) {
                 Switch switchView = (Switch) child;
 
-                if(thumbColorStateList == null && trackColorStateList == null) {
-                    int thumbColor = themeColorUtils.primaryAccentColor(getContext());
-                    if (themeColorUtils.darkTheme(getContext()) &&
-                        AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES) {
-                        thumbColor = Color.WHITE;
-                    }
-                    int trackColor = Color.argb(77, Color.red(thumbColor), Color.green(thumbColor), Color.blue(thumbColor));
-                    int trackColorUnchecked = getContext().getResources().getColor(R.color.switch_track_color_unchecked);
-                    thumbColorStateList = new ColorStateList(
-                        new int[][]{new int[]{android.R.attr.state_checked}, new int[]{}},
-                        new int[]{thumbColor, 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, trackColorUnchecked});
-                }
-
-                // setting the thumb color
-                DrawableCompat.setTintList(switchView.getThumbDrawable(), thumbColorStateList);
-
-                // setting the track color
-                DrawableCompat.setTintList(switchView.getTrackDrawable(), trackColorStateList);
+                viewThemeUtils.platform.colorSwitch(switchView);
 
                 break;
             } else if (child instanceof ViewGroup) {