Skip to content

Commit f4b579f

Browse files
authored
Merge pull request #460 from crimera/dev
chore: Merge branch `dev` to `main`
2 parents 047238a + 368dbf8 commit f4b579f

File tree

16 files changed

+288
-88
lines changed

16 files changed

+288
-88
lines changed

.releaserc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{ "type": "feat", "release": "minor" },
1414
{ "type": "update", "release": "patch" },
1515
{ "type": "refactor", "release": "patch" },
16+
{ "type": "perf", "release": "patch" },
1617
{ "type": "build", "scope": "Needs bump", "release": "patch" }
1718
]
1819
}
@@ -27,6 +28,7 @@
2728
{ type: "feat", section: "Features", hidden: false },
2829
{ type: "update", section: "Updates", hidden: false },
2930
{ type: "refactor", section: "Refactors", hidden: false },
31+
{ type: "perf", section: "Perfomance", hidden: false },
3032
]
3133
}
3234
}

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
## [1.45.0-dev.1](https://github.com/crimera/piko/compare/v1.44.1-dev.2...v1.45.0-dev.1) (2024-11-12)
2+
3+
### Features
4+
5+
* **Twitter:** Added `Customise post font size` patch ([ea608e0](https://github.com/crimera/piko/commit/ea608e09b7b0775f38ca1914503e1b54dc7b73f9))
6+
7+
## [1.44.1-dev.2](https://github.com/crimera/piko/compare/v1.44.1-dev.1...v1.44.1-dev.2) (2024-11-11)
8+
9+
### Perfomance
10+
11+
* **Bring back twitter:** Optimize string replacement ([#440](https://github.com/crimera/piko/issues/440)) ([7e61023](https://github.com/crimera/piko/commit/7e6102351d9488f89489f87df2ec45d6d0d178d8))
12+
13+
## [1.44.1-dev.1](https://github.com/crimera/piko/compare/v1.44.0...v1.44.1-dev.1) (2024-11-09)
14+
15+
### Bug Fixes
16+
17+
* **Twitter:** Share menu button add hook in/from 10.67 ([a640946](https://github.com/crimera/piko/commit/a640946e7045be359535ed0eead00ec80d2e10c4))
18+
19+
### Refactors
20+
21+
* **Twitter:** refactor values of list preference ([e0e5c5b](https://github.com/crimera/piko/commit/e0e5c5b8639efcd5eecd6476bc59b7f125d5b851))
22+
123
## [1.44.0](https://github.com/crimera/piko/compare/v1.43.0...v1.44.0) (2024-11-06)
224

325
### Features

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
org.gradle.parallel = true
22
org.gradle.caching = true
33
kotlin.code.style = official
4-
version = 1.44.0
4+
version = 1.45.0-dev.1

patches.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/main/kotlin/crimera/patches/twitter/misc/bringbacktwitter/BringBackTwitterResourcePatch.kt

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import app.revanced.patcher.patch.annotation.Patch
77
import app.revanced.util.ResourceGroup
88
import app.revanced.util.asSequence
99
import app.revanced.util.copyResources
10-
import app.util.measureExecutionTime
1110
import crimera.patches.twitter.misc.bringbacktwitter.custromstringsupdater.ja
11+
import crimera.patches.twitter.misc.bringbacktwitter.custromstringsupdater.pt_rBR
1212
import crimera.patches.twitter.misc.bringbacktwitter.strings.StringsMap
1313
import org.w3c.dom.Element
1414
import java.io.File
15-
import java.io.FileWriter
1615

1716
@Patch(
1817
name = "Bring back twitter",
@@ -97,20 +96,16 @@ object BringBackTwitterResourcePatch : ResourcePatch() {
9796
// update strings to old ones
9897
updateStrings(context)
9998
ja.updateStrings(context)
99+
pt_rBR.updateStrings(context)
100100
}
101101

102102
private fun updateStrings(context: ResourceContext) {
103103
val langs = StringsMap.replacementMap
104104
for ((key, value) in langs) {
105105
val stringsFile = context["res/$key/strings.xml"]
106-
if (!stringsFile.isFile) {
107-
108-
context["res/$key"].mkdirs()
109-
FileWriter(stringsFile).use {
110-
it.write("<?xml version=\"1.0\" encoding=\"utf-8\"?><resources></resources>")
111-
}
106+
if (stringsFile.exists()) {
107+
updateStringsFile(stringsFile, value, context)
112108
}
113-
updateStringsFile(stringsFile, value, context)
114109
}
115110
}
116111

@@ -121,39 +116,27 @@ object BringBackTwitterResourcePatch : ResourcePatch() {
121116
context.xmlEditor[stringsFile.toString()].use { editor ->
122117
val document = editor.file
123118

124-
for ((key, value) in stringsMap) {
125-
val nodes = document.getElementsByTagName("string")
126-
var keyReplaced = false
127-
for (i in 0 until nodes.length) {
128-
val node = nodes.item(i)
129-
val name = node.attributes.getNamedItem("name")?.nodeValue
130-
if (name == key) {
131-
node.textContent = value
132-
keyReplaced = true
133-
break
134-
} else if (name == "conference_default_title") {/*
135-
* Parsing causes the default value which contains the
136-
* character 𝕏 to be "corrupted" so we change it to a normal X
137-
*/
119+
val nodes = document.getElementsByTagName("string")
120+
for (i in 0 until nodes.length) {
121+
val node = nodes.item(i)
122+
val name = node.attributes.getNamedItem("name")?.nodeValue
123+
124+
if (name == "conference_default_title") {
125+
/*
126+
* Parsing XML causes the string which contains the
127+
* character "𝕏" to be corrupted, so we change it to "Twitter"
128+
*/
129+
node.textContent = stringsMap[name] ?: run {
138130
val content = node.textContent
139-
node.textContent = stringsMap[name] ?: run {
140-
val delimiter = if (content.contains("-")) '-' else ' '
141-
content.split(delimiter).joinToString(delimiter.toString()) {
142-
if (it.startsWithSpecialByte()) "Twitter" else it
143-
}
131+
val delimiter = if (content.contains("-")) '-' else ' '
132+
content.split(delimiter).joinToString(delimiter.toString()) {
133+
if (it.startsWithSpecialByte()) "Twitter" else it
144134
}
145135
}
136+
continue
146137
}
147138

148-
// log which keys were not found or failed
149-
if (!keyReplaced) {
150-
val colorElement = document.createElement("string")
151-
152-
colorElement.setAttribute("name", key)
153-
colorElement.textContent = value
154-
155-
document.getElementsByTagName("resources").item(0).appendChild(colorElement)
156-
}
139+
node.textContent = stringsMap[name] ?: continue
157140
}
158141
}
159142
}

src/main/kotlin/crimera/patches/twitter/misc/bringbacktwitter/strings/pt_rBR.kt renamed to src/main/kotlin/crimera/patches/twitter/misc/bringbacktwitter/custromstringsupdater/pt_rBR.kt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
package crimera.patches.twitter.misc.bringbacktwitter.strings
1+
package crimera.patches.twitter.misc.bringbacktwitter.custromstringsupdater
2+
3+
import app.revanced.patcher.data.ResourceContext
4+
import java.io.FileWriter
25

36
object pt_rBR {
47
val values = mapOf(
@@ -63,4 +66,40 @@ object pt_rBR {
6366
"ps__retweeted_on_twitter" to "*%s* retweetou em",
6467
"tweet_removed_from_your_bookmarks" to "Tweet removido dos seus Itens salvos"
6568
)
69+
70+
/*
71+
* The official X app doesn't have Brazilian Portuguese string resources.
72+
* So, add the strings instead of trying to replace them.
73+
*/
74+
fun updateStrings(context: ResourceContext) {
75+
if (!context["res/values-pt"].exists()) {
76+
// User likely intentionally excluded the Portuguese split when merging split APKs.
77+
// In this case, there is no need to add the pt-rBR strings.
78+
return
79+
}
80+
81+
val stringsFile = context["res/values-pt-rBR/strings.xml"]
82+
83+
// Note: If SettingsPatch was executed prior to this patch, stringsFile will exist.
84+
if (!stringsFile.exists()) {
85+
context["res/values-pt-rBR"].mkdirs()
86+
FileWriter(stringsFile).use {
87+
it.write("<?xml version=\"1.0\" encoding=\"utf-8\"?><resources></resources>")
88+
}
89+
}
90+
91+
// Append strings from the map.
92+
context.xmlEditor[stringsFile.toString()].use {
93+
val document = it.file
94+
val parentNode = document.getElementsByTagName("resources").item(0)
95+
96+
for ((key, value) in values) {
97+
val newElement = document.createElement("string")
98+
newElement.setAttribute("name", key)
99+
newElement.textContent = value
100+
101+
parentNode.appendChild(newElement)
102+
}
103+
}
104+
}
66105
}

src/main/kotlin/crimera/patches/twitter/misc/bringbacktwitter/strings/StringsMap.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ object StringsMap {
66
"values-en-rGB" to en_rGB.values,
77
"values-ru" to ru.values,
88
"values-hi" to hi.values,
9-
"values-pt-rBR" to pt_rBR.values,
109
"values-tr" to tr.values,
1110
"values-zh-rCN" to zh_rCN.values,
1211
"values-zh-rTW" to zh_rTW.values,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package crimera.patches.twitter.misc.customize.postFontSize
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
5+
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
6+
import app.revanced.patcher.extensions.or
7+
import app.revanced.patcher.fingerprint.MethodFingerprint
8+
import app.revanced.patcher.patch.BytecodePatch
9+
import app.revanced.patcher.patch.PatchException
10+
import app.revanced.patcher.patch.annotation.CompatiblePackage
11+
import app.revanced.patcher.patch.annotation.Patch
12+
import com.android.tools.smali.dexlib2.AccessFlags
13+
import com.android.tools.smali.dexlib2.Opcode
14+
import crimera.patches.twitter.misc.settings.SettingsPatch
15+
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint
16+
17+
object CustomizePostFontSizeFingerprint : MethodFingerprint(
18+
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
19+
customFingerprint = { methodDef, _ ->
20+
methodDef.definingClass.endsWith("TextContentView;")
21+
},
22+
)
23+
24+
@Patch(
25+
name = "Customise post font size",
26+
description = "",
27+
dependencies = [SettingsPatch::class],
28+
compatiblePackages = [CompatiblePackage("com.twitter.android")],
29+
use = true,
30+
)
31+
object CustomizePostFontSize : BytecodePatch(
32+
setOf(CustomizePostFontSizeFingerprint, SettingsStatusLoadFingerprint),
33+
) {
34+
override fun execute(context: BytecodeContext) {
35+
val result1 =
36+
CustomizePostFontSizeFingerprint.result
37+
?: throw PatchException("CustomizePostFontSizeFingerprint not found")
38+
39+
val method1 = result1.mutableMethod
40+
41+
val index1 =
42+
method1
43+
.getInstructions()
44+
.last { it.opcode == Opcode.MOVE_RESULT }
45+
.location.index
46+
method1.addInstruction(index1 + 1, "sget p1, ${SettingsPatch.PREF_DESCRIPTOR};->POST_FONT_SIZE:F")
47+
48+
SettingsStatusLoadFingerprint.enableSettings("customPostFontSize")
49+
}
50+
}

src/main/kotlin/crimera/patches/twitter/misc/settings/SettingsResourcePatch.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object SettingsResourcePatch : ResourcePatch() {
3030
parent.appendChild(prefMod)
3131
}
3232

33-
//credits aero
33+
// credits aero
3434
val sideBarLayout = context["res/layout/main_activity_app_bar.xml"]
3535
if (!sideBarLayout.exists()) throw PatchException("settings_root not found")
3636

@@ -53,23 +53,39 @@ object SettingsResourcePatch : ResourcePatch() {
5353
parent.appendChild(sideBtn)
5454
}
5555

56-
//credits @inotia00
56+
// credits @inotia00
5757
context.appendStrings("twitter/settings", "values/strings.xml")
5858
context.appendStrings("twitter/settings", "values/arrays.xml")
5959

6060
/**
6161
* create directory for the untranslated language resources
6262
*/
63-
val languages = arrayOf(
64-
"es", "ar", "ja", "hi", "in", "zh-rCN", "ru", "pl", "pt-rBR", "v21", "tr", "zh-rTW"
65-
).map { "values-$it" }
63+
val languages =
64+
arrayOf(
65+
"es",
66+
"ar",
67+
"ja",
68+
"hi",
69+
"in",
70+
"zh-rCN",
71+
"ru",
72+
"pl",
73+
"pt-rBR",
74+
"v21",
75+
"tr",
76+
"zh-rTW",
77+
).map { "values-$it" }
6678

6779
languages.forEach {
80+
// println("res/$it")
6881
if (context["res/$it"].exists()) {
6982
context.appendStrings("twitter/settings", "$it/strings.xml")
7083
} else {
7184
context["res/$it"].mkdirs()
7285
context.copyResources("twitter/settings", ResourceGroup(it, "strings.xml"))
86+
if (it.contains("v21")) {
87+
context.copyResources("twitter/settings", ResourceGroup(it, "arrays.xml"))
88+
}
7389
}
7490
}
7591
}

src/main/kotlin/crimera/patches/twitter/misc/shareMenu/hooks/ShareMenuButtonAddHook.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object ShareMenuButtonAddHook : MethodFingerprint(
1818
"3691233323:audiospace",
1919
),
2020
customFingerprint = { methodDef, _ ->
21-
methodDef.name == "a"
21+
methodDef.name == "a" && methodDef.parameters.size == 4
2222
},
2323
) {
2424
fun addButton(

0 commit comments

Comments
 (0)