feat(Reddit): add Hide recommended communities shelf patch https://github.com/inotia00/ReVanced_Extended/issues/2114

This commit is contained in:
inotia00 2024-06-22 20:11:30 +09:00
parent e1f3da76c4
commit 130a5871bd
2 changed files with 58 additions and 0 deletions

View File

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

View File

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