导航菜单

页面标题

页面副标题

Cashalo v2.25.0.0 - WebViewFragment.java 源代码

正在查看: Cashalo v2.25.0.0 应用的 WebViewFragment.java JAVA 源代码文件

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


package com.oriente.cashalo.page.fragment;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.ConsoleMessage;
import android.webkit.GeolocationPermissions;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.fullstory.FS;
import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.metrics.Trace;
import com.iterable.iterableapi.IterableConstants;
import com.oriente.adapter.R;
import com.oriente.adapter.analytics.impl.CommonAnalytics;
import com.oriente.adapter.config.ValueConfig;
import com.oriente.adapter.page.BaseUiFragment;
import com.oriente.adapter.page.LoadingEvent;
import com.oriente.adapter.utils.LanguageUtils;
import com.oriente.cashalo.service.CommonService;
import com.oriente.cashalo.service.model.borrow.BorrowInfo;
import com.oriente.cashalo.utils.BottomDialogUtils;
import com.oriente.cashalo.utils.OrientUtils;
import com.oriente.core.page.jump.BackModel;
import com.oriente.core.page.jump.Jumper;
import com.oriente.core.router.Router;
import com.oriente.core.router.RouterScene;
import com.oriente.core.store.AESPrefsManager;
import com.oriente.core.store.PrefsManager;
import com.oriente.core.task.Worker;
import com.oriente.core.utils.CoderUtils;
import com.oriente.core.utils.ResUtils;
import com.oriente.core.utils.StringUtils;
import com.oriente.core.utils.ToastUtils;
import com.oriente.http.callback.RequestCallback;
import com.oriente.http.model.RequestContext;
import com.oriente.http.model.RequestResult;
import com.oriente.manager.OrientManager;
import com.oriente.moduleapi.AnalyticsService;
import com.oriente.plugin.module.UserPlugin;
import com.oriente.uikit.group.TitleBar;
import com.oriente.uikit.group.webview.webview.ProxyWebView;
import com.oriente.uikit.utils.ViewUtils;
import com.oriente.uimodule.alert.Alert;
import com.oriente.uimodule.alert.DialogBuilder;
import com.oriente.utils.WebViewUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.greenrobot.eventbus.EventBus;

public class WebViewFragment extends BaseUiFragment {
    public static final int CLOSECONTAINER = 1;
    public static final String HOST = "https://api.cashalo.com/";
    public static final int SENDEMAIL = 0;
    private boolean isPdfLoad;
    private String mContractName;
    private String mContractUrl;
    private String mOrderNo;
    ProxyWebView mWebView;
    private String url;
    private String viewerUrl;
    private boolean mEnableGoback = true;
    private boolean isInsurance = false;
    private Trace mTrace = FirebasePerformance.getInstance().newTrace("webview-page-render");
    protected String TAG = getClass().getSimpleName();

    public boolean showWebViewReload(String str) {
        return false;
    }

    @Override
    protected View onCreateContentView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
        View inflate = layoutInflater.inflate(R.layout.layout_webview, viewGroup, false);
        this.mWebView = ViewUtils.view(inflate, R.id.webView);
        return inflate;
    }

    @Override
    protected void onContentViewCreated(View view, Bundle bundle, Bundle bundle2) {
        super.onContentViewCreated(view, bundle, bundle2);
        LanguageUtils.adjustLanguageInActivity(getActivity());
        String string = bundle.getString(ValueConfig.BUNDLE_PAGE_URL, null);
        this.mOrderNo = bundle.getString(BorrowInfo.ORDER_NO);
        this.mContractName = bundle.getString("contractName");
        this.mContractUrl = bundle.getString("contractUrl");
        this.isInsurance = bundle.getBoolean("isInsurance");
        final boolean z = bundle.getBoolean(ValueConfig.BUNDLE_PAGE_ROUTER, false);
        boolean z2 = bundle.getBoolean("needCheckEmail", false);
        this.mEnableGoback = bundle.getBoolean(ValueConfig.BUNDLE_WEBVIEW_GOBACK, true);
        this.url = string;
        if (string != null && string.endsWith(".pdf")) {
            this.url = "https://docs.google.com/gview?embedded=true&url=" + string;
            this.viewerUrl = "https://docs.google.com/viewerng/viewer?url=" + string;
            this.isPdfLoad = true;
        }
        EventBus.getDefault().post(new LoadingEvent(true));
        this.mTrace.putAttribute("url", this.url);
        ProxyWebView proxyWebView = this.mWebView;
        if (proxyWebView != null) {
            proxyWebView.setDefaultWebChrome(new WebChromeClient() {
                @Override
                public void onReceivedTitle(WebView webView, String str) {
                    super.onReceivedTitle(webView, str);
                    OrientManager.getPlugin(AnalyticsService.class).logFirebaseEvent(WebViewFragment.this.TAG, Jumper.obtain(new Object[]{"received_title", System.currentTimeMillis() + ""}));
                    if (StringUtils.isNotEmpty(str) && !StringUtils.equalTrim(webView.getTitle(), WebViewFragment.this.url) && z) {
                        WebViewFragment.this.mTitleBar.setTitle(str);
                    }
                }

                @Override
                public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
                    return super.onConsoleMessage(consoleMessage);
                }

                @Override
                public void onGeolocationPermissionsShowPrompt(String str, GeolocationPermissions.Callback callback) {
                    OrientManager.getPlugin(AnalyticsService.class).logFirebaseEvent(WebViewFragment.this.TAG, Jumper.obtain(new Object[]{"geolocation", System.currentTimeMillis() + "", "origin", str}));
                    callback.invoke(str, true, true);
                    super.onGeolocationPermissionsShowPrompt(str, callback);
                }

                @Override
                public void onProgressChanged(WebView webView, int i) {
                    super.onProgressChanged(webView, i);
                    if (i == 100) {
                        EventBus.getDefault().post(new LoadingEvent(false));
                    }
                }
            });
            this.mWebView.setDefaultWebClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView webView, String str) {
                    OrientManager.getPlugin(AnalyticsService.class).logFirebaseEvent(WebViewFragment.this.TAG, Jumper.obtain(new Object[]{"override_url", "1"}));
                    if (WebViewFragment.this.isPdfLoad && (str.equals(WebViewFragment.this.url) || (WebViewFragment.this.viewerUrl != null && str.equals(WebViewFragment.this.viewerUrl)))) {
                        FS.trackWebView(webView);
                        webView.loadUrl(str);
                        return false;
                    }
                    if (!str.startsWith("mailto:")) {
                        return Router.from(WebViewFragment.this).deliver(str, RouterScene.WEB) || super.shouldOverrideUrlLoading(webView, str);
                    }
                    WebViewFragment.this.startActivity(new Intent("android.intent.action.SENDTO", Uri.parse(str)));
                    return true;
                }

                @Override
                public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
                    OrientManager.getPlugin(AnalyticsService.class).logFirebaseEvent(WebViewFragment.this.TAG, Jumper.obtain(new Object[]{"page_started", System.currentTimeMillis() + ""}));
                    WebViewFragment.this.mTrace.start();
                }

                @Override
                public void onPageFinished(WebView webView, String str) {
                    OrientManager.getPlugin(AnalyticsService.class).logFirebaseEvent(WebViewFragment.this.TAG, Jumper.obtain(new Object[]{"page_finished", System.currentTimeMillis() + ""}));
                    if (StringUtils.isNotEmpty(webView.getTitle()) && !StringUtils.equalTrim(webView.getTitle(), str) && z) {
                        WebViewFragment.this.mTitleBar.setTitle(webView.getTitle());
                    }
                    WebViewFragment.this.mWebView.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            WebViewFragment.this.mWebView.scrollTo(0, 0);
                        }
                    }, 50L);
                    WebViewFragment.this.mTrace.stop();
                }

                @Override
                public void onReceivedError(WebView webView, int i, String str, String str2) {
                    OrientManager.getPlugin(AnalyticsService.class).logFirebaseEvent(WebViewFragment.this.TAG, Jumper.obtain(new Object[]{"received_error", System.currentTimeMillis() + ""}));
                    EventBus.getDefault().post(new LoadingEvent(false));
                    WebViewFragment.this.showWebViewReload(str2);
                }

                @Override
                public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
                    OrientManager.getPlugin(AnalyticsService.class).logFirebaseEvent(WebViewFragment.this.TAG, Jumper.obtain(new Object[]{"received_ssl_error", System.currentTimeMillis() + ""}));
                }
            });
            this.mWebView.addJavascriptInterface(new CloseJsInterface(), "obj");
            WebViewUtils.INSTANCE.updateConfig(this.mWebView);
            if (z2) {
                initTitlebarAction(0);
            }
        }
        if (StringUtils.isVisibleUnNull(this.url)) {
            loadUrl(this.url);
        }
    }

    private void initTitlebarAction(int i) {
        if (i == 0) {
            TitleBar.DefaultAction defaultAction = new TitleBar.DefaultAction(null, R.mipmap.common_icon_titlebar_share) {
                public void performAction(View view) {
                    WebViewFragment.this.showSendEmailDialog();
                }
            };
            if (this.mTitleBar != null) {
                this.mTitleBar.addAction(defaultAction);
            }
        }
    }

    public void showSendEmailDialog() {
        BottomDialogUtils.dialog(DialogBuilder.from(this), String.format(ResUtils.string(R.string.ori_common_title_send_to_email), OrientManager.getPlugin(UserPlugin.class).getUserPersonalEmail()), (List<String>) Arrays.asList(ResUtils.string(R.string.ori_common_btn_send_to_email)), new BottomDialogUtils.OnDialogClick() {
            @Override
            public boolean onDialogClick(View view, int i, Object obj) {
                if (i != 0) {
                    return false;
                }
                WebViewFragment.this.sendMail();
                return false;
            }
        });
    }

    public void sendMail() {
        CommonService.sendContractEmailToUser(this.mOrderNo, this.mContractName, this.mContractUrl, new RequestContext.Builder(this).build(new RequestCallback<Object>() {
            public void onRequestFinished(RequestContext<Object> requestContext, RequestResult<Object> requestResult) {
                if (requestResult.isSuccessFull()) {
                    ToastUtils.pop(R.layout.layout_toast_success, ResUtils.string(R.string.ori_common_msg_success));
                } else if (requestResult.getCode() == 12001 || requestResult.getCode() == 12002) {
                    Alert.from(WebViewFragment.this).button(ResUtils.string(R.string.ori_common_btn_ok)).message(requestResult.getMessage()).show();
                    requestResult.markAsHandled();
                }
            }
        }));
    }

    @Override
    public void onVisibleChanged(boolean z) {
        ProxyWebView proxyWebView;
        super.onVisibleChanged(z);
        if (z && this.isPdfLoad && (proxyWebView = this.mWebView) != null) {
            proxyWebView.reload();
        }
    }

    protected void loadUrl(String str) {
        if (this.mWebView != null) {
            Map<String, String> collectHttpHeader = OrientUtils.collectHttpHeader();
            UserPlugin plugin = OrientManager.getPlugin(UserPlugin.class);
            if (plugin != null) {
                collectHttpHeader.put("accessToken", plugin.getAccessToken());
            } else {
                collectHttpHeader.put("accessToken", getPrefs().getString(ValueConfig.PREF_USER_ACCESS_TOKEN, ""));
            }
            if (str.startsWith(HOST) && !HOST.equals(ValueConfig.sRequestHost)) {
                str = str.replace(HOST, ValueConfig.sRequestHost);
            }
            ProxyWebView proxyWebView = this.mWebView;
            FS.trackWebView(proxyWebView);
            proxyWebView.loadUrl(str, collectHttpHeader);
        }
    }

    private SharedPreferences getPrefs() {
        return PrefsManager.getSharedPreference(AESPrefsManager.getInstance().getString(CoderUtils.toMD5(IterableConstants.KEY_USER_ID), ""));
    }

    public boolean onKeyBack(boolean z) {
        ProxyWebView proxyWebView;
        ProxyWebView proxyWebView2;
        boolean z2 = this.mEnableGoback && (proxyWebView2 = this.mWebView) != null && proxyWebView2.canGoBack();
        if (z2 && (proxyWebView = this.mWebView) != null) {
            proxyWebView.goBack();
        }
        return z2 || super.onKeyBack(z);
    }

    class CloseJsInterface {
        CloseJsInterface() {
        }

        @JavascriptInterface
        public void close() {
            Worker.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (WebViewFragment.this.isInsurance) {
                        CommonAnalytics.analyticsClick("insurance_product_information", "acceptbutton", (Object) null);
                    }
                    BackModel.invokeBack(WebViewFragment.this, true);
                }
            }, 0L);
        }
    }

    public String getUrl() {
        return this.url;
    }
}