2022-06-24 00:16:32 +02:00
|
|
|
package app.revanced.integrations.utils;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2022-06-27 22:08:50 +02:00
|
|
|
import android.content.res.Resources;
|
2022-06-24 00:16:32 +02:00
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Looper;
|
|
|
|
|
2022-06-27 22:08:50 +02:00
|
|
|
import app.revanced.integrations.sponsorblock.player.PlayerType;
|
2022-06-24 00:16:32 +02:00
|
|
|
|
|
|
|
public class ReVancedUtils {
|
|
|
|
|
2022-06-27 22:08:50 +02:00
|
|
|
private static PlayerType env;
|
2022-07-24 22:28:38 +02:00
|
|
|
public static boolean newVideo = false;
|
2022-06-27 22:08:50 +02:00
|
|
|
|
|
|
|
public static Context context;
|
2022-10-29 01:54:03 +02:00
|
|
|
|
|
|
|
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;
|
2022-10-29 01:54:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
2022-06-27 22:08:50 +02:00
|
|
|
|
2022-07-05 22:31:13 +02:00
|
|
|
public static void setNewVideo(boolean started) {
|
|
|
|
LogHelper.debug(ReVancedUtils.class, "New video started: " + started);
|
|
|
|
newVideo = started;
|
|
|
|
}
|
2022-10-29 01:54:03 +02:00
|
|
|
|
2022-07-05 22:31:13 +02:00
|
|
|
public static boolean isNewVideoStarted() {
|
|
|
|
return newVideo;
|
|
|
|
}
|
|
|
|
|
2022-07-11 14:29:39 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 22:08:50 +02:00
|
|
|
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) {
|
2022-06-27 22:08:50 +02:00
|
|
|
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);
|
|
|
|
}
|
2022-06-27 22:08:50 +02:00
|
|
|
|
|
|
|
public static Context getContext() {
|
|
|
|
if (context != null) {
|
|
|
|
return context;
|
|
|
|
} else {
|
2022-06-30 13:54:00 +02:00
|
|
|
LogHelper.printException(ReVancedUtils.class, "Context is null, returning null!");
|
2022-06-27 22:08:50 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2022-07-14 18:42:43 +02:00
|
|
|
|
|
|
|
public static boolean isTablet(Context context) {
|
|
|
|
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
|
|
|
|
}
|
2022-06-24 00:16:32 +02:00
|
|
|
}
|