Skip to content

Commit

Permalink
Merge pull request #494 from swakwork/dev
Browse files Browse the repository at this point in the history
feat(Twitter): Explore search features
  • Loading branch information
crimera authored Dec 9, 2024
2 parents adfbe33 + c52c2c0 commit c454fa2
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package crimera.patches.twitter.ads.timelineEntryHook

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import crimera.patches.twitter.misc.settings.SettingsPatch
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint

@Patch(
name = "Remove top people in search",
description = "Removes people section after search",
dependencies = [SettingsPatch::class, TimelineEntryHookPatch::class],
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = true,
)
object HideTopPeopleSearch : BytecodePatch(
setOf(SettingsStatusLoadFingerprint),
) {
override fun execute(context: BytecodeContext) {
SettingsStatusLoadFingerprint.enableSettings("hideTopPeopleSearch")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package crimera.patches.twitter.misc.customize.searchtabs

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
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 com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import crimera.patches.twitter.misc.settings.SettingsPatch
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint

object CustomiseSearchTabsPatchFingerprint : MethodFingerprint(
returnType = "Ljava/util/List;",
strings =
listOf(
"search_features_media_tab_enabled",
"search_features_lists_search_enabled",
),
)

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

val method = results.mutableMethod
val instructions = method.getInstructions()

val returnObj_loc = instructions.last { it.opcode == Opcode.RETURN_OBJECT }.location.index
val r0 = method.getInstruction<OneRegisterInstruction>(returnObj_loc).registerA

method.addInstructions(
returnObj_loc,
"""
invoke-static {v$r0}, ${SettingsPatch.CUSTOMISE_DESCRIPTOR};->searchTabs(Ljava/util/List;)Ljava/util/List;
move-result-object v$r0
""".trimIndent(),
)

SettingsStatusLoadFingerprint.enableSettings("searchTabCustomisation")

// end
}
}
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")
}
}
17 changes: 17 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,21 @@
<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>

<string-array name="piko_array_searchtabs_val">
<item>0</item>
<item>1</item>
<item>2</item>
<item>5</item>
<item>3</item>
<item>7</item>
<item>13</item>
</string-array>
</resources>
18 changes: 18 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,22 @@
<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>

<string-array name="piko_array_searchtabs">
<item>@string/search_scope_top</item>
<item>@string/search_scope_latest</item>
<item>@string/subtitle_people</item>
<item>@string/search_filter_videos</item>
<item>@string/search_filter_photos</item>
<item>@string/search_filter_media</item>
<item>@string/search_scope_lists</item>
</string-array>

</resources>
12 changes: 10 additions & 2 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
<string name="piko_pref_db_del_items">Deleted items</string>
<string name="piko_pref_hide_premium_upsell">premium upsell</string>
<string name="piko_pref_hide_premium_upsell_desc">Removes premium upsell in home timeline</string>
<string name="piko_pref_top_people_search">top people in search</string>
<string name="piko_pref_top_people_search_desc">Removes people section after search</string>

<!-- Misc Settings -->
<string name="piko_title_misc">Misc</string>
Expand Down Expand Up @@ -112,17 +114,19 @@
<!-- Customization Settings -->
<string name="piko_title_customisation">Customization</string>
<string name="piko_pref_customisation_profiletabs">Profile tabs to hide</string>
<string name="piko_pref_customisation_timelinetabs">Timeline tabs</string>
<string name="piko_pref_customisation_timelinetabs">Timeline tabs to hide</string>
<string name="piko_pref_customisation_timelinetabs_foryou">Remove \"For You\"</string>
<string name="piko_pref_customisation_timelinetabs_following">Remove \"Following\"</string>
<string name="piko_pref_customisation_timelinetabs_both">Show both</string>
<string name="piko_pref_customisation_sidebartabs">Side bar items to hide</string>
<string name="piko_pref_customisation_navbartabs">Navigation bar items to hide</string>
<string name="piko_pref_customisation_inlinetabs">Inline bar items to hide</string>
<string name="piko_pref_customisation_exploretabs">Explore tabs</string>
<string name="piko_pref_customisation_exploretabs">Explore tabs to hide</string>
<string name="piko_pref_customisation_searchtabs">Search tabs to hide</string>
<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">Search suggestions to hide</string>

<!-- Backup and Restore -->
<string name="piko_title_backup">Backup and restore</string>
Expand Down Expand Up @@ -155,4 +159,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 c454fa2

Please sign in to comment.