package com.debridstream.tv;

import J0.RunnableC0371m;
import J4.a;
import S4.p;
import S4.w;
import V2.AbstractC0696m3;
import V2.C0649d1;
import V2.C0706p0;
import V2.z3;
import V4.D0;
import V4.E;
import V4.N;
import W.b;
import W.c;
import X2.j;
import Y4.c0;
import a.AbstractC0872a;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.media3.extractor.text.ttml.TtmlNode;
import c5.d;
import c5.e;
import coil.ImageLoader;
import coil.ImageLoaderFactory;
import coil.disk.DiskCache;
import coil.memory.MemoryCache;
import com.debridstream.tv.DebridStreamApp;
import com.debridstream.tv.data.home.HomeMetaItem;
import com.google.firebase.FirebaseApp;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import e3.AbstractC1964a;
import g3.AbstractC2060b;
import g3.C2059a;
import g3.k;
import i3.AbstractC2271e;
import i3.L;
import i3.M;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import okhttp3.Cache;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;
import w4.m;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 1)
public final class DebridStreamApp extends Application implements ImageLoaderFactory {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final /* synthetic */ int f13565a = 0;

    @Override // coil.ImageLoaderFactory
    public final ImageLoader newImageLoader() {
        final int i6 = 0;
        ImageLoader.Builder builderMemoryCache = new ImageLoader.Builder(this).memoryCache(new a(this) { // from class: V2.c1

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ DebridStreamApp f7715b;

            {
                this.f7715b = this;
            }

            @Override // J4.a
            public final Object invoke() {
                switch (i6) {
                    case 0:
                        int i7 = DebridStreamApp.f13565a;
                        return new MemoryCache.Builder(this.f7715b).maxSizePercent(0.1d).weakReferencesEnabled(true).build();
                    case 1:
                        int i8 = DebridStreamApp.f13565a;
                        DiskCache.Builder builder = new DiskCache.Builder();
                        File cacheDir = this.f7715b.getCacheDir();
                        kotlin.jvm.internal.o.g(cacheDir, "getCacheDir(...)");
                        return builder.directory(H4.d.r0(cacheDir, "coil_cache")).maxSizeBytes(104857600L).build();
                    default:
                        DebridStreamApp debridStreamApp = this.f7715b;
                        int i9 = DebridStreamApp.f13565a;
                        OkHttpClient.Builder builder2 = new OkHttpClient.Builder();
                        AbstractC1964a.c(builder2);
                        File cacheDir2 = debridStreamApp.getCacheDir();
                        kotlin.jvm.internal.o.g(cacheDir2, "getCacheDir(...)");
                        builder2.f22104k = new Cache(H4.d.r0(cacheDir2, "okhttp_http_cache"));
                        Dispatcher dispatcher = new Dispatcher();
                        synchronized (dispatcher) {
                            dispatcher.f22003b = 4;
                        }
                        dispatcher.c();
                        synchronized (dispatcher) {
                            dispatcher.f22002a = 8;
                        }
                        dispatcher.c();
                        builder2.f22094a = dispatcher;
                        return new OkHttpClient(builder2);
                }
            }
        });
        final int i7 = 1;
        ImageLoader.Builder builderAllowRgb565 = builderMemoryCache.diskCache(new a(this) { // from class: V2.c1

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ DebridStreamApp f7715b;

            {
                this.f7715b = this;
            }

            @Override // J4.a
            public final Object invoke() {
                switch (i7) {
                    case 0:
                        int i72 = DebridStreamApp.f13565a;
                        return new MemoryCache.Builder(this.f7715b).maxSizePercent(0.1d).weakReferencesEnabled(true).build();
                    case 1:
                        int i8 = DebridStreamApp.f13565a;
                        DiskCache.Builder builder = new DiskCache.Builder();
                        File cacheDir = this.f7715b.getCacheDir();
                        kotlin.jvm.internal.o.g(cacheDir, "getCacheDir(...)");
                        return builder.directory(H4.d.r0(cacheDir, "coil_cache")).maxSizeBytes(104857600L).build();
                    default:
                        DebridStreamApp debridStreamApp = this.f7715b;
                        int i9 = DebridStreamApp.f13565a;
                        OkHttpClient.Builder builder2 = new OkHttpClient.Builder();
                        AbstractC1964a.c(builder2);
                        File cacheDir2 = debridStreamApp.getCacheDir();
                        kotlin.jvm.internal.o.g(cacheDir2, "getCacheDir(...)");
                        builder2.f22104k = new Cache(H4.d.r0(cacheDir2, "okhttp_http_cache"));
                        Dispatcher dispatcher = new Dispatcher();
                        synchronized (dispatcher) {
                            dispatcher.f22003b = 4;
                        }
                        dispatcher.c();
                        synchronized (dispatcher) {
                            dispatcher.f22002a = 8;
                        }
                        dispatcher.c();
                        builder2.f22094a = dispatcher;
                        return new OkHttpClient(builder2);
                }
            }
        }).allowHardware(true).allowRgb565(true);
        final int i8 = 2;
        return builderAllowRgb565.okHttpClient(new a(this) { // from class: V2.c1

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ DebridStreamApp f7715b;

            {
                this.f7715b = this;
            }

            @Override // J4.a
            public final Object invoke() {
                switch (i8) {
                    case 0:
                        int i72 = DebridStreamApp.f13565a;
                        return new MemoryCache.Builder(this.f7715b).maxSizePercent(0.1d).weakReferencesEnabled(true).build();
                    case 1:
                        int i82 = DebridStreamApp.f13565a;
                        DiskCache.Builder builder = new DiskCache.Builder();
                        File cacheDir = this.f7715b.getCacheDir();
                        kotlin.jvm.internal.o.g(cacheDir, "getCacheDir(...)");
                        return builder.directory(H4.d.r0(cacheDir, "coil_cache")).maxSizeBytes(104857600L).build();
                    default:
                        DebridStreamApp debridStreamApp = this.f7715b;
                        int i9 = DebridStreamApp.f13565a;
                        OkHttpClient.Builder builder2 = new OkHttpClient.Builder();
                        AbstractC1964a.c(builder2);
                        File cacheDir2 = debridStreamApp.getCacheDir();
                        kotlin.jvm.internal.o.g(cacheDir2, "getCacheDir(...)");
                        builder2.f22104k = new Cache(H4.d.r0(cacheDir2, "okhttp_http_cache"));
                        Dispatcher dispatcher = new Dispatcher();
                        synchronized (dispatcher) {
                            dispatcher.f22003b = 4;
                        }
                        dispatcher.c();
                        synchronized (dispatcher) {
                            dispatcher.f22002a = 8;
                        }
                        dispatcher.c();
                        builder2.f22094a = dispatcher;
                        return new OkHttpClient(builder2);
                }
            }
        }).crossfade(false).build();
    }

    /* JADX WARN: Removed duplicated region for block: B:26:0x0069  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x00f6  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x012f  */
    @Override // android.app.Application
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onCreate() {
        Object objD;
        String string;
        Object objD2;
        String string2;
        Object objD3;
        Object objD4;
        String str;
        Object objD5;
        String str2;
        Object objD6;
        String str3;
        String string3;
        boolean z6;
        String string4;
        Object objD7;
        String str4;
        super.onCreate();
        D0 d0D = E.d();
        e eVar = N.f8259a;
        String str5 = null;
        E.y(E.c(AbstractC0872a.a0(d0D, d.f13466b)), null, null, new C0649d1(this, null), 3);
        if (W.d.f8386g == null) {
            Context applicationContext = getApplicationContext();
            o.g(applicationContext, "getApplicationContext(...)");
            PackageManager packageManager = applicationContext.getPackageManager();
            String packageName = applicationContext.getPackageName();
            try {
                objD7 = Build.VERSION.SDK_INT >= 33 ? packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0L)) : packageManager.getPackageInfo(packageName, 0);
            } catch (Throwable th) {
                objD7 = AbstractC2467b.d(th);
            }
            if (objD7 instanceof m) {
                objD7 = null;
            }
            PackageInfo packageInfo = (PackageInfo) objD7;
            if (packageInfo == null || (str4 = packageInfo.versionName) == null) {
                str4 = "3.0.0";
                W.d.f8386g = "DebridStream/".concat(str4);
            } else {
                if (p.Q0(str4)) {
                    str4 = null;
                }
                if (str4 == null) {
                }
                W.d.f8386g = "DebridStream/".concat(str4);
            }
        }
        if (c.f8375h == null) {
            c.f8375h = getApplicationContext();
            Context context = c.f8375h;
            if (context != null) {
                SharedPreferences sharedPreferences = context.getSharedPreferences("debridstream_remote_map", 0);
                SharedPreferences.Editor editorEdit = sharedPreferences.edit();
                String string5 = sharedPreferences.getString("config_json", null);
                if (string5 == null || (string3 = p.o1(string5).toString()) == null || string3.length() <= 0) {
                    string3 = null;
                }
                if (string3 == null || sharedPreferences.getString("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/config.json", null) != null) {
                    z6 = false;
                } else {
                    editorEdit.putString("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/config.json", string3);
                    z6 = true;
                }
                String string6 = sharedPreferences.getString("entry_map_json", null);
                if (string6 == null || (string4 = p.o1(string6).toString()) == null || string4.length() <= 0) {
                    string4 = null;
                }
                if (string4 != null && sharedPreferences.getString("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/entryMap.json", null) == null) {
                    editorEdit.putString("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/entryMap.json", string4);
                    z6 = true;
                }
                if (z6) {
                    editorEdit.remove("config_json").remove("entry_map_json").apply();
                }
            }
        }
        ArrayList arrayList = N2.c.f5134a;
        Context context2 = c.f8375h;
        if (context2 == null) {
            string = null;
        } else {
            try {
                objD = context2.getSharedPreferences("debridstream_remote_map", 0).getString("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/config.json", null);
            } catch (Throwable th2) {
                objD = AbstractC2467b.d(th2);
            }
            if (objD instanceof m) {
                objD = null;
            }
            String str6 = (String) objD;
            if (str6 == null || (string = p.o1(str6).toString()) == null || string.length() <= 0) {
            }
        }
        if (string != null) {
            N2.c.a(string);
        }
        Map map = j.f8601a;
        Context context3 = c.f8375h;
        if (context3 == null) {
            string2 = null;
        } else {
            try {
                objD2 = context3.getSharedPreferences("debridstream_remote_map", 0).getString("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/entryMap.json", null);
            } catch (Throwable th3) {
                objD2 = AbstractC2467b.d(th3);
            }
            if (objD2 instanceof m) {
                objD2 = null;
            }
            String str7 = (String) objD2;
            if (str7 == null || (string2 = p.o1(str7).toString()) == null || string2.length() <= 0) {
            }
        }
        if (string2 != null) {
            try {
                objD3 = j.c(string2);
            } catch (Throwable th4) {
                objD3 = AbstractC2467b.d(th4);
            }
            if (objD3 instanceof m) {
                objD3 = null;
            }
            Map map2 = (Map) objD3;
            if (map2 != null && !map2.isEmpty()) {
                j.f8601a = map2;
            }
        }
        ArrayList arrayList2 = N2.c.f5134a;
        new Thread(new RunnableC0371m(1), "addon-filter-config").start();
        Map map3 = j.f8601a;
        new Thread(new RunnableC0371m(2), "tmdb-imdb-overrides").start();
        if (AbstractC0696m3.f7937d0 == null) {
            AbstractC0696m3.f7937d0 = getApplicationContext();
        }
        if (b.f8366i == null) {
            b.f8366i = getApplicationContext();
        }
        c0 c0Var = z3.f8212a;
        Context applicationContext2 = getApplicationContext();
        o.g(applicationContext2, "getApplicationContext(...)");
        z3.f8212a.j(applicationContext2.getApplicationContext().getSharedPreferences("debridstream_startup_flow", 0).getString("last_selected_profile_key", null));
        c0 c0Var2 = C0706p0.f7996a;
        synchronized (AbstractC2060b.f16469a) {
            AbstractC2060b.f16470b.clear();
            Context context4 = AbstractC0696m3.f7937d0;
            if (context4 == null) {
                str = null;
            } else {
                try {
                    objD4 = context4.getSharedPreferences("debridstream_app_progress_cache", 0).getString("cw_playback_hints_by_profile_json", null);
                } catch (Throwable th5) {
                    objD4 = AbstractC2467b.d(th5);
                }
                if (objD4 instanceof m) {
                    objD4 = null;
                }
                str = (String) objD4;
            }
            if (str != null) {
                try {
                    JSONObject jSONObject = new JSONObject(str);
                    Iterator<String> itKeys = jSONObject.keys();
                    while (itKeys.hasNext()) {
                        String next = itKeys.next();
                        JSONObject jSONObjectOptJSONObject = jSONObject.optJSONObject(next);
                        if (jSONObjectOptJSONObject != null) {
                            LinkedHashMap linkedHashMap = new LinkedHashMap();
                            Iterator<String> itKeys2 = jSONObjectOptJSONObject.keys();
                            while (itKeys2.hasNext()) {
                                String next2 = itKeys2.next();
                                JSONObject jSONObjectOptJSONObject2 = jSONObjectOptJSONObject.optJSONObject(next2);
                                if (jSONObjectOptJSONObject2 != null) {
                                    String strOptString = jSONObjectOptJSONObject2.optString("u", "");
                                    o.e(strOptString);
                                    if (p.Q0(strOptString)) {
                                        strOptString = str5;
                                    }
                                    String strOptString2 = jSONObjectOptJSONObject2.optString(CmcdData.Factory.STREAMING_FORMAT_HLS, "");
                                    o.e(strOptString2);
                                    if (p.Q0(strOptString2)) {
                                        strOptString2 = str5;
                                    }
                                    String strOptString3 = jSONObjectOptJSONObject2.optString(TtmlNode.TAG_P, "");
                                    o.e(strOptString3);
                                    if (p.Q0(strOptString3)) {
                                        strOptString3 = str5;
                                    }
                                    String strOptString4 = jSONObjectOptJSONObject2.optString(CmcdData.Factory.OBJECT_TYPE_INIT_SEGMENT, "");
                                    o.e(strOptString4);
                                    if (!w.A0(strOptString4, TtmlNode.TAG_TT, true)) {
                                        strOptString4 = null;
                                    }
                                    if (strOptString != null || strOptString2 != null || strOptString3 != null || strOptString4 != null) {
                                        linkedHashMap.put(next2, new C2059a(strOptString, strOptString2, strOptString3, strOptString4));
                                    }
                                    str5 = null;
                                }
                            }
                            if (!linkedHashMap.isEmpty()) {
                                AbstractC2060b.f16470b.put(next, linkedHashMap);
                            }
                            str5 = null;
                        }
                    }
                } catch (Throwable th6) {
                    AbstractC2467b.d(th6);
                }
            }
        }
        Map mapL = AbstractC0696m3.l();
        c0 c0Var3 = C0706p0.f7996a;
        c0Var3.getClass();
        c0Var3.k(null, mapL);
        Map mapM = AbstractC0696m3.m();
        LinkedHashMap linkedHashMap2 = new LinkedHashMap();
        for (Map.Entry entry : mapM.entrySet()) {
            String str8 = (String) entry.getKey();
            List<JSONObject> list = (List) entry.getValue();
            ArrayList arrayList3 = new ArrayList();
            for (JSONObject jSONObject2 : list) {
                c0 c0Var4 = C0706p0.f7996a;
                HomeMetaItem homeMetaItemD = C0706p0.d(jSONObject2);
                if (homeMetaItemD != null) {
                    arrayList3.add(homeMetaItemD);
                }
            }
            linkedHashMap2.put(str8, arrayList3);
        }
        c0 c0Var5 = C0706p0.f7998c;
        c0Var5.getClass();
        c0Var5.k(null, linkedHashMap2);
        Context context5 = AbstractC0696m3.f7937d0;
        if (context5 == null) {
            str2 = null;
        } else {
            try {
                objD5 = context5.getSharedPreferences("debridstream_app_progress_cache", 0).getString("trakt_continue_watching_json", null);
            } catch (Throwable th7) {
                objD5 = AbstractC2467b.d(th7);
            }
            if (objD5 instanceof m) {
                objD5 = null;
            }
            str2 = (String) objD5;
        }
        if (str2 != null && !p.Q0(str2)) {
            C0706p0.i(str2);
        }
        Context context6 = AbstractC0696m3.f7937d0;
        if (context6 == null) {
            str3 = null;
        } else {
            try {
                objD6 = context6.getSharedPreferences("debridstream_app_progress_cache", 0).getString("trakt_watchlist_json", null);
            } catch (Throwable th8) {
                objD6 = AbstractC2467b.d(th8);
            }
            if (objD6 instanceof m) {
                objD6 = null;
            }
            str3 = (String) objD6;
        }
        if (str3 != null && !p.Q0(str3)) {
            try {
                C0706p0.j(new JSONArray(str3));
            } catch (Throwable th9) {
                AbstractC2467b.d(th9);
            }
        }
        Context context7 = M.f18897a;
        if (M.f18897a == null) {
            M.f18897a = getApplicationContext();
            E.y(M.f18899c, null, null, new L(2, null), 3);
        }
        Context context8 = k.f16500a;
        if (k.f16500a == null) {
            k.f16500a = getApplicationContext();
            E.y(k.f16501b, null, null, new g3.j(2, null), 3);
        }
        AbstractC2271e.f18922a.set(0);
        AbstractC2271e.f18923b.set(0);
        AbstractC2271e.f18924c.set(0);
        AbstractC2271e.f18925d.set(0);
        AbstractC2271e.f18926e.set(0);
        AbstractC2271e.f18927f.set(0);
        if (FirebaseApp.getApps(this).isEmpty()) {
            FirebaseApp.initializeApp(this);
        }
        FirebaseCrashlytics firebaseCrashlytics = FirebaseCrashlytics.getInstance();
        firebaseCrashlytics.setCrashlyticsCollectionEnabled(true);
        firebaseCrashlytics.sendUnsentReports();
    }
}
