Skip to content

Commit

Permalink
Merge branch 'dev' into revanced-extended
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Feb 13, 2025
2 parents 9146d92 + 6ee7649 commit 1926bec
Show file tree
Hide file tree
Showing 308 changed files with 9,566 additions and 5,983 deletions.
115 changes: 60 additions & 55 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,46 @@
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 CHANGE_ACTION_BAR_POSITION =
Settings.CHANGE_ACTION_BAR_POSITION.get();
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 changeActionBarPosition(boolean original) {
return SETTINGS_INITIALIZED
? CHANGE_ACTION_BAR_POSITION
: original;
}

public static boolean hideActionBarLabel() {
return Settings.HIDE_ACTION_BUTTON_LABEL.get();
return HIDE_ACTION_BUTTON_LABEL;
}

public static boolean hideActionButton() {
Expand All @@ -29,24 +57,54 @@ public static boolean hideActionButton() {
}

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());
}
}

if (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);
}

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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
package app.revanced.extension.music.patches.ads;

import static app.revanced.extension.music.patches.general.GeneralPatch.disableDimBehind;
import static app.revanced.extension.shared.utils.StringRef.str;

import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.shared.settings.BaseSettings;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.shared.utils.Utils;

@SuppressWarnings("unused")
public class PremiumPromotionPatch {
private static final boolean HIDE_PREMIUM_PROMOTION =
Settings.HIDE_PREMIUM_PROMOTION.get();

public static void hidePremiumPromotion(View view) {
if (!Settings.HIDE_PREMIUM_PROMOTION.get())
return;

view.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
try {
if (!(view instanceof ViewGroup viewGroup)) {
return;
}
if (!(viewGroup.getChildAt(0) instanceof ViewGroup mealBarLayoutRoot)) {
return;
}
if (!(mealBarLayoutRoot.getChildAt(0) instanceof LinearLayout linearLayout)) {
return;
public static void hidePremiumPromotionBottomSheet(View view) {
if (HIDE_PREMIUM_PROMOTION) {
view.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
try {
if (!(view instanceof ViewGroup viewGroup)) {
return;
}
if (!(viewGroup.getChildAt(0) instanceof ViewGroup mealBarLayoutRoot)) {
return;
}
if (!(mealBarLayoutRoot.getChildAt(0) instanceof LinearLayout linearLayout)) {
return;
}
if (!(linearLayout.getChildAt(0) instanceof ImageView imageView)) {
return;
}
if (imageView.getVisibility() == View.VISIBLE) {
view.setVisibility(View.GONE);
}
} catch (Exception ex) {
Logger.printException(() -> "hidePremiumPromotionBottomSheet failure", ex);
}
if (!(linearLayout.getChildAt(0) instanceof ImageView imageView)) {
return;
}
if (imageView.getVisibility() == View.VISIBLE) {
view.setVisibility(View.GONE);
}
} catch (Exception ex) {
Logger.printException(() -> "hideGetPremium failure", ex);
});
}
}

public static void hidePremiumPromotionDialog(Dialog dialog, View contentView) {
if (HIDE_PREMIUM_PROMOTION) {
disableDimBehind(dialog.getWindow());
dialog.setOnShowListener(DialogInterface::dismiss);
if (BaseSettings.ENABLE_DEBUG_LOGGING.get()) {
Utils.showToastShort(str("revanced_hide_premium_promotion_closed_toast"));
}
});
} else {
dialog.setContentView(contentView);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,43 @@
import android.widget.TextView;

import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.shared.utils.Logger;
import app.revanced.extension.music.shared.NavigationBar;
import app.revanced.extension.shared.utils.Utils;

@SuppressWarnings("unused")
public class PremiumRenewalPatch {
private static final String dialogGotItText =
str("dialog_got_it_text");

public static void hidePremiumRenewal(LinearLayout buttonContainerView) {
if (!Settings.HIDE_PREMIUM_RENEWAL.get())
return;

buttonContainerView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
try {
Utils.runOnMainThreadDelayed(() -> {
if (!(buttonContainerView.getChildAt(0) instanceof ViewGroup closeButtonParentView))
return;
if (!(closeButtonParentView.getChildAt(0) instanceof TextView closeButtonView))
return;
if (closeButtonView.getText().toString().equals(str("dialog_got_it_text")))
Utils.clickView(closeButtonView);
else
Utils.hideViewByLayoutParams((View) buttonContainerView.getParent());
}, 0
);
} catch (Exception ex) {
Logger.printException(() -> "hidePremiumRenewal failure", ex);
if (NavigationBar.getNavigationTabIndex() == 0) {
// Always hide the banner when the navigation bar index is 0.
hideParentViewByLayoutParams(buttonContainerView);
} else {
// This banner is exposed to the library as well as the home.
// In this case, it is necessary to check whether the text of the button is 'Got it' or not.
if (!(buttonContainerView.getChildAt(0) instanceof ViewGroup closeButtonParentView))
return;
if (!(closeButtonParentView.getChildAt(0) instanceof TextView closeButtonView))
return;
// If the text of the button is 'Got it', just click the button.
// If not, tab sometimes becomes freezing.
if (closeButtonView.getText().toString().equals(dialogGotItText)) {
Utils.clickView(closeButtonView);
} else {
hideParentViewByLayoutParams(buttonContainerView);
}
}
});
}

private static void hideParentViewByLayoutParams(View view) {
if (view.getParent() instanceof View parentView) {
Utils.hideViewByLayoutParams(parentView);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ public ActionButtonsFilter() {
Settings.HIDE_ACTION_BUTTON_LIKE_DISLIKE,
"segmented_like_dislike_button.eml"
);
final StringFilterGroup songVideoButton = new StringFilterGroup(
Settings.HIDE_ACTION_BUTTON_SONG_VIDEO,
"music_audio_video_button.eml"
);
addPathCallbacks(
bufferFilterPathRule,
downloadButton,
likeDislikeContainer
likeDislikeContainer,
songVideoButton
);

bufferButtonsGroupList.addAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public PlayerFlyoutMenuFilter() {
Settings.HIDE_FLYOUT_MENU_3_COLUMN_COMPONENT,
"music_highlight_menu_item_carousel.eml",
"tile_button_carousel.eml"
),
new StringFilterGroup(
Settings.HIDE_FLYOUT_MENU_DOWNLOAD,
"list_item.eml"
)
);
}
Expand Down
Loading

0 comments on commit 1926bec

Please sign in to comment.