diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/communities/RecommendedCommunitiesPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/communities/RecommendedCommunitiesPatch.kt new file mode 100644 index 000000000..d82604df1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/communities/RecommendedCommunitiesPatch.kt @@ -0,0 +1,45 @@ +package app.revanced.patches.reddit.layout.communities + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.util.smali.ExternalLabel +import app.revanced.patches.reddit.layout.communities.fingerprints.CommunityRecommendationSectionFingerprint +import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACKAGE +import app.revanced.patches.reddit.utils.integrations.Constants.PATCHES_PATH +import app.revanced.patches.reddit.utils.settings.SettingsBytecodePatch.updateSettingsStatus +import app.revanced.patches.reddit.utils.settings.SettingsPatch +import app.revanced.util.patch.BaseBytecodePatch +import app.revanced.util.resultOrThrow + +@Suppress("unused") +object RecommendedCommunitiesPatch : BaseBytecodePatch( + name = "Hide recommended communities shelf", + description = "Adds an option to hide the recommended communities shelves in subreddits.", + dependencies = setOf(SettingsPatch::class), + compatiblePackages = COMPATIBLE_PACKAGE, + fingerprints = setOf(CommunityRecommendationSectionFingerprint) +) { + private const val INTEGRATIONS_METHOD_DESCRIPTOR = + "$PATCHES_PATH/RecommendedCommunitiesPatch;->hideRecommendedCommunitiesShelf()Z" + + override fun execute(context: BytecodeContext) { + + CommunityRecommendationSectionFingerprint.resultOrThrow().let { + it.mutableMethod.apply { + addInstructionsWithLabels( + 0, + """ + invoke-static {}, $INTEGRATIONS_METHOD_DESCRIPTOR + move-result v0 + if-eqz v0, :off + return-void + """, ExternalLabel("off", getInstruction(0)) + ) + } + } + + updateSettingsStatus("enableRecommendedCommunitiesShelf") + + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/layout/communities/fingerprints/CommunityRecommendationSectionFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/layout/communities/fingerprints/CommunityRecommendationSectionFingerprint.kt new file mode 100644 index 000000000..7826cfe28 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/layout/communities/fingerprints/CommunityRecommendationSectionFingerprint.kt @@ -0,0 +1,13 @@ +package app.revanced.patches.reddit.layout.communities.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object CommunityRecommendationSectionFingerprint : MethodFingerprint( + returnType = "V", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/CommunityRecommendationSection;") + } +) \ No newline at end of file