diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java new file mode 100644 index 000000000..b9c2c53c9 --- /dev/null +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesCore.java @@ -0,0 +1,94 @@ +package ru.vtosters.lite.themes; + +import android.content.Context; +import android.util.Log; + +import androidx.annotation.IdRes; + +import java.util.HashMap; + +import ru.vtosters.lite.utils.Themes; + +public class ThemesCore { + // log tag + private static final String TAG = "ThemesCore"; + + public static HashMap themedColors = new HashMap<>(); + + private static boolean cachedAccents = false; + + private static int wallDarkColor; + private static int wallLightColor; + + public static void setThemedColors(int accentColor) { + cachedAccents = true; + themedColors.clear(); + + themedColors.put(com.vtosters.lite.R.attr.text_link, accentColor); + themedColors.put(com.vtosters.lite.R.attr.accent, accentColor); + themedColors.put(com.vtosters.lite.R.attr.newsfeed_dropdown_color, accentColor); + + themedColors.put(com.vtosters.lite.R.attr.vk_accent, accentColor); + themedColors.put(com.vtosters.lite.R.attr.accentColor, accentColor); + themedColors.put(com.vtosters.lite.R.attr.text_name, accentColor); + themedColors.put(com.vtosters.lite.R.attr.tabbar_active_icon, accentColor); + themedColors.put(com.vtosters.lite.R.attr.header_background, accentColor); + themedColors.put(com.vtosters.lite.R.attr.header_tint, accentColor); + themedColors.put(com.vtosters.lite.R.attr.header_tint_alternate, accentColor); + themedColors.put(com.vtosters.lite.R.attr.activity_indicator_tint, accentColor); + themedColors.put(com.vtosters.lite.R.attr.toolbarIconsColor, accentColor); + + themedColors.put(com.vtosters.lite.R.attr.button_primary_background, accentColor); + themedColors.put(com.vtosters.lite.R.attr.button_secondary_foreground, accentColor); + themedColors.put(com.vtosters.lite.R.attr.button_tertiary_foreground, accentColor); + themedColors.put(com.vtosters.lite.R.attr.button_outline_border, accentColor); + themedColors.put(com.vtosters.lite.R.attr.button_muted_foreground, accentColor); + themedColors.put(com.vtosters.lite.R.attr.header_tab_active_indicator, accentColor); + + themedColors.put(com.vtosters.lite.R.attr.im_dropdown_icon_color, accentColor); + themedColors.put(com.vtosters.lite.R.attr.im_dropdown_arrow_tint, accentColor); + + themedColors.put(com.vtosters.lite.R.attr.im_attach_tint, accentColor); + themedColors.put(com.vtosters.lite.R.attr.im_forward_line_tint, accentColor); + themedColors.put(com.vtosters.lite.R.attr.link_alternate, accentColor); + themedColors.put(com.vtosters.lite.R.attr.newsfeed_post_title_color, accentColor); + + themedColors.put(com.vtosters.lite.R.attr.attach_picker_tab_active_background, accentColor); + themedColors.put(com.vtosters.lite.R.attr.attach_picker_tab_active_text, accentColor); + themedColors.put(com.vtosters.lite.R.attr.newsfeed_action_color, accentColor); + themedColors.put(com.vtosters.lite.R.attr.counter_primary_background, accentColor); + + themedColors.put(com.vtosters.lite.R.attr.action_sheet_action_foreground, accentColor); + + // messages + wallDarkColor = Themes.darken(accentColor, 0.25f); + wallLightColor = Themes.lighten(accentColor, 0.25f); + + //themedColors.put(com.vtosters.lite.R.attr.im_ic_send_msg, accentColor); + themedColors.put(com.vtosters.lite.R.attr.im_bubble_wallpaper_outgoing, accentColor); + themedColors.put(com.vtosters.lite.R.attr.im_bubble_outgoing, accentColor); + themedColors.put(com.vtosters.lite.R.attr.im_bubble_outgoing_highlighted, accentColor); + } + + @SuppressWarnings("ConstantConditions") + public static int getThemedAttr(Context context, @IdRes int attr) { + if (attr == com.vtosters.lite.R.attr.im_bubble_wallpaper_outgoing || attr == com.vtosters.lite.R.attr.im_bubble_outgoing) { + return (!Themes.isDarkTheme()) ? wallLightColor : wallDarkColor; + } + + if (attr == com.vtosters.lite.R.attr.im_bubble_outgoing_highlighted) { + return (!Themes.isDarkTheme()) ? Themes.lighten(wallLightColor, 0.2f) : Themes.darken(wallDarkColor, 0.2f); + } + + return themedColors.get(attr); + } + + public static boolean hasThemedAttr(Context context, int attrID) { + Log.d(TAG, "Requesting color by attr " + context.getResources().getResourceName(attrID)); + return (themedColors.get(attrID) != null); + } + + public static boolean isCachedAccents() { + return cachedAccents; + } +} 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 3bef4e483..c976f9e5d 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 @@ -27,6 +27,11 @@ public class TextViewHook implements BaseHook { textView.setTextColor(Themes.getAccentColor()); } + if (textView.getLinkTextColors() != null && Themes.isAccentedColor(textView.getLinkTextColors())) { + textView.setLinkTextColor(Themes.getAccentColor()); + } + + if (isPositiveButton(textView) || isVkUiButton(textView)) { view.setBackgroundTintList(ColorStateList.valueOf(Themes.getAccentColor())); } @@ -55,7 +60,7 @@ public class TextViewHook implements BaseHook { } public static boolean eligibleForTinting(int id) { - return !Themes.isDarkTheme() && id == com.vtosters.lite.R.id.attach_title; + return !Themes.isDarkTheme() && (id == com.vtosters.lite.R.id.attach_title); } public static boolean isPositiveButton(View view) { diff --git a/app/src/main/java/ru/vtosters/lite/utils/Globals.java b/app/src/main/java/ru/vtosters/lite/utils/Globals.java index 44546506b..47dd11a03 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Globals.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Globals.java @@ -66,6 +66,7 @@ import java.util.List; import java.util.Locale; import ru.vtosters.lite.downloaders.notifications.NotificationChannels; +import ru.vtosters.lite.themes.ThemesCore; import ru.vtosters.lite.ui.dialogs.DisableBattery; import ru.vtosters.lite.ui.dialogs.InstallGMS; import ru.vtosters.lite.ui.dialogs.OTADialog; @@ -95,6 +96,7 @@ public class Globals{ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannels.createChannels(); } + ThemesCore.setThemedColors(Themes.getAccentColor()); // VKIDProtection.alert(activity); } diff --git a/app/src/main/java/ru/vtosters/lite/utils/Themes.java b/app/src/main/java/ru/vtosters/lite/utils/Themes.java index 39034a41c..85a0da2c9 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Themes.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Themes.java @@ -48,7 +48,7 @@ import java.util.List; public class Themes{ public static List accentColors = Arrays.asList( "3f8ae0", - "5692d7", "528bcc", "7aa0cc", "518bcc", "6296d0", "2f68aa", "638ebf", "5181b8", "71aaeb", "4774a8", "5baaf4", "4186c8", "add3ff", "4774a8", "718198", "5a9eff", "99a2ad", "74a2d6", "e9eef3", "dfe3e7", "eff1f3", "5c9ce6", "4986cc", "4680c2" + "5692d7", "528bcc", "7aa0cc", "518bcc", "6296d0", "2f68aa", "638ebf", "5181b8", "71aaeb", "4774a8", "5baaf4", "4186c8", "add3ff", "718198", "5a9eff", "99a2ad", "74a2d6", "e9eef3", "dfe3e7", "eff1f3", "5c9ce6", "4986cc", "4680c2" ); public static void applyTheme(VKTheme theme){ diff --git a/smali/smali_classes2/com/vk/core/util/ContextExtKt.smali b/smali/smali_classes2/com/vk/core/util/ContextExtKt.smali index f536180e8..bf655baf4 100644 --- a/smali/smali_classes2/com/vk/core/util/ContextExtKt.smali +++ b/smali/smali_classes2/com/vk/core/util/ContextExtKt.smali @@ -920,6 +920,20 @@ .end annotation .end param + invoke-static {p0, p1}, Lru/vtosters/lite/themes/ThemesCore;->hasThemedAttr(Landroid/content/Context;I)Z + + move-result v1 + + if-eqz v1, :cond_b + + invoke-static {p0, p1}, Lru/vtosters/lite/themes/ThemesCore;->getThemedAttr(Landroid/content/Context;I)I + + move-result v1 + + return v1 + + :cond_b + .line 1 invoke-virtual {p0}, Landroid/content/Context;->getTheme()Landroid/content/res/Resources$Theme;