Skip to content

Commit

Permalink
feat(Twitter): Added Customize explore tabs patch
Browse files Browse the repository at this point in the history
  • Loading branch information
swakwork committed Nov 27, 2024
1 parent 0792795 commit 4be6a7f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package crimera.patches.twitter.misc.customize.timelinetabs

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 CustomiseExploreTabsFingerprint : MethodFingerprint(
opcodes = listOf(Opcode.NEW_INSTANCE),
customFingerprint = { it, _ ->
it.definingClass.endsWith("JsonPageTabs;")
},
)

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

val method = result.mutableMethod

val instructions = method.getInstructions()

val index = instructions.first { it.opcode == Opcode.IGET_OBJECT }.location.index

method.addInstructions(
index + 1,
"""
invoke-static {v1}, ${SettingsPatch.CUSTOMISE_DESCRIPTOR};->exploretabs(Ljava/util/ArrayList;)Ljava/util/ArrayList;
move-result-object v1
""".trimIndent(),
)

SettingsStatusLoadFingerprint.enableSettings("exploreTabCustomisation")
}
}
9 changes: 9 additions & 0 deletions src/main/resources/twitter/settings/values-v21/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
<item>hide_following</item>
</string-array>

<string-array name="piko_array_exploretabs_val">
<item>for_you</item>
<item>trending</item>
<item>fun</item>
<item>news</item>
<item>sports</item>
<item>entertainment</item>
</string-array>

<string-array name="piko_array_download_media_handle_val">
<item>download_media</item>
<item>copy_media_link</item>
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/twitter/settings/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
<item>@string/profile_tab_title_likes</item>
</string-array>

<string-array name="piko_array_exploretabs">
<item>@string/guide_tab_title_for_you</item>
<item>@string/guide_tab_title_trending</item>
<item>@string/guide_tab_title_fun</item>
<item>@string/guide_tab_title_news</item>
<item>@string/guide_tab_title_sports</item>
<item>@string/guide_tab_title_entertainment</item>
</string-array>

<string-array name="piko_array_timelinetabs">
<item>@string/piko_pref_customisation_timelinetabs_both</item>
<item>@string/piko_pref_customisation_timelinetabs_foryou</item>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/twitter/settings/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<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_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>
Expand Down

0 comments on commit 4be6a7f

Please sign in to comment.