From 9972d56e9aa67ff144ac12629bdeb408b5fd8079 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:55:05 +0300 Subject: [PATCH 1/7] init --- .../ru/vtosters/lite/themes/ThemesHacks.java | 2 +- .../vtosters/lite/themes/ThemesManager.java | 106 ++++++++++-------- .../ru/vtosters/lite/themes/VTLResources.java | 26 +++-- .../ru/vtosters/lite/themes/ViewInjector.java | 11 +- .../lite/themes/hooks/ToolbarHook.java | 16 ++- .../lite/themes/items/VTLPalette.java | 63 ++++++----- .../themes/loaders/AssetManagerHelper.java | 12 -- .../lite/themes/loaders/ResourcesLoader.java | 29 ----- .../lite/themes/palettes/PalettesManager.java | 73 ++++++------ .../lite/themes/utils/ArscEditor.java | 41 +++---- .../lite/themes/utils/VkUiThemer.java | 2 +- 11 files changed, 187 insertions(+), 194 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java index 958ea2ed1e..77b4c233ba 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java @@ -46,7 +46,7 @@ public static int getHackedColor(@NonNull Context context, @ColorRes int color) // Фиксит селектор (все/свои/архив) в профиле public static void fixProfileSelector(View view) { if (!ThemesUtils.isMilkshake()) return; - var id = view.getId(); + int id = view.getId(); if (id == R.id.profile_wall_owner_posts || id == R.id.profile_wall_all_posts || id == R.id.profile_wall_archived_posts) { StateListDrawable states = (StateListDrawable) ((LayerDrawable) view.getBackground()).getDrawable(0); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java index 6dd0684fbf..5989ea17f9 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java @@ -3,6 +3,7 @@ import android.app.Application; import android.content.Context; import android.graphics.Color; +import android.os.Build; import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceFile; import com.vtosters.lite.R; import ru.vtosters.hooks.other.Preferences; @@ -12,6 +13,8 @@ import ru.vtosters.lite.utils.IOUtils; import java.io.*; +import java.util.Arrays; +import java.util.Enumeration; import java.util.zip.CRC32; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -123,7 +126,7 @@ public static void init(Application app) { ResourcesLoader.load(app, modApk.getAbsolutePath(), false); } } catch (Exception e) { - e.printStackTrace(); + // } } @@ -152,59 +155,70 @@ public static boolean canApplyCustomAccent() { } public static void generateModApk(int accentColor) throws Throwable { - try (var apk = new ZipFile(baseApkPath)) { - var arscEntry = apk.getEntry("resources.arsc"); - var arscBis = new BufferedInputStream(apk.getInputStream(arscEntry)); - var arsc = BinaryResourceFile.fromInputStream(arscBis); - ArscEditor.changeColors(arsc, ACCENT_COLORS, accentColor); - - try (var zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(modApk)))) { - var arscBuff = arsc.toByteArray(); - var newArscEntry = new ZipEntry("resources.arsc"); - - var crc = new CRC32(); - crc.update(arscBuff); + try (ZipFile apk = new ZipFile(baseApkPath); + ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(modApk)))) { - newArscEntry.setSize(arscBuff.length); - newArscEntry.setMethod(ZipEntry.STORED); - newArscEntry.setCrc(crc.getValue()); - - zos.putNextEntry(newArscEntry); - zos.write(arscBuff); - zos.closeEntry(); + ZipEntry arscEntry = apk.getEntry("resources.arsc"); + BufferedInputStream arscBis = new BufferedInputStream(apk.getInputStream(arscEntry)); + BinaryResourceFile arsc = BinaryResourceFile.fromInputStream(arscBis); + ArscEditor.changeColors(arsc, ACCENT_COLORS, accentColor); - var entries = apk.entries(); + byte[] arscBuff = arsc.toByteArray(); + ZipEntry newArscEntry = new ZipEntry("resources.arsc"); + + CRC32 crc = new CRC32(); + crc.update(arscBuff); + + newArscEntry.setSize(arscBuff.length); + newArscEntry.setMethod(ZipEntry.STORED); + newArscEntry.setCrc(crc.getValue()); + + zos.putNextEntry(newArscEntry); + zos.write(arscBuff); + zos.closeEntry(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + apk.stream() + .filter(entry -> entry.getName().startsWith("res/") || entry.getName().startsWith("assets/") && !entry.getName().equals("resources.arsc")) + .forEach(entry -> { + try { + String name = entry.getName(); + workWithApk(zos, name, apk.getInputStream(entry), entry.getSize(), entry.getCrc()); + } catch (IOException e) { + e.fillInStackTrace(); + } + }); + } else { + Enumeration entries = apk.entries(); while (entries.hasMoreElements()) { - var entry = entries.nextElement(); - var name = entry.getName(); - - if (!name.startsWith("res/") && !name.startsWith("assets/") || name.equals("resources.arsc")) - continue; - - var doNotCompress = false; - for (var suffix : DO_NOT_COMPRESS) { - if (name.endsWith(suffix)) { - doNotCompress = true; - break; - } + ZipEntry entry = entries.nextElement(); + String name = entry.getName(); + if (name.startsWith("res/") || name.startsWith("assets/") && !name.equals("resources.arsc")) { + workWithApk(zos, name, apk.getInputStream(entry), entry.getSize(), entry.getCrc()); } + } + } + } + } - var entryBis = new BufferedInputStream(apk.getInputStream(entry)); - var newEntry = new ZipEntry(name); + private static void workWithApk(ZipOutputStream zos, String name, InputStream inputStream, long size, long crc) throws IOException { + boolean doNotCompress = Arrays.stream(DO_NOT_COMPRESS).anyMatch(name::endsWith); - if (doNotCompress) { - newEntry.setMethod(ZipEntry.STORED); - newEntry.setSize(entry.getSize()); - newEntry.setCrc(entry.getCrc()); - } else newEntry.setMethod(ZipEntry.DEFLATED); + BufferedInputStream entryBis = new BufferedInputStream(inputStream); + ZipEntry newEntry = new ZipEntry(name); - zos.putNextEntry(newEntry); - IOUtils.copy(entryBis, zos); - entryBis.close(); - zos.closeEntry(); - } - } + if (doNotCompress) { + newEntry.setMethod(ZipEntry.STORED); + newEntry.setSize(size); + newEntry.setCrc(crc); + } else { + newEntry.setMethod(ZipEntry.DEFLATED); } + + zos.putNextEntry(newEntry); + IOUtils.copy(entryBis, zos); + entryBis.close(); + zos.closeEntry(); } public static void deleteModification() { 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 97f5265cf4..d90917f4ab 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java +++ b/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java @@ -13,6 +13,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.stream.IntStream; public class VTLResources extends Resources { private static final String TAG = "VTLResources"; @@ -32,12 +33,9 @@ public class VTLResources extends Resources { attributesToTheme.add(16843173); } - private final Context context; - public VTLResources(Context context, Resources parent) { super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration()); - this.context = context; -// Log.d(TAG, "VTLResources: init"); + // Log.d(TAG, "VTLResources: init"); } private static boolean isAttrThemeable(int attrID) { @@ -49,16 +47,16 @@ private static int[] getArrayData(TypedArray arr) { return (int[]) typedArrayField.get(arr); } catch (IllegalAccessException e) { Log.e(TAG, "getArrayData: ", e); - e.printStackTrace(); + e.fillInStackTrace(); return new int[0]; } } @Override public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { - var typedArray = super.obtainAttributes(set, attrs); - var data = getArrayData(typedArray); - for (int i = 0; i < attrs.length; i++) { + TypedArray typedArray = super.obtainAttributes(set, attrs); + int[] data = getArrayData(typedArray); + IntStream.range(0, attrs.length).forEach(i -> { try { int attrID = attrs[i]; if (attributesToTheme.contains(attrID)) { @@ -73,18 +71,22 @@ public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { } } catch (Exception e) { Log.e(TAG, "TAVzlom failed! (obtainAttributes)"); - e.printStackTrace(); + e.fillInStackTrace(); } - } + }); return typedArray; } @Override public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundException { - var drawable = super.getDrawable(id, theme); + Drawable drawable = super.getDrawable(id, theme); + fixDropdown(id, drawable); + return drawable; + } + + private void fixDropdown(int id, Drawable drawable) { if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16) { ThemesHacks.fixDropdown(drawable); } - return drawable; } } \ No newline at end of file diff --git a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java index e00ed01510..d4b0ee7a33 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java @@ -6,6 +6,7 @@ import ru.vtosters.lite.themes.hooks.*; import java.util.ArrayList; +import java.util.stream.IntStream; public class ViewInjector { public static ArrayList hooks = new ArrayList<>(); @@ -22,15 +23,13 @@ public class ViewInjector { public static View inject(View view, int i, boolean z) { if (ThemesUtils.isMonetTheme()) { - for (BaseHook hook : hooks) { - hook.inject(view, i, z); - } + hooks.forEach(hook -> hook.inject(view, i, z)); if (view instanceof ViewGroup) { var viewGroup = (ViewGroup) view; - for (int i2 = 0; i2 < viewGroup.getChildCount(); i2++) { - inject(viewGroup.getChildAt(i2), i, false); - } + IntStream.range(0, viewGroup.getChildCount()) + .mapToObj(viewGroup::getChildAt) + .forEach(child -> inject(child, i, false)); } } return view; diff --git a/app/src/main/java/ru/vtosters/lite/themes/hooks/ToolbarHook.java b/app/src/main/java/ru/vtosters/lite/themes/hooks/ToolbarHook.java index 7617a48ba7..77aa361536 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/hooks/ToolbarHook.java +++ b/app/src/main/java/ru/vtosters/lite/themes/hooks/ToolbarHook.java @@ -1,5 +1,8 @@ package ru.vtosters.lite.themes.hooks; +import android.graphics.drawable.Drawable; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import androidx.appcompat.widget.Toolbar; import com.vk.core.drawable.RecoloredDrawable; @@ -9,16 +12,17 @@ public class ToolbarHook implements BaseHook { @Override public void inject(View view, int i, boolean z) { if (view instanceof Toolbar) { - var color = (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText(); - var menu = ((Toolbar) view).getMenu(); + int color = (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText(); + Menu menu = ((Toolbar) view).getMenu(); for (int j = 0; j < menu.size(); ++j) { - var item = menu.getItem(j); - var icon = item.getIcon(); + MenuItem item = menu.getItem(j); + Drawable icon = item.getIcon(); if (icon != null) { - if (icon instanceof RecoloredDrawable) + if (icon instanceof RecoloredDrawable) { ((RecoloredDrawable) icon).a(color); - else + } else { icon = new RecoloredDrawable(icon, color); + } item.setIcon(icon); } } diff --git a/app/src/main/java/ru/vtosters/lite/themes/items/VTLPalette.java b/app/src/main/java/ru/vtosters/lite/themes/items/VTLPalette.java index b7bdb8a1b3..94ff7b1046 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/items/VTLPalette.java +++ b/app/src/main/java/ru/vtosters/lite/themes/items/VTLPalette.java @@ -1,11 +1,13 @@ package ru.vtosters.lite.themes.items; import android.graphics.Color; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; +import java.util.stream.IntStream; public class VTLPalette { public String id; @@ -25,29 +27,38 @@ public VTLPalette(String id, String name, String author, List colors) } public static VTLPalette fromJson(JSONObject json) throws JSONException { - var palette = new VTLPalette() + VTLPalette palette = new VTLPalette() .setId(json.optString("palette_id")) .setName(json.optString("name")) .setAuthor(json.optString("author")); - var paletteNode = json.getJSONArray("palette"); - for (int i = 0; i < paletteNode.length(); i++) { - var colorNode = paletteNode.getJSONObject(i); - var name = colorNode.getString("name"); - if (colorNode.has("colors")) { - var colorsNode = colorNode.getJSONArray("colors"); - for (int j = 0; j < colorsNode.length(); j++) { - var subColorNode = colorsNode.getJSONObject(j); - var index = subColorNode.getString("index"); - var subColor = subColorNode.getString("color"); - if (!subColor.startsWith("#")) subColor = "#" + subColor; - palette.setColor(name + " " + index, Color.parseColor(subColor)); - } - } else { - var color = colorNode.getString("color"); - if (!color.startsWith("#")) color = "#" + color; - palette.setColor(name, Color.parseColor(color)); - } - } + JSONArray paletteNode = json.getJSONArray("palette"); + IntStream.range(0, paletteNode.length()) + .mapToObj(paletteNode::optJSONObject) + .forEach(colorNode -> { + String name = colorNode.optString("name"); + if (colorNode.has("colors")) { + JSONArray colorsNode; + try { + colorsNode = colorNode.getJSONArray("colors"); + } catch (JSONException e) { + throw new RuntimeException(e); + } + IntStream.range(0, colorsNode.length()) + .mapToObj(colorsNode::optJSONObject) + .forEach(subColorNode -> { + String index = subColorNode.optString("index"); + String subColor = subColorNode.optString("color"); + if (!subColor.startsWith("#")) subColor = "#" + subColor; + palette.setColor(name + " " + index, Color.parseColor(subColor)); + }); + } else { + String color = colorNode.optString("color"); + if (!color.startsWith("#")) { + color = "#" + color; + } + palette.setColor(name, Color.parseColor(color)); + } + }); return palette; } @@ -79,15 +90,15 @@ public VTLPalette setColors(List colors) { return this; } - public VTLPalette setColor(String name, int color) { + public void setColor(String name, int color) { this.colors.add(new VTLColor(name, 0, color)); - return this; } public int getColor(String name) { - for (var item : colors) - if (name.equals(item.resName)) - return item.color; - return -1; + return colors.stream() + .filter(item -> name.equals(item.resName)) + .map(item -> item.color) + .findFirst() + .orElse(-1); } } diff --git a/app/src/main/java/ru/vtosters/lite/themes/loaders/AssetManagerHelper.java b/app/src/main/java/ru/vtosters/lite/themes/loaders/AssetManagerHelper.java index 2ce6d8f94e..a187b08ebb 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/loaders/AssetManagerHelper.java +++ b/app/src/main/java/ru/vtosters/lite/themes/loaders/AssetManagerHelper.java @@ -2,23 +2,11 @@ import android.annotation.SuppressLint; import android.content.res.AssetManager; -import ru.vtosters.lite.utils.ReflectionUtils; import java.lang.reflect.InvocationTargetException; @SuppressLint("PrivateApi") public class AssetManagerHelper { - public static String getApkPath(Object assetManager, String packagename) throws InvocationTargetException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException { - Object[] apkAssetsArr = (Object[]) ReflectionUtils.findMethod(Class.forName("android.content.res.ApkAssets"), "getAssetPath").invoke(assetManager); - // By default, base apk is the last element of array if is not, for execution speed, we should iterate array from the end to the beginning - for (int i = apkAssetsArr.length - 1; i >= 0; i--) { - String pathname = (String) ReflectionUtils.findMethod(AssetManager.class, "getApkAssets").invoke(apkAssetsArr[i]); - if (pathname != null && pathname.contains(packagename)) return pathname; - } - - throw new NullPointerException(); - } - //region Uses for adding own assets or getting existing cookies public static void addAssetPath(AssetManager manager, String path) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { manager.getClass().getMethod("addAssetPath", String.class).invoke(manager, path); diff --git a/app/src/main/java/ru/vtosters/lite/themes/loaders/ResourcesLoader.java b/app/src/main/java/ru/vtosters/lite/themes/loaders/ResourcesLoader.java index eecf4d755b..83ca828d00 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/loaders/ResourcesLoader.java +++ b/app/src/main/java/ru/vtosters/lite/themes/loaders/ResourcesLoader.java @@ -171,8 +171,6 @@ public static void load(Context context, String resPath, boolean reinject) throw implAssets.set(resourceImpl, sAssetManager); } - clearPreloadTypedArrayIssue(resources); - resources.updateConfiguration(resources.getConfiguration(), resources.getDisplayMetrics()); } @@ -235,33 +233,6 @@ private static void recordCurrentPatchedResModifiedTime(String patchedResPath) { } } - /** - * Why must I do these? - * Resource has mTypedArrayPool field, which just like Message Poll to reduce gc - * MiuiResource change TypedArray to MiuiTypedArray, but it get string block from offset instead of assetManager - */ - private static void clearPreloadTypedArrayIssue(Resources resources) { - // Perform this trick not only in Miui system since we can't predict if any other - // manufacturer would do the same modification to Android. - // if (!isMiuiSystem) { - // return; - // } - Log.w("ResourcesLoader", "try to clear typedArray cache!"); - // Clear typedArray cache. - try { - Field typedArrayPoolField = ReflectionUtils.findField(Resources.class, "mTypedArrayPool"); - Object origTypedArrayPool = typedArrayPoolField.get(resources); - Method acquireMethod = ReflectionUtils.findMethod(origTypedArrayPool, "acquire"); - while (true) { - if (acquireMethod.invoke(origTypedArrayPool) == null) { - break; - } - } - } catch (Throwable ignored) { - Log.e("ResourcesLoader", "clearPreloadTypedArrayIssue failed, ignore error: " + ignored); - } - } - private static boolean shouldAddSharedLibraryAssets(ApplicationInfo applicationInfo) { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && applicationInfo != null && applicationInfo.sharedLibraryFiles != null; diff --git a/app/src/main/java/ru/vtosters/lite/themes/palettes/PalettesManager.java b/app/src/main/java/ru/vtosters/lite/themes/palettes/PalettesManager.java index 87db482e01..82cdbdf2c1 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/palettes/PalettesManager.java +++ b/app/src/main/java/ru/vtosters/lite/themes/palettes/PalettesManager.java @@ -1,8 +1,8 @@ package ru.vtosters.lite.themes.palettes; +import android.content.res.AssetManager; import android.os.Build; import android.os.Environment; -import android.util.Log; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -15,8 +15,7 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import static android.widget.Toast.makeText; import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext; @@ -51,7 +50,7 @@ public void load() { return; } - var palettes = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json")); + File[] palettes = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json")); if (palettes == null || palettes.length == 0) copyPaletteFromAssets(); parsePalettes(); @@ -59,45 +58,49 @@ public void load() { private void copyPaletteFromAssets() { try { - var manager = AndroidUtils.getGlobalContext().getAssets(); - var assets = manager.list(ASSETS_DIR); - if (assets == null || assets.length == 0) return; - for (var asset : assets) { - try { - IOUtils.copy(manager.open(ASSETS_DIR + asset), new File(PALETTES_DIR, asset)); - } catch (IOException e) { - e.printStackTrace(); - } - } + AssetManager manager = getGlobalContext().getAssets(); + Arrays.stream(manager.list(ASSETS_DIR)) + .filter(Objects::nonNull) + .forEach(asset -> { + try { + IOUtils.copy(manager.open(ASSETS_DIR + asset), new File(PALETTES_DIR, asset)); + } catch (IOException e) { + e.fillInStackTrace(); + } + }); } catch (IOException e) { - e.printStackTrace(); + e.fillInStackTrace(); } } private void parsePalettes() { - var arr = PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json")); - - if (arr == null || arr.length == 0) { - Log.d("PalettesManager", "arr.length null"); - return; - } - - for (var file : arr) { - try { - var json = new JSONObject(IOUtils.readAllLines(file)); - mPalettes.add(VTLPalette.fromJson(json)); - } catch (IOException | JSONException e) { - e.printStackTrace(); - } - } + Optional.ofNullable(PALETTES_DIR.listFiles((dir, name) -> name.endsWith(".json"))) + .ifPresent(arr -> Arrays.stream(arr) + .map(file -> { + try { + return new JSONObject(IOUtils.readAllLines(file)); + } catch (IOException | JSONException e) { + e.printStackTrace(); + return null; + } + }) + .filter(Objects::nonNull) + .map(json -> { + try { + return json != null ? VTLPalette.fromJson(json) : null; + } catch (JSONException e) { + throw new RuntimeException(e); + } + }) + .forEach(mPalettes::add)); } @Nullable public VTLPalette getPalette(String id) { - for (var palette : mPalettes) - if (id.equals(palette.id)) - return palette; - return null; + return mPalettes.stream() + .filter(palette -> id.equals(palette.id)) + .findFirst() + .orElse(null); } @NonNull @@ -108,4 +111,4 @@ public VTLPalette getPalette(int i) { public int getPalettesCount() { return mPalettes.size(); } -} +} \ No newline at end of file diff --git a/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java b/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java index 4541c0deea..af0f958b04 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java +++ b/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java @@ -4,29 +4,30 @@ import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue; import com.google.devrel.gmscore.tools.apk.arsc.ResourceTableChunk; +import java.util.AbstractMap; +import java.util.Arrays; + public class ArscEditor { public static void changeColors(BinaryResourceFile arsc, int[] colorIds, int color) { - for (var chunk : arsc.getChunks()) { - var resTableChunk = (ResourceTableChunk) chunk; - for (var packageChunk : resTableChunk.getPackages()) { - for (var typeChunk : packageChunk.getTypeChunks("color")) { - for (var entry : typeChunk.getEntries().entrySet()) { - var value = entry.getValue(); - if (value.isComplex()) continue; - var binValue = value.value(); - if (!isColorResourceValue(binValue)) continue; - var resId = packageChunk.getId() << 24 | typeChunk.getId() << 16 | entry.getKey(); - for (var colodId : colorIds) { - if (resId == colodId) { - binValue.data = color; - break; + arsc.getChunks().stream() + .filter(chunk -> chunk instanceof ResourceTableChunk) + .map(chunk -> (ResourceTableChunk) chunk) + .flatMap(resTableChunk -> resTableChunk.getPackages().stream()) + .flatMap(packageChunk -> packageChunk.getTypeChunks("color").stream() + .map(typeChunk -> new AbstractMap.SimpleEntry<>(packageChunk, typeChunk))) + .forEach(entry -> entry.getValue().getEntries().entrySet().stream() + .filter(e -> !e.getValue().isComplex()) + .filter(e -> isColorResourceValue(e.getValue().value())) + .forEach(e -> { + BinaryResourceValue binValue = e.getValue().value(); + int resId = entry.getKey().getId() << 24 | entry.getValue().getId() << 16 | e.getKey(); + if (Arrays.stream(colorIds).anyMatch(colorId -> resId == colorId)) { + if (binValue != null) { + binValue.data = color; + } } - } - } - } - } - } + })); } private static boolean isColorResourceValue(BinaryResourceValue value) { @@ -35,4 +36,4 @@ private static boolean isColorResourceValue(BinaryResourceValue value) { || value.type == BinaryResourceValue.Type.INT_COLOR_ARGB4 || value.type == BinaryResourceValue.Type.INT_COLOR_RGB4; } -} +} \ No newline at end of file diff --git a/app/src/main/java/ru/vtosters/lite/themes/utils/VkUiThemer.java b/app/src/main/java/ru/vtosters/lite/themes/utils/VkUiThemer.java index 64716a3938..349a9248b3 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/utils/VkUiThemer.java +++ b/app/src/main/java/ru/vtosters/lite/themes/utils/VkUiThemer.java @@ -74,7 +74,7 @@ public static void autoThemeVkuiButtons(TextView view) { } } catch (Exception e) { // This must go wrong, so we ignore any exceptions that may occur - e.printStackTrace(); // REMOVE THIS! + e.fillInStackTrace(); // REMOVE THIS! } } } \ No newline at end of file From e627c9023554b6a8811d0bcc281e094d351dc75c Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 01:50:02 +0300 Subject: [PATCH 2/7] fixes --- .../ru/vtosters/lite/themes/VTLResources.java | 38 ++++++++++--------- .../lite/themes/hooks/TextViewHook.java | 2 +- .../lite/themes/utils/RecolorUtils.java | 18 ++------- 3 files changed, 25 insertions(+), 33 deletions(-) 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 d90917f4ab..328043365d 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java +++ b/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java @@ -35,7 +35,6 @@ public class VTLResources extends Resources { public VTLResources(Context context, Resources parent) { super(parent.getAssets(), parent.getDisplayMetrics(), parent.getConfiguration()); - // Log.d(TAG, "VTLResources: init"); } private static boolean isAttrThemeable(int attrID) { @@ -55,25 +54,28 @@ private static int[] getArrayData(TypedArray arr) { @Override public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { TypedArray typedArray = super.obtainAttributes(set, attrs); - int[] data = getArrayData(typedArray); - IntStream.range(0, attrs.length).forEach(i -> { - try { - int attrID = attrs[i]; - if (attributesToTheme.contains(attrID)) { - int type = data[i * 6]; - int cnt = data[(i * 6) + 1]; - if (type == TypedValue.TYPE_ATTRIBUTE && isAttrThemeable(cnt)) { - data[i * 6] = TypedValue.TYPE_INT_COLOR_RGB8; - data[(i * 6) + 1] = ThemesUtils.getAccentColor(); - data[(i * 6) + 2] = 0; // clear reference content + if (ThemesUtils.isMonetTheme()) { + int[] data = getArrayData(typedArray); + IntStream.range(0, attrs.length).forEach(i -> { + try { + int attrID = attrs[i]; + if (attributesToTheme.contains(attrID)) { + int type = data[i * 6]; + int cnt = data[(i * 6) + 1]; + + if (type == TypedValue.TYPE_ATTRIBUTE && isAttrThemeable(cnt)) { + data[i * 6] = TypedValue.TYPE_INT_COLOR_RGB8; + data[(i * 6) + 1] = ThemesUtils.getAccentColor(); + data[(i * 6) + 2] = 0; // clear reference content + } } + } catch (Exception e) { + Log.e(TAG, "TAVzlom failed! (obtainAttributes)"); + e.fillInStackTrace(); } - } catch (Exception e) { - Log.e(TAG, "TAVzlom failed! (obtainAttributes)"); - e.fillInStackTrace(); - } - }); + }); + } return typedArray; } @@ -85,7 +87,7 @@ public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundExcept } private void fixDropdown(int id, Drawable drawable) { - if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16) { + if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16 && ThemesUtils.isMonetTheme()) { ThemesHacks.fixDropdown(drawable); } } diff --git a/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java b/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java index f7036c0768..3d2d284980 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java +++ b/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java @@ -43,7 +43,7 @@ public static boolean isVkUiButton(View view) { @SuppressLint("RestrictedApi") @Override public void inject(View view, int i, boolean z) { - if (view instanceof TextView) { + if (view instanceof TextView && ThemesUtils.isMonetTheme()) { var textView = (TextView) view; if (ColorReferences.isAccentedColor(textView.getCurrentTextColor())) { diff --git a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java index 131e7b9e7f..b1714eb088 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java +++ b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java @@ -15,16 +15,6 @@ import ru.vtosters.lite.utils.AndroidUtils; public class RecolorUtils { - public static Drawable recolorDrawableToolbar(Drawable drawable) { - if (drawable == null) return null; - - return new RecoloredDrawable(drawable, ThemesUtils.getHeaderText()); - } // Recolor toolbar drawable to accent color - - public static Drawable recolorDrawableInt(int drawable) { - return recolorDrawable(drawable, ThemesUtils.getAccentColor()); - } // Get res drawable via id and coloring to accent - public static Drawable recolorDrawable(int drawable, int color) { return new RecoloredDrawable(AndroidUtils.getResources().getDrawable(drawable), color); } // Get res drawable via id and coloring to accent @@ -34,19 +24,19 @@ public static Drawable fixActionMenuIcons(int drawable) { } public static int getColor(TypedArray ta, int index, int defval) { - return recolorHexColor(ta.getColor(index, defval)); + return ThemesUtils.isMonetTheme() ? ta.getColor(index, defval) : recolorHexColor(ta.getColor(index, defval)); } public static void recolorTextView(TextView tw) { - if (ColorReferences.isAccentedColor(tw.getTextColors())) { + if (ColorReferences.isAccentedColor(tw.getTextColors()) && ThemesUtils.isMonetTheme()) { tw.setTextColor(ThemesUtils.getAccentColor()); } } public static int recolorHexColor(int i) { if (!ThemesUtils.isMonetTheme() || !ThemesManager.canApplyCustomAccent()) return i; - var accented = ColorReferences.isAccentedColor(i); - var mutedaccented = ColorReferences.isMutedAccentedColor(i); + boolean accented = ColorReferences.isAccentedColor(i); + boolean mutedaccented = ColorReferences.isMutedAccentedColor(i); return (accented || mutedaccented) ? (accented ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : i; } From ad9580dc332b0969819a70bf3d68e7a576de4459 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 03:06:40 +0300 Subject: [PATCH 3/7] important fixes --- .../msg_list/adapter/vh/VhMsg.java | 59 ++++++++----------- .../BottomNavigationItemView.java | 4 +- .../ru/vtosters/hooks/DockBarInjector.java | 4 +- .../ru/vtosters/hooks/other/ThemesUtils.java | 7 ++- .../ru/vtosters/lite/themes/ThemesHacks.java | 8 ++- 5 files changed, 39 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/vk/im/ui/components/viewcontrollers/msg_list/adapter/vh/VhMsg.java b/app/src/main/java/com/vk/im/ui/components/viewcontrollers/msg_list/adapter/vh/VhMsg.java index e3627a332b..2f33420bd6 100644 --- a/app/src/main/java/com/vk/im/ui/components/viewcontrollers/msg_list/adapter/vh/VhMsg.java +++ b/app/src/main/java/com/vk/im/ui/components/viewcontrollers/msg_list/adapter/vh/VhMsg.java @@ -49,6 +49,7 @@ import com.vk.im.ui.views.sticker.StickerAnimationState; import kotlin.Unit; import kotlin.jvm.b.Functions; +import ru.vtosters.lite.themes.ThemesHacks; public class VhMsg extends VhBase implements SwipeToReplyItemTouchCallback.b { public static final int h0 = Screen.a(124); @@ -133,7 +134,7 @@ public VhMsg(View itemView, MsgPartHolderBase vhBase) { this.h = itemView.findViewById(com.vk.im.ui.h.status_space); this.P = itemView.findViewById(com.vk.im.ui.h.bomb); this.B = vhBase; - this.H = new ColorDrawable(context.getResources().getColor(com.vk.im.ui.d.msg_search_selection)); + this.H = new ColorDrawable(ThemesHacks.getColors(context, com.vk.im.ui.d.msg_search_selection)); this.I = ContextExtKt.b(context, com.vk.im.ui.e.msg_bubble_max_width); this.J = ContextExtKt.b(context, com.vk.im.ui.e.msg_reply_max_width); this.K = ContextExtKt.b(context, com.vk.im.ui.e.msg_sticker_max_width); @@ -150,48 +151,38 @@ public VhMsg(View itemView, MsgPartHolderBase vhBase) { var6.right = var7.rightMargin; var6.top = var7.topMargin; var6.bottom = var7.bottomMargin; - ViewExtKt.b(this.c, new View.OnClickListener() { - public void onClick(View var1) { - if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { - VhMsg.this.c0.a(VhMsg.this.d0.getFrom()); - } - + ViewExtKt.b(this.c, var1 -> { + if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { + VhMsg.this.c0.a(VhMsg.this.d0.getFrom()); } + }); - this.c.setOnLongClickListener(new View.OnLongClickListener() { - public boolean onLongClick(View var1) { - if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { - VhMsg.this.c0.a(VhMsg.this.d0.getFrom()); - return true; - } else { - return false; - } + this.c.setOnLongClickListener(var1 -> { + if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { + VhMsg.this.c0.a(VhMsg.this.d0.getFrom()); + return true; + } else { + return false; } }); - ViewExtKt.b(this.g, new View.OnClickListener() { - public void onClick(View var1) { - if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { - VhMsg.this.c0.a(VhMsg.this.d0); - } - + ViewExtKt.b(this.g, var1 -> { + if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { + VhMsg.this.c0.a(VhMsg.this.d0); } - }); - ViewExtKt.b(this.itemView, new View.OnClickListener() { - public void onClick(View var1) { - if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { - VhMsg.this.c0.a(VhMsg.this.d0.getLocalId()); - } - } }); - this.itemView.setOnLongClickListener(new View.OnLongClickListener() { - public boolean onLongClick(View var1) { - if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { - VhMsg.this.c0.b(VhMsg.this.d0.getLocalId()); - } + ViewExtKt.b(this.itemView, (View.OnClickListener) var1 -> { + if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { + VhMsg.this.c0.a(VhMsg.this.d0.getLocalId()); + } - return true; + }); + this.itemView.setOnLongClickListener((View.OnLongClickListener) var1 -> { + if (VhMsg.this.c0 != null && VhMsg.this.d0 != null) { + VhMsg.this.c0.b(VhMsg.this.d0.getLocalId()); } + + return true; }); this.R = ContextExtKt.i(context, com.vk.im.ui.c.im_msg_part_corner_radius_small); this.S = ContextExtKt.i(context, com.vk.im.ui.c.im_msg_part_corner_radius_big); diff --git a/app/src/main/java/com/vtosters/lite/ui/bottomnavigation/BottomNavigationItemView.java b/app/src/main/java/com/vtosters/lite/ui/bottomnavigation/BottomNavigationItemView.java index c9a572e174..04634a8979 100644 --- a/app/src/main/java/com/vtosters/lite/ui/bottomnavigation/BottomNavigationItemView.java +++ b/app/src/main/java/com/vtosters/lite/ui/bottomnavigation/BottomNavigationItemView.java @@ -69,10 +69,10 @@ public BottomNavigationItemView(Context context, AttributeSet attrs, int defStyl this.mIcon.getLayoutParams().height = V.a(28.0F); this.mSmallLabel = this.findViewById(R.id.smallLabel); - mSmallLabel.setTextColor(getCSTDock()); + mSmallLabel.setTextColor(getCSTDock(this.getContext())); this.mLargeLabel = this.findViewById(R.id.largeLabel); - mLargeLabel.setTextColor(getCSTDock()); + mLargeLabel.setTextColor(getCSTDock(this.getContext())); LayoutInflater.from(this.getContext()).inflate(R.layout.navigation_bottom_counter, this, true); this.mCounterContainer = this.findViewById(R.id.counter_container); diff --git a/app/src/main/java/ru/vtosters/hooks/DockBarInjector.java b/app/src/main/java/ru/vtosters/hooks/DockBarInjector.java index 08557a531d..84a9425860 100644 --- a/app/src/main/java/ru/vtosters/hooks/DockBarInjector.java +++ b/app/src/main/java/ru/vtosters/hooks/DockBarInjector.java @@ -65,7 +65,7 @@ public static void inject(BottomNavigationView navigationView) { for (DockBarTab tab : sManager.getSelectedTabs()) { MenuItem add = menu.add(0, tab.id, 0, tab.titleID); - add.setIcon(new RecoloredDrawable(getResources().getDrawable(tab.iconID), getCSTDock())); + add.setIcon(new RecoloredDrawable(getResources().getDrawable(tab.iconID), getCSTDock(navigationView.getContext()))); add.setTitle(getGlobalContext().getString(tab.titleID)); add.setCheckable(true); } @@ -76,7 +76,7 @@ public static void inject(BottomNavigationView navigationView) { item.setStaticMode(true); item.setIconsMode(false); item.setShiftingMode(false); - item.setTextColor(getCSTDock()); + item.setTextColor(getCSTDock(item.getContext())); } } } diff --git a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java index 184e709b42..21bddf1cb2 100644 --- a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java +++ b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java @@ -2,6 +2,7 @@ import android.annotation.SuppressLint; import android.app.Activity; +import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Color; @@ -340,7 +341,7 @@ public static int halfAlpha(int src) { } public static int getColor(int i) { - return ThemesHacks.getHackedColor(getGlobalContext(), i); + return ThemesHacks.getHackedColor(LifecycleUtils.getCurrentActivity(), i); } // Android Support color injector + accent color checker public static int getAlertStyle() { @@ -391,14 +392,14 @@ public static int getNavigationWidth(int Default) { return vkme() ? R.dimen.app_minimumsize_h : Default; } - public static ColorStateList getCSTDock() { + public static ColorStateList getCSTDock(Context ctx) { return new ColorStateList( new int[][]{ new int[]{android.R.attr.state_checked}, new int[]{-android.R.attr.state_checked} }, new int[]{ - dockbar_accent() ? getAccentColor() : (isDarkTheme() ? getResources().getColor(R.color.white) : getResources().getColor(R.color.gray_700)), + dockbar_accent() ? getAccentColor() : (isDarkTheme() ? ThemesHacks.getColors(ctx, R.color.white) : ThemesHacks.getColors(ctx, R.color.gray_700)), getColorFromAttr(R.attr.tabbar_inactive_icon) } ); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java index 77b4c233ba..590611e4b6 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java @@ -31,15 +31,19 @@ public static int getHackedColor(@NonNull Context context, @ColorRes int color) } } - if (ThemesCore.isCachedAccents() && ColorReferences.isAccentedColor(context.getResources().getColor(color))) { + if (ThemesCore.isCachedAccents() && ColorReferences.isAccentedColor(getColors(context, color))) { return ThemesUtils.getAccentColor(); } - if (ThemesCore.isCachedAccents() && ColorReferences.isMutedAccentedColor(context.getResources().getColor(color))) { + if (ThemesCore.isCachedAccents() && ColorReferences.isMutedAccentedColor(getColors(context, color))) { return ThemesUtils.getMutedAccentColor(); } } + return getColors(context, color); + } + + public static int getColors(Context context, int color) { return Build.VERSION.SDK_INT > 23 ? context.getColor(color) : context.getResources().getColor(color); } From fc2101c3e84a52ef5ad982baec576b202e1f6549 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 12:56:47 +0300 Subject: [PATCH 4/7] some 5.1 android fixes --- .../java/ru/vtosters/hooks/other/ThemesUtils.java | 7 ++++--- .../main/java/ru/vtosters/lite/themes/ThemesCore.java | 5 +++-- .../java/ru/vtosters/lite/themes/ViewInjector.java | 11 +++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java index 21bddf1cb2..53e71d50c1 100644 --- a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java +++ b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java @@ -74,7 +74,7 @@ public static boolean isDarkTheme() { } public static boolean isMonetTheme() { - return getBoolValue("monettheme", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; + return getBoolValue("monettheme", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1; // android 5.1 fix } public static boolean isAmoledTheme() { @@ -248,6 +248,7 @@ public static int getNeededColorNavbar() { public static int getDarkThemeRes() { if (isMonetTheme()) { + if (isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (isAmoledTheme()) { return getIdentifier(isMilkshake() ? "VkMilkAmoledMonetStyle" : "VkAmoledMonetStyle", "style"); } else { @@ -263,7 +264,7 @@ public static int getDarkThemeRes() { } // Return needed res theme public static int getLightThemeRes() { - if (isMonetTheme()) { + if (isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { return getIdentifier(isMilkshake() ? "VkMilkLightMonetStyle" : "VkLightMonetStyle", "style"); } else { return isMilkshake() ? R.style.VkMilkLightStyle : R.style.VkLightStyle; @@ -322,7 +323,7 @@ public static int darken(int color, float by) { } public static int fixSeparator(float f) { - if (isMonetTheme()) { + if (isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { return 0; } else { return (int) Math.floor(f * Resources.getSystem().getDisplayMetrics().density); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java index eea7712c05..f958022a82 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java @@ -2,6 +2,7 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.os.Build; import android.util.Log; import android.util.SparseBooleanArray; import android.util.SparseIntArray; @@ -143,8 +144,8 @@ public static void setThemedColors(int accentColor) { themedColors.put(R.attr.im_reply_separator, accentColor); themedColors.put(R.attr.im_text_name, accentColor); - float out = ThemesUtils.isMonetTheme() ? 0.85f : 0.76f; - float outhighlight = ThemesUtils.isMonetTheme() ? 0.75f : 0.5f; + float out = ThemesUtils.isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? 0.85f : 0.76f; + float outhighlight = ThemesUtils.isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? 0.75f : 0.5f; outgoinging_msg = ThemesUtils.lighten(accentColor, out); outgoinging_msg_highlight = ThemesUtils.lighten(accentColor, outhighlight); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java index d4b0ee7a33..275cbf9172 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java @@ -1,5 +1,6 @@ package ru.vtosters.lite.themes; +import android.os.Build; import android.view.View; import android.view.ViewGroup; import ru.vtosters.hooks.other.ThemesUtils; @@ -23,10 +24,16 @@ public class ViewInjector { public static View inject(View view, int i, boolean z) { if (ThemesUtils.isMonetTheme()) { - hooks.forEach(hook -> hook.inject(view, i, z)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + hooks.forEach(hook -> hook.inject(view, i, z)); + } else { + for (BaseHook hook : hooks) { + hook.inject(view, i, z); + } + } if (view instanceof ViewGroup) { - var viewGroup = (ViewGroup) view; + ViewGroup viewGroup = (ViewGroup) view; IntStream.range(0, viewGroup.getChildCount()) .mapToObj(viewGroup::getChildAt) .forEach(child -> inject(child, i, false)); From a43d564e17a88c9ff1a04c711e8f71bf1da87552 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 13:37:08 +0300 Subject: [PATCH 5/7] fixed 5.1 android coloring --- .../ru/vtosters/hooks/other/ThemesUtils.java | 1 - .../ru/vtosters/lite/themes/ThemesHacks.java | 6 +- .../lite/themes/utils/RecolorUtils.java | 102 ++++++++++++++++-- 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java index 53e71d50c1..bdf749d334 100644 --- a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java +++ b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java @@ -247,7 +247,6 @@ public static int getNeededColorNavbar() { } public static int getDarkThemeRes() { - if (isMonetTheme()) { if (isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (isAmoledTheme()) { return getIdentifier(isMilkshake() ? "VkMilkAmoledMonetStyle" : "VkAmoledMonetStyle", "style"); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java index 590611e4b6..5936b0a342 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java @@ -44,7 +44,11 @@ public static int getHackedColor(@NonNull Context context, @ColorRes int color) } public static int getColors(Context context, int color) { - return Build.VERSION.SDK_INT > 23 ? context.getColor(color) : context.getResources().getColor(color); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return context.getColor(color); + } else { + return context.getResources().getColor(color); + } } // Фиксит селектор (все/свои/архив) в профиле diff --git a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java index b1714eb088..ce6f27f632 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java +++ b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java @@ -3,18 +3,56 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; +import android.content.res.Configuration; +import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Build; +import android.util.SparseArray; +import android.util.TypedValue; import android.widget.TextView; +import androidx.annotation.ColorRes; +import androidx.annotation.NonNull; +import androidx.core.content.res.ColorStateListInflaterCompat; import com.vk.core.drawable.RecoloredDrawable; import ru.vtosters.hooks.other.ThemesUtils; import ru.vtosters.lite.themes.ColorReferences; import ru.vtosters.lite.themes.ThemesManager; import ru.vtosters.lite.utils.AndroidUtils; +import java.util.WeakHashMap; + public class RecolorUtils { + private static final ThreadLocal TL_TYPED_VALUE = new ThreadLocal<>(); + private static final WeakHashMap> sColorStateCaches = new WeakHashMap<>(0); + private static final Object sColorStateCacheLock = new Object(); + + private static void addColorStateListToCache(@NonNull Context context, @ColorRes int i, @NonNull ColorStateList colorStateList) { + synchronized (sColorStateCacheLock) { + SparseArray sparseArray = sColorStateCaches.get(context); + if (sparseArray == null) { + sparseArray = new SparseArray<>(); + sColorStateCaches.put(context, sparseArray); + } + sparseArray.append(i, new ColorStateListCacheEntry(colorStateList, context.getResources().getConfiguration())); + } + } + + private static ColorStateList getCachedColorStateList(@NonNull Context context, @ColorRes int i) { + ColorStateListCacheEntry colorStateListCacheEntry; + synchronized (sColorStateCacheLock) { + SparseArray sparseArray = sColorStateCaches.get(context); + if (sparseArray != null && sparseArray.size() > 0 && (colorStateListCacheEntry = sparseArray.get(i)) != null) { + if (colorStateListCacheEntry.configuration.equals(context.getResources().getConfiguration())) { + return colorStateListCacheEntry.value; + } + sparseArray.remove(i); + } + return null; + } + } + public static Drawable recolorDrawable(int drawable, int color) { return new RecoloredDrawable(AndroidUtils.getResources().getDrawable(drawable), color); } // Get res drawable via id and coloring to accent @@ -46,9 +84,51 @@ public static ColorStateList recolorCSL(ColorStateList colorStateList) { return ColorStateList.valueOf(ThemesUtils.getAccentColor()); } // Recolor ColorStateList to accent color + @SuppressLint("RestrictedApi") + private static ColorStateList inflateColorStateList(Context context, int i) { + if (isColorInt(context, i)) { + return null; + } + Resources resources = context.getResources(); + try { + return ColorStateListInflaterCompat.createFromXml(resources, resources.getXml(i), context.getTheme()); + } catch (Exception e) { + return null; + } + } + + private static boolean isColorInt(@NonNull Context context, @ColorRes int i) { + Resources resources = context.getResources(); + TypedValue typedValue = getTypedValue(); + resources.getValue(i, typedValue, true); + int i2 = typedValue.type; + return i2 >= 28 && i2 <= 31; + } + + private static TypedValue getTypedValue() { + TypedValue typedValue = TL_TYPED_VALUE.get(); + if (typedValue == null) { + TypedValue typedValue2 = new TypedValue(); + TL_TYPED_VALUE.set(typedValue2); + return typedValue2; + } + return typedValue; + } + @SuppressLint("UseCompatLoadingForColorStateLists") public static ColorStateList themeCSL(Context context, int color) { - if (!ThemesUtils.isMonetTheme()) { + if (!ThemesUtils.isMonetTheme() || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { + ColorStateList cachedColorStateList = getCachedColorStateList(context, color); + if (cachedColorStateList != null) { + return cachedColorStateList; + } + + ColorStateList inflateColorStateList = inflateColorStateList(context, color); + if (inflateColorStateList != null) { + addColorStateListToCache(context, color, inflateColorStateList); + return inflateColorStateList; + } + if (Build.VERSION.SDK_INT >= 23) { return context.getColorStateList(color); } else { @@ -62,15 +142,7 @@ public static ColorStateList themeCSL(Context context, int color) { return ColorStateList.valueOf(ThemesUtils.getMutedAccentColor()); } - ColorStateList csl; - - if (Build.VERSION.SDK_INT >= 23) { - csl = context.getColorStateList(color); - } else { - csl = context.getResources().getColorStateList(color); - } - - return themeCSL(csl); + return themeCSL(context.getColorStateList(color)); } // Recolor ColorStateList public static ColorStateList themeCSL(ColorStateList csl) { @@ -110,4 +182,14 @@ public static ColorStateList themeCSL(ColorStateList csl) { return null; } } + + static class ColorStateListCacheEntry { + final Configuration configuration; + final ColorStateList value; + + ColorStateListCacheEntry(@NonNull ColorStateList colorStateList, @NonNull Configuration configuration) { + this.value = colorStateList; + this.configuration = configuration; + } + } } From 2f74345a8672a3bff58b8d948e0e3be3ad8306c1 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 13:46:23 +0300 Subject: [PATCH 6/7] some monet fixes --- .../ru/vtosters/hooks/MainActivityInjector.java | 2 +- .../ru/vtosters/hooks/other/ThemesUtils.java | 16 ++++++++++------ .../java/ru/vtosters/lite/themes/ThemesCore.java | 6 +++--- .../ru/vtosters/lite/themes/ThemesHacks.java | 2 +- .../ru/vtosters/lite/themes/ThemesManager.java | 2 +- .../ru/vtosters/lite/themes/VTLResources.java | 4 ++-- .../ru/vtosters/lite/themes/ViewInjector.java | 2 +- .../vtosters/lite/themes/hooks/TextViewHook.java | 2 +- .../vtosters/lite/themes/utils/RecolorUtils.java | 10 +++++----- .../lite/ui/fragments/ThemesFragment.java | 2 +- 10 files changed, 26 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java b/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java index 3b582785b5..e2b384acaa 100644 --- a/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java +++ b/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java @@ -49,7 +49,7 @@ public static void inject(Activity activity) { } if (Preferences.isNewBuild() - && !ThemesUtils.isMonetTheme() + && !ThemesUtils.needToColoring() && ThemesManager.canApplyCustomAccent()) { Preferences.updateBuildNumber(); updateBinsAndTmpArchive(activity); diff --git a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java index bdf749d334..6858923e98 100644 --- a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java +++ b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java @@ -61,7 +61,7 @@ public static void setThemeFL(VKTheme theme, Activity activity, float[] fl, Bool activity = LifecycleUtils.getCurrentActivity(); } VKThemeHelper.theme(theme, activity, fl); - if (isMonetTheme() || ThemesManager.canApplyCustomAccent()) ThemesCore.clear(); + if (needToColoring() || ThemesManager.canApplyCustomAccent()) ThemesCore.clear(); if (restartActivity) activity.recreate(); ThemeTracker.a(); WebViewColoringUtils.isLoaded = false; @@ -73,8 +73,12 @@ public static boolean isDarkTheme() { return VKThemeHelper.r(); } + public static boolean needToColoring() { + return isMonetTheme() || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1; // android 5.1 fix + } + public static boolean isMonetTheme() { - return getBoolValue("monettheme", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1; // android 5.1 fix + return getBoolValue("monettheme", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; } public static boolean isAmoledTheme() { @@ -247,7 +251,7 @@ public static int getNeededColorNavbar() { } public static int getDarkThemeRes() { - if (isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (isMonetTheme()) { if (isAmoledTheme()) { return getIdentifier(isMilkshake() ? "VkMilkAmoledMonetStyle" : "VkAmoledMonetStyle", "style"); } else { @@ -263,7 +267,7 @@ public static int getDarkThemeRes() { } // Return needed res theme public static int getLightThemeRes() { - if (isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (isMonetTheme()) { return getIdentifier(isMilkshake() ? "VkMilkLightMonetStyle" : "VkLightMonetStyle", "style"); } else { return isMilkshake() ? R.style.VkMilkLightStyle : R.style.VkLightStyle; @@ -300,7 +304,7 @@ public static Drawable recolorDrawable(Drawable drawable) { } // Recolor drawable to accent color public static Drawable recolorToolbarDrawable(Drawable drawable) { - if (!ThemesUtils.isMonetTheme()) return drawable; + if (!ThemesUtils.needToColoring()) return drawable; if (drawable == null) return null; return new RecoloredDrawable(drawable, (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText()); } @@ -322,7 +326,7 @@ public static int darken(int color, float by) { } public static int fixSeparator(float f) { - if (isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (isMonetTheme()) { return 0; } else { return (int) Math.floor(f * Resources.getSystem().getDisplayMetrics().density); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java index f958022a82..4dec2995e8 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java @@ -144,8 +144,8 @@ public static void setThemedColors(int accentColor) { themedColors.put(R.attr.im_reply_separator, accentColor); themedColors.put(R.attr.im_text_name, accentColor); - float out = ThemesUtils.isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? 0.85f : 0.76f; - float outhighlight = ThemesUtils.isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ? 0.75f : 0.5f; + float out = ThemesUtils.isMonetTheme() ? 0.85f : 0.76f; + float outhighlight = ThemesUtils.isMonetTheme() ? 0.75f : 0.5f; outgoinging_msg = ThemesUtils.lighten(accentColor, out); outgoinging_msg_highlight = ThemesUtils.lighten(accentColor, outhighlight); @@ -174,7 +174,7 @@ public static boolean hasThemedAttr(Context context, int attrID) { } } - if (ThemesUtils.isMonetTheme() || ThemesManager.canApplyCustomAccent()) { + if (ThemesUtils.needToColoring() || ThemesManager.canApplyCustomAccent()) { if (isCachedAccents()) { boolean isDark = ThemesUtils.isDarkTheme(); boolean isMilkshake = ThemesUtils.isMilkshake(); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java index 5936b0a342..81b91e28cb 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java @@ -23,7 +23,7 @@ public static void fixDropdown(Drawable drawable) { } public static int getHackedColor(@NonNull Context context, @ColorRes int color) { - if (ThemesUtils.isMonetTheme() || ThemesManager.canApplyCustomAccent()) { + if (ThemesUtils.needToColoring() || ThemesManager.canApplyCustomAccent()) { if (Preferences.getBoolValue("logColors", false)) { try { Log.d("ThemesCore", "Requesting color by color " + context.getResources().getResourceName(color)); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java index 5989ea17f9..65692535cc 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java @@ -121,7 +121,7 @@ public static void init(Application app) { initPaths(app); validateModApk(); - if (!Preferences.isNewBuild() && !ThemesUtils.isMonetTheme() && canApplyCustomAccent()) { + if (!Preferences.isNewBuild() && !ThemesUtils.needToColoring() && canApplyCustomAccent()) { ResourcesLoader.init(app); ResourcesLoader.load(app, modApk.getAbsolutePath(), false); } 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 328043365d..1a68afb53a 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java +++ b/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java @@ -55,7 +55,7 @@ private static int[] getArrayData(TypedArray arr) { public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { TypedArray typedArray = super.obtainAttributes(set, attrs); - if (ThemesUtils.isMonetTheme()) { + if (ThemesUtils.needToColoring()) { int[] data = getArrayData(typedArray); IntStream.range(0, attrs.length).forEach(i -> { try { @@ -87,7 +87,7 @@ public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundExcept } private void fixDropdown(int id, Drawable drawable) { - if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16 && ThemesUtils.isMonetTheme()) { + if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16 && ThemesUtils.needToColoring()) { ThemesHacks.fixDropdown(drawable); } } diff --git a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java index 275cbf9172..16b6921ea8 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java @@ -23,7 +23,7 @@ public class ViewInjector { } public static View inject(View view, int i, boolean z) { - if (ThemesUtils.isMonetTheme()) { + if (ThemesUtils.needToColoring()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { hooks.forEach(hook -> hook.inject(view, i, z)); } else { diff --git a/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java b/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java index 3d2d284980..46fffe291c 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java +++ b/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java @@ -43,7 +43,7 @@ public static boolean isVkUiButton(View view) { @SuppressLint("RestrictedApi") @Override public void inject(View view, int i, boolean z) { - if (view instanceof TextView && ThemesUtils.isMonetTheme()) { + if (view instanceof TextView && ThemesUtils.needToColoring()) { var textView = (TextView) view; if (ColorReferences.isAccentedColor(textView.getCurrentTextColor())) { diff --git a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java index ce6f27f632..90b3993798 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java +++ b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java @@ -62,17 +62,17 @@ public static Drawable fixActionMenuIcons(int drawable) { } public static int getColor(TypedArray ta, int index, int defval) { - return ThemesUtils.isMonetTheme() ? ta.getColor(index, defval) : recolorHexColor(ta.getColor(index, defval)); + return ThemesUtils.needToColoring() ? ta.getColor(index, defval) : recolorHexColor(ta.getColor(index, defval)); } public static void recolorTextView(TextView tw) { - if (ColorReferences.isAccentedColor(tw.getTextColors()) && ThemesUtils.isMonetTheme()) { + if (ColorReferences.isAccentedColor(tw.getTextColors()) && ThemesUtils.needToColoring()) { tw.setTextColor(ThemesUtils.getAccentColor()); } } public static int recolorHexColor(int i) { - if (!ThemesUtils.isMonetTheme() || !ThemesManager.canApplyCustomAccent()) return i; + if (!ThemesUtils.needToColoring() || !ThemesManager.canApplyCustomAccent()) return i; boolean accented = ColorReferences.isAccentedColor(i); boolean mutedaccented = ColorReferences.isMutedAccentedColor(i); return (accented || mutedaccented) ? (accented ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : i; @@ -117,7 +117,7 @@ private static TypedValue getTypedValue() { @SuppressLint("UseCompatLoadingForColorStateLists") public static ColorStateList themeCSL(Context context, int color) { - if (!ThemesUtils.isMonetTheme() || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { + if (!ThemesUtils.needToColoring() || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { ColorStateList cachedColorStateList = getCachedColorStateList(context, color); if (cachedColorStateList != null) { return cachedColorStateList; @@ -146,7 +146,7 @@ public static ColorStateList themeCSL(Context context, int color) { } // Recolor ColorStateList public static ColorStateList themeCSL(ColorStateList csl) { - if (!ThemesUtils.isMonetTheme()) return csl; + if (!ThemesUtils.needToColoring()) return csl; try { int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK); diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java index 5961d092e9..89a1b2fb9a 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java @@ -109,7 +109,7 @@ private void initPreferences() { newsfeedNotificationsPreference.setVisible(Preferences.milkshake()); - findPreference("accentprefs").setVisible(!ThemesUtils.isMonetTheme()); + findPreference("accentprefs").setVisible(!ThemesUtils.needToColoring()); findPreference("systememoji").setOnPreferenceClickListener(preference -> { restart(); From 3b07cdcb5342d4fe163408716fcfc6c3430dd523 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sun, 18 Feb 2024 14:48:17 +0300 Subject: [PATCH 7/7] fixed 5.1 perfomance --- .../java/ru/vtosters/hooks/MainActivityInjector.java | 2 +- .../main/java/ru/vtosters/hooks/other/ThemesUtils.java | 10 +++------- .../main/java/ru/vtosters/lite/themes/ThemesCore.java | 3 +-- .../main/java/ru/vtosters/lite/themes/ThemesHacks.java | 2 +- .../java/ru/vtosters/lite/themes/ThemesManager.java | 2 +- .../java/ru/vtosters/lite/themes/VTLResources.java | 4 ++-- .../java/ru/vtosters/lite/themes/ViewInjector.java | 2 +- .../ru/vtosters/lite/themes/hooks/TextViewHook.java | 2 +- .../ru/vtosters/lite/themes/utils/RecolorUtils.java | 10 +++++----- .../ru/vtosters/lite/ui/fragments/ThemesFragment.java | 2 +- 10 files changed, 17 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java b/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java index e2b384acaa..3b582785b5 100644 --- a/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java +++ b/app/src/main/java/ru/vtosters/hooks/MainActivityInjector.java @@ -49,7 +49,7 @@ public static void inject(Activity activity) { } if (Preferences.isNewBuild() - && !ThemesUtils.needToColoring() + && !ThemesUtils.isMonetTheme() && ThemesManager.canApplyCustomAccent()) { Preferences.updateBuildNumber(); updateBinsAndTmpArchive(activity); diff --git a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java index 6858923e98..2a63789b62 100644 --- a/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java +++ b/app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java @@ -61,7 +61,7 @@ public static void setThemeFL(VKTheme theme, Activity activity, float[] fl, Bool activity = LifecycleUtils.getCurrentActivity(); } VKThemeHelper.theme(theme, activity, fl); - if (needToColoring() || ThemesManager.canApplyCustomAccent()) ThemesCore.clear(); + if (isMonetTheme() || ThemesManager.canApplyCustomAccent()) ThemesCore.clear(); if (restartActivity) activity.recreate(); ThemeTracker.a(); WebViewColoringUtils.isLoaded = false; @@ -73,12 +73,8 @@ public static boolean isDarkTheme() { return VKThemeHelper.r(); } - public static boolean needToColoring() { - return isMonetTheme() || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1; // android 5.1 fix - } - public static boolean isMonetTheme() { - return getBoolValue("monettheme", false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; + return getBoolValue("monettheme", false); } public static boolean isAmoledTheme() { @@ -304,7 +300,7 @@ public static Drawable recolorDrawable(Drawable drawable) { } // Recolor drawable to accent color public static Drawable recolorToolbarDrawable(Drawable drawable) { - if (!ThemesUtils.needToColoring()) return drawable; + if (!ThemesUtils.isMonetTheme()) return drawable; if (drawable == null) return null; return new RecoloredDrawable(drawable, (ThemesUtils.isMilkshake() && !ThemesUtils.isDarkTheme()) ? ThemesUtils.getAccentColor() : ThemesUtils.getHeaderText()); } diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java index 4dec2995e8..eea7712c05 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java @@ -2,7 +2,6 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.os.Build; import android.util.Log; import android.util.SparseBooleanArray; import android.util.SparseIntArray; @@ -174,7 +173,7 @@ public static boolean hasThemedAttr(Context context, int attrID) { } } - if (ThemesUtils.needToColoring() || ThemesManager.canApplyCustomAccent()) { + if (ThemesUtils.isMonetTheme() || ThemesManager.canApplyCustomAccent()) { if (isCachedAccents()) { boolean isDark = ThemesUtils.isDarkTheme(); boolean isMilkshake = ThemesUtils.isMilkshake(); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java index 81b91e28cb..5936b0a342 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java @@ -23,7 +23,7 @@ public static void fixDropdown(Drawable drawable) { } public static int getHackedColor(@NonNull Context context, @ColorRes int color) { - if (ThemesUtils.needToColoring() || ThemesManager.canApplyCustomAccent()) { + if (ThemesUtils.isMonetTheme() || ThemesManager.canApplyCustomAccent()) { if (Preferences.getBoolValue("logColors", false)) { try { Log.d("ThemesCore", "Requesting color by color " + context.getResources().getResourceName(color)); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java index 65692535cc..5989ea17f9 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java @@ -121,7 +121,7 @@ public static void init(Application app) { initPaths(app); validateModApk(); - if (!Preferences.isNewBuild() && !ThemesUtils.needToColoring() && canApplyCustomAccent()) { + if (!Preferences.isNewBuild() && !ThemesUtils.isMonetTheme() && canApplyCustomAccent()) { ResourcesLoader.init(app); ResourcesLoader.load(app, modApk.getAbsolutePath(), false); } 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 1a68afb53a..328043365d 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java +++ b/app/src/main/java/ru/vtosters/lite/themes/VTLResources.java @@ -55,7 +55,7 @@ private static int[] getArrayData(TypedArray arr) { public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { TypedArray typedArray = super.obtainAttributes(set, attrs); - if (ThemesUtils.needToColoring()) { + if (ThemesUtils.isMonetTheme()) { int[] data = getArrayData(typedArray); IntStream.range(0, attrs.length).forEach(i -> { try { @@ -87,7 +87,7 @@ public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundExcept } private void fixDropdown(int id, Drawable drawable) { - if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16 && ThemesUtils.needToColoring()) { + if (id == com.vtosters.lite.R.drawable.newsfeed_tab_dropdown_16 && ThemesUtils.isMonetTheme()) { ThemesHacks.fixDropdown(drawable); } } diff --git a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java index 16b6921ea8..275cbf9172 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ViewInjector.java @@ -23,7 +23,7 @@ public class ViewInjector { } public static View inject(View view, int i, boolean z) { - if (ThemesUtils.needToColoring()) { + if (ThemesUtils.isMonetTheme()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { hooks.forEach(hook -> hook.inject(view, i, z)); } else { diff --git a/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java b/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java index 46fffe291c..3d2d284980 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java +++ b/app/src/main/java/ru/vtosters/lite/themes/hooks/TextViewHook.java @@ -43,7 +43,7 @@ public static boolean isVkUiButton(View view) { @SuppressLint("RestrictedApi") @Override public void inject(View view, int i, boolean z) { - if (view instanceof TextView && ThemesUtils.needToColoring()) { + if (view instanceof TextView && ThemesUtils.isMonetTheme()) { var textView = (TextView) view; if (ColorReferences.isAccentedColor(textView.getCurrentTextColor())) { diff --git a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java index 90b3993798..1dae9af0e0 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java +++ b/app/src/main/java/ru/vtosters/lite/themes/utils/RecolorUtils.java @@ -62,17 +62,17 @@ public static Drawable fixActionMenuIcons(int drawable) { } public static int getColor(TypedArray ta, int index, int defval) { - return ThemesUtils.needToColoring() ? ta.getColor(index, defval) : recolorHexColor(ta.getColor(index, defval)); + return ThemesUtils.isMonetTheme() ? ta.getColor(index, defval) : recolorHexColor(ta.getColor(index, defval)); } public static void recolorTextView(TextView tw) { - if (ColorReferences.isAccentedColor(tw.getTextColors()) && ThemesUtils.needToColoring()) { + if (ColorReferences.isAccentedColor(tw.getTextColors()) && ThemesUtils.isMonetTheme()) { tw.setTextColor(ThemesUtils.getAccentColor()); } } public static int recolorHexColor(int i) { - if (!ThemesUtils.needToColoring() || !ThemesManager.canApplyCustomAccent()) return i; + if (!ThemesUtils.isMonetTheme() || !ThemesManager.canApplyCustomAccent()) return i; boolean accented = ColorReferences.isAccentedColor(i); boolean mutedaccented = ColorReferences.isMutedAccentedColor(i); return (accented || mutedaccented) ? (accented ? ThemesUtils.getAccentColor() : ThemesUtils.getMutedAccentColor()) : i; @@ -117,7 +117,7 @@ private static TypedValue getTypedValue() { @SuppressLint("UseCompatLoadingForColorStateLists") public static ColorStateList themeCSL(Context context, int color) { - if (!ThemesUtils.needToColoring() || Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { + if (!ThemesUtils.isMonetTheme()) { ColorStateList cachedColorStateList = getCachedColorStateList(context, color); if (cachedColorStateList != null) { return cachedColorStateList; @@ -146,7 +146,7 @@ public static ColorStateList themeCSL(Context context, int color) { } // Recolor ColorStateList public static ColorStateList themeCSL(ColorStateList csl) { - if (!ThemesUtils.needToColoring()) return csl; + if (!ThemesUtils.isMonetTheme()) return csl; try { int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK); diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java index 89a1b2fb9a..6455ce8365 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java @@ -109,7 +109,7 @@ private void initPreferences() { newsfeedNotificationsPreference.setVisible(Preferences.milkshake()); - findPreference("accentprefs").setVisible(!ThemesUtils.needToColoring()); + findPreference("accentprefs").setVisible(!ThemesUtils.isMonetTheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M); findPreference("systememoji").setOnPreferenceClickListener(preference -> { restart();