fix: android api 23 compat

Fixes revanced/revanced-integrations#136
This commit is contained in:
Sculas 2022-09-08 12:19:50 +02:00
parent ab9587df5a
commit 136fb7bcbb
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89
2 changed files with 16 additions and 11 deletions

View File

@ -7,7 +7,7 @@ android {
defaultConfig { defaultConfig {
applicationId "app.revanced.integrations" applicationId "app.revanced.integrations"
minSdkVersion 24 minSdkVersion 23
targetSdkVersion 32 targetSdkVersion 32
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
@ -34,8 +34,6 @@ android {
} }
dependencies { dependencies {
//implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.22.1'
compileOnly 'androidx.annotation:annotation:1.4.0' compileOnly 'androidx.annotation:annotation:1.4.0'
} }

View File

@ -1,17 +1,13 @@
package app.revanced.integrations.patches; package app.revanced.integrations.patches;
import android.os.Build; import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import androidx.annotation.RequiresApi;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
public class GeneralBytecodeAdsPatch { public class GeneralBytecodeAdsPatch {
//Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch //Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
@ -59,7 +55,7 @@ public class GeneralBytecodeAdsPatch {
bufferBlockList.add("YouTube Movies"); bufferBlockList.add("YouTube Movies");
} }
if (containsAny(value, "home_video_with_context", "related_video_with_context") && if (containsAny(value, "home_video_with_context", "related_video_with_context") &&
bufferBlockList.stream().anyMatch(new String(buffer.array(), StandardCharsets.UTF_8)::contains) anyMatch(bufferBlockList, new String(buffer.array(), StandardCharsets.UTF_8)::contains)
) return true; ) return true;
if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) { if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) {
@ -117,7 +113,7 @@ public class GeneralBytecodeAdsPatch {
"-button" "-button"
)) return false; )) return false;
if (blockList.stream().anyMatch(value::contains)) { if (anyMatch(blockList, value::contains)) {
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + value); LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + value);
return true; return true;
} }
@ -149,4 +145,15 @@ public class GeneralBytecodeAdsPatch {
return builder.toString(); return builder.toString();
} }
private static <T> boolean anyMatch(List<T> value, APredicate<? super T> predicate) {
for (T t : value) {
if (predicate.test(t)) return true;
}
return false;
}
@FunctionalInterface
public interface APredicate<T> {
boolean test(T t);
}
} }