mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +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:
@ -6,18 +6,38 @@ import static app.revanced.extension.shared.utils.Utils.hideViewUnderCondition;
|
||||
import android.view.View;
|
||||
|
||||
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.utils.VideoUtils;
|
||||
import app.revanced.extension.shared.utils.Logger;
|
||||
import app.revanced.extension.shared.utils.PackageUtils;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
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
|
||||
private static String buttonType = "";
|
||||
|
||||
public static boolean hideActionBarLabel() {
|
||||
return Settings.HIDE_ACTION_BUTTON_LABEL.get();
|
||||
return HIDE_ACTION_BUTTON_LABEL;
|
||||
}
|
||||
|
||||
public static boolean hideActionButton() {
|
||||
@ -29,24 +49,54 @@ public class ActionBarPatch {
|
||||
}
|
||||
|
||||
public static void hideLikeDislikeButton(View view) {
|
||||
final boolean enabled = Settings.HIDE_ACTION_BUTTON_LIKE_DISLIKE.get();
|
||||
hideViewUnderCondition(
|
||||
enabled,
|
||||
HIDE_ACTION_BUTTON_LIKE_DISLIKE,
|
||||
view
|
||||
);
|
||||
hideViewBy0dpUnderCondition(
|
||||
enabled,
|
||||
HIDE_ACTION_BUTTON_LIKE_DISLIKE,
|
||||
view
|
||||
);
|
||||
}
|
||||
|
||||
public static void inAppDownloadButtonOnClick(View view) {
|
||||
if (!Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.get()) {
|
||||
return;
|
||||
if (EXTERNAL_DOWNLOADER_ACTION_BUTTON &&
|
||||
buttonType.equals(ActionButton.DOWNLOAD.name)) {
|
||||
view.setOnClickListener(imageView -> VideoUtils.launchExternalDownloader());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inAppDownloadButtonOnClick(@Nullable Map<Object, Object> map) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (buttonType.equals(ActionButton.DOWNLOAD.name))
|
||||
view.setOnClickListener(imageView -> VideoUtils.launchExternalDownloader());
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user