mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-24 02:42:11 +02:00
feat(YouTube Music - Hide action bar components): Add support for setting Override Download action button
on YouTube Music 7.25.53+ https://github.com/inotia00/ReVanced_Extended/issues/2733
This commit is contained in:
parent
835f6759f8
commit
9adcdbfbc7
@ -6,18 +6,38 @@ import static app.revanced.extension.shared.utils.Utils.hideViewUnderCondition;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.facebook.litho.ComponentHost;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import app.revanced.extension.music.settings.Settings;
|
import app.revanced.extension.music.settings.Settings;
|
||||||
import app.revanced.extension.music.utils.VideoUtils;
|
import app.revanced.extension.music.utils.VideoUtils;
|
||||||
|
import app.revanced.extension.shared.utils.Logger;
|
||||||
|
import app.revanced.extension.shared.utils.PackageUtils;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class ActionBarPatch {
|
public class ActionBarPatch {
|
||||||
|
private static final boolean HIDE_ACTION_BUTTON_LABEL =
|
||||||
|
Settings.HIDE_ACTION_BUTTON_LABEL.get();
|
||||||
|
private static final boolean HIDE_ACTION_BUTTON_LIKE_DISLIKE =
|
||||||
|
Settings.HIDE_ACTION_BUTTON_LIKE_DISLIKE.get() || PackageUtils.getAppVersionName().compareTo("7.25.00") >= 0;
|
||||||
|
private static final boolean EXTERNAL_DOWNLOADER_ACTION_BUTTON =
|
||||||
|
Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.get();
|
||||||
|
private static final boolean SETTINGS_INITIALIZED =
|
||||||
|
Settings.SETTINGS_INITIALIZED.get();
|
||||||
|
private static final String ELEMENTS_SENDER_VIEW =
|
||||||
|
"com.google.android.libraries.youtube.rendering.elements.sender_view";
|
||||||
|
private static final String EXTERNAL_DOWNLOADER_LAUNCHED =
|
||||||
|
"external_downloader_launched";
|
||||||
|
private static String downloadButtonLabel = "";
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static String buttonType = "";
|
private static String buttonType = "";
|
||||||
|
|
||||||
public static boolean hideActionBarLabel() {
|
public static boolean hideActionBarLabel() {
|
||||||
return Settings.HIDE_ACTION_BUTTON_LABEL.get();
|
return HIDE_ACTION_BUTTON_LABEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hideActionButton() {
|
public static boolean hideActionButton() {
|
||||||
@ -29,24 +49,54 @@ public class ActionBarPatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void hideLikeDislikeButton(View view) {
|
public static void hideLikeDislikeButton(View view) {
|
||||||
final boolean enabled = Settings.HIDE_ACTION_BUTTON_LIKE_DISLIKE.get();
|
|
||||||
hideViewUnderCondition(
|
hideViewUnderCondition(
|
||||||
enabled,
|
HIDE_ACTION_BUTTON_LIKE_DISLIKE,
|
||||||
view
|
view
|
||||||
);
|
);
|
||||||
hideViewBy0dpUnderCondition(
|
hideViewBy0dpUnderCondition(
|
||||||
enabled,
|
HIDE_ACTION_BUTTON_LIKE_DISLIKE,
|
||||||
view
|
view
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void inAppDownloadButtonOnClick(View view) {
|
public static void inAppDownloadButtonOnClick(View view) {
|
||||||
if (!Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.get()) {
|
if (EXTERNAL_DOWNLOADER_ACTION_BUTTON &&
|
||||||
return;
|
buttonType.equals(ActionButton.DOWNLOAD.name)) {
|
||||||
|
view.setOnClickListener(imageView -> VideoUtils.launchExternalDownloader());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonType.equals(ActionButton.DOWNLOAD.name))
|
public static boolean inAppDownloadButtonOnClick(@Nullable Map<Object, Object> map) {
|
||||||
view.setOnClickListener(imageView -> VideoUtils.launchExternalDownloader());
|
try {
|
||||||
|
if (EXTERNAL_DOWNLOADER_ACTION_BUTTON &&
|
||||||
|
!downloadButtonLabel.isEmpty() &&
|
||||||
|
map != null &&
|
||||||
|
map.get(ELEMENTS_SENDER_VIEW) instanceof ComponentHost componentHost &&
|
||||||
|
componentHost.getContentDescription().toString().equals(downloadButtonLabel)
|
||||||
|
) {
|
||||||
|
if (!map.containsKey(EXTERNAL_DOWNLOADER_LAUNCHED)) {
|
||||||
|
map.put(EXTERNAL_DOWNLOADER_LAUNCHED, Boolean.TRUE);
|
||||||
|
VideoUtils.runOnMainThreadDelayed(VideoUtils::launchExternalDownloader, 0);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.printException(() -> "inAppDownloadButtonOnClick failed", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CharSequence onLithoTextLoaded(@NonNull Object conversionContext,
|
||||||
|
@NonNull CharSequence original) {
|
||||||
|
if (EXTERNAL_DOWNLOADER_ACTION_BUTTON &&
|
||||||
|
downloadButtonLabel.isEmpty() &&
|
||||||
|
conversionContext.toString().contains("music_download_button.eml")) {
|
||||||
|
downloadButtonLabel = original.toString();
|
||||||
|
Logger.printDebug(() -> "set download button label: " + original);
|
||||||
|
}
|
||||||
|
|
||||||
|
return original;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setButtonType(@NonNull Object obj) {
|
public static void setButtonType(@NonNull Object obj) {
|
||||||
|
@ -23,6 +23,8 @@ import app.revanced.patches.music.utils.settings.settingsPatch
|
|||||||
import app.revanced.patches.music.video.information.videoInformationPatch
|
import app.revanced.patches.music.video.information.videoInformationPatch
|
||||||
import app.revanced.patches.shared.litho.addLithoFilter
|
import app.revanced.patches.shared.litho.addLithoFilter
|
||||||
import app.revanced.patches.shared.litho.lithoFilterPatch
|
import app.revanced.patches.shared.litho.lithoFilterPatch
|
||||||
|
import app.revanced.patches.shared.textcomponent.hookSpannableString
|
||||||
|
import app.revanced.patches.shared.textcomponent.textComponentPatch
|
||||||
import app.revanced.util.fingerprint.matchOrThrow
|
import app.revanced.util.fingerprint.matchOrThrow
|
||||||
import app.revanced.util.fingerprint.methodOrThrow
|
import app.revanced.util.fingerprint.methodOrThrow
|
||||||
import app.revanced.util.getReference
|
import app.revanced.util.getReference
|
||||||
@ -50,6 +52,7 @@ val actionBarComponentsPatch = bytecodePatch(
|
|||||||
settingsPatch,
|
settingsPatch,
|
||||||
lithoFilterPatch,
|
lithoFilterPatch,
|
||||||
sharedResourceIdPatch,
|
sharedResourceIdPatch,
|
||||||
|
textComponentPatch,
|
||||||
videoInformationPatch,
|
videoInformationPatch,
|
||||||
versionCheckPatch,
|
versionCheckPatch,
|
||||||
)
|
)
|
||||||
@ -57,6 +60,23 @@ val actionBarComponentsPatch = bytecodePatch(
|
|||||||
execute {
|
execute {
|
||||||
if (is_7_17_or_greater) {
|
if (is_7_17_or_greater) {
|
||||||
addLithoFilter(FILTER_CLASS_DESCRIPTOR)
|
addLithoFilter(FILTER_CLASS_DESCRIPTOR)
|
||||||
|
hookSpannableString(ACTIONBAR_CLASS_DESCRIPTOR, "onLithoTextLoaded")
|
||||||
|
|
||||||
|
commandResolverFingerprint.methodOrThrow().addInstruction(
|
||||||
|
0,
|
||||||
|
"invoke-static {p2}, $ACTIONBAR_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick(Ljava/util/Map;)Z"
|
||||||
|
)
|
||||||
|
|
||||||
|
offlineVideoEndpointFingerprint.methodOrThrow().addInstructionsWithLabels(
|
||||||
|
0, """
|
||||||
|
invoke-static {p2}, $ACTIONBAR_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick(Ljava/util/Map;)Z
|
||||||
|
move-result v0
|
||||||
|
if-eqz v0, :ignore
|
||||||
|
return-void
|
||||||
|
:ignore
|
||||||
|
nop
|
||||||
|
"""
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_7_25_or_greater) {
|
if (!is_7_25_or_greater) {
|
||||||
@ -181,12 +201,12 @@ val actionBarComponentsPatch = bytecodePatch(
|
|||||||
)
|
)
|
||||||
addSwitchPreference(
|
addSwitchPreference(
|
||||||
CategoryType.ACTION_BAR,
|
CategoryType.ACTION_BAR,
|
||||||
"revanced_hide_action_button_share",
|
"revanced_hide_action_button_radio",
|
||||||
"false"
|
"false"
|
||||||
)
|
)
|
||||||
addSwitchPreference(
|
addSwitchPreference(
|
||||||
CategoryType.ACTION_BAR,
|
CategoryType.ACTION_BAR,
|
||||||
"revanced_hide_action_button_radio",
|
"revanced_hide_action_button_share",
|
||||||
"false"
|
"false"
|
||||||
)
|
)
|
||||||
if (!is_7_25_or_greater) {
|
if (!is_7_25_or_greater) {
|
||||||
@ -195,6 +215,7 @@ val actionBarComponentsPatch = bytecodePatch(
|
|||||||
"revanced_hide_action_button_label",
|
"revanced_hide_action_button_label",
|
||||||
"false"
|
"false"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
addSwitchPreference(
|
addSwitchPreference(
|
||||||
CategoryType.ACTION_BAR,
|
CategoryType.ACTION_BAR,
|
||||||
"revanced_external_downloader_action",
|
"revanced_external_downloader_action",
|
||||||
@ -205,7 +226,6 @@ val actionBarComponentsPatch = bytecodePatch(
|
|||||||
"revanced_external_downloader_package_name",
|
"revanced_external_downloader_package_name",
|
||||||
"revanced_external_downloader_action"
|
"revanced_external_downloader_action"
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
updatePatchStatus(HIDE_ACTION_BAR_COMPONENTS)
|
updatePatchStatus(HIDE_ACTION_BAR_COMPONENTS)
|
||||||
|
|
||||||
|
@ -28,3 +28,19 @@ internal val likeDislikeContainerFingerprint = legacyFingerprint(
|
|||||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
|
||||||
literals = listOf(likeDislikeContainer)
|
literals = listOf(likeDislikeContainer)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internal val commandResolverFingerprint = legacyFingerprint(
|
||||||
|
name = "commandResolverFingerprint",
|
||||||
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.FINAL,
|
||||||
|
returnType = "Z",
|
||||||
|
parameters = listOf("L", "L", "Ljava/util/Map;"),
|
||||||
|
strings = listOf("CommandResolver threw exception during resolution")
|
||||||
|
)
|
||||||
|
|
||||||
|
internal val offlineVideoEndpointFingerprint = legacyFingerprint(
|
||||||
|
name = "offlineVideoEndpointFingerprint",
|
||||||
|
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||||
|
returnType = "V",
|
||||||
|
parameters = listOf("L", "Ljava/util/Map;"),
|
||||||
|
strings = listOf("Object is not an offlineable video: %s")
|
||||||
|
)
|
||||||
|
@ -34,10 +34,10 @@
|
|||||||
<string name="revanced_hide_action_button_add_to_playlist_summary">Hides the Save button.</string>
|
<string name="revanced_hide_action_button_add_to_playlist_summary">Hides the Save button.</string>
|
||||||
<string name="revanced_hide_action_button_download_title">Hide Download button</string>
|
<string name="revanced_hide_action_button_download_title">Hide Download button</string>
|
||||||
<string name="revanced_hide_action_button_download_summary">Hides the Download button.</string>
|
<string name="revanced_hide_action_button_download_summary">Hides the Download button.</string>
|
||||||
<string name="revanced_hide_action_button_share_title">Hide Share button</string>
|
|
||||||
<string name="revanced_hide_action_button_share_summary">Hides the Share button.</string>
|
|
||||||
<string name="revanced_hide_action_button_radio_title">Hide Radio button</string>
|
<string name="revanced_hide_action_button_radio_title">Hide Radio button</string>
|
||||||
<string name="revanced_hide_action_button_radio_summary">Hides the Radio button.</string>
|
<string name="revanced_hide_action_button_radio_summary">Hides the Radio button.</string>
|
||||||
|
<string name="revanced_hide_action_button_share_title">Hide Share button</string>
|
||||||
|
<string name="revanced_hide_action_button_share_summary">Hides the Share button.</string>
|
||||||
<string name="revanced_hide_action_button_label_title">Hide action button labels</string>
|
<string name="revanced_hide_action_button_label_title">Hide action button labels</string>
|
||||||
<string name="revanced_hide_action_button_label_summary">Hides the labels of the action buttons.</string>
|
<string name="revanced_hide_action_button_label_summary">Hides the labels of the action buttons.</string>
|
||||||
<string name="revanced_external_downloader_action_title">Override Download action button</string>
|
<string name="revanced_external_downloader_action_title">Override Download action button</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user