package com.airbnb.lottie; import android.content.Context; import android.content.res.AssetManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.view.MotionEvent; import android.view.ViewConfiguration; import com.airbnb.lottie.model.LottieCompositionCache; import com.airbnb.lottie.parser.LottieCompositionMoshiParser; import com.airbnb.lottie.parser.moshi.JsonReader; import com.airbnb.lottie.utils.Logger; import com.airbnb.lottie.utils.Utils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import o.C15160gio; import o.InterfaceC15149gid; import o.xzZ; import org.json.JSONObject; /* loaded from: classes.dex */ public class LottieCompositionFactory { private static int a = 0; private static int c = 1; private static final Map> taskCache = new HashMap(); private static final byte[] MAGIC = {80, 75, 3, 4}; private LottieCompositionFactory() { } public static void setMaxCacheSize(int i) { LottieCompositionCache.getInstance().resize(i); } public static void clearCache(Context context) { taskCache.clear(); LottieCompositionCache.getInstance().clear(); L.networkCache(context).clear(); } public static LottieTask fromUrl(Context context, String str) { return fromUrl(context, str, "url_".concat(String.valueOf(str))); } public static LottieTask fromUrl(final Context context, final String str, final String str2) { return cache(str2, new Callable(context, str, str2) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda2 public final Context f$0; public final String f$1; public final String f$2; @Override // java.util.concurrent.Callable public final Object call() { return LottieCompositionFactory.lambda$fromUrl$0(this.f$0, this.f$1, this.f$2); } { this.f$0 = context; this.f$1 = str; this.f$2 = str2; } }); } /* JADX INFO: Access modifiers changed from: package-private */ public static /* synthetic */ LottieResult lambda$fromUrl$0(Context context, String str, String str2) throws Exception { LottieResult fetchSync = L.networkFetcher(context).fetchSync(str, str2); if (str2 != null && fetchSync.getValue() != null) { LottieCompositionCache.getInstance().put(str2, fetchSync.getValue()); } return fetchSync; } public static LottieResult fromUrlSync(Context context, String str) { return fromUrlSync(context, str, str); } public static LottieResult fromUrlSync(Context context, String str, String str2) { LottieResult fetchSync = L.networkFetcher(context).fetchSync(str, str2); if (str2 != null && fetchSync.getValue() != null) { LottieCompositionCache.getInstance().put(str2, fetchSync.getValue()); } return fetchSync; } public static LottieTask fromAsset(Context context, String str) { return fromAsset(context, str, "asset_".concat(String.valueOf(str))); } public static LottieTask fromAsset(Context context, final String str, final String str2) { final Context applicationContext = context.getApplicationContext(); return cache(str2, new Callable(applicationContext, str, str2) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda10 public final Context f$0; public final String f$1; public final String f$2; @Override // java.util.concurrent.Callable public final Object call() { LottieResult fromAssetSync; fromAssetSync = LottieCompositionFactory.fromAssetSync(this.f$0, this.f$1, this.f$2); return fromAssetSync; } { this.f$0 = applicationContext; this.f$1 = str; this.f$2 = str2; } }); } public static LottieResult fromAssetSync(Context context, String str) { return fromAssetSync(context, str, "asset_".concat(String.valueOf(str))); } public static LottieResult fromAssetSync(Context context, String str, String str2) { int i = 2 % 2; int i2 = a + 31; c = i2 % 128; int i3 = i2 % 2; try { try { if (!((Boolean) String.class.getMethod("endsWith", String.class).invoke(str, ".zip")).booleanValue()) { int i4 = a + 65; c = i4 % 128; int i5 = i4 % 2; try { if (!((Boolean) String.class.getMethod("endsWith", String.class).invoke(str, ".lottie")).booleanValue()) { try { Object[] objArr = {context.getAssets(), str}; Object obj = xzZ.y.get(-867414553); if (obj == null) { obj = ((Class) xzZ.c(Drawable.resolveOpacity(0, 0) + 5, 5 - TextUtils.getOffsetBefore("", 0), (char) Color.red(0))).getMethod("NN_", AssetManager.class, String.class); xzZ.y.put(-867414553, obj); } LottieResult fromJsonInputStreamSync = fromJsonInputStreamSync((InputStream) ((Method) obj).invoke(null, objArr), str2); int i6 = a + 73; c = i6 % 128; int i7 = i6 % 2; return fromJsonInputStreamSync; } catch (Throwable th) { Throwable cause = th.getCause(); if (cause != null) { throw cause; } throw th; } } } catch (Throwable th2) { Throwable cause2 = th2.getCause(); if (cause2 != null) { throw cause2; } throw th2; } } try { Object[] objArr2 = {context.getAssets(), str}; Object obj2 = xzZ.y.get(-867414553); if (obj2 == null) { obj2 = ((Class) xzZ.c(5 - (ViewConfiguration.getScrollBarSize() >> 8), 5 - (ViewConfiguration.getMaximumFlingVelocity() >> 16), (char) ((-1) - MotionEvent.axisFromString("")))).getMethod("NN_", AssetManager.class, String.class); xzZ.y.put(-867414553, obj2); } return fromZipStreamSync(new ZipInputStream((InputStream) ((Method) obj2).invoke(null, objArr2)), str2); } catch (Throwable th3) { Throwable cause3 = th3.getCause(); if (cause3 != null) { throw cause3; } throw th3; } } catch (Throwable th4) { Throwable cause4 = th4.getCause(); if (cause4 != null) { throw cause4; } throw th4; } } catch (IOException e) { return new LottieResult<>((Throwable) e); } } public static LottieTask fromRawRes(Context context, int i) { return fromRawRes(context, i, rawResCacheKey(context, i)); } public static LottieTask fromRawRes(Context context, final int i, final String str) { final WeakReference weakReference = new WeakReference(context); final Context applicationContext = context.getApplicationContext(); return cache(str, new Callable(weakReference, applicationContext, i, str) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda1 public final WeakReference f$0; public final Context f$1; public final int f$2; public final String f$3; @Override // java.util.concurrent.Callable public final Object call() { return LottieCompositionFactory.lambda$fromRawRes$2(this.f$0, this.f$1, this.f$2, this.f$3); } { this.f$0 = weakReference; this.f$1 = applicationContext; this.f$2 = i; this.f$3 = str; } }); } /* JADX INFO: Access modifiers changed from: package-private */ public static /* synthetic */ LottieResult lambda$fromRawRes$2(WeakReference weakReference, Context context, int i, String str) throws Exception { Context context2 = (Context) weakReference.get(); if (context2 != null) { context = context2; } return fromRawResSync(context, i, str); } public static LottieResult fromRawResSync(Context context, int i) { return fromRawResSync(context, i, rawResCacheKey(context, i)); } public static LottieResult fromRawResSync(Context context, int i, String str) { try { InterfaceC15149gid c2 = C15160gio.c(C15160gio.e(context.getResources().openRawResource(i))); if (isZipCompressed(c2).booleanValue()) { return fromZipStreamSync(new ZipInputStream(c2.h()), str); } return fromJsonInputStreamSync(c2.h(), str); } catch (Resources.NotFoundException e) { return new LottieResult<>((Throwable) e); } } private static String rawResCacheKey(Context context, int i) { StringBuilder sb = new StringBuilder("rawRes"); sb.append(isNightMode(context) ? "_night_" : "_day_"); sb.append(i); return sb.toString(); } private static boolean isNightMode(Context context) { return (context.getResources().getConfiguration().uiMode & 48) == 32; } public static LottieTask fromJsonInputStream(final InputStream inputStream, final String str) { return cache(str, new Callable(inputStream, str) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda8 public final InputStream f$0; public final String f$1; @Override // java.util.concurrent.Callable public final Object call() { LottieResult fromJsonInputStreamSync; fromJsonInputStreamSync = LottieCompositionFactory.fromJsonInputStreamSync(this.f$0, this.f$1); return fromJsonInputStreamSync; } { this.f$0 = inputStream; this.f$1 = str; } }); } public static LottieResult fromJsonInputStreamSync(InputStream inputStream, String str) { return fromJsonInputStreamSync(inputStream, str, true); } private static LottieResult fromJsonInputStreamSync(InputStream inputStream, String str, boolean z) { try { return fromJsonReaderSync(JsonReader.of(C15160gio.c(C15160gio.e(inputStream))), str); } finally { if (z) { Utils.closeQuietly(inputStream); } } } @Deprecated public static LottieTask fromJson(final JSONObject jSONObject, final String str) { return cache(str, new Callable(jSONObject, str) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda3 public final JSONObject f$0; public final String f$1; @Override // java.util.concurrent.Callable public final Object call() { LottieResult fromJsonSync; fromJsonSync = LottieCompositionFactory.fromJsonSync(this.f$0, this.f$1); return fromJsonSync; } { this.f$0 = jSONObject; this.f$1 = str; } }); } @Deprecated public static LottieResult fromJsonSync(JSONObject jSONObject, String str) { return fromJsonStringSync(jSONObject.toString(), str); } public static LottieTask fromJsonString(final String str, final String str2) { return cache(str2, new Callable(str, str2) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda7 public final String f$0; public final String f$1; @Override // java.util.concurrent.Callable public final Object call() { LottieResult fromJsonStringSync; fromJsonStringSync = LottieCompositionFactory.fromJsonStringSync(this.f$0, this.f$1); return fromJsonStringSync; } { this.f$0 = str; this.f$1 = str2; } }); } public static LottieResult fromJsonStringSync(String str, String str2) { return fromJsonReaderSync(JsonReader.of(C15160gio.c(C15160gio.e(new ByteArrayInputStream(str.getBytes())))), str2); } public static LottieTask fromJsonReader(final JsonReader jsonReader, final String str) { return cache(str, new Callable(jsonReader, str) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda0 public final JsonReader f$0; public final String f$1; @Override // java.util.concurrent.Callable public final Object call() { LottieResult fromJsonReaderSync; fromJsonReaderSync = LottieCompositionFactory.fromJsonReaderSync(this.f$0, this.f$1); return fromJsonReaderSync; } { this.f$0 = jsonReader; this.f$1 = str; } }); } public static LottieResult fromJsonReaderSync(JsonReader jsonReader, String str) { return fromJsonReaderSyncInternal(jsonReader, str, true); } private static LottieResult fromJsonReaderSyncInternal(JsonReader jsonReader, String str, boolean z) { try { try { LottieComposition parse = LottieCompositionMoshiParser.parse(jsonReader); if (str != null) { LottieCompositionCache.getInstance().put(str, parse); } LottieResult lottieResult = new LottieResult<>(parse); if (z) { Utils.closeQuietly(jsonReader); } return lottieResult; } catch (Exception e) { LottieResult lottieResult2 = new LottieResult<>(e); if (z) { Utils.closeQuietly(jsonReader); } return lottieResult2; } } catch (Throwable th) { if (z) { Utils.closeQuietly(jsonReader); } throw th; } } public static LottieTask fromZipStream(final ZipInputStream zipInputStream, final String str) { return cache(str, new Callable(zipInputStream, str) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda9 public final ZipInputStream f$0; public final String f$1; @Override // java.util.concurrent.Callable public final Object call() { LottieResult fromZipStreamSync; fromZipStreamSync = LottieCompositionFactory.fromZipStreamSync(this.f$0, this.f$1); return fromZipStreamSync; } { this.f$0 = zipInputStream; this.f$1 = str; } }); } public static LottieResult fromZipStreamSync(ZipInputStream zipInputStream, String str) { try { return fromZipStreamSyncInternal(zipInputStream, str); } finally { Utils.closeQuietly(zipInputStream); } } private static LottieResult fromZipStreamSyncInternal(ZipInputStream zipInputStream, String str) { HashMap hashMap = new HashMap(); try { ZipEntry nextEntry = zipInputStream.getNextEntry(); LottieComposition lottieComposition = null; while (nextEntry != null) { String name = nextEntry.getName(); if (name.contains("__MACOSX")) { zipInputStream.closeEntry(); } else if (nextEntry.getName().equalsIgnoreCase("manifest.json")) { zipInputStream.closeEntry(); } else if (nextEntry.getName().contains(".json")) { lottieComposition = fromJsonReaderSyncInternal(JsonReader.of(C15160gio.c(C15160gio.e(zipInputStream))), null, false).getValue(); } else { if (!name.contains(".png") && !name.contains(".webp") && !name.contains(".jpg") && !name.contains(".jpeg")) { zipInputStream.closeEntry(); } hashMap.put(name.split("/")[r1.length - 1], BitmapFactory.decodeStream(zipInputStream)); } nextEntry = zipInputStream.getNextEntry(); } if (lottieComposition == null) { return new LottieResult<>((Throwable) new IllegalArgumentException("Unable to parse composition")); } for (Map.Entry entry : hashMap.entrySet()) { LottieImageAsset findImageAssetForFileName = findImageAssetForFileName(lottieComposition, (String) entry.getKey()); if (findImageAssetForFileName != null) { findImageAssetForFileName.setBitmap(Utils.resizeBitmapIfNeeded((Bitmap) entry.getValue(), findImageAssetForFileName.getWidth(), findImageAssetForFileName.getHeight())); } } for (Map.Entry entry2 : lottieComposition.getImages().entrySet()) { if (entry2.getValue().getBitmap() == null) { StringBuilder sb = new StringBuilder("There is no image for "); sb.append(entry2.getValue().getFileName()); return new LottieResult<>((Throwable) new IllegalStateException(sb.toString())); } } if (str != null) { LottieCompositionCache.getInstance().put(str, lottieComposition); } return new LottieResult<>(lottieComposition); } catch (IOException e) { return new LottieResult<>((Throwable) e); } } private static Boolean isZipCompressed(InterfaceC15149gid interfaceC15149gid) { try { InterfaceC15149gid g = interfaceC15149gid.g(); for (byte b : MAGIC) { if (g.f() != b) { return Boolean.FALSE; } } g.close(); return Boolean.TRUE; } catch (Exception e) { Logger.error("Failed to check zip file header", e); return Boolean.FALSE; } catch (NoSuchMethodError unused) { return Boolean.FALSE; } } private static LottieImageAsset findImageAssetForFileName(LottieComposition lottieComposition, String str) { for (LottieImageAsset lottieImageAsset : lottieComposition.getImages().values()) { if (lottieImageAsset.getFileName().equals(str)) { return lottieImageAsset; } } return null; } private static LottieTask cache(final String str, Callable> callable) { final LottieComposition lottieComposition = str == null ? null : LottieCompositionCache.getInstance().get(str); if (lottieComposition != null) { return new LottieTask<>(new Callable(lottieComposition) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda4 public final LottieComposition f$0; @Override // java.util.concurrent.Callable public final Object call() { return LottieCompositionFactory.lambda$cache$8(this.f$0); } { this.f$0 = lottieComposition; } }); } if (str != null) { Map> map = taskCache; if (map.containsKey(str)) { return map.get(str); } } LottieTask lottieTask = new LottieTask<>(callable); if (str != null) { final AtomicBoolean atomicBoolean = new AtomicBoolean(false); lottieTask.addListener(new LottieListener(str, atomicBoolean) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda5 public final String f$0; public final AtomicBoolean f$1; @Override // com.airbnb.lottie.LottieListener public final void onResult(Object obj) { LottieCompositionFactory.lambda$cache$9(this.f$0, this.f$1, (LottieComposition) obj); } { this.f$0 = str; this.f$1 = atomicBoolean; } }); lottieTask.addFailureListener(new LottieListener(str, atomicBoolean) { // from class: com.airbnb.lottie.LottieCompositionFactory$$ExternalSyntheticLambda6 public final String f$0; public final AtomicBoolean f$1; @Override // com.airbnb.lottie.LottieListener public final void onResult(Object obj) { LottieCompositionFactory.lambda$cache$10(this.f$0, this.f$1, (Throwable) obj); } { this.f$0 = str; this.f$1 = atomicBoolean; } }); if (!atomicBoolean.get()) { taskCache.put(str, lottieTask); } } return lottieTask; } /* JADX INFO: Access modifiers changed from: package-private */ public static /* synthetic */ LottieResult lambda$cache$8(LottieComposition lottieComposition) throws Exception { return new LottieResult(lottieComposition); } /* JADX INFO: Access modifiers changed from: package-private */ public static /* synthetic */ void lambda$cache$9(String str, AtomicBoolean atomicBoolean, LottieComposition lottieComposition) { taskCache.remove(str); atomicBoolean.set(true); } /* JADX INFO: Access modifiers changed from: package-private */ public static /* synthetic */ void lambda$cache$10(String str, AtomicBoolean atomicBoolean, Throwable th) { taskCache.remove(str); atomicBoolean.set(true); } }