some code fixes
This commit is contained in:
@@ -11,15 +11,15 @@ public class ImBanner {
|
||||
private static final String TAG = "ImBanner";
|
||||
|
||||
public static JSONObject convertToBanner(JSONObject original) {
|
||||
final String PEER = "peer";
|
||||
final String ID = "id";
|
||||
final String PICTURE = "picture";
|
||||
final String TEXT = "text";
|
||||
final String LINK = "link";
|
||||
final String LINK_TEXT = "link_text";
|
||||
final String NAME = "name";
|
||||
final String BUTTONS = "buttons";
|
||||
final String ICON = "icon";
|
||||
String PEER = "peer";
|
||||
String ID = "id";
|
||||
String PICTURE = "picture";
|
||||
String TEXT = "text";
|
||||
String LINK = "link";
|
||||
String LINK_TEXT = "link_text";
|
||||
String NAME = "name";
|
||||
String BUTTONS = "buttons";
|
||||
String ICON = "icon";
|
||||
|
||||
Optional<JSONObject> user = Optional.ofNullable(original.optJSONObject(PEER));
|
||||
int userId = user.map(u -> u.optInt(ID)).orElse(0);
|
||||
|
||||
@@ -1,59 +1,60 @@
|
||||
package ru.vtosters.lite.themes.loaders;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.AssetManager;
|
||||
import ru.vtosters.lite.utils.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@SuppressLint("PrivateApi")
|
||||
public class AssetManagerHelper {
|
||||
|
||||
|
||||
// methods
|
||||
private static final Method getAssetPathMtd;
|
||||
private static final Method getApkAssetsMtd;
|
||||
private static final Method addAssetPathMtd;
|
||||
private static final Method addAssetPathAsSharedLibraryMtd;
|
||||
private static final Method addOverlayPathMtd;
|
||||
|
||||
static {
|
||||
try {
|
||||
getAssetPathMtd = ReflectionUtils.findMethod(Class.forName("android.content.res.ApkAssets"), "getAssetPath");
|
||||
getApkAssetsMtd = ReflectionUtils.findMethod(AssetManager.class, "getApkAssets");
|
||||
addAssetPathMtd = AssetManager.class.getMethod("addAssetPath", String.class);
|
||||
addAssetPathAsSharedLibraryMtd = AssetManager.class.getMethod("addAssetPathAsSharedLibrary", String.class);
|
||||
addOverlayPathMtd = AssetManager.class.getMethod("addOverlayPath", String.class);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getApkPath(Object assetManager, String packagename)
|
||||
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
public static String getApkPath(Object assetManager, String packagename) throws InvocationTargetException, IllegalAccessException {
|
||||
Object[] apkAssetsArr = (Object[]) getAssetPathMtd.invoke(assetManager);
|
||||
// By default, base apk is the last element of array if is not, for execution speed, we should iterate array from the end to the beginning
|
||||
for (int i = apkAssetsArr.length - 1; i >= 0; i--) {
|
||||
String pathname = (String) getApkAssetsMtd.invoke(apkAssetsArr[i]);
|
||||
if (pathname.contains(packagename)) return pathname;
|
||||
if (pathname != null && pathname.contains(packagename)) return pathname;
|
||||
}
|
||||
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
//region Uses for adding own assets or getting existing cookies
|
||||
public static int addAssetPath(AssetManager manager, String path)
|
||||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
return (int) addAssetPathMtd.invoke(manager, path);
|
||||
public static int addAssetPath(AssetManager manager, String path) {
|
||||
try {
|
||||
return (int) AssetManager.class.getMethod("addAssetPath", String.class).invoke(manager, path);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int addAssetPathAsSharedLibrary(AssetManager manager, String path)
|
||||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
return (int) addAssetPathAsSharedLibraryMtd.invoke(manager, path);
|
||||
public static int addAssetPathAsSharedLibrary(AssetManager manager, String path) {
|
||||
try {
|
||||
return (int) AssetManager.class.getMethod("addAssetPathAsSharedLibrary", String.class).invoke(manager, path);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int addOverlayPath(AssetManager manager, String path)
|
||||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
return (int) addOverlayPathMtd.invoke(manager, path);
|
||||
public static int addOverlayPath(AssetManager manager, String path) {
|
||||
try {
|
||||
return (int) AssetManager.class.getMethod("addOverlayPath", String.class).invoke(manager, path);
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user