Skip to content

Commit

Permalink
feat(Twitter): Added Remember filter for Customize reply sort filter
Browse files Browse the repository at this point in the history
  • Loading branch information
swakwork committed Aug 11, 2024
1 parent 121b8a6 commit 24df398
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ object ReplySortingInvokeClassFinderFingerprint: MethodFingerprint(
}
)

object ReplySortingLastSelectedFinderFingerprint: MethodFingerprint(
strings = listOf(
"controller_data",
"reply_sorting_enabled",
"reply_sorting"
)
)


@Patch(
name = "Customize reply sort filter",
Expand All @@ -32,13 +40,12 @@ object ReplySortingInvokeClassFinderFingerprint: MethodFingerprint(
)
@Suppress("unused")
object DefaultReplySortingPatch:BytecodePatch(
setOf(SettingsStatusLoadFingerprint,ReplySortingInvokeClassFinderFingerprint)
setOf(SettingsStatusLoadFingerprint,ReplySortingInvokeClassFinderFingerprint,ReplySortingLastSelectedFinderFingerprint)
){
override fun execute(context: BytecodeContext) {
val result = ReplySortingInvokeClassFinderFingerprint.result
?:throw PatchException("ReplySortingInvokeClassFinderFingerprint not found")


val replySortingInvokeClass= result.classDef.fields.first().type
val method = context.findClass(replySortingInvokeClass)!!.mutableClass.directMethods.first()
val instructions = method.getInstructions()
Expand All @@ -53,6 +60,22 @@ object DefaultReplySortingPatch:BytecodePatch(
move-result-object v$r0
""".trimIndent())

val result2 = ReplySortingLastSelectedFinderFingerprint.result
?:throw PatchException("ReplySortingLastSelectedFinderFingerprint not found")

val method2 = result2.mutableMethod
result2.scanResult.stringsScanResult!!.matches.forEach{ match ->
val str = match.string
if(str.equals("reply_sorting")){
var loc = match.index
var r = method2.getInstruction<OneRegisterInstruction>(loc-1).registerA
method2.addInstructions(loc,"""
invoke-static {v$r},${SettingsPatch.PREF_DESCRIPTOR};->setReplySortFilter(Ljava/lang/String;)V
""".trimIndent())
return@forEach
}
}

SettingsStatusLoadFingerprint.enableSettings("defaultReplySortFilter")

}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/twitter/settings/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<item>@string/detail_filter_trending_title</item>
<item>@string/detail_filter_recent_title</item>
<item>@string/detail_filter_most_liked_title</item>
<item>@string/piko_pref_customisation_reply_sorting_remember</item>
</string-array>

</resources>
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 @@ -102,6 +102,7 @@
<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_reply_sorting">Default reply sorting filter</string>
<string name="piko_pref_customisation_reply_sorting_remember">Remember last selected</string>

<string name="piko_title_backup">Backup and restore</string>
<string name="piko_pref_export">Export %s</string>
Expand Down

0 comments on commit 24df398

Please sign in to comment.