Skip to content

Commit

Permalink
feat(Twitter): Added Customize search suggestions patch
Browse files Browse the repository at this point in the history
  • Loading branch information
swakwork committed Dec 7, 2024
1 parent 95b5ef9 commit aaca565
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package crimera.patches.twitter.misc.customize.typeAheadResponse

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import com.android.tools.smali.dexlib2.Opcode
import crimera.patches.twitter.misc.settings.SettingsPatch
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint

object CustomiseTypeAheadResponseFingerprint : MethodFingerprint(
returnType = "Ljava/lang/Object",
customFingerprint = { methodDef, _ ->
methodDef.name == "parse" && methodDef.definingClass.endsWith("JsonTypeaheadResponse\$\$JsonObjectMapper;")
},
)

@Patch(
name = "Customize search suggestions",
dependencies = [SettingsPatch::class],
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = true,
)
@Suppress("unused")
object CustomiseTypeAheadResponsePatch : BytecodePatch(
setOf(CustomiseTypeAheadResponseFingerprint, SettingsStatusLoadFingerprint),
) {
override fun execute(context: BytecodeContext) {
val result =
CustomiseTypeAheadResponseFingerprint.result
?: throw PatchException("CustomiseTypeAheadResponseFingerprint not found")

val method = result.mutableMethod

val instructions = method.getInstructions()

val returnObj = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index

method.addInstructions(
returnObj,
"""
invoke-static {p1}, ${SettingsPatch.CUSTOMISE_DESCRIPTOR};->typeAheadResponse(Lcom/twitter/model/json/search/JsonTypeaheadResponse;)Lcom/twitter/model/json/search/JsonTypeaheadResponse;
move-result-object p1
""",
)

SettingsStatusLoadFingerprint.enableSettings("typeaheadCustomisation")
}
}
8 changes: 8 additions & 0 deletions src/main/resources/twitter/settings/values-v21/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@
<item>1</item>
</string-array>

<string-array name="piko_array_search_type_ahead_val">
<item>users</item>
<item>topics</item>
<item>events</item>
<item>lists</item>
<item>ordered_section</item>
</string-array>

</resources>
8 changes: 8 additions & 0 deletions src/main/resources/twitter/settings/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@
<item>@string/piko_native_translator_google_v2</item>
</string-array>

<string-array name="piko_array_search_type_ahead">
<item>@string/piko_pref_search_type_ahead_users</item>
<item>@string/channel_topics_title</item>
<item>@string/piko_pref_search_type_ahead_events</item>
<item>@string/search_scope_lists</item>
<item>@string/piko_pref_search_type_ahead_ordered_section</item>
</string-array>

</resources>
5 changes: 5 additions & 0 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<string name="piko_pref_customisation_reply_sorting">Default reply sorting filter</string>
<string name="piko_pref_customisation_reply_sorting_remember">Previously selected</string>
<string name="piko_pref_customisation_post_font_size">Post font size</string>
<string name="piko_pref_customisation_search_type_ahead">Customize search suggestions</string>

<!-- Backup and Restore -->
<string name="piko_title_backup">Backup and restore</string>
Expand Down Expand Up @@ -157,4 +158,8 @@
<string name="piko_native_translator_google">Google translator</string>
<string name="piko_native_translator_google_v2">Google translator V2</string>

<string name="piko_pref_search_type_ahead_users">Users</string>
<string name="piko_pref_search_type_ahead_events">Events</string>
<string name="piko_pref_search_type_ahead_ordered_section">Ordered section</string>

</resources>

0 comments on commit aaca565

Please sign in to comment.