refactored color attributes storing and color value replacement
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Integer> 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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user