fix(YouTube - Overlay Buttons): When the patch option Bottom margin is 0, all player bottom buttons are hidden https://github.com/inotia00/ReVanced_Extended/issues/2720

This commit is contained in:
inotia00
2025-01-22 13:15:50 +09:00
parent f6f478ccca
commit 5dd79073f1

View File

@ -21,6 +21,7 @@ import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.patches.youtube.video.information.videoEndMethod
import app.revanced.patches.youtube.video.information.videoInformationPatch
import app.revanced.util.ResourceGroup
import app.revanced.util.Utils.printWarn
import app.revanced.util.copyResources
import app.revanced.util.copyXmlNode
import app.revanced.util.doRecursively
@ -55,7 +56,7 @@ private val overlayButtonsBytecodePatch = bytecodePatch(
}
}
private const val MARGIN_NONE = "0.0dip"
private const val MARGIN_MINIMUM = "0.1dip"
private const val MARGIN_DEFAULT = "2.5dip"
private const val MARGIN_WIDER = "5.0dip"
@ -95,7 +96,7 @@ val overlayButtonsPatch = resourcePatch(
default = MARGIN_DEFAULT,
values = mapOf(
"Default" to MARGIN_DEFAULT,
"None" to MARGIN_NONE,
"Minimum" to MARGIN_MINIMUM,
"Wider" to MARGIN_WIDER,
),
title = "Bottom margin",
@ -125,9 +126,20 @@ val overlayButtonsPatch = resourcePatch(
val iconType = iconTypeOption
.lowerCaseOrThrow()
val marginBottom = bottomMarginOption
var marginBottom = bottomMarginOption
.lowerCaseOrThrow()
try {
val marginBottomFloat = marginBottom.split("dip")[0].toFloat()
if (marginBottomFloat <= 0f) {
printWarn("Patch option \"Bottom margin\" must be greater than 0, fallback to minimum.")
marginBottom = MARGIN_MINIMUM
}
} catch (e: NumberFormatException) {
printWarn("Patch option \"Bottom margin\" failed validation, fallback to default.")
marginBottom = MARGIN_DEFAULT
}
val useWiderButtonsSpace = widerButtonsSpace == true
// Inject hooks for overlay buttons.