diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/player/requests/ActionButtonRequest.kt b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/player/requests/ActionButtonRequest.kt index a10bd26d4..af38ab459 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/player/requests/ActionButtonRequest.kt +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/player/requests/ActionButtonRequest.kt @@ -147,7 +147,7 @@ class ActionButtonRequest private constructor( } catch (ex: IOException) { handleConnectionError("Network error", ex) } catch (ex: Exception) { - Logger.printException({ "sendApplicationRequest failed" }, ex) + Logger.printException({ "sendRequest failed" }, ex) } finally { Logger.printDebug { "video: " + videoId + " took: " + (System.currentTimeMillis() - startTime) + "ms" } } diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/utils/PatchStatus.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/utils/PatchStatus.java index 6c9ddcbfd..d5317e396 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/utils/PatchStatus.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/utils/PatchStatus.java @@ -1,5 +1,7 @@ package app.revanced.extension.youtube.patches.utils; +import app.revanced.extension.shared.utils.Utils; + public class PatchStatus { public static boolean ImageSearchButton() { @@ -7,6 +9,11 @@ public class PatchStatus { return false; } + public static boolean OldSplashAnimation() { + // Replace this with true if the Restore old splash animation (Custom branding icon) succeeds + return false; + } + public static boolean PlayerButtons() { // Replace this with true if the Hide player buttons patch succeeds return false; @@ -22,6 +29,12 @@ public class PatchStatus { return false; } + public static boolean SplashAnimation() { + // If 'Restore old splash animation' is included and device is running Android 12+, + // YouTube TV splash animations will be disabled by default. + return OldSplashAnimation() && Utils.isSDKAbove(31); + } + public static boolean SponsorBlock() { // Replace this with true if the SponsorBlock patch succeeds return false; diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java index be1315321..6ea0ffe24 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -147,7 +147,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting CHANGE_START_PAGE_TYPE = new BooleanSetting("revanced_change_start_page_type", FALSE, true, new ChangeStartPagePatch.ChangeStartPageTypeAvailability()); public static final BooleanSetting DISABLE_AUTO_AUDIO_TRACKS = new BooleanSetting("revanced_disable_auto_audio_tracks", FALSE); - public static final BooleanSetting DISABLE_SPLASH_ANIMATION = new BooleanSetting("revanced_disable_splash_animation", FALSE, true); + public static final BooleanSetting DISABLE_SPLASH_ANIMATION = new BooleanSetting("revanced_disable_splash_animation", PatchStatus.SplashAnimation(), true); public static final BooleanSetting DISABLE_TRANSLUCENT_STATUS_BAR = new BooleanSetting("revanced_disable_translucent_status_bar", TRUE, true); public static final BooleanSetting ENABLE_GRADIENT_LOADING_SCREEN = new BooleanSetting("revanced_enable_gradient_loading_screen", FALSE, true); public static final BooleanSetting HIDE_FLOATING_MICROPHONE = new BooleanSetting("revanced_hide_floating_microphone", TRUE, true); diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt index 797477de2..a4cedb451 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt @@ -4,12 +4,14 @@ import app.revanced.patcher.patch.booleanOption import app.revanced.patcher.patch.resourcePatch import app.revanced.patcher.patch.stringOption import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE +import app.revanced.patches.youtube.utils.extension.Constants.PATCH_STATUS_CLASS_DESCRIPTOR import app.revanced.patches.youtube.utils.patch.PatchList.CUSTOM_BRANDING_ICON_FOR_YOUTUBE import app.revanced.patches.youtube.utils.playservice.is_19_17_or_greater import app.revanced.patches.youtube.utils.playservice.is_19_32_or_greater import app.revanced.patches.youtube.utils.playservice.is_19_34_or_greater import app.revanced.patches.youtube.utils.playservice.versionCheckPatch import app.revanced.patches.youtube.utils.settings.ResourceUtils.updatePatchStatusIcon +import app.revanced.patches.youtube.utils.settings.getBytecodeContext import app.revanced.patches.youtube.utils.settings.settingsPatch import app.revanced.util.ResourceGroup import app.revanced.util.Utils.printWarn @@ -19,6 +21,7 @@ import app.revanced.util.copyFile import app.revanced.util.copyResources import app.revanced.util.getResourceGroup import app.revanced.util.underBarOrThrow +import app.revanced.util.updatePatchStatus import app.revanced.util.valueOrThrow import org.w3c.dom.Element @@ -247,11 +250,17 @@ val customBrandingIconPatch = resourcePatch( resourcesNode.appendChild(style) } } + + getBytecodeContext().apply { + updatePatchStatus(PATCH_STATUS_CLASS_DESCRIPTOR, "OldSplashAnimation") + } } updatePatchStatusIcon(appIcon) } + CUSTOM_BRANDING_ICON_FOR_YOUTUBE.included = true + // region fix app icon if (!is_19_34_or_greater) { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt index 23bdab4dd..9372f471f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/player/seekbar/SeekbarComponentsPatch.kt @@ -123,7 +123,7 @@ val seekbarComponentsPatch = bytecodePatch( execute { val restoreOldSplashAnimationIncluded = CUSTOM_BRANDING_ICON_FOR_YOUTUBE.included == true && - customBrandingIconPatch.getBooleanOptionValue("restoreOldSplashAnimationOption").value == true + customBrandingIconPatch.getBooleanOptionValue("restoreOldSplashAnimation").value == true var settingArray = arrayOf( "PREFERENCE_SCREEN: PLAYER", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt index eb7f1f294..198a22138 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/fix/splash/DarkModeSplashScreenPatch.kt @@ -1,8 +1,11 @@ package app.revanced.patches.youtube.utils.fix.splash import app.revanced.patcher.patch.resourcePatch +import app.revanced.patches.youtube.layout.branding.icon.customBrandingIconPatch +import app.revanced.patches.youtube.utils.patch.PatchList.CUSTOM_BRANDING_ICON_FOR_YOUTUBE import app.revanced.patches.youtube.utils.playservice.is_19_32_or_greater import app.revanced.patches.youtube.utils.playservice.versionCheckPatch +import app.revanced.util.getBooleanOptionValue import org.w3c.dom.Element val darkModeSplashScreenPatch = resourcePatch( @@ -10,10 +13,10 @@ val darkModeSplashScreenPatch = resourcePatch( ) { dependsOn(versionCheckPatch) - execute { - if (!is_19_32_or_greater) { - return@execute - } + finalize { + val restoreOldSplashAnimationIncluded = is_19_32_or_greater && + CUSTOM_BRANDING_ICON_FOR_YOUTUBE.included == true && + customBrandingIconPatch.getBooleanOptionValue("restoreOldSplashAnimation").value == true /** * Fix the splash screen dark mode background color. @@ -24,30 +27,57 @@ val darkModeSplashScreenPatch = resourcePatch( * This is a bug in unpatched YouTube. * Should always be applied even if the `Theme` patch is excluded. */ - document("res/values-night-v27/styles.xml").use { document -> - // Create a night mode specific override for the splash screen background. - val style = document.createElement("style") - style.setAttribute("name", "Theme.YouTube.Home") - style.setAttribute("parent", "@style/Base.V27.Theme.YouTube.Home") + if (restoreOldSplashAnimationIncluded) { + document("res/values-night/styles.xml").use { document -> + val resourcesNode = document.getElementsByTagName("resources").item(0) as Element + val childNodes = resourcesNode.childNodes - // Fix status and navigation bar showing white on some Android devices, - // such as SDK 28 Android 10 medium tablet. - val colorSplashBackgroundColor = "@color/yt_black1" - arrayOf( - "android:navigationBarColor" to colorSplashBackgroundColor, - "android:windowBackground" to colorSplashBackgroundColor, - "android:colorBackground" to colorSplashBackgroundColor, - "colorPrimaryDark" to colorSplashBackgroundColor, - "android:windowLightStatusBar" to "false", - ).forEach { (name, value) -> - val styleItem = document.createElement("item") - styleItem.setAttribute("name", name) - styleItem.textContent = value - style.appendChild(styleItem) + for (i in 0 until childNodes.length) { + val node = childNodes.item(i) as? Element ?: continue + val nodeAttributeName = node.getAttribute("name") + if (nodeAttributeName.startsWith("Theme.YouTube.Launcher")) { + val nodeAttributeParent = node.getAttribute("parent") + + val style = document.createElement("style") + style.setAttribute("name", "Theme.YouTube.Home") + style.setAttribute("parent", nodeAttributeParent) + + val windowItem = document.createElement("item") + windowItem.setAttribute("name", "android:windowBackground") + windowItem.textContent = "@color/yt_black1" + style.appendChild(windowItem) + + resourcesNode.removeChild(node) + resourcesNode.appendChild(style) + } + } } + } else { + document("res/values-night-v27/styles.xml").use { document -> + // Create a night mode specific override for the splash screen background. + val style = document.createElement("style") + style.setAttribute("name", "Theme.YouTube.Home") + style.setAttribute("parent", "@style/Base.V27.Theme.YouTube.Home") - val resourcesNode = document.getElementsByTagName("resources").item(0) as Element - resourcesNode.appendChild(style) + // Fix status and navigation bar showing white on some Android devices, + // such as SDK 28 Android 10 medium tablet. + val colorSplashBackgroundColor = "@color/yt_black1" + arrayOf( + "android:navigationBarColor" to colorSplashBackgroundColor, + "android:windowBackground" to colorSplashBackgroundColor, + "android:colorBackground" to colorSplashBackgroundColor, + "colorPrimaryDark" to colorSplashBackgroundColor, + "android:windowLightStatusBar" to "false", + ).forEach { (name, value) -> + val styleItem = document.createElement("item") + styleItem.setAttribute("name", name) + styleItem.textContent = value + style.appendChild(styleItem) + } + + val resourcesNode = document.getElementsByTagName("resources").item(0) as Element + resourcesNode.appendChild(style) + } } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt index 032dbc5b6..d3fe3da10 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/settings/SettingsPatch.kt @@ -1,6 +1,7 @@ package app.revanced.patches.youtube.utils.settings import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.resourcePatch import app.revanced.patcher.patch.stringOption @@ -39,6 +40,10 @@ private const val EXTENSION_INITIALIZATION_CLASS_DESCRIPTOR = private const val EXTENSION_THEME_METHOD_DESCRIPTOR = "$EXTENSION_UTILS_PATH/BaseThemeUtils;->setTheme(Ljava/lang/Enum;)V" +private lateinit var bytecodeContext: BytecodePatchContext + +internal fun getBytecodeContext() = bytecodeContext + private val settingsBytecodePatch = bytecodePatch( description = "settingsBytecodePatch" ) { @@ -50,6 +55,7 @@ private val settingsBytecodePatch = bytecodePatch( ) execute { + bytecodeContext = this // apply the current theme of the settings page themeSetterSystemFingerprint.methodOrThrow().apply {