package ce;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.view.View;
import com.google.android.gms.measurement.internal.u1;
import com.google.zxing.BarcodeFormat;
import dd.a0;
import ed.q;
import ed.s;
import ed.t;
import ed.u;
import ed.x;
import io.flutter.plugin.platform.i;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import kotlin.Pair;
import kotlin.collections.EmptyList;
import mc.r;
import nb.g;
import net.touchcapture.qr.flutterqrplus.CustomFramingRectBarcodeView;
import xyz.stream.utils.e0;

/* JADX INFO: loaded from: classes.dex */
public final class c implements i, s, x {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f4976a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashMap f4977b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int f4978c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final u f4979d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f4980e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f4981f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f4982g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public CustomFramingRectBarcodeView f4983h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final e0 f4984i;

    /* JADX WARN: Type inference failed for: r4v5, types: [ce.b] */
    /* JADX WARN: Type inference failed for: r5v3, types: [ce.b] */
    public c(Context context, ed.i iVar, int i10, HashMap map) {
        e0 e0Var;
        g.i(context, "context");
        g.i(iVar, "messenger");
        g.i(map, "params");
        this.f4976a = context;
        this.f4977b = map;
        this.f4978c = 513469796 + i10;
        u uVar = new u(iVar, u1.g("net.touchcapture.qr.flutterqrplus/qrview_", i10));
        this.f4979d = uVar;
        final int i11 = 1;
        this.f4980e = 1;
        bd.c cVar = ua.b.f33388b;
        if (cVar != null) {
            ((xc.e) cVar).f34785c.add(this);
        }
        uVar.setMethodCallHandler(this);
        Activity activity = ua.b.f33387a;
        if (activity != null) {
            final int i12 = 0;
            e eVar = new e(activity, new sd.a(this) { // from class: ce.b

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

                {
                    this.f4975b = this;
                }

                @Override // sd.a
                public final Object invoke() {
                    CustomFramingRectBarcodeView customFramingRectBarcodeView;
                    CustomFramingRectBarcodeView customFramingRectBarcodeView2;
                    kd.e eVar2 = kd.e.f29109a;
                    int i13 = i12;
                    c cVar2 = this.f4975b;
                    switch (i13) {
                        case 0:
                            if (!cVar2.f4982g && cVar2.c() && (customFramingRectBarcodeView = cVar2.f4983h) != null) {
                                customFramingRectBarcodeView.e();
                            }
                            break;
                        default:
                            if (!cVar2.c()) {
                                cVar2.b();
                            } else if (!cVar2.f4982g && cVar2.c() && (customFramingRectBarcodeView2 = cVar2.f4983h) != null) {
                                customFramingRectBarcodeView2.g();
                            }
                            break;
                    }
                    return eVar2;
                }
            }, new sd.a(this) { // from class: ce.b

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

                {
                    this.f4975b = this;
                }

                @Override // sd.a
                public final Object invoke() {
                    CustomFramingRectBarcodeView customFramingRectBarcodeView;
                    CustomFramingRectBarcodeView customFramingRectBarcodeView2;
                    kd.e eVar2 = kd.e.f29109a;
                    int i13 = i11;
                    c cVar2 = this.f4975b;
                    switch (i13) {
                        case 0:
                            if (!cVar2.f4982g && cVar2.c() && (customFramingRectBarcodeView = cVar2.f4983h) != null) {
                                customFramingRectBarcodeView.e();
                            }
                            break;
                        default:
                            if (!cVar2.c()) {
                                cVar2.b();
                            } else if (!cVar2.f4982g && cVar2.c() && (customFramingRectBarcodeView2 = cVar2.f4983h) != null) {
                                customFramingRectBarcodeView2.g();
                            }
                            break;
                    }
                    return eVar2;
                }
            });
            activity.getApplication().registerActivityLifecycleCallbacks(eVar);
            Application application = activity.getApplication();
            g.h(application, "getApplication(...)");
            e0Var = new e0(application, eVar);
        } else {
            e0Var = null;
        }
        this.f4984i = e0Var;
    }

    @Override // ed.x
    public final boolean a(int i10, String[] strArr, int[] iArr) {
        g.i(strArr, "permissions");
        g.i(iArr, "grantResults");
        boolean z10 = false;
        if (i10 != this.f4978c) {
            return false;
        }
        Integer numValueOf = iArr.length == 0 ? null : Integer.valueOf(iArr[0]);
        if (numValueOf != null && numValueOf.intValue() == 0) {
            z10 = true;
        }
        this.f4979d.invokeMethod("onPermissionSet", Boolean.valueOf(z10));
        return z10;
    }

    public final void b() {
        if (c()) {
            this.f4979d.invokeMethod("onPermissionSet", Boolean.TRUE);
        } else {
            Activity activity = ua.b.f33387a;
            if (activity != null) {
                activity.requestPermissions(new String[]{"android.permission.CAMERA"}, this.f4978c);
            }
        }
    }

    public final boolean c() {
        return g0.d.a(this.f4976a, "android.permission.CAMERA") == 0;
    }

    public final void d(a0 a0Var) {
        CustomFramingRectBarcodeView customFramingRectBarcodeView = this.f4983h;
        if (customFramingRectBarcodeView == null) {
            a0Var.error("404", "No barcode view found", null);
            return;
        }
        if (customFramingRectBarcodeView.f24582g) {
            this.f4982g = true;
            customFramingRectBarcodeView.e();
        }
        a0Var.success(Boolean.TRUE);
    }

    @Override // io.flutter.plugin.platform.i
    public final void dispose() {
        e0 e0Var = this.f4984i;
        if (e0Var != null) {
            ((Application) e0Var.f36128b).unregisterActivityLifecycleCallbacks((Application.ActivityLifecycleCallbacks) e0Var.f36129c);
        }
        bd.c cVar = ua.b.f33388b;
        if (cVar != null) {
            ((xc.e) cVar).f34785c.remove(this);
        }
        CustomFramingRectBarcodeView customFramingRectBarcodeView = this.f4983h;
        if (customFramingRectBarcodeView != null) {
            customFramingRectBarcodeView.e();
        }
        this.f4983h = null;
    }

    @Override // io.flutter.plugin.platform.i
    public final View getView() {
        nc.i cameraSettings;
        CustomFramingRectBarcodeView customFramingRectBarcodeView = this.f4983h;
        if (customFramingRectBarcodeView == null) {
            customFramingRectBarcodeView = new CustomFramingRectBarcodeView(ua.b.f33387a);
            this.f4983h = customFramingRectBarcodeView;
            customFramingRectBarcodeView.setDecoderFactory(new r(null, null, null, 2));
            Object obj = this.f4977b.get("cameraFacing");
            g.g(obj, "null cannot be cast to non-null type kotlin.Int");
            if (((Integer) obj).intValue() == 1 && (cameraSettings = customFramingRectBarcodeView.getCameraSettings()) != null) {
                cameraSettings.f31232a = this.f4980e;
            }
        } else if (!this.f4982g) {
            customFramingRectBarcodeView.g();
        }
        return customFramingRectBarcodeView;
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r13v2, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r13v26 */
    /* JADX WARN: Type inference failed for: r13v5 */
    /* JADX WARN: Type inference failed for: r1v2, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r1v3 */
    /* JADX WARN: Type inference failed for: r1v5 */
    /* JADX WARN: Type inference failed for: r1v6 */
    /* JADX WARN: Type inference failed for: r1v7, types: [kotlin.collections.EmptyList] */
    /* JADX WARN: Type inference failed for: r1v8 */
    @Override // ed.s
    public final void onMethodCall(q qVar, t tVar) {
        ?? arrayList;
        ?? r13;
        nc.i cameraSettings;
        g.i(qVar, "call");
        String str = qVar.f25842a;
        if (str != null) {
            int iHashCode = str.hashCode();
            Context context = this.f4976a;
            switch (iHashCode) {
                case -2129330689:
                    if (str.equals("startScan")) {
                        Object obj = qVar.f25843b;
                        List list = obj instanceof List ? (List) obj : null;
                        b();
                        if (list != null) {
                            try {
                                List list2 = list;
                                arrayList = new ArrayList(kotlin.collections.i.Z0(10, list2));
                                Iterator it = list2.iterator();
                                while (it.hasNext()) {
                                    arrayList.add(BarcodeFormat.values()[((Number) it.next()).intValue()]);
                                }
                            } catch (Exception e10) {
                                ((a0) tVar).error("", e10.getMessage(), null);
                                r13 = EmptyList.f29203a;
                            }
                        } else {
                            arrayList = 0;
                        }
                        if (arrayList == 0) {
                            arrayList = EmptyList.f29203a;
                            break;
                        }
                        r13 = arrayList;
                        if (list == null) {
                            CustomFramingRectBarcodeView customFramingRectBarcodeView = this.f4983h;
                            if (customFramingRectBarcodeView != null) {
                                customFramingRectBarcodeView.setDecoderFactory(new r(null, null, null, 2));
                            }
                        } else {
                            CustomFramingRectBarcodeView customFramingRectBarcodeView2 = this.f4983h;
                            if (customFramingRectBarcodeView2 != null) {
                                customFramingRectBarcodeView2.setDecoderFactory(new r((Collection) r13, null, null, 2));
                            }
                        }
                        CustomFramingRectBarcodeView customFramingRectBarcodeView3 = this.f4983h;
                        if (customFramingRectBarcodeView3 != null) {
                            customFramingRectBarcodeView3.k(new mc.q((List) r13, this));
                            return;
                        }
                        return;
                    }
                    break;
                case -2110134142:
                    if (str.equals("getSystemFeatures")) {
                        try {
                            Pair[] pairArr = new Pair[4];
                            pairArr[0] = new Pair("hasFrontCamera", Boolean.valueOf(context.getPackageManager().hasSystemFeature("android.hardware.camera.front")));
                            pairArr[1] = new Pair("hasBackCamera", Boolean.valueOf(context.getPackageManager().hasSystemFeature("android.hardware.camera")));
                            pairArr[2] = new Pair("hasFlash", Boolean.valueOf(context.getPackageManager().hasSystemFeature("android.hardware.camera.flash")));
                            CustomFramingRectBarcodeView customFramingRectBarcodeView4 = this.f4983h;
                            pairArr[3] = new Pair("activeCamera", (customFramingRectBarcodeView4 == null || (cameraSettings = customFramingRectBarcodeView4.getCameraSettings()) == null) ? null : Integer.valueOf(cameraSettings.f31232a));
                            LinkedHashMap linkedHashMap = new LinkedHashMap(ua.b.D(4));
                            kotlin.collections.q.a0(linkedHashMap, pairArr);
                            ((a0) tVar).success(linkedHashMap);
                            return;
                        } catch (Exception e11) {
                            ((a0) tVar).error("", e11.getMessage(), null);
                            return;
                        }
                    }
                    break;
                case -1824838201:
                    if (str.equals("stopCamera")) {
                        d((a0) tVar);
                        return;
                    }
                    break;
                case -1176613766:
                    if (str.equals("changeScanArea")) {
                        Object objArgument = qVar.argument("scanAreaWidth");
                        if (objArgument == null) {
                            throw new IllegalArgumentException("Required value was null.".toString());
                        }
                        double dDoubleValue = ((Number) objArgument).doubleValue();
                        Object objArgument2 = qVar.argument("scanAreaHeight");
                        if (objArgument2 == null) {
                            throw new IllegalArgumentException("Required value was null.".toString());
                        }
                        double dDoubleValue2 = ((Number) objArgument2).doubleValue();
                        Object objArgument3 = qVar.argument("cutOutBottomOffset");
                        if (objArgument3 == null) {
                            throw new IllegalArgumentException("Required value was null.".toString());
                        }
                        double dDoubleValue3 = ((Number) objArgument3).doubleValue();
                        CustomFramingRectBarcodeView customFramingRectBarcodeView5 = this.f4983h;
                        if (customFramingRectBarcodeView5 != null) {
                            customFramingRectBarcodeView5.setFramingRect((int) (dDoubleValue * ((double) context.getResources().getDisplayMetrics().density)), (int) (dDoubleValue2 * ((double) context.getResources().getDisplayMetrics().density)), (int) (dDoubleValue3 * ((double) context.getResources().getDisplayMetrics().density)));
                        }
                        ((a0) tVar).success(Boolean.TRUE);
                        return;
                    }
                    break;
                case -1157185016:
                    if (str.equals("getFlashInfo")) {
                        if (this.f4983h == null) {
                            ((a0) tVar).error("404", "No barcode view found", null);
                            return;
                        } else {
                            ((a0) tVar).success(Boolean.valueOf(this.f4981f));
                            return;
                        }
                    }
                    break;
                case -668845828:
                    if (str.equals("toggleFlash")) {
                        CustomFramingRectBarcodeView customFramingRectBarcodeView6 = this.f4983h;
                        if (customFramingRectBarcodeView6 == null) {
                            ((a0) tVar).error("404", "No barcode view found", null);
                            return;
                        }
                        if (!context.getPackageManager().hasSystemFeature("android.hardware.camera.flash")) {
                            ((a0) tVar).error("404", "This device doesn't support flash", null);
                            return;
                        }
                        customFramingRectBarcodeView6.setTorch(!this.f4981f);
                        boolean z10 = !this.f4981f;
                        this.f4981f = z10;
                        ((a0) tVar).success(Boolean.valueOf(z10));
                        return;
                    }
                    break;
                case 437643762:
                    if (str.equals("flipCamera")) {
                        CustomFramingRectBarcodeView customFramingRectBarcodeView7 = this.f4983h;
                        if (customFramingRectBarcodeView7 == null) {
                            ((a0) tVar).error("404", "No barcode view found", null);
                            return;
                        }
                        customFramingRectBarcodeView7.e();
                        nc.i cameraSettings2 = customFramingRectBarcodeView7.getCameraSettings();
                        int i10 = cameraSettings2.f31232a;
                        int i11 = this.f4980e;
                        if (i10 == i11) {
                            cameraSettings2.f31232a = 0;
                        } else {
                            cameraSettings2.f31232a = i11;
                        }
                        customFramingRectBarcodeView7.g();
                        ((a0) tVar).success(Integer.valueOf(cameraSettings2.f31232a));
                        return;
                    }
                    break;
                case 1026482610:
                    if (str.equals("resumeCamera")) {
                        CustomFramingRectBarcodeView customFramingRectBarcodeView8 = this.f4983h;
                        if (customFramingRectBarcodeView8 == null) {
                            ((a0) tVar).error("404", "No barcode view found", null);
                            return;
                        }
                        if (!customFramingRectBarcodeView8.f24582g) {
                            this.f4982g = false;
                            customFramingRectBarcodeView8.g();
                        }
                        ((a0) tVar).success(Boolean.TRUE);
                        return;
                    }
                    break;
                case 1669188213:
                    if (str.equals("requestPermissions")) {
                        b();
                        return;
                    }
                    break;
                case 1714778527:
                    if (str.equals("stopScan")) {
                        CustomFramingRectBarcodeView customFramingRectBarcodeView9 = this.f4983h;
                        if (customFramingRectBarcodeView9 != null) {
                            customFramingRectBarcodeView9.o();
                            return;
                        }
                        return;
                    }
                    break;
                case 1899593587:
                    if (str.equals("invertScan")) {
                        Boolean bool = (Boolean) qVar.argument("isInvertScan");
                        boolean zBooleanValue = bool != null ? bool.booleanValue() : false;
                        CustomFramingRectBarcodeView customFramingRectBarcodeView10 = this.f4983h;
                        if (customFramingRectBarcodeView10 == null) {
                            return;
                        }
                        customFramingRectBarcodeView10.e();
                        customFramingRectBarcodeView10.getCameraSettings().f31233b = zBooleanValue;
                        customFramingRectBarcodeView10.g();
                        return;
                    }
                    break;
                case 1984772457:
                    if (str.equals("getCameraInfo")) {
                        CustomFramingRectBarcodeView customFramingRectBarcodeView11 = this.f4983h;
                        if (customFramingRectBarcodeView11 == null) {
                            ((a0) tVar).error("404", "No barcode view found", null);
                            return;
                        } else {
                            ((a0) tVar).success(Integer.valueOf(customFramingRectBarcodeView11.getCameraSettings().f31232a));
                            return;
                        }
                    }
                    break;
                case 2013529275:
                    if (str.equals("pauseCamera")) {
                        d((a0) tVar);
                        return;
                    }
                    break;
            }
        }
        ((a0) tVar).notImplemented();
    }
}
