diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt new file mode 100644 index 000000000..07b317dd1 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt @@ -0,0 +1,80 @@ +package app.revanced.patches.music.flyoutpanel.replace + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.music.flyoutpanel.replace.fingerprints.TouchOutsideFingerprint +import app.revanced.patches.music.flyoutpanel.shared.FlyoutPanelMenuItemPatch +import app.revanced.patches.music.utils.integrations.Constants.FLYOUT +import app.revanced.patches.music.utils.overridespeed.OverrideSpeedHookPatch +import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch +import app.revanced.patches.music.utils.settings.CategoryType +import app.revanced.patches.music.utils.settings.SettingsPatch +import app.revanced.util.exception +import app.revanced.util.getTargetIndexWithMethodReferenceName +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction + +@Patch( + name = "Replace report", + description = "Adds an option to replace \"Report\" with \"Playback speed\" in the flyout menu.", + dependencies = [ + FlyoutPanelMenuItemPatch::class, + OverrideSpeedHookPatch::class, + ReplaceReportResourcePatch::class, + SettingsPatch::class, + SharedResourceIdPatch::class + ], + compatiblePackages = [ + CompatiblePackage( + "com.google.android.apps.youtube.music", + [ + "6.21.52", + "6.22.52", + "6.23.56", + "6.25.53", + "6.26.51", + "6.27.54", + "6.28.53", + "6.29.58", + "6.31.55", + "6.33.52" + ] + ) + ] +) +@Suppress("unused") +object ReplaceReportPatch : BytecodePatch( + setOf(TouchOutsideFingerprint) +) { + override fun execute(context: BytecodeContext) { + FlyoutPanelMenuItemPatch.replaceComponents() + + TouchOutsideFingerprint.result?.let { + it.mutableMethod.apply { + val setOnClickListenerIndex = getTargetIndexWithMethodReferenceName("setOnClickListener") + val setOnClickListenerRegister = getInstruction(setOnClickListenerIndex).registerC + + addInstruction( + setOnClickListenerIndex + 1, + "sput-object v$setOnClickListenerRegister, $FLYOUT->touchOutSideView:Landroid/view/View;" + ) + } + } ?: throw TouchOutsideFingerprint.exception + + SettingsPatch.addMusicPreference( + CategoryType.FLYOUT, + "revanced_replace_flyout_panel_report", + "true" + ) + SettingsPatch.addMusicPreference( + CategoryType.FLYOUT, + "revanced_replace_flyout_panel_report_only_player", + "true", + "revanced_replace_flyout_panel_report" + ) + + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportResourcePatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportResourcePatch.kt new file mode 100644 index 000000000..8c4a9de90 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportResourcePatch.kt @@ -0,0 +1,29 @@ +package app.revanced.patches.music.flyoutpanel.replace + +import app.revanced.patcher.data.ResourceContext +import app.revanced.patcher.patch.ResourcePatch +import app.revanced.util.ResourceGroup +import app.revanced.util.copyResources + +object ReplaceReportResourcePatch : ResourcePatch() { + override fun execute(context: ResourceContext) { + + fun copyResources(resourceGroups: List) { + resourceGroups.forEach { context.copyResources("music/flyout", it) } + } + + val resourceFileNames = arrayOf( + "yt_outline_play_arrow_half_circle_black_24" + ).map { "$it.png" }.toTypedArray() + + fun createGroup(directory: String) = ResourceGroup( + directory, *resourceFileNames + ) + + arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi") + .map { "drawable-$it" } + .map(::createGroup) + .let(::copyResources) + + } +} \ No newline at end of file diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 1ca4bb026..2a6785533 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -195,6 +195,10 @@ This does not bypass the age restriction. It just accepts it automatically."Continue watching Replaces \"Dismiss queue\" with \"Watch on YouTube\". Replace dismiss queue + Report menu in comments will not be replaced. + Applies only to player flyout menu + Replaces \"Report\" with \"Playback speed\". + Replace report "Replace the cast button in the player with the "Open music" button. (Experimental) Known issue: If one or more music that cannot be played in the playlist, it does not work normally." Replace cast button