package com.ss.android.ugc.aweme.crossplatform.platform.webview;

import X.4Ms;
import X.9EH;
import X.C5586Hlr;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.util.SparseArray;
import android.webkit.ValueCallback;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import java.io.File;
import kotlin.h.b.n;

public final class UploadFileFragment extends Fragment {
    public static final C5586Hlr LJ = new C5586Hlr((byte) 0);
    public ValueCallback<Uri> LIZ;
    public ValueCallback<Uri[]> LIZIZ;
    public String LIZJ;
    public boolean LIZLLL;
    public SparseArray LJFF;

    static {
        Covode.recordClassIndex(63060);
    }

    private final Intent LIZJ() {
        return new Intent("android.media.action.VIDEO_CAPTURE");
    }

    private final Intent LIZLLL() {
        return new Intent("android.provider.MediaStore.RECORD_SOUND");
    }

    public final /* synthetic */ void onDestroyView() {
        UploadFileFragment.super.onDestroyView();
        SparseArray sparseArray = this.LJFF;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    private final Intent LIZ() {
        Intent intent = new Intent("android.intent.action.GET_CONTENT");
        intent.addCategory("android.intent.category.OPENABLE");
        intent.setType("*/*");
        Intent LIZ2 = LIZ(LIZIZ(), LIZJ(), LIZLLL());
        LIZ2.putExtra("android.intent.extra.INTENT", intent);
        return LIZ2;
    }

    private final Intent LIZIZ() {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        File LIZ2 = LIZ(9EH.LJJIFFI.LIZ(), Environment.DIRECTORY_DCIM);
        if (LIZ2 == null) {
            LIZ2 = new File(LIZ(9EH.LJJIFFI.LIZ()), Environment.DIRECTORY_DCIM);
        }
        n.LIZIZ(LIZ2, "");
        File file = new File(LIZ2.getAbsolutePath() + File.separator + "browser-photos");
        file.mkdirs();
        this.LIZJ = file.getAbsolutePath() + File.separator + System.currentTimeMillis() + ".jpg";
        Context context = getContext();
        String str = this.LIZJ;
        if (str == null) {
            n.LIZIZ();
        }
        intent.putExtra("output", LIZ(context, new File(str)));
        return intent;
    }

    private final Intent LIZ(String str) {
        Intent intent = new Intent("android.intent.action.GET_CONTENT");
        intent.addCategory("android.intent.category.OPENABLE");
        intent.setType(str);
        return intent;
    }

    private final Intent LIZ(Intent... intentArr) {
        Intent intent = new Intent("android.intent.action.CHOOSER");
        intent.putExtra("android.intent.extra.INITIAL_INTENTS", intentArr);
        return intent;
    }

    public static File LIZ(Context context) {
        if (4Ms.LIZJ != null && 4Ms.LJ) {
            return 4Ms.LIZJ;
        }
        File filesDir = context.getFilesDir();
        4Ms.LIZJ = filesDir;
        return filesDir;
    }

    private final Uri LIZ(Context context, File file) {
        if (context == null || Build.VERSION.SDK_INT < 24 || context.getApplicationInfo().targetSdkVersion < 24) {
            return Uri.fromFile(file);
        }
        return FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
    }

    public static File LIZ(Context context, String str) {
        if (!TextUtils.isEmpty(str)) {
            return context.getExternalFilesDir(str);
        }
        if (4Ms.LIZLLL != null && 4Ms.LJ) {
            return 4Ms.LIZLLL;
        }
        File externalFilesDir = context.getExternalFilesDir(str);
        4Ms.LIZLLL = externalFilesDir;
        return externalFilesDir;
    }

    /* JADX WARNING: Removed duplicated region for block: B:18:0x0058 A[SYNTHETIC, Splitter:B:18:0x0058] */
    /* JADX WARNING: Removed duplicated region for block: B:81:0x0167 A[Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LIZ(java.lang.String r16, java.lang.String r17) {
        /*
            r15 = this;
            r10 = r16
            java.lang.String r6 = "audio/*"
            java.lang.String r7 = "video/*"
            java.lang.String r8 = "image/*"
            r4 = r17
            X.M12.LIZ(r4)
            java.lang.String r9 = ""
            r2 = 2048(0x800, float:2.87E-42)
            r3 = 1
            if (r10 != 0) goto L_0x0015
            r10 = r9
        L_0x0015:
            java.lang.String r1 = ";"
            X.Lf3 r0 = new X.Lf3     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r0.<init>(r1)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r5 = 0
            java.util.List r10 = r0.split(r10, r5)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            boolean r0 = r10.isEmpty()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 != 0) goto L_0x004c
            int r0 = r10.size()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.util.ListIterator r1 = r10.listIterator(r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
        L_0x002f:
            boolean r0 = r1.hasPrevious()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x004c
            java.lang.Object r0 = r1.previous()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.lang.String r0 = (java.lang.String) r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            int r0 = r0.length()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 != 0) goto L_0x0042
            goto L_0x002f
        L_0x0042:
            int r0 = r1.nextIndex()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            int r0 = r0 + r3
            java.util.List r1 = X.Lea.LIZLLL(r10, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            goto L_0x004e
        L_0x004c:
            X.Lel r1 = X.Lel.INSTANCE     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
        L_0x004e:
            java.lang.String[] r0 = new java.lang.String[r5]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.lang.Object[] r13 = r1.toArray(r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.lang.String r11 = "null cannot be cast to non-null type kotlin.Array<T>"
            if (r13 == 0) goto L_0x0167
            java.lang.String[] r13 = (java.lang.String[]) r13     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            int r0 = r13.length     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 != 0) goto L_0x0062
        L_0x005d:
            boolean r1 = android.text.TextUtils.isEmpty(r4)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            goto L_0x0065
        L_0x0062:
            r9 = r13[r5]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            goto L_0x005d
        L_0x0065:
            java.lang.String r0 = "filesystem"
            if (r1 != 0) goto L_0x006b
            r1 = r4
            goto L_0x006c
        L_0x006b:
            r1 = r0
        L_0x006c:
            boolean r0 = kotlin.h.b.n.LIZ(r4, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x00d3
            int r12 = r13.length     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r10 = 0
        L_0x0074:
            if (r10 >= r12) goto L_0x00d3
            r14 = r13[r10]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.lang.String r4 = "="
            X.Lf3 r0 = new X.Lf3     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r0.<init>(r4)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.util.List r4 = r0.split(r14, r5)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            boolean r0 = r4.isEmpty()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 != 0) goto L_0x00ae
            int r0 = r4.size()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.util.ListIterator r14 = r4.listIterator(r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
        L_0x0091:
            boolean r0 = r14.hasPrevious()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x00ae
            java.lang.Object r0 = r14.previous()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.lang.String r0 = (java.lang.String) r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            int r0 = r0.length()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 != 0) goto L_0x00a4
            goto L_0x0091
        L_0x00a4:
            int r0 = r14.nextIndex()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            int r0 = r0 + r3
            java.util.List r4 = X.Lea.LIZLLL(r4, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            goto L_0x00b0
        L_0x00ae:
            X.Lel r4 = X.Lel.INSTANCE     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
        L_0x00b0:
            java.lang.String[] r0 = new java.lang.String[r5]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.lang.Object[] r4 = r4.toArray(r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r4 == 0) goto L_0x00cd
            java.lang.String[] r4 = (java.lang.String[]) r4     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            int r14 = r4.length     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r0 = 2
            if (r14 != r0) goto L_0x00ca
            java.lang.String r14 = "capture"
            r0 = r4[r5]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            boolean r0 = kotlin.h.b.n.LIZ(r14, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x00ca
            r1 = r4[r3]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
        L_0x00ca:
            int r10 = r10 + 1
            goto L_0x0074
        L_0x00cd:
            java.lang.NullPointerException r0 = new java.lang.NullPointerException     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r0.<init>(r11)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            throw r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
        L_0x00d3:
            r0 = 0
            r15.LIZJ = r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            boolean r0 = kotlin.h.b.n.LIZ(r9, r8)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            java.lang.String r4 = "android.intent.extra.INTENT"
            if (r0 == 0) goto L_0x0105
            java.lang.String r0 = "camera"
            boolean r0 = kotlin.h.b.n.LIZ(r1, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x00ee
            android.content.Intent r0 = r15.LIZIZ()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r15.startActivityForResult(r0, r2)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            return
        L_0x00ee:
            android.content.Intent[] r1 = new android.content.Intent[r3]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r0 = r15.LIZIZ()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r1[r5] = r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r1 = r15.LIZ((android.content.Intent[]) r1)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r0 = r15.LIZ((java.lang.String) r8)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r1.putExtra(r4, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r15.startActivityForResult(r1, r2)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            return
        L_0x0105:
            boolean r0 = kotlin.h.b.n.LIZ(r9, r7)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x0132
            java.lang.String r0 = "camcorder"
            boolean r0 = kotlin.h.b.n.LIZ(r1, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x011b
            android.content.Intent r0 = r15.LIZJ()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r15.startActivityForResult(r0, r2)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            return
        L_0x011b:
            android.content.Intent[] r1 = new android.content.Intent[r3]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r0 = r15.LIZJ()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r1[r5] = r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r1 = r15.LIZ((android.content.Intent[]) r1)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r0 = r15.LIZ((java.lang.String) r7)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r1.putExtra(r4, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r15.startActivityForResult(r1, r2)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            return
        L_0x0132:
            boolean r0 = kotlin.h.b.n.LIZ(r9, r6)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x015f
            java.lang.String r0 = "microphone"
            boolean r0 = kotlin.h.b.n.LIZ(r1, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            if (r0 == 0) goto L_0x0148
            android.content.Intent r0 = r15.LIZLLL()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r15.startActivityForResult(r0, r2)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            return
        L_0x0148:
            android.content.Intent[] r1 = new android.content.Intent[r3]     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r0 = r15.LIZLLL()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r1[r5] = r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r1 = r15.LIZ((android.content.Intent[]) r1)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            android.content.Intent r0 = r15.LIZ((java.lang.String) r6)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r1.putExtra(r4, r0)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r15.startActivityForResult(r1, r2)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            return
        L_0x015f:
            android.content.Intent r0 = r15.LIZ()     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r15.startActivityForResult(r0, r2)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            return
        L_0x0167:
            java.lang.NullPointerException r0 = new java.lang.NullPointerException     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            r0.<init>(r11)     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
            throw r0     // Catch:{ ActivityNotFoundException -> 0x0172, Exception -> 0x016d }
        L_0x016d:
            r0 = move-exception
            X.0HH.LIZ(r0)
            return
        L_0x0172:
            r1 = move-exception
            r15.LIZLLL = r3     // Catch:{ ActivityNotFoundException -> 0x017d }
            android.content.Intent r0 = r15.LIZ()     // Catch:{ ActivityNotFoundException -> 0x017d }
            r15.startActivityForResult(r0, r2)     // Catch:{ ActivityNotFoundException -> 0x017d }
            return
        L_0x017d:
            X.0HH.LIZ(r1)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.crossplatform.platform.webview.UploadFileFragment.LIZ(java.lang.String, java.lang.String):void");
    }

    /* JADX WARNING: Code restructure failed: missing block: B:38:0x0074, code lost:
        if (r4 == null) goto L_0x001d;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void onActivityResult(int r8, int r9, android.content.Intent r10) {
        /*
            r7 = this;
            r0 = 2048(0x800, float:2.87E-42)
            if (r8 != r0) goto L_0x0069
            android.webkit.ValueCallback<android.net.Uri> r0 = r7.LIZ
            if (r0 != 0) goto L_0x000c
            android.webkit.ValueCallback<android.net.Uri[]> r0 = r7.LIZIZ
            if (r0 == 0) goto L_0x0069
        L_0x000c:
            r6 = 0
            if (r9 != 0) goto L_0x0016
            boolean r0 = r7.LIZLLL
            if (r0 == 0) goto L_0x0016
            r7.LIZLLL = r6
            return
        L_0x0016:
            r0 = -1
            r5 = 0
            if (r10 == 0) goto L_0x001c
            if (r9 == r0) goto L_0x0070
        L_0x001c:
            r4 = r5
        L_0x001d:
            if (r10 != 0) goto L_0x0052
            if (r9 != r0) goto L_0x0052
            java.io.File r1 = new java.io.File
            java.lang.String r0 = r7.LIZJ
            if (r0 != 0) goto L_0x002a
            kotlin.h.b.n.LIZIZ()
        L_0x002a:
            r1.<init>(r0)
            boolean r0 = r1.exists()
            if (r0 == 0) goto L_0x0052
            android.net.Uri r4 = android.net.Uri.fromFile(r1)
            X.9EH r0 = X.9EH.LJJIFFI
            android.content.Context r3 = r0.LIZ()
            java.lang.String r2 = r7.LIZJ
            if (r2 != 0) goto L_0x0044
            kotlin.h.b.n.LIZIZ()
        L_0x0044:
            java.lang.String r1 = r1.getName()
            java.lang.String r0 = ""
            kotlin.h.b.n.LIZIZ(r1, r0)
            java.lang.String r0 = "image"
            X.940.LIZ(r3, r2, r1, r0)
        L_0x0052:
            android.webkit.ValueCallback<android.net.Uri> r0 = r7.LIZ
            if (r0 == 0) goto L_0x005b
            r0.onReceiveValue(r4)
            r7.LIZ = r5
        L_0x005b:
            android.webkit.ValueCallback<android.net.Uri[]> r1 = r7.LIZIZ
            if (r1 == 0) goto L_0x0067
            if (r4 != 0) goto L_0x006a
            r0 = r5
        L_0x0062:
            r1.onReceiveValue(r0)
            r7.LIZIZ = r5
        L_0x0067:
            r7.LIZLLL = r6
        L_0x0069:
            return
        L_0x006a:
            r0 = 1
            android.net.Uri[] r0 = new android.net.Uri[r0]
            r0[r6] = r4
            goto L_0x0062
        L_0x0070:
            android.net.Uri r4 = r10.getData()
            if (r4 != 0) goto L_0x0052
            goto L_0x001d
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.crossplatform.platform.webview.UploadFileFragment.onActivityResult(int, int, android.content.Intent):void");
    }
}
