revanced-integrations/app/src/main/java/app/revanced/integrations/utils/ReVancedUtils.java

71 lines
2.1 KiB
Java
Raw Normal View History

2022-06-24 00:16:32 +02:00
package app.revanced.integrations.utils;
import android.content.Context;
import android.content.res.Resources;
2022-06-24 00:16:32 +02:00
import android.os.Handler;
import android.os.Looper;
import app.revanced.integrations.sponsorblock.player.PlayerType;
2022-06-24 00:16:32 +02:00
public class ReVancedUtils {
private static PlayerType env;
public static boolean newVideo = false;
public static Context context;
public static boolean containsAny(final String value, final String... targets) {
for (String string : targets)
2022-11-19 23:22:34 +01:00
if (!string.isEmpty() && value.contains(string)) return true;
return false;
}
public static void setNewVideo(boolean started) {
LogHelper.debug(ReVancedUtils.class, "New video started: " + started);
newVideo = started;
}
public static boolean isNewVideoStarted() {
return newVideo;
}
public static Integer getResourceIdByName(Context context, String type, String name) {
try {
Resources res = context.getResources();
return res.getIdentifier(name, type, context.getPackageName());
} catch (Throwable exception) {
LogHelper.printException(ReVancedUtils.class, "Resource not found.", exception);
return null;
}
}
public static void setPlayerType(PlayerType type) {
env = type;
}
public static PlayerType getPlayerType() {
return env;
}
2022-06-24 00:16:32 +02:00
public static int getIdentifier(String name, String defType) {
Context context = getContext();
2022-06-24 00:16:32 +02:00
return context.getResources().getIdentifier(name, defType, context.getPackageName());
}
public static void runOnMainThread(Runnable runnable) {
new Handler(Looper.getMainLooper()).post(runnable);
}
public static Context getContext() {
if (context != null) {
return context;
} else {
LogHelper.printException(ReVancedUtils.class, "Context is null, returning null!");
return null;
}
}
public static boolean isTablet(Context context) {
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
}
2022-06-24 00:16:32 +02:00
}