From f13477cc17cc2cd8326c22c0291cff41aeb22196 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Thu, 6 Jul 2023 11:49:34 +0900 Subject: [PATCH] feat(reddit/hide-navigation-buttons): split into `hide-discover-button`, `hide-chat-button`, `hide-create-button` --- .../navigation/patch/ChatButtonPatch.kt | 38 +++++++++++++++++++ .../navigation/patch/CreateButtonPatch.kt | 38 +++++++++++++++++++ .../navigation/patch/DiscoverButtonPatch.kt | 38 +++++++++++++++++++ .../patch/NavigationButtonsPatch.kt | 29 +++++++++----- 4 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/ChatButtonPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/ChatButtonPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/ChatButtonPatch.kt new file mode 100644 index 000000000..95c32734f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/ChatButtonPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.reddit.layout.navigation.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.reddit.layout.navigation.patch.NavigationButtonsPatch.Companion.setValue +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus +import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch + +@Patch +@Name("hide-chat-button") +@Description("Hide chat button at navigation bar.") +@DependsOn( + [ + NavigationButtonsPatch::class, + SettingsPatch::class + ] +) +@RedditCompatibility +@Version("0.0.1") +class ChatButtonPatch : BytecodePatch() { + override fun execute(context: BytecodeContext): PatchResult { + + updateSettingsStatus("ChatButtons") + + if (SettingsPatch.AddRedditSettings == "true") + context.setValue("ChatButtons") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt new file mode 100644 index 000000000..c6a9a641f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/CreateButtonPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.reddit.layout.navigation.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.reddit.layout.navigation.patch.NavigationButtonsPatch.Companion.setValue +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus +import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch + +@Patch +@Name("hide-create-button") +@Description("Hide create button at navigation bar.") +@DependsOn( + [ + NavigationButtonsPatch::class, + SettingsPatch::class + ] +) +@RedditCompatibility +@Version("0.0.1") +class CreateButtonPatch : BytecodePatch() { + override fun execute(context: BytecodeContext): PatchResult { + + updateSettingsStatus("CreateButtons") + + if (SettingsPatch.AddRedditSettings == "true") + context.setValue("CreateButtons") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt new file mode 100644 index 000000000..7872519ab --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/DiscoverButtonPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.reddit.layout.navigation.patch + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.reddit.layout.navigation.patch.NavigationButtonsPatch.Companion.setValue +import app.revanced.patches.reddit.utils.annotations.RedditCompatibility +import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsBytecodePatch.Companion.updateSettingsStatus +import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsPatch + +@Patch +@Name("hide-discover-button") +@Description("Hide discover button at navigation bar.") +@DependsOn( + [ + NavigationButtonsPatch::class, + SettingsPatch::class + ] +) +@RedditCompatibility +@Version("0.0.1") +class DiscoverButtonPatch : BytecodePatch() { + override fun execute(context: BytecodeContext): PatchResult { + + updateSettingsStatus("DiscoverButtons") + + if (SettingsPatch.AddRedditSettings == "true") + context.setValue("DiscoverButtons") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt index b0f65a24d..fa518251a 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/navigation/patch/NavigationButtonsPatch.kt @@ -5,25 +5,20 @@ import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.reddit.layout.navigation.fingerprints.BottomNavScreenFingerprint import app.revanced.patches.reddit.utils.annotations.RedditCompatibility -import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch -import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch.Companion.updateSettingsStatus import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction -@Patch @Name("hide-navigation-buttons") @Description("Hide navigation buttons.") -@DependsOn([SettingsPatch::class]) @RedditCompatibility @Version("0.0.1") class NavigationButtonsPatch : BytecodePatch( @@ -53,14 +48,28 @@ class NavigationButtonsPatch : BytecodePatch( } } ?: return BottomNavScreenFingerprint.toErrorResult() - updateSettingsStatus("NavigationButtons") - return PatchResultSuccess() } - private companion object { - private const val INTEGRATIONS_METHOD_DESCRIPTOR = + companion object { + const val INTEGRATIONS_METHOD_DESCRIPTOR = "Lapp/revanced/reddit/patches/NavigationButtonsPatch;" + "->hideNavigationButtons(Ljava/util/List;)Ljava/util/List;" + + internal fun BytecodeContext.setValue(patch: String) { + this.classes.forEach { classDef -> + classDef.methods.forEach { method -> + if (classDef.type == "Lapp/revanced/reddit/settingsmenu/SettingsStatus;" && method.name == patch) { + val patchStatusMethod = + this.proxy(classDef).mutableClass.methods.first { it.name == patch } + + patchStatusMethod.addInstruction( + 2, + "return-void" + ) + } + } + } + } } }