Skip to content

Commit 2d90967

Browse files
authored
Merge pull request #673 from swakwork/fix/v21
Some fixes for v21
2 parents 9936459 + fa0dfac commit 2d90967

File tree

29 files changed

+76
-59
lines changed

29 files changed

+76
-59
lines changed

extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/DatabasePatch.java

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,55 +71,64 @@ private static StringBuilder removeFromDB(boolean[] checkedItems){
7171
database = SQLiteDatabase.openDatabase(DATABASE_PATH, null, SQLiteDatabase.OPEN_READWRITE);
7272
if (database != null && database.isOpen()) {
7373
for (int i = 0; i < checkedItems.length; i++) {
74+
List<String> keywords = new ArrayList<String>();
7475
if (checkedItems[i]) {
75-
String entry_id_str = "";
76-
String entry_id_str2 = "";
7776
switch (i) {
7877
case 0: {
79-
entry_id_str = "promoted%";
80-
entry_id_str2 = "rtb%";
78+
keywords.add("promoted%");
79+
keywords.add("rtb%");
80+
keywords.add("%promoted%");
8181
break;
8282
}
8383
case 1: {
84-
entry_id_str = "who-to-follow%";
84+
keywords.add("who-to-follow%");
8585
break;
8686
}
8787
case 2: {
88-
entry_id_str = "who-to-subscribe%";
88+
keywords.add("who-to-follow%");
89+
// entry_id_str = "who-to-subscribe%";
8990
break;
9091
}
9192
case 3: {
92-
entry_id_str = "community-to-join%";
93+
keywords.add("community-to-join%");
94+
// entry_id_str = "community-to-join%";
9395
break;
9496
}
9597
case 4: {
96-
entry_id_str = "bookmarked%";
98+
keywords.add("bookmarked%");
99+
//entry_id_str = "bookmarked%";
97100
break;
98101
}
99102
case 5: {
100-
entry_id_str = "pinned-tweets%";
103+
keywords.add("tweets%");
104+
//entry_id_str = "pinned-tweets%";
101105
break;
102106
}
103107
case 6: {
104-
entry_id_str = "tweetdetailrelatedtweets%";
108+
keywords.add("tweetdetailrelatedtweets%");
109+
//entry_id_str = "tweetdetailrelatedtweets%";
105110
break;
106111
}
107112
case 7: {
108-
entry_id_str = "messageprompt%";
113+
keywords.add("messageprompt%");
114+
//entry_id_str = "messageprompt%";
109115
break;
110116
}
111117
case 8: {
112-
entry_id_str = "stories%";
118+
keywords.add("stories%");
119+
//entry_id_str = "stories%";
113120
break;
114121
}
115122
}
116-
int deletedRows = 0;
117-
if (entry_id_str != "") {
118-
deletedRows = database.delete("timeline", "entity_id LIKE ?", new String[]{entry_id_str}); }
119-
if (entry_id_str2 != "") {
120-
int deletedRows2 = database.delete("timeline", "entity_id LIKE ?", new String[]{entry_id_str2});
121-
deletedRows+=deletedRows2;
123+
124+
StringBuilder selection = new StringBuilder();
125+
String[] selectionArgs = new String[keywords.size()];
126+
for (int ind = 0; ind < keywords.size(); ind++) {
127+
if (ind > 0) selection.append(" OR ");
128+
selection.append("entity_id LIKE ?");
129+
selectionArgs[ind] = "%" + keywords.get(ind) + "%";
122130
}
131+
int deletedRows = database.delete("timeline", selection.toString(), selectionArgs);
123132
result.append("• "+listItems[i]+" = "+String.valueOf(deletedRows)+"\n");
124133
}
125134
}

extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/FeatureSwitchPatch.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ private static void chirpFont() {
2424
}
2525

2626
private static void hideGoogleAds() { addFlag("ssp_ads_dsp_client_context_enabled", !Pref.hideAds()); }
27-
2827
private static void viewCount() {
2928
addFlag("view_counts_public_visibility_enabled", Pref.hideViewCount());
3029
}

extensions/twitter/src/main/java/app/revanced/extension/twitter/patches/TimelineEntry.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.twitter.model.json.timeline.urt.JsonTimelineEntry;
44
import com.twitter.model.json.core.JsonSensitiveMediaWarning;
5-
5+
import com.twitter.model.json.timeline.urt.JsonTimelineModuleItem;
66
import app.revanced.extension.twitter.Pref;
77
import app.revanced.extension.twitter.settings.SettingsStatus;
88

@@ -28,7 +28,7 @@ private static boolean isEntryIdRemove(String entryId) {
2828
String[] split = entryId.split("-");
2929
String entryId2 = split[0];
3030
if (!entryId2.equals("cursor") && !entryId2.equals("Guide") && !entryId2.startsWith("semantic_core")) {
31-
if ((entryId.contains("promoted") || ((entryId2.equals("conversationthread") && split.length == 3))) && hideAds) {
31+
if (entryId.contains("promoted") || ((entryId2.equals("conversationthread") && split.length == 3)) && hideAds) {
3232
return true;
3333
}
3434
if ((entryId2.equals("superhero") || entryId2.equals("eventsummary")) && hideAds) {
@@ -83,6 +83,18 @@ public static JsonTimelineEntry checkEntry(JsonTimelineEntry jsonTimelineEntry)
8383
return jsonTimelineEntry;
8484
}
8585

86+
public static JsonTimelineModuleItem checkEntry(JsonTimelineModuleItem jsonTimelineModuleItem) {
87+
try {
88+
String entryId = jsonTimelineModuleItem.a;
89+
if(isEntryIdRemove(entryId)){
90+
return null;
91+
}
92+
} catch (Exception unused) {
93+
94+
}
95+
return jsonTimelineModuleItem;
96+
}
97+
8698
public static JsonSensitiveMediaWarning sensitiveMedia(JsonSensitiveMediaWarning jsonSensitiveMediaWarning) {
8799
try {
88100
if(showSensitiveMedia){
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.twitter.model.json.timeline.urt;
2+
3+
public class JsonTimelineModuleItem {
4+
public String a;
5+
}

patches/api/patches.api

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ public final class app/crimera/utils/UtilsKt {
319319
public static final fun getMethodName (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/Fingerprint;I)Ljava/lang/String;
320320
public static final fun getReference (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/Fingerprint;I)Lcom/android/tools/smali/dexlib2/iface/reference/Reference;
321321
public static final fun instructionToString (Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;)Ljava/lang/String;
322-
public static final fun mergeXmlResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;Ljava/lang/String;)V
323-
public static synthetic fun mergeXmlResources$default (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;Ljava/lang/String;ILjava/lang/Object;)V
324322
public static final fun replaceStringsInFile (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;Ljava/util/Map;)V
325323
public static final fun replaceXmlResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;)V
326324
}

patches/src/main/kotlin/app/crimera/patches/twitter/ads/timelineEntryHook/TimelineEntryHookPatch.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@ private val timelineEntryHookFingerprint =
1515
}
1616
}
1717

18+
private val timelineModuleItemHookFingerprint =
19+
fingerprint {
20+
returns("Ljava/lang/Object")
21+
custom { it, _ ->
22+
it.definingClass == "Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem\$\$JsonObjectMapper;" && it.name == "parse"
23+
}
24+
}
25+
1826
val timelineEntryHookPatch =
1927
bytecodePatch(
2028
description = "Hooks timeline object",
2129
) {
2230
execute {
23-
val methods = timelineEntryHookFingerprint.method
24-
val instructions = methods.instructions
31+
var methods = timelineEntryHookFingerprint.method
32+
var instructions = methods.instructions
2533

26-
val returnObj = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index
34+
var returnObj = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index
2735

2836
methods.addInstructions(
2937
returnObj,
@@ -32,6 +40,19 @@ val timelineEntryHookPatch =
3240
move-result-object p1
3341
""".trimIndent(),
3442
)
43+
44+
methods = timelineModuleItemHookFingerprint.method
45+
instructions = methods.instructions
46+
47+
returnObj = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index
48+
49+
methods.addInstructions(
50+
returnObj,
51+
"""
52+
invoke-static {p1}, $PATCHES_DESCRIPTOR/TimelineEntry;->checkEntry(Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem;)Lcom/twitter/model/json/timeline/urt/JsonTimelineModuleItem;
53+
move-result-object p1
54+
""".trimIndent(),
55+
)
3556
// ends.
3657
}
3758
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package app.crimera.patches.twitter.misc.settings
22

3-
import app.crimera.utils.mergeXmlResources
43
import app.revanced.patcher.patch.resourcePatch
54
import app.revanced.patches.shared.misc.mapping.resourceMappingPatch
65
import app.revanced.util.ResourceGroup
6+
import app.revanced.util.copyResources
77
import org.w3c.dom.Element
88
import java.nio.file.Files
99

@@ -43,8 +43,8 @@ internal val settingsResourcePatch =
4343
parent.appendChild(sideBtn)
4444
}
4545

46-
mergeXmlResources("twitter/settings", ResourceGroup("values", "strings.xml"))
47-
mergeXmlResources("twitter/settings", ResourceGroup("values", "arrays.xml"))
46+
copyResources("twitter/settings", ResourceGroup("values", "piko_strings.xml"))
47+
copyResources("twitter/settings", ResourceGroup("values", "piko_arrays.xml"))
4848

4949
/**
5050
* create directory for the untranslated language resources
@@ -75,10 +75,10 @@ internal val settingsResourcePatch =
7575
if (!vDirectory.isDirectory) {
7676
Files.createDirectories(vDirectory.toPath())
7777
if (it.contains("v21")) {
78-
mergeXmlResources("twitter/settings", ResourceGroup(it, "arrays.xml"))
78+
copyResources("twitter/settings", ResourceGroup(it, "piko_arrays.xml"))
7979
}
8080
}
81-
mergeXmlResources("twitter/settings", ResourceGroup(it, "strings.xml"))
81+
copyResources("twitter/settings", ResourceGroup(it, "piko_strings.xml"))
8282
}
8383

8484
// execute end

patches/src/main/kotlin/app/crimera/utils/Utils.kt

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,6 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
2929
import com.android.tools.smali.dexlib2.iface.reference.Reference
3030
import org.w3c.dom.Element
3131

32-
fun ResourcePatchContext.mergeXmlResources(
33-
sourceResourceDirectory: String,
34-
vararg resourceGroups: ResourceGroup,
35-
tagName: String = "resources",
36-
) {
37-
for (resourceGroup in resourceGroups) {
38-
resourceGroup.resources.forEach { resource ->
39-
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"
40-
val targetFile = get("res").resolve(resourceFile)
41-
42-
// If target file doesn't exist, use copyResources as fallback
43-
if (!targetFile.exists()) {
44-
copyResources(sourceResourceDirectory, resourceGroup)
45-
return@forEach
46-
}
47-
48-
inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)?.let { inputStream ->
49-
tagName
50-
.copyXmlNode(
51-
document(inputStream),
52-
document("res/$resourceFile"),
53-
).close()
54-
} ?: throw PatchException("Could not find $resourceFile in $sourceResourceDirectory")
55-
}
56-
}
57-
}
58-
5932
fun ResourcePatchContext.replaceXmlResources(
6033
sourceResourceDirectory: String,
6134
vararg resourceGroups: ResourceGroup,

patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ val changeVersionCodePatch =
3131
execute {
3232
document("AndroidManifest.xml").use { document ->
3333
val manifestElement = document.getNode("manifest") as Element
34-
manifestElement.setAttribute("android:versionCode", versionCode.toString())
34+
manifestElement.setAttribute("android:versionCode", "$versionCode")
3535
}
3636
}
3737
}

patches/src/main/resources/twitter/settings/values-ar/strings.xml renamed to patches/src/main/resources/twitter/settings/values-ar/piko_strings.xml

File renamed without changes.

0 commit comments

Comments
 (0)