mirror of
https://github.com/revanced/revanced-patches
synced 2024-12-28 04:15:55 +01:00
refactor(YouTube - Theme): Use more robust gradient theme insert index
This commit is contained in:
parent
3e285e503d
commit
88709e1222
@ -21,6 +21,8 @@ public class ThemePatch {
|
||||
-98492127 // video chapters list background
|
||||
};
|
||||
|
||||
private static final boolean GRADIENT_LOADING_SCREEN_ENABLED = Settings.GRADIENT_LOADING_SCREEN.get();
|
||||
|
||||
// background colors
|
||||
private static int whiteColor = 0;
|
||||
private static int blackColor = 0;
|
||||
@ -39,25 +41,29 @@ public class ThemePatch {
|
||||
} else {
|
||||
if (anyEquals(originalValue, WHITE_VALUES)) return getWhiteColor();
|
||||
}
|
||||
|
||||
return originalValue;
|
||||
}
|
||||
|
||||
public static boolean gradientLoadingScreenEnabled() {
|
||||
return Settings.GRADIENT_LOADING_SCREEN.get();
|
||||
return GRADIENT_LOADING_SCREEN_ENABLED;
|
||||
}
|
||||
|
||||
private static int getBlackColor() {
|
||||
if (blackColor == 0) blackColor = Utils.getResourceColor("yt_black1");
|
||||
|
||||
return blackColor;
|
||||
}
|
||||
|
||||
private static int getWhiteColor() {
|
||||
if (whiteColor == 0) whiteColor = Utils.getResourceColor("yt_white1");
|
||||
|
||||
return whiteColor;
|
||||
}
|
||||
|
||||
private static boolean anyEquals(int value, int... of) {
|
||||
for (int v : of) if (value == v) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
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_CAPTIONS_BUTTON = new BooleanSetting("revanced_hide_captions_button", FALSE);
|
||||
public static final BooleanSetting HIDE_CHANNEL_BAR = new BooleanSetting("revanced_hide_channel_bar", FALSE);
|
||||
|
@ -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.settingsPatch
|
||||
import app.revanced.util.forEachChildElement
|
||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@ -210,18 +212,19 @@ val themePatch = bytecodePatch(
|
||||
)
|
||||
|
||||
useGradientLoadingScreenFingerprint.method.apply {
|
||||
|
||||
val isEnabledIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT) + 3
|
||||
val isEnabledRegister = getInstruction<OneRegisterInstruction>(isEnabledIndex - 1).registerA
|
||||
val literalIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT)
|
||||
val isEnabledIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT)
|
||||
val isEnabledRegister = getInstruction<OneRegisterInstruction>(isEnabledIndex).registerA
|
||||
|
||||
addInstructions(
|
||||
isEnabledIndex,
|
||||
isEnabledIndex + 1,
|
||||
"""
|
||||
invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->gradientLoadingScreenEnabled()Z
|
||||
move-result v$isEnabledRegister
|
||||
""",
|
||||
)
|
||||
}
|
||||
|
||||
mapOf(
|
||||
themeHelperLightColorFingerprint to lightThemeBackgroundColor,
|
||||
themeHelperDarkColorFingerprint to darkThemeBackgroundColor,
|
||||
|
Loading…
Reference in New Issue
Block a user