chore: lint code

This commit is contained in:
inotia00
2024-06-27 23:32:11 +09:00
parent 8b1f2e8aaf
commit 2683e6bdde

View File

@ -95,16 +95,15 @@ object OverlayButtonsPatch : BaseResourcePatch(
}
// Copy necessary resources for the overlay buttons.
arrayOf(
context.copyResources(
"youtube/overlaybuttons/shared",
ResourceGroup(
"drawable",
"playlist_repeat_button.xml",
"playlist_shuffle_button.xml",
"revanced_repeat_icon.xml"
)
).forEach { resourceGroup ->
context.copyResources("youtube/overlaybuttons/shared", resourceGroup)
}
)
// Apply the selected icon type to the overlay buttons.
arrayOf(
@ -153,8 +152,9 @@ object OverlayButtonsPatch : BaseResourcePatch(
// Modify the layout of fullscreen button for newer YouTube versions (19.09.xx+)
arrayOf(
"youtube_controls_bottom_ui_container.xml",
"youtube_controls_fullscreen_button.xml",
"youtube_controls_cf_fullscreen_button.xml",
"youtube_controls_fullscreen_button.xml"
).forEach { xmlFile ->
val targetXml = context["res"].resolve("layout").resolve(xmlFile)
if (targetXml.exists()) {
@ -162,79 +162,49 @@ object OverlayButtonsPatch : BaseResourcePatch(
editor.file.doRecursively loop@{ node ->
if (node !is Element) return@loop
if (node.getAttribute("android:id").endsWith("_button")) {
// Change the relationship between buttons
node.getAttributeNode("yt:layout_constraintRight_toLeftOf")
?.let { attribute ->
if (attribute.textContent == "@id/fullscreen_button") {
attribute.textContent = "@+id/speed_dialog_button"
}
}
val (id, height, width) = Triple(
node.getAttribute("android:id"),
node.getAttribute("android:layout_height"),
node.getAttribute("android:layout_width")
)
val (heightIsNotZero, widthIsNotZero, isButton) = Triple(
height != "0.0dip",
width != "0.0dip",
id.endsWith("_button") || id == "@id/youtube_controls_fullscreen_button_stub"
)
// Adjust TimeBar and Chapter bottom padding
val timBarItem = mutableMapOf(
"@id/time_bar_chapter_title" to "16.0dip",
"@id/timestamps_container" to "14.0dip"
)
if (isButton) {
node.setAttribute("android:layout_marginBottom", marginBottom)
node.setAttribute("android:paddingLeft", "0.0dip")
node.setAttribute("android:paddingRight", "0.0dip")
node.setAttribute("android:paddingBottom", "22.0dip")
if (!node.getAttribute("android:layout_height").equals("0.0dip") &&
!node.getAttribute("android:layout_width").equals("0.0dip")
) {
if (heightIsNotZero && widthIsNotZero) {
node.setAttribute("android:layout_height", "48.0dip")
node.setAttribute("android:layout_width", "48.0dip")
}
} else if (timBarItem.containsKey(id)) {
node.setAttribute("android:layout_marginBottom", marginBottom)
node.setAttribute("android:paddingBottom", timBarItem.getValue(id))
}
}
}
}
}
context.xmlEditor["res/layout/youtube_controls_bottom_ui_container.xml"].use { editor ->
editor.file.doRecursively loop@{ node ->
if (node !is Element) return@loop
// Change the relationship between buttons
node.getAttributeNode("yt:layout_constraintRight_toLeftOf")
?.let { attribute ->
if (attribute.textContent == "@id/fullscreen_button") {
attribute.textContent = "@+id/speed_dialog_button"
}
}
// Adjust TimeBar and Chapter bottom padding
arrayOf(
"@id/time_bar_chapter_title" to "16.0dip",
"@id/timestamps_container" to "14.0dip"
).forEach { (id, replace) ->
node.getAttributeNode("android:id")?.let { attribute ->
if (attribute.textContent == id) {
node.getAttributeNode("android:paddingBottom").textContent =
replace
}
}
}
// Adjust layout for fullscreen button stub
if (node.getAttribute("android:id") == "@id/youtube_controls_fullscreen_button_stub") {
node.setAttribute("android:layout_marginBottom", marginBottom)
if (!node.getAttribute("android:layout_height").equals("0.0dip") &&
!node.getAttribute("android:layout_width").equals("0.0dip")
) {
node.setAttribute("android:layout_height", "48.0dip")
node.setAttribute("android:layout_width", "48.0dip")
}
}
// Adjust margin and padding for other buttons
if (node.getAttribute("android:id").endsWith("_button")) {
node.setAttribute("android:layout_marginBottom", marginBottom)
node.setAttribute("android:paddingLeft", "0.0dip")
node.setAttribute("android:paddingRight", "0.0dip")
node.setAttribute("android:paddingBottom", "22.0dip")
if (!node.getAttribute("android:layout_height").equals("0.0dip") &&
!node.getAttribute("android:layout_width").equals("0.0dip")
) {
node.setAttribute("android:layout_height", "48.0dip")
node.setAttribute("android:layout_width", "48.0dip")
}
} else if (node.getAttribute("android:id") == "@id/time_bar_chapter_title_container" ||
node.getAttribute("android:id") == "@id/timestamps_container"
) {
node.setAttribute("android:layout_marginBottom", marginBottom)
}
}
}
/**
* Add settings for the overlay buttons.
*/