Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Исправление покрасок на Android 5.1 и улучшения/ускорение работы пересборки arsc #1566

Merged
merged 7 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ru/vtosters/hooks/DockBarInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()));
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/ru/vtosters/hooks/other/ThemesUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,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);
}

public static boolean isAmoledTheme() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
);
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/ru/vtosters/lite/themes/ThemesHacks.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,30 @@ 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 Build.VERSION.SDK_INT > 23 ? context.getColor(color) : context.getResources().getColor(color);
return getColors(context, color);
}

public static int getColors(Context context, int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return context.getColor(color);
} else {
return context.getResources().getColor(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);
Expand Down
106 changes: 60 additions & 46 deletions app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -123,7 +126,7 @@ public static void init(Application app) {
ResourcesLoader.load(app, modApk.getAbsolutePath(), false);
}
} catch (Exception e) {
e.printStackTrace();
//
}
}

Expand Down Expand Up @@ -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<? extends ZipEntry> 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() {
Expand Down
Loading
Loading