导航菜单

页面标题

页面副标题

BAM Crawford v6.14.1 - BrowserFragment.java 源代码

正在查看: BAM Crawford v6.14.1 应用的 BrowserFragment.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.subsplash.thechurchapp.handlers.browser;

import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.MailTo;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.ConsoleMessage;
import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.google.gson.GsonBuilder;
import com.subsplash.thechurchapp.FullscreenFragmentActivity;
import com.subsplash.thechurchapp.TheChurchApp;
import com.subsplash.thechurchapp.api.e;
import com.subsplash.thechurchapp.api.i;
import com.subsplash.thechurchapp.dataObjects.ColorPalette;
import com.subsplash.thechurchapp.dataObjects.DisplayOptions;
import com.subsplash.thechurchapp.handlers.browser.BrowserHandler;
import com.subsplash.thechurchapp.handlers.common.HandlerFragment;
import com.subsplash.thechurchapp.handlers.common.NavigationHandler;
import com.subsplash.thechurchapp.handlers.common.a;
import com.subsplash.thechurchapp.handlers.notes.NoteHandler;
import com.subsplash.thechurchapp.handlers.pdf.PDFHandler;
import com.subsplash.util.e0;
import com.subsplash.util.f0;
import com.subsplash.util.h0;
import com.subsplash.util.j0;
import com.subsplash.util.n0;
import com.subsplash.util.o0;
import com.subsplash.util.s0;
import com.subsplash.util.u;
import com.subsplash.util.y;
import java.lang.ref.WeakReference;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import okhttp3.HttpUrl;
import pi.n;
import pi.o;
import pi.q;

public class BrowserFragment extends HandlerFragment implements i.c {
    private static final int FILECHOOSER_RESULTCODE = 1;
    public static final int REQUEST_SELECT_FILE = 100;
    private static final String SHOW_BROWSER_BAR = "showBrowserBar";
    private static final String TAG = "BrowserFragment";
    private static final String WEBVIEW_BLANK = "about:blank";
    private boolean clickOpensExternalBrowser;
    private String currentCacheUrl;
    private WebChromeClient.CustomViewCallback fullscreenCallback;
    private i gestureManager;
    private boolean hideNavBar;
    private ArrayList<String> history;
    private int historyIndex;
    protected boolean initialLoadComplete;
    private boolean isErrorActive;
    private boolean isInterceptingBack;
    protected com.subsplash.thechurchapp.api.e jsManagerCompat;
    private ValueCallback<Uri> mUploadMessage;
    private boolean needsReloadForAuth;
    protected String originalUrl;
    private String pageContent;
    private String pageTitle;
    protected String pageUrl;
    private boolean showBrowserBar;
    protected boolean suppressWebViewTitle;
    public ValueCallback<Uri[]> uploadMessage;
    private com.subsplash.thechurchapp.handlers.browser.a webArchiveDiskCache;
    private boolean webArchiveLoadComplete;
    private WebView webView;

    class a implements View.OnClickListener {
        a() {
        }

        @Override
        public void onClick(View view) {
            BrowserFragment.this.showActionsDialog();
        }
    }

    class b implements View.OnClickListener {
        b() {
        }

        @Override
        public void onClick(View view) {
            BrowserFragment.this.webView.reload();
        }
    }

    class c implements View.OnClickListener {
        c() {
        }

        @Override
        public void onClick(View view) {
            BrowserFragment.this.webViewGoForward();
            BrowserFragment.this.refreshToolbar();
        }
    }

    class d implements View.OnClickListener {
        d() {
        }

        @Override
        public void onClick(View view) {
            BrowserFragment.this.webViewGoBack();
            BrowserFragment.this.refreshToolbar();
        }
    }

    class e extends WebViewClient {
        final WeakReference a;

        e(WeakReference weakReference) {
            this.a = weakReference;
        }

        @Override
        public void onPageFinished(WebView webView, String str) {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            if (browserFragment == null) {
                return;
            }
            browserFragment.onPageFinished(webView, str);
        }

        @Override
        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            if (browserFragment == null) {
                return;
            }
            browserFragment.onPageStarted(webView, str);
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView webView, HttpAuthHandler httpAuthHandler, String str, String str2) {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            if (browserFragment == null) {
                return;
            }
            browserFragment.onReceivedHttpAuthRequest(webView, httpAuthHandler, str, str2);
        }

        @Override
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            if (browserFragment == null) {
                return;
            }
            browserFragment.onReceivedError(webView, webResourceRequest, webResourceResponse);
        }

        @Override
        public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            sslErrorHandler.cancel();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            if (browserFragment == null) {
                return false;
            }
            return browserFragment.shouldOverrideUrlLoading(webView, webResourceRequest);
        }
    }

    class f extends WebChromeClient {
        final WeakReference a;

        class a extends HashMap {
            final String p;

            a(String str) {
                this.p = str;
                put("error_js_exception", str);
                put("context", getClass().toString());
            }
        }

        f(WeakReference weakReference) {
            this.a = weakReference;
        }

        private ConstraintLayout a() {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            View view = (browserFragment == null || ((HandlerFragment) browserFragment).contentRootView == null) ? null : ((HandlerFragment) browserFragment).contentRootView;
            if (view != null) {
                return view.findViewById(n.browser_fullscreen_view_holder);
            }
            return null;
        }

        private void b(WebChromeClient.CustomViewCallback customViewCallback) {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            if (browserFragment != null) {
                browserFragment.fullscreenCallback = customViewCallback;
            }
        }

        private void c(boolean z) {
            BrowserFragment browserFragment = (BrowserFragment) this.a.get();
            ConstraintLayout.b bVar = null;
            View view = (browserFragment == null || ((HandlerFragment) browserFragment).contentRootView == null) ? null : ((HandlerFragment) browserFragment).contentRootView;
            Object context = view != null ? view.getContext() : null;
            if (context instanceof FullscreenFragmentActivity) {
                FullscreenFragmentActivity fullscreenFragmentActivity = (FullscreenFragmentActivity) context;
                fullscreenFragmentActivity.z0(z);
                fullscreenFragmentActivity.m0(z);
                ConstraintLayout findViewById = fullscreenFragmentActivity.findViewById(n.fragment_container_window_fitter);
                if (findViewById != null && (findViewById.getLayoutParams() instanceof ConstraintLayout.b)) {
                    bVar = (ConstraintLayout.b) findViewById.getLayoutParams();
                }
                if (bVar != null) {
                    if (z) {
                        bVar.i = n.toolbar_container;
                        bVar.h = -1;
                    } else {
                        bVar.i = -1;
                        bVar.h = 0;
                    }
                    findViewById.setLayoutParams(bVar);
                }
            }
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            if (consoleMessage.messageLevel() != ConsoleMessage.MessageLevel.ERROR) {
                return super.onConsoleMessage(consoleMessage);
            }
            o0.a.c("javascript_error", new a(consoleMessage.message()));
            return true;
        }

        @Override
        public void onHideCustomView() {
            super.onHideCustomView();
            ConstraintLayout a2 = a();
            if (a2 != null) {
                a2.removeAllViews();
                c(true);
                b(null);
            }
        }

        @Override
        public void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
            super.onShowCustomView(view, customViewCallback);
            ConstraintLayout a2 = a();
            if (a2 != null) {
                a2.removeAllViews();
                c(false);
                ConstraintLayout.b bVar = new ConstraintLayout.b(-2, -2);
                bVar.q = 0;
                bVar.s = 0;
                bVar.h = 0;
                bVar.k = 0;
                a2.addView(view, bVar);
                b(customViewCallback);
            }
        }

        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
            ValueCallback<Uri[]> valueCallback2 = BrowserFragment.this.uploadMessage;
            if (valueCallback2 != null) {
                valueCallback2.onReceiveValue(null);
                BrowserFragment.this.uploadMessage = null;
            }
            BrowserFragment.this.uploadMessage = valueCallback;
            try {
                BrowserFragment.this.startActivityForResult(fileChooserParams.createIntent(), 100);
                return true;
            } catch (ActivityNotFoundException unused) {
                BrowserFragment.this.uploadMessage = null;
                return false;
            }
        }
    }

    class g implements DialogInterface.OnClickListener {
        g() {
        }

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    }

    class h implements DialogInterface.OnClickListener {
        final WeakReference p;

        h(WeakReference weakReference) {
            this.p = weakReference;
        }

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            BrowserFragment browserFragment = (BrowserFragment) this.p.get();
            if (browserFragment == null) {
                return;
            }
            androidx.fragment.app.d activity = browserFragment.getActivity();
            if (i == 0) {
                com.subsplash.util.i.m(activity, browserFragment.webView.getUrl());
            } else {
                if (i != 1) {
                    return;
                }
                com.subsplash.util.i.r(activity, activity.getString(q.email_share_subject), browserFragment.webView.getUrl());
            }
        }
    }

    public BrowserFragment() {
        this.jsManagerCompat = null;
        this.gestureManager = null;
        this.hideNavBar = false;
        this.showBrowserBar = false;
        this.clickOpensExternalBrowser = false;
        this.isErrorActive = false;
        this.isInterceptingBack = false;
        this.initialLoadComplete = false;
        this.needsReloadForAuth = false;
        this.suppressWebViewTitle = false;
        this.fullscreenCallback = null;
        this.currentCacheUrl = null;
        this.webArchiveDiskCache = new com.subsplash.thechurchapp.handlers.browser.a();
        this.webArchiveLoadComplete = false;
        this.history = new ArrayList<>();
        this.historyIndex = 0;
    }

    private void addToHistory(String str) {
        if (str == null || str.isEmpty()) {
            return;
        }
        if (this.history.isEmpty()) {
            this.history.add(str);
            this.historyIndex = 0;
            return;
        }
        int i = this.historyIndex;
        if (i >= 0 && i < this.history.size() - 1 && str.equals(this.history.get(this.historyIndex + 1))) {
            this.historyIndex++;
            return;
        }
        ArrayList<String> arrayList = this.history;
        arrayList.subList(this.historyIndex + 1, arrayList.size()).clear();
        this.history.add(str);
        this.historyIndex = this.history.size() - 1;
    }

    private boolean closeIfInterceptingBack() {
        if (!this.isInterceptingBack) {
            return false;
        }
        getActivity().finish();
        return true;
    }

    private com.subsplash.thechurchapp.handlers.common.i createNavigationItem(String str, String str2, String str3, HashMap<String, String> hashMap) {
        com.subsplash.thechurchapp.handlers.common.i iVar = new com.subsplash.thechurchapp.handlers.common.i(false);
        iVar.setName(str);
        iVar.setNavigationHandler(NavigationHandler.CreateHandler(str2, str3));
        if (hashMap != null) {
            for (Map.Entry<String, String> entry : hashMap.entrySet()) {
                iVar.getNavigationHandler().setExtra(entry.getKey(), entry.getValue());
            }
        }
        return iVar;
    }

    private WebViewClient createWebViewClient() {
        return new e(new WeakReference(this));
    }

    private View.OnClickListener getActionsOnClickListener() {
        return new a();
    }

    private View.OnClickListener getBackOnClickListener() {
        return new d();
    }

    private boolean getBooleanParameterValue(String str, String str2, boolean z) {
        try {
            return new Integer(getParameterValue(str, str2, z ? "1" : "0")).intValue() != 0;
        } catch (NumberFormatException e2) {
            Log.e(TAG, e2.toString());
            return z;
        }
    }

    private boolean getClickOpensExternalBrowserParameter(String str) {
        return getBooleanParameterValue(str, ".+clickOpensExternalBrowser=([0-1])&*.*", this.clickOpensExternalBrowser);
    }

    private boolean getCloseParameter(String str) {
        return getBooleanParameterValue(str, ".+close=([0-1])&*.*", false);
    }

    private View.OnClickListener getForwardOnClickListener() {
        return new c();
    }

    private void getHandlerData() {
        BrowserHandler browserHandler = (BrowserHandler) this.handler;
        if (this.originalUrl == null && browserHandler != null && browserHandler.getContentUri() != null) {
            this.originalUrl = browserHandler.getContentUri().toString();
        }
        if (!u.k(this.originalUrl)) {
            this.currentCacheUrl = this.originalUrl;
        }
        if (this.originalUrl == null) {
            showError();
            return;
        }
        if (isActivityContextAlive()) {
            if (e0.i(this.originalUrl)) {
                this.originalUrl = e0.c(this.originalUrl).toString();
            }
            Log.d(TAG, "Original URL: " + this.originalUrl);
            Bundle extras = getActivity().getIntent().getExtras();
            if (extras != null) {
                this.pageTitle = extras.getString(NoteHandler.JSON_KEY_TITLE);
                this.pageContent = extras.getString("content");
            }
            NavigationHandler navigationHandler = this.handler;
            this.showBrowserBar = !(navigationHandler == null || navigationHandler.getHandlerName() == null || !this.handler.getHandlerName().contains(SHOW_BROWSER_BAR)) || browserHandler.showBrowserControls;
        }
    }

    private HashMap<String, String> getHashMapFromUrlParameters(String str) {
        HashMap<String, String> hashMap = new HashMap<>();
        if (!y.c(str)) {
            for (String str2 : str.split("&")) {
                String[] split = str2.split("=");
                hashMap.put(split[0], split[1]);
            }
        }
        return hashMap;
    }

    private boolean getHideNavBarParameter(String str) {
        return getBooleanParameterValue(str, ".+hideNavBar=([0-1])&*.*", this.hideNavBar);
    }

    private boolean getIsInterceptingBackParameter(String str) {
        return getBooleanParameterValue(str, ".+interceptBackButton=([0-1])&*.*", this.isInterceptingBack);
    }

    private String getLinkParameter(String str) {
        return getParameterValue(str, ".+link=([.[^&]]+)&*.*", WEBVIEW_BLANK);
    }

    private View.OnClickListener getRefreshOnClickListener() {
        return new b();
    }

    private boolean getShowBrowserBarParameter(String str) {
        return getBooleanParameterValue(str, ".+showBrowserBar=([0-1])&*.*", this.showBrowserBar);
    }

    private String getTitleParameter(String str) {
        return URLDecoder.decode(getParameterValue(str, ".+title=([.[^&]]+)&*.*", HttpUrl.FRAGMENT_ENCODE_SET));
    }

    private boolean isSubsplashURI(String str) {
        return Pattern.compile("subsplash://(.*)", 2).matcher(str).matches();
    }

    private void launchLink(String str) {
        String decode = URLDecoder.decode(str);
        if (y.c(decode) || decode.toLowerCase().equals(WEBVIEW_BLANK)) {
            return;
        }
        String str2 = this.clickOpensExternalBrowser ? "externalBrowser" : "internalBrowser";
        com.subsplash.thechurchapp.handlers.common.i createNavigationItem = createNavigationItem(str2, str2, decode, null);
        if (isActivityContextAlive()) {
            NavigationHandler.loadHandler(TAG, createNavigationItem.getNavigationHandler(), getActivity());
        }
    }

    private void launchUsingNativeIntent(String str, String str2) {
        if (isActivityContextAlive()) {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setDataAndType(e0.j(Uri.parse(str)), str2);
            getActivity().startActivity(intent);
        }
    }

    private boolean launched3GP(String str) {
        if (!str.contains(".3gp")) {
            return false;
        }
        launchUsingNativeIntent(str, "video/3gp");
        return true;
    }

    private boolean launchedCallbackUri(String str) {
        BrowserHandler.CallbackContent callbackContent;
        Uri parse = Uri.parse(str);
        Class callbackClass = getCallbackClass(parse);
        if (callbackClass == null) {
            return false;
        }
        String lastPathSegment = parse.getLastPathSegment();
        if (y.b(lastPathSegment)) {
            return false;
        }
        try {
            callbackContent = (BrowserHandler.CallbackContent) new GsonBuilder().create().fromJson(new String(Base64.decode(lastPathSegment, 8)), callbackClass);
        } catch (Exception unused) {
            callbackContent = null;
        }
        return handleCallbackWithContent(callbackContent);
    }

    private boolean launchedChromeIntent(String str) {
        Matcher matcher = Pattern.compile("intent://(.+);S.browser_fallback_url=(.+?);(.*)", 2).matcher(str);
        String decode = (!matcher.matches() || matcher.groupCount() < 2) ? null : URLDecoder.decode(matcher.group(2));
        if (decode != null && decode != this.webView.getUrl()) {
            this.webView.loadUrl(decode);
        }
        return decode != null;
    }

    private boolean launchedEmailHandler(String str) {
        Matcher matcher = Pattern.compile("subsplash://email\\?subject=(.+)&address=(.+@.+\\..+)&body=(.+)", 2).matcher(str);
        if (!matcher.matches()) {
            return false;
        }
        Intent intent = new Intent("android.intent.action.SEND");
        intent.putExtra("android.intent.extra.EMAIL", new String[]{URLDecoder.decode(matcher.group(2))});
        intent.putExtra("android.intent.extra.SUBJECT", URLDecoder.decode(matcher.group(1)));
        intent.putExtra("android.intent.extra.TEXT", URLDecoder.decode(matcher.group(3)));
        intent.setType("plain/text");
        String string = getString(q.email_chooser);
        if (isActivityContextAlive()) {
            getActivity().startActivity(Intent.createChooser(intent, string));
        }
        return true;
    }

    private boolean launchedHandler(String str) {
        Matcher matcher = Pattern.compile("subsplash://([a-zA-Z 0-9]+)\\?link=([.[^&]]+)&?(.*)", 2).matcher(str);
        if (!matcher.matches()) {
            return false;
        }
        if (!isActivityContextAlive()) {
            return true;
        }
        String group = matcher.group(1);
        NavigationHandler.loadHandler(TAG, createNavigationItem(group, group, URLDecoder.decode(matcher.group(2)), getHashMapFromUrlParameters(matcher.group(3))).getNavigationHandler(), getActivity());
        return true;
    }

    private boolean launchedInternalBrowserHandler(String str) {
        if (!Pattern.compile("subsplash://internalBrowser\\?(.*)", 2).matcher(str).matches()) {
            return false;
        }
        if (!isActivityContextAlive()) {
            return true;
        }
        if (getCloseParameter(str)) {
            getActivity().finish();
            return true;
        }
        String linkParameter = getLinkParameter(str);
        boolean hideNavBarParameter = getHideNavBarParameter(str);
        this.hideNavBar = hideNavBarParameter;
        boolean z = !hideNavBarParameter;
        if (z != getActivity().K().n()) {
            getActivity().findViewById(n.main_toolbar);
            if (z) {
                getThemeBuilderForTopBar().c();
                getActivity().K().C();
            } else {
                getThemeBuilderForTopBar().g(null).d(-16777216).e(-1).c();
                getActivity().K().l();
            }
        }
        this.showBrowserBar = getShowBrowserBarParameter(str);
        this.clickOpensExternalBrowser = getClickOpensExternalBrowserParameter(str);
        this.isInterceptingBack = getIsInterceptingBackParameter(str);
        updateInternalBrowser(getTitleParameter(str));
        launchLink(linkParameter);
        return true;
    }

    private boolean launchedMP3(String str) {
        if (!str.contains(".mp3")) {
            return false;
        }
        launchUsingNativeIntent(str, "audio/mp3");
        return true;
    }

    private boolean launchedMP4(String str) {
        if (!str.contains(".mp4")) {
            return false;
        }
        launchUsingNativeIntent(str, "video/mp4");
        return true;
    }

    private boolean launchedMailToScheme(String str) {
        if (!str.startsWith("mailto:")) {
            return false;
        }
        MailTo parse = MailTo.parse(str);
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType("text/plain");
        intent.putExtra("android.intent.extra.EMAIL", new String[]{parse.getTo()});
        intent.putExtra("android.intent.extra.SUBJECT", parse.getSubject());
        intent.putExtra("android.intent.extra.CC", parse.getCc());
        intent.putExtra("android.intent.extra.TEXT", parse.getBody());
        Context context = getContext();
        if (context == null) {
            return false;
        }
        context.startActivity(intent);
        return true;
    }

    private boolean launchedPDFHandler(String str) {
        if (!NavigationHandler.isPDF(Uri.parse(str))) {
            return false;
        }
        if (!isActivityContextAlive()) {
            return true;
        }
        NavigationHandler.navigate(PDFHandler.JSON_VALUE, str, (Context) getActivity());
        return true;
    }

    private boolean launchedSapURI(String str) {
        com.subsplash.thechurchapp.handlers.common.a createSapActionItem;
        Uri parse = Uri.parse(str);
        if ((f0.k(parse) || f0.l(parse)) && (createSapActionItem = com.subsplash.thechurchapp.handlers.common.a.createSapActionItem(parse)) != null) {
            if (createSapActionItem instanceof BrowserHandler) {
                BrowserHandler browserHandler = (BrowserHandler) createSapActionItem;
                if (browserHandler.style == BrowserHandler.BrowserStyle.Internal && browserHandler.contentUri != null) {
                    this.handler = browserHandler;
                    browserHandler.setFragment(this);
                    getHandlerData();
                    this.initialLoadComplete = false;
                    this.webArchiveLoadComplete = false;
                    String str2 = this.originalUrl;
                    this.pageUrl = str2;
                    if (!u.k(str2)) {
                        this.currentCacheUrl = this.originalUrl;
                    }
                    if (loadContent()) {
                        addToHistory(this.originalUrl);
                    }
                    return true;
                }
            }
            if (createSapActionItem instanceof NavigationHandler) {
                if (isActivityContextAlive()) {
                    ((NavigationHandler) createSapActionItem).navigate(getActivity());
                }
                return true;
            }
        }
        return false;
    }

    private boolean launchedSmsScheme(String str) {
        if (!str.startsWith("sms:")) {
            return false;
        }
        Intent intent = new Intent("android.intent.action.SENDTO", Uri.parse(str));
        Context context = getContext();
        if (context == null) {
            return false;
        }
        context.startActivity(intent);
        return true;
    }

    private boolean launchedTelScheme(String str) {
        if (!str.startsWith("tel:")) {
            return false;
        }
        Intent intent = new Intent("android.intent.action.DIAL", Uri.parse(str));
        Context context = getContext();
        if (context == null) {
            return false;
        }
        context.startActivity(intent);
        return true;
    }

    private boolean launchedTelephoneHandler(String str) {
        if (!Pattern.compile("subsplash://phone\\?number=[0-9]+", 2).matcher(str).matches()) {
            return false;
        }
        if (!isActivityContextAlive()) {
            return true;
        }
        com.subsplash.util.i.b(getActivity(), str.replace("subsplash://phone?number=", HttpUrl.FRAGMENT_ENCODE_SET));
        return true;
    }

    private boolean launchedYouTubeUrl(String str) {
        if (!Pattern.compile("vnd.youtube:([^\\?]+)?.*", 2).matcher(str).matches()) {
            return false;
        }
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setData(Uri.parse(str));
        if (!isActivityContextAlive()) {
            return true;
        }
        getActivity().startActivity(intent);
        return true;
    }

    private boolean loadContent() {
        if (this.webView == null) {
            return false;
        }
        String e2 = this.webArchiveDiskCache.e(this.currentCacheUrl);
        if (y.d(this.pageContent)) {
            this.webView.loadUrl(String.format("data:text/html;charset=utf-8;base64,%s", Base64.encodeToString(this.pageContent.getBytes(), 0)));
            showContent();
        } else {
            NavigationHandler navigationHandler = this.handler;
            if (navigationHandler != null && navigationHandler.enableCache && !this.webArchiveLoadComplete && e2 != null) {
                this.webView.loadUrl(e2);
                showContent();
            } else {
                if (this.initialLoadComplete && !this.isErrorActive && !this.needsReloadForAuth && this.webView.getUrl() != null) {
                    return false;
                }
                this.isErrorActive = false;
                this.needsReloadForAuth = false;
                if (u.k(this.originalUrl)) {
                    this.webView.loadUrl(this.originalUrl);
                } else {
                    if (!j0.a.e()) {
                        NavigationHandler navigationHandler2 = this.handler;
                        if (navigationHandler2 != null && navigationHandler2.enableCache && e2 != null) {
                            return false;
                        }
                        showError();
                        return false;
                    }
                    Log.i(TAG, "Loading url in webView: " + this.originalUrl);
                    NavigationHandler navigationHandler3 = this.handler;
                    this.webView.loadUrl(this.originalUrl, navigationHandler3 != null ? f0.h(navigationHandler3.getHttpURLConnectionOptions()) : null);
                }
            }
        }
        return true;
    }

    public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
        if (this.handler != null && webResourceRequest.isForMainFrame()) {
            int statusCode = webResourceResponse.getStatusCode();
            if (f0.i(statusCode)) {
                setNeedsReloadForAuth();
                Map<String, String> responseHeaders = webResourceResponse.getResponseHeaders();
                boolean handleAuthErrorResponse = this.handler.handleAuthErrorResponse(responseHeaders);
                if (h0.j(TAG, n0.i("Content-Length", responseHeaders)) <= 5 || !handleAuthErrorResponse) {
                    setErrorActive(a.f.AUTH_FAILED);
                    return;
                }
                return;
            }
            if (this.handler.enableCache && this.webArchiveDiskCache.e(this.currentCacheUrl) != null) {
                return;
            }
            if (this.handler.isValidatingAuth) {
                setNeedsReloadForAuth();
                return;
            }
            if (isActivityContextAlive()) {
                if (statusCode == -2) {
                    setErrorActive(a.f.NONE);
                    return;
                }
                String reasonPhrase = webResourceResponse.getReasonPhrase();
                Log.e(TAG, String.format(Locale.US, "Loading page: %s failed with error code: %d. %s", webResourceRequest.getUrl().toString(), Integer.valueOf(statusCode), reasonPhrase));
                String string = getActivity().getString(q.error_sorry);
                Toast.makeText((Context) getActivity(), (CharSequence) (string + " " + reasonPhrase), 0).show();
            }
        }
    }

    private void removeListeners() {
        i iVar = this.gestureManager;
        if (iVar != null) {
            iVar.d();
        }
        this.gestureManager = null;
        View findViewById = findViewById(n.browser_bar);
        if (findViewById == null) {
            return;
        }
        ImageButton imageButton = (ImageButton) findViewById.findViewById(n.browser_back);
        ImageButton imageButton2 = (ImageButton) findViewById.findViewById(n.browser_forward);
        ImageButton imageButton3 = (ImageButton) findViewById.findViewById(n.browser_refresh);
        ImageButton imageButton4 = (ImageButton) findViewById.findViewById(n.browser_actions);
        if (imageButton != null) {
            imageButton.setOnClickListener(null);
        }
        if (imageButton2 != null) {
            imageButton2.setOnClickListener(null);
        }
        if (imageButton3 != null) {
            imageButton3.setOnClickListener(null);
        }
        if (imageButton4 != null) {
            imageButton4.setOnClickListener(null);
        }
    }

    private void setErrorActive(a.f fVar) {
        this.isErrorActive = true;
        this.webView.clearHistory();
        NavigationHandler navigationHandler = this.handler;
        if (navigationHandler != null) {
            navigationHandler.loadDataFailed(fVar);
        }
    }

    private void setupModifiers() {
        String stringExtra;
        if (!isActivityContextAlive() || (stringExtra = getActivity().getIntent().getStringExtra("modifier")) == null || stringExtra.equals(HttpUrl.FRAGMENT_ENCODE_SET)) {
            return;
        }
        for (String str : stringExtra.split("\\s+")) {
            String lowerCase = str.toLowerCase();
            if (lowerCase.equals("hidenavbar")) {
                this.hideNavBar = true;
            } else if (lowerCase.equals("showbrowserbar")) {
                this.showBrowserBar = true;
            }
        }
        updateInternalBrowser();
    }

    public void showActionsDialog() {
        WeakReference weakReference = new WeakReference(this);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Actions");
        builder.setItems(new String[]{"Open in Browser", "Mail Link to this Page"}, new h(weakReference)).setNegativeButton("Cancel", new g());
        builder.show();
    }

    private void updatePageUrl(String str) {
        if (n0.a(this.pageUrl, str)) {
            return;
        }
        this.pageUrl = n0.b(str);
        if (this.handler == null || u.k(str)) {
            return;
        }
        this.handler.hasAttemptedAuthRefresh = false;
    }

    private boolean webViewCanGoBack() {
        return this.history.size() > 1 && this.historyIndex > 0;
    }

    private boolean webViewCanGoForward() {
        return this.history.size() > 0 && this.historyIndex < this.history.size() - 1;
    }

    public void webViewGoBack() {
        int i;
        if (this.history.size() <= 1 || (i = this.historyIndex) <= 0) {
            return;
        }
        String str = this.history.get(i - 1);
        this.originalUrl = str;
        this.currentCacheUrl = str;
        this.initialLoadComplete = false;
        this.webArchiveLoadComplete = false;
        if (loadContent()) {
            this.historyIndex--;
        }
    }

    public void webViewGoForward() {
        if (this.history.size() <= 1 || this.historyIndex >= this.history.size() - 1) {
            return;
        }
        String str = this.history.get(this.historyIndex + 1);
        this.originalUrl = str;
        this.currentCacheUrl = str;
        this.initialLoadComplete = false;
        this.webArchiveLoadComplete = false;
        if (loadContent()) {
            this.historyIndex++;
        }
    }

    protected String currentPageTitle() {
        return this.pageTitle;
    }

    protected boolean didLaunchNatively(String str) {
        return launchedMP3(str) || launchedMP4(str) || launched3GP(str) || launchedChromeIntent(str) || launchedTelephoneHandler(str) || launchedEmailHandler(str) || launchedPDFHandler(str) || launchedInternalBrowserHandler(str) || launchedHandler(str) || launchedYouTubeUrl(str) || launchedSapURI(str) || launchedCallbackUri(str) || launchedMailToScheme(str) || launchedSmsScheme(str) || launchedTelScheme(str);
    }

    protected Class getCallbackClass(Uri uri) {
        return null;
    }

    @Override
    public n0.a getDefaultViewModelCreationExtras() {
        return super/*androidx.lifecycle.e*/.getDefaultViewModelCreationExtras();
    }

    protected e.b getJSManagerCompatDelegate() {
        return null;
    }

    @Override
    public int getLayoutResourceId() {
        return o.browser;
    }

    protected String getParameterValue(String str, String str2, String str3) {
        Matcher matcher = Pattern.compile(str2, 2).matcher(str);
        return (!matcher.matches() || matcher.groupCount() <= 0) ? str3 : matcher.group(1);
    }

    @Override
    public int getSupportedOrientations() {
        return Build.VERSION.SDK_INT >= 28 ? 2 : 4;
    }

    protected WebView getWebView() {
        return this.webView;
    }

    protected boolean handleCallbackWithContent(BrowserHandler.CallbackContent callbackContent) {
        return false;
    }

    @Override
    public void initializeContent() {
        super.initializeContent();
        getHandlerData();
        setupModifiers();
        updatePageTitle();
        setupListeners();
        updateInternalBrowser();
        if (loadContent()) {
            this.history.clear();
            this.historyIndex = 0;
            addToHistory(this.originalUrl);
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        ValueCallback<Uri[]> valueCallback;
        if (i != 100 || (valueCallback = this.uploadMessage) == null) {
            return;
        }
        valueCallback.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(i2, intent));
        this.uploadMessage = null;
    }

    @Override
    public boolean onBackKeyPressed() {
        WebChromeClient.CustomViewCallback customViewCallback = this.fullscreenCallback;
        if (customViewCallback != null) {
            customViewCallback.onCustomViewHidden();
            this.fullscreenCallback = null;
            return true;
        }
        if (closeIfInterceptingBack() || !webViewCanGoBack()) {
            this.webView.loadUrl(WEBVIEW_BLANK);
            return false;
        }
        webViewGoBack();
        return true;
    }

    @Override
    public void onContentScrollFast() {
    }

    @Override
    public void onContentScrollVertical(boolean z) {
    }

    @Override
    public void onContentTapped() {
    }

    @Override
    public void onContentTouch(View view, MotionEvent motionEvent) {
        refreshToolbar();
    }

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        Log.i(TAG, "onCreateView()");
        if (this.viewPort == null) {
            super.onCreateView(layoutInflater, viewGroup, bundle);
            ColorPalette c2 = getThemeBuilderForBottomBar().j(null).c();
            if (c2 == null) {
                c2 = DisplayOptions.getLightThemePalette();
            }
            int primaryColor = c2.getPrimaryColor();
            int primaryAccentColor = c2.getPrimaryAccentColor();
            int blockColor = c2.getBlockColor();
            setBackgroundColor(primaryColor);
            View findViewById = getActivity().findViewById(n.fragment_container);
            if (findViewById != null) {
                findViewById.setBackgroundColor(primaryColor);
            }
            View findViewById2 = this.contentRootView.findViewById(n.browser_bar);
            if (findViewById2 != null) {
                findViewById2.setBackgroundColor(primaryColor);
            }
            View findViewById3 = this.contentRootView.findViewById(n.browser_bar_top_divider);
            if (findViewById3 != null) {
                findViewById3.setBackgroundColor(blockColor);
            }
            s0.y(this.contentRootView.findViewById(n.browser_forward), primaryAccentColor);
            s0.y(this.contentRootView.findViewById(n.browser_back), primaryAccentColor);
            s0.y(this.contentRootView.findViewById(n.browser_refresh), primaryAccentColor);
            s0.y(this.contentRootView.findViewById(n.browser_actions), primaryAccentColor);
            setupWebView();
        }
        return this.viewPort;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        removeListeners();
        com.subsplash.thechurchapp.api.e eVar = this.jsManagerCompat;
        if (eVar != null) {
            eVar.b();
        }
        this.jsManagerCompat = null;
        this.webView = null;
        this.history.clear();
        this.historyIndex = 0;
    }

    protected void onPageFinished(WebView webView, String str) {
        Log.i(TAG, "onPageFinished()");
        if (y.b(currentPageTitle()) && !this.suppressWebViewTitle) {
            String title = webView.getTitle();
            Uri n = h0.n(TAG, title);
            if (!n0.a(title, WEBVIEW_BLANK) && (n == null || n.getHost() == null || !n.getHost().contains("subsplash"))) {
                setTitle(title);
            }
        }
        showContent();
        refreshToolbar();
        webView.requestFocus(130);
        NavigationHandler navigationHandler = this.handler;
        boolean z = (navigationHandler == null || !navigationHandler.enableCache || this.webArchiveDiskCache.e(this.currentCacheUrl) == null) ? false : true;
        boolean e2 = j0.a.e();
        if (!this.webArchiveLoadComplete && z) {
            this.webArchiveLoadComplete = true;
            if (e2) {
                loadContent();
                return;
            }
            return;
        }
        this.initialLoadComplete = true;
        NavigationHandler navigationHandler2 = this.handler;
        if (navigationHandler2 == null || !navigationHandler2.enableCache || !e2 || str == null || u.k(str) || WEBVIEW_BLANK.equalsIgnoreCase(str)) {
            return;
        }
        this.webArchiveDiskCache.d(this.webView, this.currentCacheUrl);
    }

    protected void onPageStarted(WebView webView, String str) {
        updatePageUrl(str);
    }

    public void onPause() {
        super.onPause();
        WebView webView = this.webView;
        if (webView != null) {
            webView.onPause();
        }
    }

    protected void onReceivedHttpAuthRequest(WebView webView, HttpAuthHandler httpAuthHandler, String str, String str2) {
    }

    @Override
    public void onResume() {
        super.onResume();
        WebView webView = this.webView;
        if (webView != null) {
            webView.onResume();
            this.webView.loadUrl("javascript:dispatchEvent(new Event('pageshow'));");
        }
    }

    protected void refreshToolbar() {
        View view = this.contentRootView;
        if (view == null) {
            return;
        }
        ImageButton imageButton = (ImageButton) view.findViewById(n.browser_back);
        ImageButton imageButton2 = (ImageButton) view.findViewById(n.browser_forward);
        if (imageButton != null) {
            imageButton.setEnabled(webViewCanGoBack());
        }
        if (imageButton2 != null) {
            imageButton2.setEnabled(webViewCanGoForward());
        }
    }

    public void setNeedsReloadForAuth() {
        this.needsReloadForAuth = true;
    }

    protected void setupListeners() {
        if (isActivityContextAlive()) {
            this.gestureManager = new i(getActivity(), this.webView, this);
            View findViewById = findViewById(n.browser_bar);
            if (findViewById == null) {
                return;
            }
            ImageButton imageButton = (ImageButton) findViewById.findViewById(n.browser_back);
            ImageButton imageButton2 = (ImageButton) findViewById.findViewById(n.browser_forward);
            ImageButton imageButton3 = (ImageButton) findViewById.findViewById(n.browser_refresh);
            ImageButton imageButton4 = (ImageButton) findViewById.findViewById(n.browser_actions);
            refreshToolbar();
            if (imageButton != null) {
                imageButton.setOnClickListener(getBackOnClickListener());
            }
            if (imageButton2 != null) {
                imageButton2.setOnClickListener(getForwardOnClickListener());
            }
            if (imageButton3 != null) {
                imageButton3.setOnClickListener(getRefreshOnClickListener());
            }
            if (imageButton4 != null) {
                imageButton4.setOnClickListener(getActionsOnClickListener());
            }
        }
    }

    protected void setupWebView() {
        if (this.webView == null) {
            if ((TheChurchApp.n().getApplicationInfo().flags & 2) != 0) {
                WebView.setWebContentsDebuggingEnabled(true);
            }
            WebView webView = (WebView) this.contentRootView.findViewById(n.browser_webview);
            this.webView = webView;
            webView.setScrollBarStyle(33554432);
            this.webView.setWebViewClient(createWebViewClient());
            this.webView.setWebChromeClient(new f(new WeakReference(this)));
            WebSettings settings = this.webView.getSettings();
            settings.setBuiltInZoomControls(true);
            settings.setDefaultTextEncodingName("utf-8");
            settings.setDomStorageEnabled(true);
            settings.setDisplayZoomControls(false);
            settings.setJavaScriptEnabled(true);
            settings.setLoadWithOverviewMode(true);
            settings.setSupportZoom(true);
            settings.setUseWideViewPort(true);
            settings.setAllowFileAccess(true);
            this.webView.requestFocus(130);
            this.jsManagerCompat = new com.subsplash.thechurchapp.api.e(getWebView(), getJSManagerCompatDelegate());
        }
    }

    protected boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
        String uri = webResourceRequest.getUrl().toString();
        boolean z = didLaunchNatively(uri) || isSubsplashURI(uri);
        if (!z && webResourceRequest.isForMainFrame()) {
            updatePageUrl(uri);
            if (!u.k(uri)) {
                this.originalUrl = uri;
                this.currentCacheUrl = uri;
                this.initialLoadComplete = false;
                this.webArchiveLoadComplete = false;
                if (loadContent() && webResourceRequest.hasGesture()) {
                    addToHistory(this.originalUrl);
                }
            }
        }
        return z;
    }

    @Override
    public void showContent() {
        if (this.isErrorActive) {
            return;
        }
        super.showContent();
    }

    @Override
    public void showLoading() {
        NavigationHandler navigationHandler = this.handler;
        if (((navigationHandler == null || !navigationHandler.enableCache || this.webArchiveDiskCache.e(this.currentCacheUrl) == null) ? false : true) || !j0.a.e()) {
            return;
        }
        if (!this.initialLoadComplete || this.isErrorActive) {
            super.showLoading();
        }
    }

    protected void updateInternalBrowser() {
        updateInternalBrowser(null);
    }

    public void updatePageTitle() {
        String currentPageTitle = currentPageTitle();
        if (y.d(currentPageTitle)) {
            setTitle(currentPageTitle);
        }
    }

    private void updateInternalBrowser(String str) {
        View findViewById = findViewById(n.browser_bar);
        if (findViewById != null) {
            findViewById.setVisibility(this.showBrowserBar ? 0 : 8);
        }
    }

    public BrowserFragment(NavigationHandler navigationHandler) {
        super(navigationHandler);
        this.jsManagerCompat = null;
        this.gestureManager = null;
        this.hideNavBar = false;
        this.showBrowserBar = false;
        this.clickOpensExternalBrowser = false;
        this.isErrorActive = false;
        this.isInterceptingBack = false;
        this.initialLoadComplete = false;
        this.needsReloadForAuth = false;
        this.suppressWebViewTitle = false;
        this.fullscreenCallback = null;
        this.currentCacheUrl = null;
        this.webArchiveDiskCache = new com.subsplash.thechurchapp.handlers.browser.a();
        this.webArchiveLoadComplete = false;
        this.history = new ArrayList<>();
        this.historyIndex = 0;
    }
}