package ml;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.f;
import com.journeyapps.barcodescanner.CaptureActivity;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* loaded from: classes3.dex */
public class a {

    /* renamed from: h, reason: collision with root package name */
    public static final Collection f29194h = h("UPC_A", "UPC_E", "EAN_8", "EAN_13", "RSS_14");

    /* renamed from: i, reason: collision with root package name */
    public static final Collection f29195i = h("UPC_A", "UPC_E", "EAN_8", "EAN_13", "RSS_14", "CODE_39", "CODE_93", "CODE_128", "ITF", "RSS_14", "RSS_EXPANDED");

    /* renamed from: j, reason: collision with root package name */
    public static final Collection f29196j = null;

    /* renamed from: a, reason: collision with root package name */
    private final Activity f29197a;

    /* renamed from: b, reason: collision with root package name */
    private Fragment f29198b;

    /* renamed from: c, reason: collision with root package name */
    private f f29199c;

    /* renamed from: e, reason: collision with root package name */
    private Collection f29201e;

    /* renamed from: f, reason: collision with root package name */
    private Class f29202f;

    /* renamed from: d, reason: collision with root package name */
    private final Map f29200d = new HashMap(3);

    /* renamed from: g, reason: collision with root package name */
    private int f29203g = 49374;

    public a(Activity activity) {
        this.f29197a = activity;
    }

    private void b(Intent intent) {
        for (Map.Entry entry : this.f29200d.entrySet()) {
            String str = (String) entry.getKey();
            Object value = entry.getValue();
            if (value instanceof Integer) {
                intent.putExtra(str, (Integer) value);
            } else if (value instanceof Long) {
                intent.putExtra(str, (Long) value);
            } else if (value instanceof Boolean) {
                intent.putExtra(str, (Boolean) value);
            } else if (value instanceof Double) {
                intent.putExtra(str, (Double) value);
            } else if (value instanceof Float) {
                intent.putExtra(str, (Float) value);
            } else if (value instanceof Bundle) {
                intent.putExtra(str, (Bundle) value);
            } else if (value instanceof int[]) {
                intent.putExtra(str, (int[]) value);
            } else if (value instanceof long[]) {
                intent.putExtra(str, (long[]) value);
            } else if (value instanceof boolean[]) {
                intent.putExtra(str, (boolean[]) value);
            } else if (value instanceof double[]) {
                intent.putExtra(str, (double[]) value);
            } else if (value instanceof float[]) {
                intent.putExtra(str, (float[]) value);
            } else if (value instanceof String[]) {
                intent.putExtra(str, (String[]) value);
            } else {
                intent.putExtra(str, value.toString());
            }
        }
    }

    public static a d(f fVar) {
        a aVar = new a(fVar.getActivity());
        aVar.f29199c = fVar;
        return aVar;
    }

    private static List h(String... strArr) {
        return Collections.unmodifiableList(Arrays.asList(strArr));
    }

    public static b i(int i10, int i11, Intent intent) {
        if (i10 == 49374) {
            return j(i11, intent);
        }
        return null;
    }

    public static b j(int i10, Intent intent) {
        if (i10 != -1) {
            return new b(intent);
        }
        String stringExtra = intent.getStringExtra("SCAN_RESULT");
        String stringExtra2 = intent.getStringExtra("SCAN_RESULT_FORMAT");
        byte[] byteArrayExtra = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
        int intExtra = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
        return new b(stringExtra, stringExtra2, byteArrayExtra, intExtra == Integer.MIN_VALUE ? null : Integer.valueOf(intExtra), intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL"), intent.getStringExtra("SCAN_RESULT_IMAGE_PATH"), intent);
    }

    public final a a(String str, Object obj) {
        this.f29200d.put(str, obj);
        return this;
    }

    public Intent c() {
        Intent intent = new Intent(this.f29197a, (Class<?>) e());
        intent.setAction("com.google.zxing.client.android.SCAN");
        if (this.f29201e != null) {
            StringBuilder sb2 = new StringBuilder();
            for (String str : this.f29201e) {
                if (sb2.length() > 0) {
                    sb2.append(',');
                }
                sb2.append(str);
            }
            intent.putExtra("SCAN_FORMATS", sb2.toString());
        }
        intent.addFlags(67108864);
        intent.addFlags(524288);
        b(intent);
        return intent;
    }

    public Class e() {
        if (this.f29202f == null) {
            this.f29202f = f();
        }
        return this.f29202f;
    }

    protected Class f() {
        return CaptureActivity.class;
    }

    public final void g() {
        o(c(), this.f29203g);
    }

    public a k(Class cls) {
        this.f29202f = cls;
        return this;
    }

    public a l(Collection collection) {
        this.f29201e = collection;
        return this;
    }

    public a m(boolean z10) {
        a("SCAN_ORIENTATION_LOCKED", Boolean.valueOf(z10));
        return this;
    }

    public final a n(String str) {
        if (str != null) {
            a("PROMPT_MESSAGE", str);
        }
        return this;
    }

    protected void o(Intent intent, int i10) {
        Fragment fragment = this.f29198b;
        if (fragment != null) {
            fragment.startActivityForResult(intent, i10);
            return;
        }
        f fVar = this.f29199c;
        if (fVar != null) {
            fVar.startActivityForResult(intent, i10);
        } else {
            this.f29197a.startActivityForResult(intent, i10);
        }
    }
}
