Skip to content

Commit

Permalink
feat(twitter): Add selectable text patch
Browse files Browse the repository at this point in the history
  • Loading branch information
crimera committed Feb 8, 2024
1 parent edc35df commit ee3bcf1
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package crimera.patches.twitter.selectabletext

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotation.Patch
import org.w3c.dom.Element

@Patch(
name = "SelectableTextPatch",
description = "Makes bio and username selectable",
)
@Suppress("unused")
object SelectableTextPatch: ResourcePatch() {
override fun execute(context: ResourceContext) {
val profileDetailsXml = context["res/layout/profile_details.xml"]
if (!profileDetailsXml.exists()) throw PatchException("profile_details.xml not found")

val ids = listOf(
"user_name",
"user_bio",
).map { "@id/$it" }

context.xmlEditor["res/layout/profile_details.xml"].use { editor ->
val texts = editor.file.getElementsByTagName("com.twitter.ui.components.text.legacy.TypefacesTextView")
for (i in 0 until texts.length) {
val text = texts.item(i) as Element
val id = text.getAttribute("android:id")

if (ids.contains(id)) {
text.setAttribute("android:textIsSelectable", "true")
}
}
}
}
}

0 comments on commit ee3bcf1

Please sign in to comment.