From 40a09ed46b57842816c12fac0056287f63a9a1e5 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Thu, 6 Apr 2023 20:03:25 +0900 Subject: [PATCH] add `enable-compact-dialog` patch --- .../fingerprints/DialogSolidFingerprint.kt | 26 +++++++++ .../compactdialog/patch/CompactDialogPatch.kt | 58 +++++++++++++++++++ .../resourceid/patch/SharedResourceIdPatch.kt | 2 + .../music/settings/host/values/strings.xml | 2 + 4 files changed, 88 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/compactdialog/fingerprints/DialogSolidFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/music/layout/compactdialog/patch/CompactDialogPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/music/layout/compactdialog/fingerprints/DialogSolidFingerprint.kt b/src/main/kotlin/app/revanced/patches/music/layout/compactdialog/fingerprints/DialogSolidFingerprint.kt new file mode 100644 index 000000000..b54b1a61d --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/compactdialog/fingerprints/DialogSolidFingerprint.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.music.layout.compactdialog.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object DialogSolidFingerprint : MethodFingerprint( + returnType = "V", + access = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf("L"), + opcodes = listOf( + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_STATIC + ), + customFingerprint = { methodDef -> + methodDef.implementation?.instructions?.any { + it.opcode.ordinal == Opcode.CONST.ordinal && + (it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.dialogSolidLabelId + } == true + } +) + diff --git a/src/main/kotlin/app/revanced/patches/music/layout/compactdialog/patch/CompactDialogPatch.kt b/src/main/kotlin/app/revanced/patches/music/layout/compactdialog/patch/CompactDialogPatch.kt new file mode 100644 index 000000000..6b998b74b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/music/layout/compactdialog/patch/CompactDialogPatch.kt @@ -0,0 +1,58 @@ +package app.revanced.patches.music.layout.compactdialog.patch + +import app.revanced.extensions.toErrorResult +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.data.toMethodWalker +import app.revanced.patcher.extensions.addInstructions +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.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.music.layout.compactdialog.fingerprints.DialogSolidFingerprint +import app.revanced.patches.music.misc.resourceid.patch.SharedResourceIdPatch +import app.revanced.patches.music.misc.settings.patch.MusicSettingsPatch +import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility +import app.revanced.util.integrations.Constants.MUSIC_SETTINGS_PATH + +@Patch +@Name("enable-compact-dialog") +@Description("Enable compact dialog on phone.") +@DependsOn( + [ + MusicSettingsPatch::class, + SharedResourceIdPatch::class + ] +) +@YouTubeMusicCompatibility +@Version("0.0.1") +class CompactDialogPatch : BytecodePatch( + listOf( + DialogSolidFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + DialogSolidFingerprint.result?.let { + with(context + .toMethodWalker(it.method) + .nextMethod(it.scanResult.patternScanResult!!.endIndex, true) + .getMethod() as MutableMethod + ) { + addInstructions( + 2, """ + invoke-static {p0}, $MUSIC_SETTINGS_PATH->enableCompactDialog(I)I + move-result p0 + """ + ) + } + } ?: return DialogSolidFingerprint.toErrorResult() + + MusicSettingsPatch.addMusicPreference("navigation", "revanced_enable_compact_dialog", "true") + + return PatchResultSuccess() + } +} diff --git a/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt index b231a07f0..7c0ba3beb 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/resourceid/patch/SharedResourceIdPatch.kt @@ -17,6 +17,7 @@ import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch class SharedResourceIdPatch : ResourcePatch { internal companion object { var colorGreyLabelId: Long = -1 + var dialogSolidLabelId: Long = -1 var disabledIconLabelId: Long = -1 var isTabletLabelId: Long = -1 } @@ -28,6 +29,7 @@ class SharedResourceIdPatch : ResourcePatch { .single { it.type == type && it.name == name }.id colorGreyLabelId = findSharedResourceId("color", "ytm_color_grey_12") + dialogSolidLabelId = findSharedResourceId("style", "Theme.YouTubeMusic.Dialog.Solid") disabledIconLabelId = findSharedResourceId("dimen", "disabled_icon_alpha") isTabletLabelId = findSharedResourceId("bool", "is_tablet") diff --git a/src/main/resources/music/settings/host/values/strings.xml b/src/main/resources/music/settings/host/values/strings.xml index 4f37ce54f..9b1c7ff20 100644 --- a/src/main/resources/music/settings/host/values/strings.xml +++ b/src/main/resources/music/settings/host/values/strings.xml @@ -10,6 +10,8 @@ Enable black navbar Matches the fullscreen player color with the minimized one. Enable color match Players + Enable compact dialog on phone. + Enable compact dialog Keep player permanently minimized even if another track is played. Enable force minimized player Enable force shuffle even if another track is played.