refactor(YouTube - Theme): Use more robust gradient theme insert index

This commit is contained in:
LisoUseInAIKyrios 2024-11-07 08:20:39 -04:00
parent 3e285e503d
commit 88709e1222
3 changed files with 15 additions and 6 deletions

View File

@ -21,6 +21,8 @@ public class ThemePatch {
-98492127 // video chapters list background -98492127 // video chapters list background
}; };
private static final boolean GRADIENT_LOADING_SCREEN_ENABLED = Settings.GRADIENT_LOADING_SCREEN.get();
// background colors // background colors
private static int whiteColor = 0; private static int whiteColor = 0;
private static int blackColor = 0; private static int blackColor = 0;
@ -39,25 +41,29 @@ public class ThemePatch {
} else { } else {
if (anyEquals(originalValue, WHITE_VALUES)) return getWhiteColor(); if (anyEquals(originalValue, WHITE_VALUES)) return getWhiteColor();
} }
return originalValue; return originalValue;
} }
public static boolean gradientLoadingScreenEnabled() { public static boolean gradientLoadingScreenEnabled() {
return Settings.GRADIENT_LOADING_SCREEN.get(); return GRADIENT_LOADING_SCREEN_ENABLED;
} }
private static int getBlackColor() { private static int getBlackColor() {
if (blackColor == 0) blackColor = Utils.getResourceColor("yt_black1"); if (blackColor == 0) blackColor = Utils.getResourceColor("yt_black1");
return blackColor; return blackColor;
} }
private static int getWhiteColor() { private static int getWhiteColor() {
if (whiteColor == 0) whiteColor = Utils.getResourceColor("yt_white1"); if (whiteColor == 0) whiteColor = Utils.getResourceColor("yt_white1");
return whiteColor; return whiteColor;
} }
private static boolean anyEquals(int value, int... of) { private static boolean anyEquals(int value, int... of) {
for (int v : of) if (value == v) return true; for (int v : of) if (value == v) return true;
return false; return false;
} }
} }

View File

@ -80,7 +80,7 @@ public class Settings extends BaseSettings {
// Uncategorized layout related settings. Do not add to this section, and instead move these out and categorize them. // Uncategorized layout related settings. Do not add to this section, and instead move these out and categorize them.
public static final BooleanSetting DISABLE_SUGGESTED_VIDEO_END_SCREEN = new BooleanSetting("revanced_disable_suggested_video_end_screen", FALSE, true); public static final BooleanSetting DISABLE_SUGGESTED_VIDEO_END_SCREEN = new BooleanSetting("revanced_disable_suggested_video_end_screen", FALSE, true);
public static final BooleanSetting GRADIENT_LOADING_SCREEN = new BooleanSetting("revanced_gradient_loading_screen", FALSE); public static final BooleanSetting GRADIENT_LOADING_SCREEN = new BooleanSetting("revanced_gradient_loading_screen", FALSE, true);
public static final BooleanSetting HIDE_HORIZONTAL_SHELVES = new BooleanSetting("revanced_hide_horizontal_shelves", TRUE); public static final BooleanSetting HIDE_HORIZONTAL_SHELVES = new BooleanSetting("revanced_hide_horizontal_shelves", TRUE);
public static final BooleanSetting HIDE_CAPTIONS_BUTTON = new BooleanSetting("revanced_hide_captions_button", FALSE); public static final BooleanSetting HIDE_CAPTIONS_BUTTON = new BooleanSetting("revanced_hide_captions_button", FALSE);
public static final BooleanSetting HIDE_CHANNEL_BAR = new BooleanSetting("revanced_hide_channel_bar", FALSE); public static final BooleanSetting HIDE_CHANNEL_BAR = new BooleanSetting("revanced_hide_channel_bar", FALSE);

View File

@ -17,7 +17,9 @@ import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.forEachChildElement import app.revanced.util.forEachChildElement
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import org.w3c.dom.Element import org.w3c.dom.Element
@ -210,18 +212,19 @@ val themePatch = bytecodePatch(
) )
useGradientLoadingScreenFingerprint.method.apply { useGradientLoadingScreenFingerprint.method.apply {
val literalIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT)
val isEnabledIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT) + 3 val isEnabledIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT)
val isEnabledRegister = getInstruction<OneRegisterInstruction>(isEnabledIndex - 1).registerA val isEnabledRegister = getInstruction<OneRegisterInstruction>(isEnabledIndex).registerA
addInstructions( addInstructions(
isEnabledIndex, isEnabledIndex + 1,
""" """
invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->gradientLoadingScreenEnabled()Z invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->gradientLoadingScreenEnabled()Z
move-result v$isEnabledRegister move-result v$isEnabledRegister
""", """,
) )
} }
mapOf( mapOf(
themeHelperLightColorFingerprint to lightThemeBackgroundColor, themeHelperLightColorFingerprint to lightThemeBackgroundColor,
themeHelperDarkColorFingerprint to darkThemeBackgroundColor, themeHelperDarkColorFingerprint to darkThemeBackgroundColor,