feat(reddit/hide-navigation-buttons): split into hide-discover-button, hide-chat-button, hide-create-button

This commit is contained in:
inotia00
2023-07-06 11:49:34 +09:00
parent 498e5d2001
commit f13477cc17
4 changed files with 133 additions and 10 deletions

View File

@ -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()
}
}

View File

@ -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()
}
}

View File

@ -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()
}
}

View File

@ -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"
)
}
}
}
}
}
}