package ir.devixor.app.activity;

import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.webkit.CookieManager;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import androidx.appcompat.app.AppCompatActivity;
import ir.devixor.app.MainActivity;
import ir.devixor.app.activity.WebViewActivity;
import java.util.ArrayList;
import o.AbstractC0662Zn;
import o.AbstractC1299gb0;
import o.AbstractC1692kh0;
import o.AbstractC1903ms;
import o.AbstractC2962y1;
import o.C0147Fr;
import o.C0684a4;
import o.C1001dS;
import o.C2468sq;
import o.C2867x1;
import o.Co0;
import o.ExecutorC1232fq;
import o.InterfaceC0220Im;
import o.InterfaceC2677v1;
import o.NC;
import o.Sb0;
import o.Tk0;
import o.Uk0;
import o.Wk0;
import o.Xk0;
import o.ZB;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class WebViewActivity extends AppCompatActivity {
    public static volatile WebViewActivity x;
    public static volatile WebView y;
    public WebView m;
    public SharedPreferences n;

    /* renamed from: o, reason: collision with root package name */
    public FrameLayout f33o;
    public View p;
    public ConnectivityManager q;
    public C1001dS r;
    public ValueCallback s;
    public Uri t;
    public AbstractC2962y1 u;
    public AbstractC2962y1 v;
    public NC w;

    public static Object f(WebViewActivity webViewActivity, Sb0 sb0) {
        C2468sq c2468sq = AbstractC1903ms.a;
        return AbstractC1692kh0.T(ExecutorC1232fq.m, new C0684a4(webViewActivity, null, 5), sb0);
    }

    public final void g() {
        ViewPropertyAnimator viewPropertyAnimatorAnimate;
        ViewPropertyAnimator viewPropertyAnimatorAlpha;
        ViewPropertyAnimator viewPropertyAnimatorTranslationY;
        ViewPropertyAnimator duration;
        ViewPropertyAnimator viewPropertyAnimatorWithEndAction;
        View view = this.p;
        if (view == null || (viewPropertyAnimatorAnimate = view.animate()) == null || (viewPropertyAnimatorAlpha = viewPropertyAnimatorAnimate.alpha(0.0f)) == null || (viewPropertyAnimatorTranslationY = viewPropertyAnimatorAlpha.translationY(300.0f)) == null || (duration = viewPropertyAnimatorTranslationY.setDuration(300L)) == null || (viewPropertyAnimatorWithEndAction = duration.withEndAction(new Tk0(this, 1))) == null) {
            return;
        }
        viewPropertyAnimatorWithEndAction.start();
    }

    public final boolean h() {
        ConnectivityManager connectivityManager = this.q;
        if (connectivityManager == null) {
            connectivityManager = null;
        }
        Network activeNetwork = connectivityManager.getActiveNetwork();
        if (activeNetwork == null) {
            return false;
        }
        ConnectivityManager connectivityManager2 = this.q;
        NetworkCapabilities networkCapabilities = (connectivityManager2 != null ? connectivityManager2 : null).getNetworkCapabilities(activeNetwork);
        return networkCapabilities != null && networkCapabilities.hasCapability(12) && networkCapabilities.hasCapability(16);
    }

    public final void i(String[] strArr, NC nc) {
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            if (Co0.l(this, str) != 0) {
                arrayList.add(str);
            }
        }
        if (arrayList.isEmpty()) {
            nc.a();
            return;
        }
        this.w = nc;
        AbstractC2962y1 abstractC2962y1 = this.v;
        if (abstractC2962y1 == null) {
            abstractC2962y1 = null;
        }
        abstractC2962y1.a(arrayList.toArray(new String[0]));
    }

    public final void j(String str) {
        if (str.equals("about:blank")) {
            return;
        }
        if (AbstractC1299gb0.L(str, "http://", false) || AbstractC1299gb0.L(str, "https://", false)) {
            SharedPreferences sharedPreferences = this.n;
            if (sharedPreferences == null) {
                sharedPreferences = null;
            }
            sharedPreferences.edit().putString("current_url", str).apply();
        }
    }

    public final void k() {
        if (this.p != null) {
            return;
        }
        runOnUiThread(new Tk0(this, 0));
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        x = this;
        this.n = getSharedPreferences(MainActivity.PREFS_NAME, 0);
        this.q = (ConnectivityManager) getSystemService("connectivity");
        final int i = 0;
        this.v = registerForActivityResult(new C2867x1(1), new InterfaceC2677v1(this) { // from class: o.Sk0
            public final /* synthetic */ WebViewActivity m;

            {
                this.m = this;
            }

            /* JADX WARN: Removed duplicated region for block: B:52:0x00bd  */
            @Override // o.InterfaceC2677v1
            /*
                Code decompiled incorrectly, please refer to instructions dump.
                To view partially-correct add '--show-bad-code' argument
            */
            public final void c(java.lang.Object r9) {
                /*
                    r8 = this;
                    int r0 = r2
                    r1 = 0
                    switch(r0) {
                        case 0: goto L77;
                        default: goto L6;
                    }
                L6:
                    ir.devixor.app.activity.WebViewActivity r0 = r8.m
                    o.u1 r9 = (o.C2582u1) r9
                    android.webkit.ValueCallback r2 = r0.s
                    if (r2 != 0) goto L11
                    r0.t = r1
                    goto L76
                L11:
                    int r3 = r9.l
                    r4 = -1
                    if (r3 != r4) goto L6f
                    android.content.Intent r9 = r9.m
                    java.util.ArrayList r3 = new java.util.ArrayList
                    r3.<init>()
                    if (r9 == 0) goto L24
                    android.content.ClipData r4 = r9.getClipData()
                    goto L25
                L24:
                    r4 = r1
                L25:
                    r5 = 0
                    if (r4 == 0) goto L43
                    int r6 = r4.getItemCount()
                    if (r6 <= 0) goto L43
                    int r9 = r4.getItemCount()
                    r6 = r5
                L33:
                    if (r6 >= r9) goto L4e
                    android.content.ClipData$Item r7 = r4.getItemAt(r6)
                    android.net.Uri r7 = r7.getUri()
                    r3.add(r7)
                    int r6 = r6 + 1
                    goto L33
                L43:
                    if (r9 == 0) goto L4e
                    android.net.Uri r9 = r9.getData()
                    if (r9 == 0) goto L4e
                    r3.add(r9)
                L4e:
                    boolean r9 = r3.isEmpty()
                    if (r9 == 0) goto L5b
                    android.net.Uri r9 = r0.t
                    if (r9 == 0) goto L5b
                    r3.add(r9)
                L5b:
                    boolean r9 = r3.isEmpty()
                    if (r9 != 0) goto L6b
                    android.net.Uri[] r9 = new android.net.Uri[r5]
                    java.lang.Object[] r9 = r3.toArray(r9)
                    r2.onReceiveValue(r9)
                    goto L72
                L6b:
                    r2.onReceiveValue(r1)
                    goto L72
                L6f:
                    r2.onReceiveValue(r1)
                L72:
                    r0.s = r1
                    r0.t = r1
                L76:
                    return
                L77:
                    ir.devixor.app.activity.WebViewActivity r0 = r8.m
                    java.util.Map r9 = (java.util.Map) r9
                    ir.devixor.app.activity.WebViewActivity r2 = ir.devixor.app.activity.WebViewActivity.x
                    java.util.Set r9 = r9.entrySet()
                    java.lang.Iterable r9 = (java.lang.Iterable) r9
                    boolean r2 = r9 instanceof java.util.Collection
                    if (r2 == 0) goto L91
                    r2 = r9
                    java.util.Collection r2 = (java.util.Collection) r2
                    boolean r2 = r2.isEmpty()
                    if (r2 == 0) goto L91
                    goto Lb9
                L91:
                    java.util.Iterator r9 = r9.iterator()
                L95:
                    boolean r2 = r9.hasNext()
                    if (r2 == 0) goto Lb9
                    java.lang.Object r2 = r9.next()
                    java.util.Map$Entry r2 = (java.util.Map.Entry) r2
                    java.lang.Object r2 = r2.getValue()
                    java.lang.Boolean r2 = (java.lang.Boolean) r2
                    boolean r2 = r2.booleanValue()
                    if (r2 != 0) goto L95
                    android.webkit.ValueCallback r9 = r0.s
                    if (r9 == 0) goto Lb4
                    r9.onReceiveValue(r1)
                Lb4:
                    r0.s = r1
                    r0.t = r1
                    goto Lc0
                Lb9:
                    o.NC r9 = r0.w
                    if (r9 == 0) goto Lc0
                    r9.a()
                Lc0:
                    r0.w = r1
                    return
                */
                throw new UnsupportedOperationException("Method not decompiled: o.Sk0.c(java.lang.Object):void");
            }
        });
        final int i2 = 1;
        this.u = registerForActivityResult(new C2867x1(3), new InterfaceC2677v1(this) { // from class: o.Sk0
            public final /* synthetic */ WebViewActivity m;

            {
                this.m = this;
            }

            @Override // o.InterfaceC2677v1
            public final void c(Object v) {
                /*
                    this = this;
                    int r0 = r2
                    r1 = 0
                    switch(r0) {
                        case 0: goto L77;
                        default: goto L6;
                    }
                L6:
                    ir.devixor.app.activity.WebViewActivity r0 = r8.m
                    o.u1 r9 = (o.C2582u1) r9
                    android.webkit.ValueCallback r2 = r0.s
                    if (r2 != 0) goto L11
                    r0.t = r1
                    goto L76
                L11:
                    int r3 = r9.l
                    r4 = -1
                    if (r3 != r4) goto L6f
                    android.content.Intent r9 = r9.m
                    java.util.ArrayList r3 = new java.util.ArrayList
                    r3.<init>()
                    if (r9 == 0) goto L24
                    android.content.ClipData r4 = r9.getClipData()
                    goto L25
                L24:
                    r4 = r1
                L25:
                    r5 = 0
                    if (r4 == 0) goto L43
                    int r6 = r4.getItemCount()
                    if (r6 <= 0) goto L43
                    int r9 = r4.getItemCount()
                    r6 = r5
                L33:
                    if (r6 >= r9) goto L4e
                    android.content.ClipData$Item r7 = r4.getItemAt(r6)
                    android.net.Uri r7 = r7.getUri()
                    r3.add(r7)
                    int r6 = r6 + 1
                    goto L33
                L43:
                    if (r9 == 0) goto L4e
                    android.net.Uri r9 = r9.getData()
                    if (r9 == 0) goto L4e
                    r3.add(r9)
                L4e:
                    boolean r9 = r3.isEmpty()
                    if (r9 == 0) goto L5b
                    android.net.Uri r9 = r0.t
                    if (r9 == 0) goto L5b
                    r3.add(r9)
                L5b:
                    boolean r9 = r3.isEmpty()
                    if (r9 != 0) goto L6b
                    android.net.Uri[] r9 = new android.net.Uri[r5]
                    java.lang.Object[] r9 = r3.toArray(r9)
                    r2.onReceiveValue(r9)
                    goto L72
                L6b:
                    r2.onReceiveValue(r1)
                    goto L72
                L6f:
                    r2.onReceiveValue(r1)
                L72:
                    r0.s = r1
                    r0.t = r1
                L76:
                    return
                L77:
                    ir.devixor.app.activity.WebViewActivity r0 = r8.m
                    java.util.Map r9 = (java.util.Map) r9
                    ir.devixor.app.activity.WebViewActivity r2 = ir.devixor.app.activity.WebViewActivity.x
                    java.util.Set r9 = r9.entrySet()
                    java.lang.Iterable r9 = (java.lang.Iterable) r9
                    boolean r2 = r9 instanceof java.util.Collection
                    if (r2 == 0) goto L91
                    r2 = r9
                    java.util.Collection r2 = (java.util.Collection) r2
                    boolean r2 = r2.isEmpty()
                    if (r2 == 0) goto L91
                    goto Lb9
                L91:
                    java.util.Iterator r9 = r9.iterator()
                L95:
                    boolean r2 = r9.hasNext()
                    if (r2 == 0) goto Lb9
                    java.lang.Object r2 = r9.next()
                    java.util.Map$Entry r2 = (java.util.Map.Entry) r2
                    java.lang.Object r2 = r2.getValue()
                    java.lang.Boolean r2 = (java.lang.Boolean) r2
                    boolean r2 = r2.booleanValue()
                    if (r2 != 0) goto L95
                    android.webkit.ValueCallback r9 = r0.s
                    if (r9 == 0) goto Lb4
                    r9.onReceiveValue(r1)
                Lb4:
                    r0.s = r1
                    r0.t = r1
                    goto Lc0
                Lb9:
                    o.NC r9 = r0.w
                    if (r9 == 0) goto Lc0
                    r9.a()
                Lc0:
                    r0.w = r1
                    return
                */
                throw new UnsupportedOperationException("Method not decompiled: o.Sk0.c(java.lang.Object):void");
            }
        });
        FrameLayout frameLayout = new FrameLayout(this);
        frameLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        this.f33o = frameLayout;
        WebView webView = new WebView(this);
        webView.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        this.m = webView;
        y = webView;
        WebView webView2 = this.m;
        Object[] objArr = 0;
        if (webView2 == null) {
            webView2 = null;
        }
        webView2.setLayerType(1, null);
        WebView webView3 = this.m;
        if (webView3 == null) {
            webView3 = null;
        }
        WebSettings settings = webView3.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setCacheMode(2);
        settings.setSupportZoom(false);
        settings.setBuiltInZoomControls(false);
        settings.setAllowFileAccess(true);
        settings.setAllowContentAccess(true);
        if (Build.VERSION.SDK_INT >= 26) {
            settings.setSafeBrowsingEnabled(true);
        }
        WebView webView4 = this.m;
        if (webView4 == null) {
            webView4 = null;
        }
        webView4.addJavascriptInterface(new C0147Fr(this), "AndroidDevice");
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        WebView webView5 = this.m;
        if (webView5 == null) {
            webView5 = null;
        }
        cookieManager.setAcceptThirdPartyCookies(webView5, true);
        WebView webView6 = this.m;
        if (webView6 == null) {
            webView6 = null;
        }
        webView6.setWebChromeClient(new Wk0(this));
        WebView webView7 = this.m;
        if (webView7 == null) {
            webView7 = null;
        }
        webView7.setWebViewClient(new Xk0(this));
        FrameLayout frameLayout2 = this.f33o;
        if (frameLayout2 == null) {
            frameLayout2 = null;
        }
        WebView webView8 = this.m;
        if (webView8 == null) {
            webView8 = null;
        }
        frameLayout2.addView(webView8);
        FrameLayout frameLayout3 = this.f33o;
        if (frameLayout3 == null) {
            frameLayout3 = null;
        }
        setContentView(frameLayout3);
        if (h()) {
            SharedPreferences sharedPreferences = this.n;
            if (sharedPreferences == null) {
                sharedPreferences = null;
            }
            String string = sharedPreferences.getString("current_url", null);
            if (string == null || string.length() == 0) {
                AbstractC1692kh0.C(AbstractC0662Zn.w(this), null, new Uk0(this, objArr == true ? 1 : 0, 2), 3);
            } else {
                WebView webView9 = this.m;
                if (webView9 == null) {
                    webView9 = null;
                }
                webView9.loadUrl(string);
            }
        } else {
            WebView webView10 = this.m;
            if (webView10 == null) {
                webView10 = null;
            }
            webView10.loadUrl("about:blank");
            k();
        }
        getOnBackPressedDispatcher().a(new ZB(2, this), this);
        this.r = new C1001dS(2, this);
        NetworkRequest networkRequestBuild = new NetworkRequest.Builder().addCapability(12).addCapability(16).build();
        ConnectivityManager connectivityManager = this.q;
        (connectivityManager != null ? connectivityManager : null).registerNetworkCallback(networkRequestBuild, this.r);
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public final void onDestroy() {
        super.onDestroy();
        C1001dS c1001dS = this.r;
        if (c1001dS != null) {
            try {
                ConnectivityManager connectivityManager = this.q;
                if (connectivityManager == null) {
                    connectivityManager = null;
                }
                connectivityManager.unregisterNetworkCallback(c1001dS);
            } catch (Exception unused) {
            }
        }
        this.r = null;
        WebView webView = this.m;
        if (webView != null) {
            FrameLayout frameLayout = this.f33o;
            if (frameLayout == null) {
                frameLayout = null;
            }
            frameLayout.removeView(webView);
            WebView webView2 = this.m;
            if (webView2 == null) {
                webView2 = null;
            }
            webView2.stopLoading();
            WebView webView3 = this.m;
            if (webView3 == null) {
                webView3 = null;
            }
            webView3.clearHistory();
            WebView webView4 = this.m;
            if (webView4 == null) {
                webView4 = null;
            }
            webView4.clearCache(true);
            WebView webView5 = this.m;
            if (webView5 == null) {
                webView5 = null;
            }
            webView5.destroy();
        }
        y = null;
        x = null;
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public final void onPause() {
        super.onPause();
        WebView webView = this.m;
        if (webView != null) {
            if (webView == null) {
                webView = null;
            }
            String url = webView.getUrl();
            if (url != null) {
                j(url);
            }
            WebView webView2 = this.m;
            (webView2 != null ? webView2 : null).onPause();
        }
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public final void onResume() {
        super.onResume();
        x = this;
        WebView webView = this.m;
        InterfaceC0220Im interfaceC0220Im = null;
        if (webView == null) {
            webView = null;
        }
        y = webView;
        WebView webView2 = this.m;
        if (webView2 != null) {
            webView2.onResume();
            AbstractC1692kh0.C(AbstractC0662Zn.w(this), null, new Uk0(this, interfaceC0220Im, 0), 3);
        }
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, android.app.Activity
    public final void onStart() throws IllegalAccessException, NoSuchFieldException, PackageManager.NameNotFoundException, SecurityException, IllegalArgumentException {
        super.onStart();
        x = this;
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity, android.content.ComponentCallbacks2
    public final void onTrimMemory(int i) {
        WebView webView;
        super.onTrimMemory(i);
        if (i < 60 || (webView = this.m) == null) {
            return;
        }
        if (webView == null) {
            webView = null;
        }
        webView.clearCache(true);
    }
}
