Skip to content

Commit

Permalink
fix: android api 23 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Sculas committed Sep 8, 2022
1 parent ab9587d commit 136fb7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 1 addition & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {

defaultConfig {
applicationId "app.revanced.integrations"
minSdkVersion 24
minSdkVersion 23
targetSdkVersion 32
versionCode 1
versionName "1.0"
Expand All @@ -34,8 +34,6 @@ android {
}

dependencies {
//implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.22.1'

compileOnly 'androidx.annotation:annotation:1.4.0'
}

Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package app.revanced.integrations.patches;

import android.os.Build;

import androidx.annotation.RequiresApi;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;

public class GeneralBytecodeAdsPatch {

//Used by app.revanced.patches.youtube.ad.general.bytecode.patch.GeneralBytecodeAdsPatch
Expand Down Expand Up @@ -59,7 +55,7 @@ private static boolean containsLithoAd(String value, ByteBuffer buffer) {
bufferBlockList.add("YouTube Movies");
}
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;

if (SettingsEnum.ADREMOVER_COMMENTS_REMOVAL.getBoolean()) {
Expand Down Expand Up @@ -117,7 +113,7 @@ private static boolean containsLithoAd(String value, ByteBuffer buffer) {
"-button"
)) return false;

if (blockList.stream().anyMatch(value::contains)) {
if (anyMatch(blockList, value::contains)) {
LogHelper.debug(GeneralBytecodeAdsPatch.class, "Blocking ad: " + value);
return true;
}
Expand Down Expand Up @@ -149,4 +145,15 @@ private static String bytesToHex(byte[] bytes) {
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);
}
}

0 comments on commit 136fb7b

Please sign in to comment.