package o;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import ir.devixor.app.activity.WebViewActivity;
import java.net.URISyntaxException;

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

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

    @Override // android.webkit.WebViewClient
    public final void onPageFinished(WebView webView, String str) {
        super.onPageFinished(webView, str);
        if (str != null) {
            WebViewActivity webViewActivity = this.a;
            WebViewActivity webViewActivity2 = WebViewActivity.x;
            webViewActivity.j(str);
        }
    }

    @Override // android.webkit.WebViewClient
    public final void onPageStarted(WebView webView, String str, Bitmap bitmap) {
        super.onPageStarted(webView, str, bitmap);
        WebViewActivity webViewActivity = this.a;
        WebViewActivity webViewActivity2 = WebViewActivity.x;
        if (webViewActivity.h()) {
            return;
        }
        if (webView != null) {
            webView.stopLoading();
        }
        webViewActivity.k();
    }

    @Override // android.webkit.WebViewClient
    public final void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
        super.onReceivedError(webView, webResourceRequest, webResourceError);
        if (webResourceRequest == null || !webResourceRequest.isForMainFrame()) {
            return;
        }
        if (webView != null) {
            webView.stopLoading();
        }
        if (webView != null) {
            webView.loadUrl("about:blank");
        }
        WebViewActivity webViewActivity = this.a;
        WebViewActivity webViewActivity2 = WebViewActivity.x;
        webViewActivity.k();
    }

    @Override // android.webkit.WebViewClient
    public final boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) throws URISyntaxException {
        Uri url;
        WebViewActivity webViewActivity = this.a;
        if (webResourceRequest != null && (url = webResourceRequest.getUrl()) != null) {
            String string = url.toString();
            WebViewActivity webViewActivity2 = WebViewActivity.x;
            if (!webViewActivity.h()) {
                webViewActivity.k();
                return true;
            }
            if (Za0.P(string, "://", false)) {
                String scheme = url.getScheme();
                if (scheme == null) {
                    scheme = "";
                }
                if (scheme.equals("http") || scheme.equals("https")) {
                    return false;
                }
                try {
                    if (!scheme.equals("intent")) {
                        webViewActivity.startActivity(new Intent("android.intent.action.VIEW", url));
                        return true;
                    }
                    Intent uri = Intent.parseUri(string, 1);
                    try {
                        webViewActivity.startActivity(uri);
                    } catch (Exception unused) {
                        String stringExtra = uri.getStringExtra("browser_fallback_url");
                        if (stringExtra != null && stringExtra.length() != 0 && webView != null) {
                            webView.loadUrl(stringExtra);
                        }
                    }
                } catch (Exception unused2) {
                }
            } else {
                String strConcat = "https://".concat(string);
                if (webView != null) {
                    webView.loadUrl(strConcat);
                    return true;
                }
            }
        }
        return true;
    }
}
