removed old ui hooks for recoloring and added some new

This commit is contained in:
Vologhat
2022-11-22 11:45:52 +03:00
parent e3b33a88c7
commit 752c59e2a2
28 changed files with 53 additions and 339 deletions
@@ -1,67 +1,17 @@
package ru.vtosters.lite.themes;
import android.content.res.ColorStateList;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import java.util.ArrayList;
import java.util.List;
import com.vk.core.view.TintTextView;
import ru.vtosters.lite.themes.models.ViewModel;
import ru.vtosters.lite.themes.modifiers.FloatingActionButtonRecolor;
import ru.vtosters.lite.themes.modifiers.IModifier;
import ru.vtosters.lite.themes.modifiers.ImageViewRecolor;
import ru.vtosters.lite.themes.modifiers.ProgressBarRecolor;
import ru.vtosters.lite.themes.modifiers.SwitchCompatRecolor;
import ru.vtosters.lite.themes.modifiers.TabLayoutRecolor;
import ru.vtosters.lite.themes.modifiers.TextViewRecolor;
import ru.vtosters.lite.themes.modifiers.TintTextViewRecolor;
import ru.vtosters.lite.themes.modifiers.ToolbarRecolor;
import ru.vtosters.lite.themes.modifiers.ViewRecolor;
import ru.vtosters.lite.utils.ThemesUtils;
public class Recolor {
private static final List<IModifier> recolors = new ArrayList<>();
static {
recolors.add(new FloatingActionButtonRecolor());
recolors.add(new ImageViewRecolor());
recolors.add(new ProgressBarRecolor());
recolors.add(new SwitchCompatRecolor());
recolors.add(new TabLayoutRecolor());
recolors.add(new TextViewRecolor());
recolors.add(new TintTextViewRecolor());
recolors.add(new ToolbarRecolor());
recolors.add(new ViewRecolor());
}
public static void recolorViewOrViewGroup(View target, SparseArray<ViewModel> satts) {
if (target instanceof ViewGroup) {
var viewGroup = (ViewGroup) target;
for (int i = 0; i < viewGroup.getChildCount(); i++)
recolorViewOrViewGroup(viewGroup.getChildAt(i), satts);
}
var viewModel = satts.get(target.getId(), null);
if (viewModel != null)
recolorView(target, viewModel);
}
private static void recolorView(View target, ViewModel viewModel) {
for (var recolor : recolors) {
if (!recolor.isModifiable(target)) continue;
for (var attr : viewModel.attrs) {
int aname = attr.first, avalue = attr.second;
recolor.modify(target, aname, getColor(avalue));
}
}
}
private static int getColor(int original) {
var color = VTLColors.getColor(original);
if (color != -1) return color;
@@ -81,4 +31,8 @@ public class Recolor {
public static void recolorTextToAccent(TextView iv) {
iv.setTextColor(VTLColors.getAccentColor());
}
public static void recolorTintTextViewToAccent(TintTextView ttv) {
ttv.setDrawableTint(VTLColors.getAccentColor());
}
}
@@ -1,29 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.content.res.ColorStateList;
import android.view.View;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.vtosters.lite.R;
public class FloatingActionButtonRecolor implements IModifier<View> {
public static final int tint = R.attr.tint;
public static final int androidTint = android.R.attr.tint;
@Override
public boolean isModifiable(View target) {
return target instanceof FloatingActionButton;
}
@Override
public void modify(View target, int attr, int color) {
var fab = (FloatingActionButton) target;
switch (attr) {
case tint:
case androidTint:
fab.setImageTintList(ColorStateList.valueOf(color));
break;
}
}
}
@@ -1,8 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
public interface IModifier<T> {
boolean isModifiable(T target);
void modify(T target, int attr, int color);
}
@@ -1,29 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.content.res.ColorStateList;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
public class ImageViewRecolor implements IModifier<View> {
public static final int tint = com.vtosters.lite.R.attr.tint;
public static final int androidTint = android.R.attr.tint;
@Override
public boolean isModifiable(View target) {
return target instanceof ImageView;
}
@Override
public void modify(View target, int attr, int color) {
var iv = (ImageView) target;
switch (attr) {
case tint:
case androidTint:
Log.d("ImageViewRecolor", "setColor");
iv.setImageTintList(ColorStateList.valueOf(color));
break;
}
}
}
@@ -1,33 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.content.res.ColorStateList;
import android.view.View;
import android.widget.ProgressBar;
public class ProgressBarRecolor implements IModifier<View> {
public static final int progressBackgroundTint = android.R.attr.progressBackgroundTint;
public static final int progressTint = android.R.attr.progressTint;
public static final int indeterminateTint = android.R.attr.indeterminateTint;
@Override
public boolean isModifiable(View target) {
return target instanceof ProgressBar;
}
@Override
public void modify(View target, int attr, int color) {
var pb = (ProgressBar) target;
switch (attr) {
case progressBackgroundTint:
pb.setProgressBackgroundTintList(ColorStateList.valueOf(color));
break;
case progressTint:
pb.setProgressTintList(ColorStateList.valueOf(color));
break;
case indeterminateTint:
pb.setIndeterminateTintList(ColorStateList.valueOf(color));
break;
}
}
}
@@ -1,31 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.content.res.ColorStateList;
import android.view.View;
import androidx.appcompat.widget.SwitchCompat;
import com.vtosters.lite.R;
public class SwitchCompatRecolor implements IModifier<View> {
public static final int thumbTint = R.attr.thumbTint;
public static final int trackTint = R.attr.trackTint;
@Override
public boolean isModifiable(View target) {
return target instanceof SwitchCompat;
}
@Override
public void modify(View target, int attr, int color) {
var sc = (SwitchCompat) target;
switch (attr) {
case thumbTint:
sc.setThumbTintList(ColorStateList.valueOf(color));
break;
case trackTint:
sc.setTrackTintList(ColorStateList.valueOf(color));
break;
}
}
}
@@ -1,26 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.view.View;
import com.google.android.material.tabs.TabLayout;
import com.vtosters.lite.R;
public class TabLayoutRecolor implements IModifier<View> {
public static final int tabIndicatorColor = R.attr.tabIndicatorColor;
@Override
public boolean isModifiable(View target) {
return target instanceof TabLayout;
}
@Override
public void modify(View target, int attr, int color) {
var tl = (TabLayout) target;
switch (attr) {
case tabIndicatorColor:
tl.setSelectedTabIndicatorColor(color);
break;
}
}
}
@@ -1,43 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;
import com.vk.core.drawable.RecoloredDrawable;
public class TextViewRecolor implements IModifier<View> {
public static final int textColor = android.R.attr.textColor;
public static final int textColorLink = android.R.attr.textColorLink;
public static final int textColorHint = android.R.attr.textColorHint;
@Override
public boolean isModifiable(View target) {
return target instanceof TextView;
}
@Override
public void modify(View target, int attr, int color) {
var tv = (TextView) target;
switch (attr) {
case textColor:
tv.setTextColor(color);
break;
case textColorLink:
tv.setLinkTextColor(color);
break;
case textColorHint:
tv.setHintTextColor(color);
break;
}
var drawables = tv.getCompoundDrawablesRelative();
for (int i = 0; i < drawables.length; i++) {
var drawable = drawables[i];
if (drawable != null)
drawables[i] = new RecoloredDrawable(drawable, Color.BLACK);
}
tv.invalidate();
}
}
@@ -1,26 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.view.View;
import com.vk.core.view.TintTextView;
import com.vtosters.lite.R;
public class TintTextViewRecolor implements IModifier<View> {
public static final int drawableTint = R.attr.drawableTint;
@Override
public boolean isModifiable(View target) {
return target instanceof TintTextView;
}
@Override
public void modify(View target, int attr, int color) {
var ttv = (TintTextView) target;
switch (attr) {
case drawableTint:
ttv.setDrawableTint(color);
break;
}
}
}
@@ -1,34 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.view.View;
import androidx.appcompat.widget.Toolbar;
import com.vtosters.lite.R;
public class ToolbarRecolor implements IModifier<View> {
public static final int subtitleTextColor = R.attr.subtitleTextColor;
public static final int titleTextColor = R.attr.titleTextColor;
public static final int textColorPrimary = android.R.attr.textColorPrimary;
public static final int background = android.R.attr.background;
@Override
public boolean isModifiable(View target) {
return target instanceof Toolbar;
}
@Override
public void modify(View target, int attr, int color) {
var t = (Toolbar) target;
switch (attr) {
case subtitleTextColor:
t.setSubtitleTextColor(color);
break;
case titleTextColor:
t.setTitleTextColor(color);
break;
case background:
t.setBackgroundColor(color);
}
}
}
@@ -1,27 +0,0 @@
package ru.vtosters.lite.themes.modifiers;
import android.content.res.ColorStateList;
import android.view.View;
public class ViewRecolor implements IModifier<View> {
public static final int backgroundTint = android.R.attr.backgroundTint;
public static final int background = android.R.attr.background;
@Override
public boolean isModifiable(View target) {
return true;
}
@Override
public void modify(View target, int attr, int color) {
switch (attr) {
case backgroundTint:
target.setBackgroundTintList(ColorStateList.valueOf(color));
break;
case background:
target.setBackgroundColor(color);
break;
}
}
}
@@ -67,6 +67,8 @@
check-cast p1, Lcom/vk/imageloader/view/VKImageView;
iput-object p1, p0, Lcom/vk/apps/AppsFragment$CarouselViewHolder$CarouselAppHolder;->c:Lcom/vk/imageloader/view/VKImageView;
.line 3
@@ -74,6 +74,8 @@
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
iput-object p1, p0, Lcom/vk/apps/AppsFragment$k;->c:Landroid/widget/TextView;
.line 4
@@ -67,7 +67,11 @@
move-result-object p1
check-cast p1, Landroid/widget/TextView;
check-cast p1, Lcom/vk/core/view/TintTextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTintTextViewToAccent(Lcom/vk/core/view/TintTextView;)V
iput-object p1, p0, Lcom/vk/articles/authorpage/holders/ArticleAuthorPageSortHolder;->c:Landroid/widget/TextView;
@@ -156,6 +156,8 @@
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
iput-object p1, p0, Lcom/vk/attachpicker/stickers/post/BaseStoryPostSticker;->g:Landroid/widget/TextView;
.line 6
@@ -58,6 +58,8 @@
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
iput-object p1, p0, Lcom/vk/identity/adapters/IdentityContextAdapter$AddIdentityHolder;->b:Landroid/widget/TextView;
const p1, 0x7f080329
@@ -70,6 +70,10 @@
move-result-object v0
check-cast v0, Landroid/widget/TextView;
invoke-static {v0}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
new-instance v1, Lcom/vk/music/attach/a/MusicAdapterHelper$a$a;
invoke-direct {v1, p0}, Lcom/vk/music/attach/a/MusicAdapterHelper$a$a;-><init>(Lcom/vk/music/attach/a/MusicAdapterHelper$a;)V
@@ -70,6 +70,10 @@
move-result-object v0
check-cast v0, Landroid/widget/TextView;
invoke-static {v0}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
new-instance v1, Lcom/vk/music/attach/a/PlaylistsController$c$a;
invoke-direct {v1, p0}, Lcom/vk/music/attach/a/PlaylistsController$c$a;-><init>(Lcom/vk/music/attach/a/PlaylistsController$c;)V
@@ -70,6 +70,10 @@
move-result-object v0
check-cast v0, Landroid/widget/TextView;
invoke-static {v0}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
new-instance v1, Lcom/vk/music/attach/a/PlaylistsSearchController$b$a;
invoke-direct {v1, p0}, Lcom/vk/music/attach/a/PlaylistsSearchController$b$a;-><init>(Lcom/vk/music/attach/a/PlaylistsSearchController$b;)V
@@ -154,7 +154,9 @@
move-result-object v2
check-cast v2, Landroid/widget/TextView;
check-cast v2, Lcom/vk/core/view/TintTextView;
invoke-static {v2}, Lru/vtosters/lite/themes/Recolor;->recolorTintTextViewToAccent(Lcom/vk/core/view/TintTextView;)V
.line 6
new-instance v3, Lcom/vk/navigation/right/RightMenu$initView$1;
@@ -172,6 +174,8 @@
check-cast v2, Landroid/widget/ImageView;
invoke-static {v2}, Lru/vtosters/lite/themes/Recolor;->recolorIconToAccent(Landroid/widget/ImageView;)V
.line 8
new-instance v3, Lcom/vk/navigation/right/RightMenu$initView$2;
@@ -89,6 +89,8 @@
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
iput-object p1, p0, Lcom/vk/newsfeed/holders/ActivityEventHolder;->H:Landroid/widget/TextView;
.line 5
@@ -323,6 +323,8 @@
check-cast p3, Landroid/widget/TextView;
invoke-static/range {p3 .. p3}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
.line 27
invoke-virtual {p3}, Landroid/widget/TextView;->getContext()Landroid/content/Context;
@@ -84,6 +84,8 @@
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
iput-object p1, p0, Lcom/vk/newsfeed/holders/attachments/EventHolder;->I:Landroid/widget/TextView;
.line 4
@@ -170,6 +170,8 @@
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
iput-object p1, p0, Lcom/vk/newsfeed/holders/c1/InlineCommentHolder;->K:Landroid/widget/TextView;
.line 8
@@ -86,6 +86,8 @@
check-cast p1, Lcom/vk/imageloader/view/VKImageView;
invoke-static {p1}, Lru/vtosters/lite/themes/Recolor;->recolorIconToAccent(Landroid/widget/ImageView;)V
iput-object p1, p0, Lcom/vk/profile/adapter/items/DetailsUserCategoryItem$a;->e:Lcom/vk/imageloader/view/VKImageView;
.line 5
@@ -404,6 +404,8 @@
check-cast v0, Landroid/widget/TextView;
invoke-static {v0}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
.line 39
new-instance v1, Lcom/vk/superapp/holders/SuperAppWidgetSportsHolder$e;
@@ -100,6 +100,8 @@
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
iput-object p1, p0, Lcom/vtosters/lite/fragments/gifts/ProfileGiftsFragment$f;->e:Landroid/widget/TextView;
const p1, 0x7f0a0e55
@@ -71,6 +71,10 @@
iput-object p1, p0, Lcom/vtosters/lite/ui/holder/gamepage/GameSectionTitle;->d:Landroid/view/View;
check-cast p1, Landroid/widget/TextView;
invoke-static/range {p1 .. p1}, Lru/vtosters/lite/themes/Recolor;->recolorTextToAccent(Landroid/widget/TextView;)V
return-void
.end method