package o;

import android.content.Intent;
import android.os.Build;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import ir.devixor.app.activity.WebViewActivity;
import java.util.ArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Wk0 extends WebChromeClient {
    public final /* synthetic */ WebViewActivity a;

    public Wk0(WebViewActivity webViewActivity) {
        this.a = webViewActivity;
    }

    @Override // android.webkit.WebChromeClient
    public final boolean onShowFileChooser(WebView webView, ValueCallback valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
        String[] acceptTypes;
        final WebViewActivity webViewActivity = this.a;
        ValueCallback valueCallback2 = webViewActivity.s;
        final String[] strArr = null;
        if (valueCallback2 != null) {
            valueCallback2.onReceiveValue(null);
        }
        webViewActivity.s = valueCallback;
        if (fileChooserParams != null && (acceptTypes = fileChooserParams.getAcceptTypes()) != null) {
            ArrayList arrayList = new ArrayList();
            for (String str : acceptTypes) {
                if (str.length() > 0) {
                    arrayList.add(str);
                }
            }
            strArr = (String[]) arrayList.toArray(new String[0]);
        }
        final boolean z = fileChooserParams != null && fileChooserParams.getMode() == 1;
        boolean z2 = fileChooserParams != null && fileChooserParams.isCaptureEnabled();
        if (strArr == null || strArr.length == 0) {
            strArr = new String[]{"*/*"};
        }
        if (z2) {
            for (String str2 : strArr) {
                if (AbstractC1299gb0.L(str2, "image", false) || AbstractC1299gb0.L(str2, "video", false)) {
                    webViewActivity.i(new String[]{"android.permission.CAMERA"}, new C2590u5(19, webViewActivity, strArr));
                    return true;
                }
            }
        }
        NC nc = new NC() { // from class: o.Vk0
            @Override // o.NC
            public final Object a() {
                String str3;
                WebViewActivity webViewActivity2 = webViewActivity;
                String[] strArr2 = strArr;
                boolean z3 = z;
                WebViewActivity webViewActivity3 = WebViewActivity.x;
                Intent intent = new Intent("android.intent.action.GET_CONTENT");
                intent.addCategory("android.intent.category.OPENABLE");
                if (strArr2.length == 1) {
                    str3 = strArr2[0];
                } else {
                    int length = strArr2.length;
                    for (int i = 0; i < length && !F3.c(strArr2[i], "*/*"); i++) {
                    }
                    str3 = "*/*";
                }
                intent.setType(str3);
                if (strArr2.length != 0 && !F3.c(strArr2[0], "*/*")) {
                    intent.putExtra("android.intent.extra.MIME_TYPES", strArr2);
                }
                intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", z3);
                AbstractC2962y1 abstractC2962y1 = webViewActivity2.u;
                if (abstractC2962y1 == null) {
                    abstractC2962y1 = null;
                }
                abstractC2962y1.a(Intent.createChooser(intent, "انتخاب فایل"));
                return Oh0.a;
            }
        };
        ArrayList arrayList2 = new ArrayList();
        int i = Build.VERSION.SDK_INT;
        if (i >= 33) {
            arrayList2.add("android.permission.READ_MEDIA_IMAGES");
            arrayList2.add("android.permission.READ_MEDIA_VIDEO");
        } else {
            arrayList2.add("android.permission.READ_EXTERNAL_STORAGE");
            if (i < 29) {
                arrayList2.add("android.permission.WRITE_EXTERNAL_STORAGE");
            }
        }
        webViewActivity.i((String[]) arrayList2.toArray(new String[0]), nc);
        return true;
    }
}
