package F5;

import F7.C0140y;
import O1.C0225a;
import a.AbstractC0386a;
import a5.C0404c;
import a5.C0405d;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorSpace;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import androidx.lifecycle.P;
import androidx.lifecycle.a0;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.tv.R;
import com.martsnew.tv.customviews.keyboard.KeyboardView;
import com.martsnew.tv.ui.update.TVUpdateFragment;
import e5.InterfaceC0883c;
import f0.C0903c;
import f0.C0907g;
import g2.AbstractC0982j;
import g2.C0976d;
import g2.C0978f;
import g2.C0979g;
import g2.C0980h;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import n4.u0;
import p2.C1423m;
import t5.C1555c;
import v5.C1679e;
import v5.C1680f;
import v5.InterfaceC1676b;
import x7.C1730f;
import y5.AbstractActivityC1764i;

/* JADX INFO: renamed from: F5.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final /* synthetic */ class C0115b implements O6.a {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final /* synthetic */ int f2530q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final /* synthetic */ Object f2531r;

    public /* synthetic */ C0115b(int i, Object obj) {
        this.f2530q = i;
        this.f2531r = obj;
    }

    /* JADX WARN: Removed duplicated region for block: B:221:0x00f2 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00ea  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00f9  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00fd  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00ff  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x0101  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x0103  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0109  */
    @Override // O6.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object a() throws Exception {
        C0979g c0979g;
        Context context;
        int i;
        int i5;
        int i8;
        int iMin;
        double dMax;
        Bitmap bitmapCreateBitmap;
        ColorSpace colorSpace;
        int iE;
        C0903c c0903cC;
        int iE2;
        int i9;
        A6.n nVar = A6.n.f457a;
        int i10 = 1;
        Object obj = this.f2531r;
        switch (this.f2530q) {
            case u0.f15495q /* 0 */:
                return ((g) obj).a0();
            case 1:
                return ((C0225a) obj).b(":memory:");
            case 2:
                return new T5.h(new n(1, (T5.l) obj, T5.l.class, "onQualityClick", "onQualityClick(Lcom/martsnew/domain/type/Quality;)V", 0, 5));
            case 3:
                U1.e eVar = (U1.e) obj;
                eVar.C().f(new U1.b(0, eVar));
                return nVar;
            case 4:
                return obj;
            case 5:
                Z1.h hVar = (Z1.h) obj;
                String str = hVar.f7413r;
                P.g gVar = new P.g(13);
                gVar.f5246r = null;
                Z1.g gVar2 = new Z1.g(hVar.f7412q, hVar.f7413r, gVar, hVar.f7414s);
                gVar2.setWriteAheadLoggingEnabled(hVar.f7416u);
                return gVar2;
            case Z.g.STRING_SET_FIELD_NUMBER /* 6 */:
                TVUpdateFragment tVUpdateFragment = (TVUpdateFragment) obj;
                try {
                    tVUpdateFragment.f11220y0.a("android.permission.WRITE_EXTERNAL_STORAGE");
                    break;
                } catch (Exception unused) {
                    tVUpdateFragment.o0(new y5.n(R.string.msg_unknown_error));
                }
                return nVar;
            case Z.g.DOUBLE_FIELD_NUMBER /* 7 */:
                return P.g((a0) obj);
            case Z.g.BYTES_FIELD_NUMBER /* 8 */:
                Object obj2 = ((O1.A) obj).i.get(P6.n.a(C0404c.class));
                P6.g.c(obj2, "null cannot be cast to non-null type T of androidx.room.RoomDatabase.getTypeConverter");
                return (C0404c) obj2;
            case 9:
                ((AbstractActivityC1764i) obj).reportFullyDrawn();
                return null;
            case 10:
                C2.a aVar = new C2.a(1);
                K2.e eVar2 = (K2.e) obj;
                aVar.f(C1.v((C0405d) eVar2.f3552q));
                ((ArrayList) aVar.f1157r).add(new G7.a(new o6.x(new N0.c(2))));
                aVar.f1158s = (k7.w) eVar2.f3553r;
                return (InterfaceC0883c) aVar.g().b(InterfaceC0883c.class);
            case 11:
                BitmapFactory.Options options = new BitmapFactory.Options();
                C0976d c0976d = (C0976d) obj;
                g2.m mVar = c0976d.f12893a;
                C0140y c0140y = new C0140y(mVar.b());
                x7.B bC = s7.l.c(c0140y);
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(new C1730f(s7.l.c(new x7.y(bC)), i10), null, options);
                Exception exc = (Exception) c0140y.f2736s;
                if (exc != null) {
                    throw exc;
                }
                options.inJustDecodeBounds = false;
                Paint paint = AbstractC0982j.f12911a;
                String str2 = options.outMimeType;
                Set set = g2.k.f12912a;
                int iOrdinal = c0976d.f12896d.ordinal();
                if (iOrdinal == 0) {
                    c0979g = C0979g.f12904c;
                } else {
                    if (iOrdinal != 1) {
                        if (iOrdinal != 2) {
                            throw new A6.b();
                        }
                    } else if (str2 == null || !g2.k.f12912a.contains(str2)) {
                    }
                    C0907g c0907g = new C0907g(new C0980h(new C1730f(s7.l.c(new x7.y(bC)), i10)));
                    C0903c c0903cC2 = c0907g.c("Orientation");
                    if (c0903cC2 == null) {
                        iE = 1;
                        boolean z8 = iE != 2 || iE == 7 || iE == 4 || iE == 5;
                        c0903cC = c0907g.c("Orientation");
                        if (c0903cC != null) {
                            iE2 = 1;
                            switch (iE2) {
                                case 3:
                                case 4:
                                    i9 = 180;
                                    break;
                                case 5:
                                case Z.g.BYTES_FIELD_NUMBER /* 8 */:
                                    i9 = 270;
                                    break;
                                case Z.g.STRING_SET_FIELD_NUMBER /* 6 */:
                                case Z.g.DOUBLE_FIELD_NUMBER /* 7 */:
                                    i9 = 90;
                                    break;
                                default:
                                    i9 = 0;
                                    break;
                            }
                            c0979g = new C0979g(i9, z8);
                        } else {
                            try {
                                iE2 = c0903cC.e(c0907g.f12654f);
                            } catch (NumberFormatException unused2) {
                                iE2 = 1;
                            }
                            switch (iE2) {
                            }
                            c0979g = new C0979g(i9, z8);
                        }
                    } else {
                        try {
                            iE = c0903cC2.e(c0907g.f12654f);
                        } catch (NumberFormatException unused3) {
                            iE = 1;
                        }
                        if (iE != 2) {
                            c0903cC = c0907g.c("Orientation");
                            if (c0903cC != null) {
                            }
                        }
                    }
                }
                Exception exc2 = (Exception) c0140y.f2736s;
                if (exc2 != null) {
                    throw exc2;
                }
                options.inMutable = false;
                int i11 = Build.VERSION.SDK_INT;
                C1423m c1423m = c0976d.f12894b;
                if (i11 >= 26 && (colorSpace = c1423m.f16095c) != null) {
                    options.inPreferredColorSpace = colorSpace;
                }
                options.inPremultiplied = c1423m.f16100h;
                int i12 = c0979g.f12906b;
                Bitmap.Config config = c1423m.f16094b;
                boolean z9 = c0979g.f12905a;
                if ((z9 || i12 > 0) && (config == null || AbstractC0386a.s(config))) {
                    config = Bitmap.Config.ARGB_8888;
                }
                if (c1423m.f16099g && config == Bitmap.Config.ARGB_8888 && P6.g.a(options.outMimeType, "image/jpeg")) {
                    config = Bitmap.Config.RGB_565;
                }
                if (i11 >= 26 && options.outConfig == Bitmap.Config.RGBA_F16 && config != Bitmap.Config.HARDWARE) {
                    config = Bitmap.Config.RGBA_F16;
                }
                options.inPreferredConfig = config;
                U2.a aVarA = mVar.a();
                boolean z10 = aVarA instanceof g2.n;
                Context context2 = c1423m.f16093a;
                q2.h hVar2 = c1423m.f16096d;
                if (z10 && P6.g.a(hVar2, q2.h.f16239c)) {
                    options.inSampleSize = 1;
                    options.inScaled = true;
                    options.inDensity = ((g2.n) aVarA).f12919h;
                    options.inTargetDensity = context2.getResources().getDisplayMetrics().densityDpi;
                    context = context2;
                    i = 1;
                } else {
                    int i13 = options.outWidth;
                    if (i13 <= 0 || (i5 = options.outHeight) <= 0) {
                        context = context2;
                        i = 1;
                        options.inSampleSize = 1;
                        options.inScaled = false;
                    } else {
                        int i14 = (i12 == 90 || i12 == 270) ? i5 : i13;
                        if (i12 != 90 && i12 != 270) {
                            i13 = i5;
                        }
                        q2.h hVar3 = q2.h.f16239c;
                        boolean zA = P6.g.a(hVar2, hVar3);
                        q2.g gVar3 = c1423m.f16097e;
                        int iE3 = zA ? i14 : u2.f.e(hVar2.f16240a, gVar3);
                        int iE4 = P6.g.a(hVar2, hVar3) ? i13 : u2.f.e(hVar2.f16241b, gVar3);
                        int iHighestOneBit = Integer.highestOneBit(i14 / iE3);
                        int iHighestOneBit2 = Integer.highestOneBit(i13 / iE4);
                        int iOrdinal2 = gVar3.ordinal();
                        if (iOrdinal2 != 0) {
                            i8 = 1;
                            if (iOrdinal2 != 1) {
                                throw new A6.b();
                            }
                            iMin = Math.max(iHighestOneBit, iHighestOneBit2);
                        } else {
                            i8 = 1;
                            iMin = Math.min(iHighestOneBit, iHighestOneBit2);
                        }
                        if (iMin < i8) {
                            iMin = 1;
                        }
                        options.inSampleSize = iMin;
                        double d8 = iMin;
                        context = context2;
                        double d9 = ((double) i13) / d8;
                        double d10 = ((double) iE3) / (((double) i14) / d8);
                        double d11 = ((double) iE4) / d9;
                        int iOrdinal3 = gVar3.ordinal();
                        if (iOrdinal3 == 0) {
                            dMax = Math.max(d10, d11);
                        } else {
                            if (iOrdinal3 != 1) {
                                throw new A6.b();
                            }
                            dMax = Math.min(d10, d11);
                        }
                        if (c1423m.f16098f && dMax > 1.0d) {
                            dMax = 1.0d;
                        }
                        boolean z11 = dMax == 1.0d;
                        options.inScaled = !z11;
                        if (!z11) {
                            if (dMax > 1.0d) {
                                options.inDensity = android.support.v4.media.session.a.s(((double) Integer.MAX_VALUE) / dMax);
                                options.inTargetDensity = Integer.MAX_VALUE;
                            } else {
                                options.inDensity = Integer.MAX_VALUE;
                                options.inTargetDensity = android.support.v4.media.session.a.s(((double) Integer.MAX_VALUE) * dMax);
                            }
                        }
                        i = 1;
                    }
                }
                try {
                    Bitmap bitmapDecodeStream = BitmapFactory.decodeStream(new C1730f(bC, i), null, options);
                    bC.close();
                    Exception exc3 = (Exception) c0140y.f2736s;
                    if (exc3 != null) {
                        throw exc3;
                    }
                    if (bitmapDecodeStream == null) {
                        throw new IllegalStateException("BitmapFactory returned a null bitmap. Often this means BitmapFactory could not decode the image data read from the input source (e.g. network, disk, or memory) as it's not encoded as a valid image format.");
                    }
                    bitmapDecodeStream.setDensity(context.getResources().getDisplayMetrics().densityDpi);
                    if (z9 || i12 > 0) {
                        Matrix matrix = new Matrix();
                        float width = bitmapDecodeStream.getWidth() / 2.0f;
                        float height = bitmapDecodeStream.getHeight() / 2.0f;
                        if (z9) {
                            matrix.postScale(-1.0f, 1.0f, width, height);
                        }
                        if (i12 > 0) {
                            matrix.postRotate(i12, width, height);
                        }
                        RectF rectF = new RectF(0.0f, 0.0f, bitmapDecodeStream.getWidth(), bitmapDecodeStream.getHeight());
                        matrix.mapRect(rectF);
                        float f3 = rectF.left;
                        if (f3 != 0.0f || rectF.top != 0.0f) {
                            matrix.postTranslate(-f3, -rectF.top);
                        }
                        if (i12 == 90 || i12 == 270) {
                            int height2 = bitmapDecodeStream.getHeight();
                            int width2 = bitmapDecodeStream.getWidth();
                            Bitmap.Config config2 = bitmapDecodeStream.getConfig();
                            if (config2 == null) {
                                config2 = Bitmap.Config.ARGB_8888;
                            }
                            bitmapCreateBitmap = Bitmap.createBitmap(height2, width2, config2);
                        } else {
                            int width3 = bitmapDecodeStream.getWidth();
                            int height3 = bitmapDecodeStream.getHeight();
                            Bitmap.Config config3 = bitmapDecodeStream.getConfig();
                            if (config3 == null) {
                                config3 = Bitmap.Config.ARGB_8888;
                            }
                            bitmapCreateBitmap = Bitmap.createBitmap(width3, height3, config3);
                        }
                        new Canvas(bitmapCreateBitmap).drawBitmap(bitmapDecodeStream, matrix, AbstractC0982j.f12911a);
                        bitmapDecodeStream.recycle();
                        bitmapDecodeStream = bitmapCreateBitmap;
                    }
                    return new C0978f(new BitmapDrawable(context.getResources(), bitmapDecodeStream), options.inSampleSize > 1 || options.inScaled);
                } finally {
                }
                break;
            case 12:
                int i15 = KeyboardView.f11118f1;
                return new C1555c((KeyboardView) obj);
            default:
                k7.v vVar = new k7.v();
                vVar.a((C1679e) ((C1680f) obj).f18112b.getValue());
                vVar.f14150f = true;
                TimeUnit timeUnit = TimeUnit.SECONDS;
                P6.g.e(timeUnit, "unit");
                vVar.f14165v = l7.b.b(15L, timeUnit);
                k7.w wVar = new k7.w(vVar);
                C2.a aVar2 = new C2.a(1);
                aVar2.f("https://base.url");
                aVar2.f1158s = wVar;
                return (InterfaceC1676b) aVar2.g().b(InterfaceC1676b.class);
        }
    }
}
