|
1 | 1 | package app.revanced.integrations.patches; |
2 | 2 |
|
3 | | -import android.os.Build; |
4 | | - |
5 | | -import androidx.annotation.RequiresApi; |
| 3 | +import app.revanced.integrations.settings.SettingsEnum; |
| 4 | +import app.revanced.integrations.utils.LogHelper; |
6 | 5 |
|
7 | 6 | import java.nio.ByteBuffer; |
8 | 7 | import java.nio.charset.StandardCharsets; |
9 | 8 | import java.util.ArrayList; |
10 | 9 | import java.util.List; |
11 | 10 |
|
12 | | -import app.revanced.integrations.settings.SettingsEnum; |
13 | | -import app.revanced.integrations.utils.LogHelper; |
14 | | - |
15 | 11 | public class GeneralBytecodeAdsPatch { |
16 | 12 |
|
17 | 13 | //Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch |
@@ -59,7 +55,7 @@ private static boolean containsLithoAd(String value, ByteBuffer buffer) { |
59 | 55 | bufferBlockList.add("YouTube Movies"); |
60 | 56 | } |
61 | 57 | if (containsAny(value, "home_video_with_context", "related_video_with_context") && |
62 | | - bufferBlockList.stream().anyMatch(new String(buffer.array(), StandardCharsets.UTF_8)::contains) |
| 58 | + anyMatch(bufferBlockList, new String(buffer.array(), StandardCharsets.UTF_8)::contains) |
63 | 59 | ) return true; |
64 | 60 |
|
65 | 61 | if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) { |
@@ -117,7 +113,7 @@ private static boolean containsLithoAd(String value, ByteBuffer buffer) { |
117 | 113 | "-button" |
118 | 114 | )) return false; |
119 | 115 |
|
120 | | - if (blockList.stream().anyMatch(value::contains)) { |
| 116 | + if (anyMatch(blockList, value::contains)) { |
121 | 117 | LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + value); |
122 | 118 | return true; |
123 | 119 | } |
@@ -149,4 +145,15 @@ private static String bytesToHex(byte[] bytes) { |
149 | 145 | return builder.toString(); |
150 | 146 | } |
151 | 147 |
|
| 148 | + private static <T> boolean anyMatch(List<T> value, APredicate<? super T> predicate) { |
| 149 | + for (T t : value) { |
| 150 | + if (predicate.test(t)) return true; |
| 151 | + } |
| 152 | + return false; |
| 153 | + } |
| 154 | + |
| 155 | + @FunctionalInterface |
| 156 | + public interface APredicate<T> { |
| 157 | + boolean test(T t); |
| 158 | + } |
152 | 159 | } |
0 commit comments