refactor(YouTube - Add more double tap to seek length options): Use more idiomatic code

This commit is contained in:
oSumAtrIX 2026-03-07 23:39:50 +01:00
parent 3c46a2d2e8
commit f10f5e2910
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4

View file

@ -28,12 +28,7 @@ val addMoreDoubleTapToSeekLengthOptionsPatch = resourcePatch(
execute { execute {
// Values are hard coded to keep patching simple. // Values are hard coded to keep patching simple.
val doubleTapLengthOptionsString = "3, 5, 10, 15, 20, 30, 60, 120, 180, 240" val doubleTapLengths = listOf(3, 5, 10, 15, 20, 30, 60, 120, 180, 240)
val doubleTapLengths = doubleTapLengthOptionsString
.replace(" ", "")
.split(",")
if (doubleTapLengths.isEmpty()) throw PatchException("Invalid double-tap length elements")
document("res/values/arrays.xml").use { document -> document("res/values/arrays.xml").use { document ->
fun Element.removeAllChildren() { fun Element.removeAllChildren() {
@ -56,10 +51,9 @@ val addMoreDoubleTapToSeekLengthOptionsPatch = resourcePatch(
entries.removeAllChildren() entries.removeAllChildren()
doubleTapLengths.forEach { length -> doubleTapLengths.forEach { length ->
val item = document.createElement("item") document.createElement("item").apply { textContent = length.toString() }
item.textContent = length .also(entries::appendChild)
entries.appendChild(item) .cloneNode(true).let(values::appendChild)
values.appendChild(item.cloneNode(true))
} }
} }
} }