[accents] add exceptions to attr hooker
This commit is contained in:
@@ -2,10 +2,13 @@ package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.IdRes;
|
||||
|
||||
import com.vk.core.ui.themes.VKTheme;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
@@ -15,12 +18,48 @@ public class ThemesCore {
|
||||
private static final String TAG = "ThemesCore";
|
||||
|
||||
public static SparseIntArray themedColors = new SparseIntArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_NOMILK = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_LIGHT = new SparseBooleanArray();
|
||||
public static SparseBooleanArray ACCENT_THEME_ONLY_MILK_DARK = new SparseBooleanArray();
|
||||
|
||||
private static boolean cachedAccents = false;
|
||||
|
||||
private static int wallDarkColor;
|
||||
private static int wallLightColor;
|
||||
|
||||
public static void setExceptions() {
|
||||
ACCENT_THEME_ONLY_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_NOMILK.clear();
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.clear();
|
||||
ACCENT_THEME_ONLY_MILK_DARK.clear();
|
||||
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_primary_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_secondary_foreground, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_tertiary_foreground, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_muted_foreground, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.button_outline_border, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.text_name, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.newsfeed_post_title_color, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.attach_picker_tab_active_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.attach_picker_tab_active_text, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.newsfeed_action_color, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.counter_primary_background, false);
|
||||
ACCENT_THEME_ONLY_LIGHT.put(com.vtosters.lite.R.attr.action_sheet_action_foreground, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK_LIGHT.put(com.vtosters.lite.R.attr.header_background, false);
|
||||
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.header_tint, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.header_tint_alternate, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.toolbarIconsColor, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.header_tab_active_indicator, false);
|
||||
ACCENT_THEME_ONLY_MILK_LIGHT.put(com.vtosters.lite.R.attr.im_dropdown_arrow_tint, false);
|
||||
|
||||
ACCENT_THEME_ONLY_NOMILK.put(com.vtosters.lite.R.attr.im_dropdown_icon_color, false);
|
||||
}
|
||||
|
||||
public static void setThemedColors(int accentColor) {
|
||||
cachedAccents = true;
|
||||
themedColors.clear();
|
||||
@@ -86,9 +125,20 @@ public class ThemesCore {
|
||||
public static boolean hasThemedAttr(Context context, int attrID) {
|
||||
try {
|
||||
Log.d(TAG, "Requesting color by attr " + context.getResources().getResourceName(attrID));
|
||||
} catch (Exception e) { }
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
return (themedColors.get(attrID) != 0);
|
||||
if (isCachedAccents()) {
|
||||
if (ThemesUtils.getCurrentTheme() == VKTheme.VKAPP_LIGHT && ThemesUtils.getCurrentTheme() == VKTheme.VKAPP_MILK_LIGHT) {
|
||||
return (themedColors.get(attrID) != 0
|
||||
&& ACCENT_THEME_ONLY_MILK_DARK.get(attrID, true)
|
||||
&& ACCENT_THEME_ONLY_NOMILK_LIGHT.get(attrID, true));
|
||||
} else {
|
||||
return (themedColors.get(attrID) != 0
|
||||
&& ACCENT_THEME_ONLY_MILK_LIGHT.get(attrID, true)
|
||||
&& ACCENT_THEME_ONLY_NOMILK_LIGHT.get(attrID, true));
|
||||
}
|
||||
} else return themedColors.get(attrID) != 0;
|
||||
}
|
||||
|
||||
public static boolean isCachedAccents() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.vtosters.lite.themes;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -8,6 +9,7 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.graphics.PorterDuff;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.core.widget.ImageViewCompat;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
@@ -14,6 +16,7 @@ public class ImageViewHook implements BaseHook {
|
||||
var imageView = (AppCompatImageView) view;
|
||||
if (imageView.getImageTintList() != null) {
|
||||
imageView.setImageTintList(ThemesUtils.themeCSL(imageView.getImageTintList()));
|
||||
imageView.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +24,7 @@ public class ImageViewHook implements BaseHook {
|
||||
var imageView = (ImageView) view;
|
||||
if (imageView.getImageTintList() != null) {
|
||||
imageView.setImageTintList(ThemesUtils.themeCSL(imageView.getImageTintList()));
|
||||
imageView.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package ru.vtosters.lite.themes.hooks;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.vk.imageloader.view.VKImageView;
|
||||
@@ -7,12 +14,18 @@ import com.vk.imageloader.view.VKImageView;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VKImageViewHook implements BaseHook {
|
||||
private static Paint paint = new Paint();
|
||||
static {
|
||||
paint.setColorFilter(new PorterDuffColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(View view, int i, boolean z) {
|
||||
if (view instanceof VKImageView) {
|
||||
var imageView = (VKImageView) view;
|
||||
if (imageView.getImageTintList() != null) {
|
||||
imageView.setImageTintList(ThemesUtils.themeCSL(imageView.getImageTintList()));
|
||||
imageView.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user