Skip to content

Commit

Permalink
chore(YouTube - Custom branding icon): Add a warning when the splash …
Browse files Browse the repository at this point in the history
…animation is unavailable for the selected icon

Closes #919
  • Loading branch information
anddea committed Dec 28, 2024
1 parent cd6e03c commit 93a442b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.patches.youtube.utils.settings.ResourceUtils.updatePatchStatusIcon
import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.ResourceGroup
import app.revanced.util.Utils.printWarn
import app.revanced.util.Utils.trimIndentMultiline
import app.revanced.util.copyAdaptiveIcon
import app.revanced.util.copyFile
Expand Down Expand Up @@ -217,41 +218,46 @@ val customBrandingIconPatch = resourcePatch(
}
}

val styleMap = mutableMapOf<String, String>()
styleMap["Base.Theme.YouTube.Launcher"] =
"@style/Theme.AppCompat.DayNight.NoActionBar"
val avdAnimPath = get("res").resolve("drawable").resolve("avd_anim.xml")
if (avdAnimPath.exists()) {
val styleMap = mutableMapOf<String, String>()
styleMap["Base.Theme.YouTube.Launcher"] =
"@style/Theme.AppCompat.DayNight.NoActionBar"

if (is_19_32_or_greater) {
styleMap["Theme.YouTube.Home"] = "@style/Base.V27.Theme.YouTube.Home"
}
if (is_19_32_or_greater) {
styleMap["Theme.YouTube.Home"] = "@style/Base.V27.Theme.YouTube.Home"
}

styleMap.forEach { (nodeAttributeName, nodeAttributeParent) ->
document("res/values-v31/styles.xml").use { document ->
val resourcesNode =
document.getElementsByTagName("resources").item(0) as Element

val style = document.createElement("style")
style.setAttribute("name", nodeAttributeName)
style.setAttribute("parent", nodeAttributeParent)

val primaryItem = document.createElement("item")
primaryItem.setAttribute("name", "android:windowSplashScreenAnimatedIcon")
primaryItem.textContent = "@drawable/avd_anim"
val secondaryItem = document.createElement("item")
secondaryItem.setAttribute(
"name",
"android:windowSplashScreenAnimationDuration"
)
secondaryItem.textContent = if (appIcon.startsWith("revancify"))
"1500"
else
"1000"

style.appendChild(primaryItem)
style.appendChild(secondaryItem)

styleMap.forEach { (nodeAttributeName, nodeAttributeParent) ->
document("res/values-v31/styles.xml").use { document ->
val resourcesNode =
document.getElementsByTagName("resources").item(0) as Element

val style = document.createElement("style")
style.setAttribute("name", nodeAttributeName)
style.setAttribute("parent", nodeAttributeParent)

val primaryItem = document.createElement("item")
primaryItem.setAttribute("name", "android:windowSplashScreenAnimatedIcon")
primaryItem.textContent = "@drawable/avd_anim"
val secondaryItem = document.createElement("item")
secondaryItem.setAttribute(
"name",
"android:windowSplashScreenAnimationDuration"
)
secondaryItem.textContent = if (appIcon.startsWith("revancify"))
"1500"
else
"1000"

style.appendChild(primaryItem)
style.appendChild(secondaryItem)

resourcesNode.appendChild(style)
resourcesNode.appendChild(style)
}
}
} else {
printWarn("Splash animation is not available for \"$appIcon\".")
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 93a442b

Please sign in to comment.