refactor(youtube/enable-wide-searchbar): apply Kotlin class structure conventions

This commit is contained in:
oSumAtrIX 2023-04-23 06:23:42 +02:00
parent 6ae0f0b466
commit d23d19b2a6
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -33,6 +33,30 @@ class WideSearchbarPatch : BytecodePatch(
SetWordmarkHeaderFingerprint, DrawActionBarFingerprint SetWordmarkHeaderFingerprint, DrawActionBarFingerprint
) )
) { ) {
override fun execute(context: BytecodeContext): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
"revanced_wide_searchbar",
StringResource("revanced_wide_searchbar_enabled_title", "Enable wide search bar"),
false,
StringResource("revanced_wide_searchbar_summary_on", "Wide search bar is enabled"),
StringResource("revanced_wide_searchbar_summary_off", "Wide search bar is disabled")
)
)
val result = DrawActionBarFingerprint.result ?: return DrawActionBarFingerprint.toErrorResult()
// patch methods
mapOf(
SetWordmarkHeaderFingerprint to 1,
DrawActionBarFingerprint to result.scanResult.patternScanResult!!.endIndex
).forEach { (fingerprint, callIndex) ->
context.walkMutable(callIndex, fingerprint).injectSearchBarHook()
}
return PatchResultSuccess()
}
private companion object { private companion object {
/** /**
* Walk a fingerprints method at a given index mutably. * Walk a fingerprints method at a given index mutably.
@ -61,28 +85,4 @@ class WideSearchbarPatch : BytecodePatch(
) )
} }
} }
override fun execute(context: BytecodeContext): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SwitchPreference(
"revanced_wide_searchbar",
StringResource("revanced_wide_searchbar_enabled_title", "Enable wide search bar"),
false,
StringResource("revanced_wide_searchbar_summary_on", "Wide search bar is enabled"),
StringResource("revanced_wide_searchbar_summary_off", "Wide search bar is disabled")
)
)
val result = DrawActionBarFingerprint.result ?: return DrawActionBarFingerprint.toErrorResult()
// patch methods
mapOf(
SetWordmarkHeaderFingerprint to 1,
DrawActionBarFingerprint to result.scanResult.patternScanResult!!.endIndex
).forEach { (fingerprint, callIndex) ->
context.walkMutable(callIndex, fingerprint).injectSearchBarHook()
}
return PatchResultSuccess()
}
} }