This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Hide ads): add
Close fullscreen ads
settings inotia00/ReVanced…
- Loading branch information
Showing
7 changed files
with
116 additions
and
66 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
app/src/main/java/app/revanced/integrations/music/patches/ads/FullscreenAdsPatch.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/src/main/java/app/revanced/integrations/shared/patches/FullscreenAdsPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package app.revanced.integrations.shared.patches; | ||
|
||
import static app.revanced.integrations.shared.utils.StringRef.str; | ||
import static app.revanced.integrations.shared.utils.Utils.hideViewBy0dpUnderCondition; | ||
import static app.revanced.integrations.shared.utils.Utils.showToastShort; | ||
|
||
import android.view.View; | ||
import android.widget.Button; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.Arrays; | ||
|
||
import app.revanced.integrations.shared.settings.BaseSettings; | ||
import app.revanced.integrations.shared.utils.Logger; | ||
import app.revanced.integrations.shared.utils.Utils; | ||
|
||
@SuppressWarnings("unused") | ||
public class FullscreenAdsPatch { | ||
private static final boolean hideFullscreenAdsEnabled = BaseSettings.HIDE_FULLSCREEN_ADS.get(); | ||
private static final boolean closeFullscreenAdsEnabled = BaseSettings.HIDE_FULLSCREEN_ADS_TYPE.get(); | ||
private static final boolean closeDialog = hideFullscreenAdsEnabled && closeFullscreenAdsEnabled; | ||
private static final boolean disableDialog = hideFullscreenAdsEnabled && !closeFullscreenAdsEnabled; | ||
|
||
private static WeakReference<Button> buttonRef = new WeakReference<>(null); | ||
|
||
public static boolean disableFullscreenAds(int code) { | ||
if (!disableDialog) return false; | ||
|
||
final DialogType dialogType = DialogType.getDialogType(code); | ||
final String dialogName = dialogType.name(); | ||
Logger.printDebug(() -> "DialogType: " + dialogName); | ||
|
||
// This method is also invoked in the 'Create new playlist' dialog, | ||
// in which case the DialogType is {@code DialogType.ALERT}. | ||
if (dialogType == DialogType.ALERT) return false; | ||
|
||
showToastShort(str("revanced_hide_fullscreen_ads_blocked_success", dialogName)); | ||
return true; | ||
} | ||
|
||
public static void setCloseButton(final Button button) { | ||
if (!closeDialog) return; | ||
buttonRef = new WeakReference<>(button); | ||
} | ||
|
||
public static void closeFullscreenAds() { | ||
if (!closeDialog) return; | ||
|
||
Utils.runOnMainThreadDelayed(() -> { | ||
final Button button = buttonRef.get(); | ||
if (button == null) return; | ||
button.callOnClick(); | ||
showToastShort(str("revanced_hide_fullscreen_ads_closed_success")); | ||
}, 100); | ||
} | ||
|
||
public static void hideFullscreenAds(View view) { | ||
hideViewBy0dpUnderCondition( | ||
hideFullscreenAdsEnabled, | ||
view | ||
); | ||
} | ||
|
||
private enum DialogType { | ||
NULL(0), | ||
ALERT(1), | ||
FULLSCREEN(2), | ||
LAYOUT_FULLSCREEN(3); | ||
|
||
private final int code; | ||
|
||
DialogType(int code) { | ||
this.code = code; | ||
} | ||
|
||
private static DialogType getDialogType(int code){ | ||
return Arrays.stream(values()) | ||
.filter(val -> code == val.code) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...rc/main/java/app/revanced/integrations/shared/patches/components/FullscreenAdsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package app.revanced.integrations.shared.patches.components; | ||
|
||
import static app.revanced.integrations.shared.patches.FullscreenAdsPatch.closeFullscreenAds; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import app.revanced.integrations.shared.settings.BaseSettings; | ||
|
||
@SuppressWarnings("unused") | ||
public final class FullscreenAdsFilter extends Filter { | ||
|
||
public FullscreenAdsFilter() { | ||
addPathCallbacks( | ||
new StringFilterGroup( | ||
BaseSettings.HIDE_FULLSCREEN_ADS, | ||
"_interstitial" | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean isFiltered(String path, @Nullable String identifier, String allValue, byte[] protobufBufferArray, | ||
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) { | ||
if (path.contains("|ImageType|")) closeFullscreenAds(); | ||
|
||
return false; // Do not actually filter the fullscreen ad otherwise it will leave a dimmed screen. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters