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 {
// Values are hard coded to keep patching simple.
val doubleTapLengthOptionsString = "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")
val doubleTapLengths = listOf(3, 5, 10, 15, 20, 30, 60, 120, 180, 240)
document("res/values/arrays.xml").use { document ->
fun Element.removeAllChildren() {
@ -56,10 +51,9 @@ val addMoreDoubleTapToSeekLengthOptionsPatch = resourcePatch(
entries.removeAllChildren()
doubleTapLengths.forEach { length ->
val item = document.createElement("item")
item.textContent = length
entries.appendChild(item)
values.appendChild(item.cloneNode(true))
document.createElement("item").apply { textContent = length.toString() }
.also(entries::appendChild)
.cloneNode(true).let(values::appendChild)
}
}
}