From 7169e3ab8bd740253720f26c583f60e0aeecabb2 Mon Sep 17 00:00:00 2001 From: Vologhat Date: Tue, 22 Nov 2022 16:48:59 +0300 Subject: [PATCH] refactored color attributes storing and color value replacement --- .../ru/vtosters/lite/hooks/JsonInjectors.java | 3 +- .../ru/vtosters/lite/themes/VTLResources.java | 43 +++++++------------ .../ru/vtosters/lite/utils/ThemesUtils.java | 2 +- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java b/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java index 6c3c55cdf..338364ca3 100644 --- a/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java +++ b/app/src/main/java/ru/vtosters/lite/hooks/JsonInjectors.java @@ -24,6 +24,7 @@ import static ru.vtosters.lite.utils.VTVerifications.isDeveloper; import static ru.vtosters.lite.utils.VTVerifications.isPrometheus; import static ru.vtosters.lite.utils.VTVerifications.isVerified; +import android.graphics.Color; import android.util.Log; import com.vk.core.network.Network; @@ -72,7 +73,7 @@ public class JsonInjectors { var item = newItem.getJSONObject(i); if (item.has("text_color")) { var textColor = item.getString("text_color"); - if (accentColors.contains(textColor.toLowerCase())) { + if (accentColors.contains(Color.parseColor(textColor.startsWith("#") ? textColor : "#" + textColor))) { item.put("text_color", hex2(getAccentColor())); } } diff --git a/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java b/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java index 5ca1dcbfc..70fdc1055 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java +++ b/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java @@ -13,8 +13,6 @@ import android.util.TypedValue; import com.vtosters.lite.R; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; import ru.vtosters.lite.themes.managers.ThemesManager; import ru.vtosters.lite.utils.ReflectionUtils; @@ -22,8 +20,8 @@ import ru.vtosters.lite.utils.ThemesUtils; public class VTLResources { private static final int STYLE_NUM_ENTRIES = Build.VERSION.SDK_INT >= 29 ? 7 : 6; - public static final SparseIntArray forcedColors = new SparseIntArray(); - public static final List colorAttrs = new ArrayList<>(); + public static final SparseIntArray forcedAttrs = new SparseIntArray(); + public static final SparseIntArray otherAttrs = new SparseIntArray(); private static Field dataField; @@ -34,23 +32,17 @@ public class VTLResources { e.printStackTrace(); } - // Custom attributes - colorAttrs.add(R.attr.vklib_alv_optionIconTint); - colorAttrs.add(R.attr.vkim_colorPrimary); - colorAttrs.add(R.attr.statusBarColorBack); - colorAttrs.add(R.attr.statusBarColorFront); - colorAttrs.add(R.attr.drawableTint); - colorAttrs.add(R.attr.bcb_cancel_text_color); - colorAttrs.add(R.attr.bcb_send_bg_color); - + otherAttrs.put(R.attr.vklib_alv_optionIconTint, R.attr.im_dropdown_icon_color); + otherAttrs.put(R.attr.vkim_colorPrimary, R.attr.accent); + otherAttrs.put(R.attr.statusBarColorBack, R.attr.statusBarColorBack); + otherAttrs.put(R.attr.statusBarColorFront, R.attr.statusBarColorFront); // android attributes - colorAttrs.add(android.R.attr.backgroundTint); - colorAttrs.add(android.R.attr.tint); - colorAttrs.add(android.R.attr.color); - colorAttrs.add(android.R.attr.background); + otherAttrs.put(android.R.attr.backgroundTint, R.attr.accent); + otherAttrs.put(android.R.attr.tint, R.attr.accent); + otherAttrs.put(android.R.attr.color, R.attr.accent); - forcedColors.put(-0x8e5515, VTLColors.getAccentColor()); - forcedColors.put(-0xe6e6e6, VTLColors.getBackgroundContent()); + forcedAttrs.put(-0x8e5515, R.attr.accent); + forcedAttrs.put(-0xe6e6e6, R.attr.background_content); } private static void prepareTypedArray(TypedArray target, int[] attrs) { @@ -62,20 +54,15 @@ public class VTLResources { var off = STYLE_NUM_ENTRIES * i; var type = data[off]; var replacement = -1; - if (type == TypedValue.TYPE_ATTRIBUTE) + if (type == TypedValue.TYPE_ATTRIBUTE) { replacement = theme.getColor(data[off + 0x1]); - if (replacement == -1) - replacement = forcedColors.get(data[off + 0x1], -1); - if (replacement == -1 && ThemesUtils.accentColors.contains(data[off + 0x1])) - replacement = ThemesUtils.getAccentColor(); - else continue; - /*else if (type == TypedValue.TYPE_INT_COLOR_ARGB8 || type == TypedValue.TYPE_INT_COLOR_RGB8) { + } else if (type == TypedValue.TYPE_INT_COLOR_ARGB8 || type == TypedValue.TYPE_INT_COLOR_RGB8) { replacement = forcedAttrs.get(data[off + 0x1], -1); if (replacement == -1 - && ThemesUtils.accentColors.contains(data[off + 0x1])) + && ThemesUtils.accentColors.contains(Integer.toHexString(data[off + 0x1]).toLowerCase())) replacement = ThemesUtils.getAccentColor(); } - if (replacement == -1) continue;*/ + if (replacement == -1) continue; try { data[off] = TypedValue.TYPE_INT_COLOR_RGB8; // type data[off + 0x1] = replacement; // data diff --git a/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java b/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java index c877626d9..a7332908a 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java +++ b/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java @@ -369,7 +369,7 @@ public class ThemesUtils { } public static boolean isAccentedColor(int target) { - return accentColors.contains(hex2(target).toLowerCase()); + return accentColors.contains(target); } @SuppressLint("NewApi")