柬埔寨通 v6.1.5版本的 MD5 值为:9b68581ac30883219d6a25858a099d6b

以下内容为反编译后的 LyWebView.java 源代码,内容仅作参考


package net.duohuo.magappx.common.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.GeolocationPermissions;
import android.webkit.JavascriptInterface;
import android.webkit.JsResult;
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.FrameLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.view.MotionEventCompat;
import androidx.core.view.NestedScrollingChild;
import androidx.core.view.NestedScrollingChildHelper;
import androidx.core.view.ViewCompat;
import com.jianpuzhaitong.forum.R;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.duohuo.core.dialog.DialogCallBack;
import net.duohuo.core.dialog.IDialog;
import net.duohuo.core.ioc.Ioc;
import net.duohuo.core.net.Net;
import net.duohuo.core.net.Result;
import net.duohuo.core.net.Task;
import net.duohuo.core.util.FileUtil;
import net.duohuo.core.util.LogUtil;
import net.duohuo.magapp.BuildConfig;
import net.duohuo.magappx.API;
import net.duohuo.magappx.SiteConfig;
import net.duohuo.magappx.UrlScheme;
import net.duohuo.magappx.chat.util.PermissionsChecker;
import net.duohuo.magappx.common.base.MagBaseActivity;
import net.duohuo.magappx.common.util.Constants;
import net.duohuo.magappx.common.util.RecognitionUtil;
import net.duohuo.magappx.common.util.UrlUtils;
import net.duohuo.magappx.common.web.MallHelper;
import net.duohuo.magappx.common.web.WebObj;
import net.duohuo.magappx.main.login.model.UserPreference;

public class LyWebView extends WebView implements NestedScrollingChild {
    public String baseUrl;
    private String defaultUserAgent;
    boolean hasDown;
    private boolean isFirstLoad;
    boolean isNestedScroll;
    private OnLoadingListener loadingListener;
    private int mLastMotionY;
    private int mNestedYOffset;
    private final int[] mScrollConsumed;
    private final int[] mScrollOffset;
    private NestedScrollingChildHelper mScrollingChildHelper;

    public interface OnLoadingListener {
        void onClearShareInfo();

        void onHideCommonPlaceBg();

        void onHideErrorPage();

        void onHideNaviAuthor();

        void onHideProgress();

        void onReceivedTitle(WebView webView, String str);

        void onShowErrorPage();

        void onShowFileUploadType(ValueCallback<Uri> valueCallback, ValueCallback<Uri[]> valueCallback2);

        void onShowProgress();

        void onShowVideoFull(View view, WebChromeClient.CustomViewCallback customViewCallback);

        void onShowVideoNormal();

        void onWebPageLoadFinished();
    }

    public LyWebView(Context context) {
        this(context, null);
    }

    public LyWebView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public LyWebView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.mScrollOffset = new int[2];
        this.mScrollConsumed = new int[2];
        this.mNestedYOffset = 0;
        this.hasDown = false;
        this.isNestedScroll = true;
        clickListener();
        init();
        this.mScrollingChildHelper = new NestedScrollingChildHelper(this);
        setNestedScrollingEnabled(true);
        addJavascriptInterface(new WebObj((MagBaseActivity) context) {
            @Override
            @JavascriptInterface
            public void getLocation() {
            }
        }, "MagAndroidClient");
    }

    public boolean isTop() {
        return getScrollY() == 0;
    }

    public void clickListener() {
        setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                WebView.HitTestResult hitTestResult = LyWebView.this.getHitTestResult();
                if (hitTestResult.getType() != 5 && hitTestResult.getType() != 8) {
                    return false;
                }
                RecognitionUtil.decode(LyWebView.this.getContext(), hitTestResult.getExtra());
                return true;
            }
        });
    }

    public void isNestedScrolling(boolean z) {
        this.isNestedScroll = z;
    }

    @Override
    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (this.isNestedScroll) {
            MotionEvent obtain = MotionEvent.obtain(motionEvent);
            int actionMasked = MotionEventCompat.getActionMasked(motionEvent);
            if (actionMasked == 0) {
                this.mNestedYOffset = 0;
            }
            obtain.offsetLocation(0.0f, this.mNestedYOffset);
            if (actionMasked == 0) {
                LogUtil.i("zmh", "down");
                this.mNestedYOffset = 0;
                this.hasDown = true;
                this.mLastMotionY = (int) motionEvent.getY();
                startNestedScroll(2);
            } else {
                if (actionMasked != 1) {
                    if (actionMasked == 2) {
                        if (!this.hasDown) {
                            this.hasDown = true;
                            this.mLastMotionY = (int) motionEvent.getY();
                            startNestedScroll(2);
                            this.mNestedYOffset = 0;
                            return true;
                        }
                        if (ViewCompat.dispatchNestedPreScroll(this, 0, this.mLastMotionY - ((int) motionEvent.getY()), this.mScrollConsumed, this.mScrollOffset)) {
                            return true;
                        }
                    }
                }
                this.hasDown = false;
                stopNestedScroll();
            }
        }
        return super.onTouchEvent(motionEvent);
    }

    public void loadFromNet(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        WebSettings settings = getSettings();
        this.baseUrl = UrlUtils.getBaseUrl(str);
        SiteConfig siteConfig = (SiteConfig) Ioc.get(SiteConfig.class);
        if (UrlUtils.isHostIP(str) || UrlUtils.isWhiteDomain(siteConfig.domainWhite, UrlUtils.getHost(str)) || MallHelper.isMallSafeUrl(this.baseUrl) || this.baseUrl.contains("paycontent.sapp.magcloud.net")) {
            settings.setUserAgentString(this.defaultUserAgent + " " + API.getUserAgent(((UserPreference) Ioc.get(UserPreference.class)).token));
            StringBuilder sb = new StringBuilder();
            sb.append("themecolor=");
            sb.append(getContext().getString(R.string.link));
            String addGetUrlParameter = UrlUtils.addGetUrlParameter(str, sb.toString());
            HashMap hashMap = new HashMap();
            hashMap.put("Referer", getUrl());
            addGetUrlParameter.startsWith("https://app.jpztong.com/");
            loadUrl(addGetUrlParameter, hashMap);
            return;
        }
        if (UrlUtils.isWhiteDomain(siteConfig.domainCooperation, UrlUtils.getHost(str))) {
            Net url = Net.url(API.Common.token);
            url.showProgress(false);
            StringBuilder sb2 = new StringBuilder();
            sb2.append(str);
            sb2.append(str.contains("?") ? "&" : "?");
            sb2.append("themecolor=");
            sb2.append(getContext().getString(R.string.link));
            final String sb3 = sb2.toString();
            url.get(new Task<Result>() {
                @Override
                public void onResult(Result result) {
                    String string = result.json().getString("data");
                    LyWebView.this.getSettings().setUserAgentString(LyWebView.this.defaultUserAgent + " " + API.getUserAgent(string));
                    HashMap hashMap2 = new HashMap();
                    hashMap2.put("Referer", LyWebView.this.getUrl());
                    LyWebView.this.loadUrl(sb3, hashMap2);
                }
            });
            return;
        }
        settings.setUserAgentString(this.defaultUserAgent + " " + API.getUserAgent(""));
        HashMap hashMap2 = new HashMap();
        hashMap2.put("Referer", getUrl());
        loadUrl(str, hashMap2);
    }

    class AnonymousClass3 extends Task<Result> {
        final String val$finalurl;

        AnonymousClass3(String str) {
            this.val$finalurl = str;
        }

        @Override
        public void onResult(Result result) {
            String httpUrl = result.response.request().url().toString();
            try {
                if (result.success()) {
                    LyWebView.this.loadDataWithBaseURL(UrlUtils.deleteGetUrlParameter(httpUrl, "html_response_json=1"), result.jo.getString("data"), "text/html", "utf-8", UrlUtils.deleteGetUrlParameter(httpUrl, "html_response_json=1"));
                } else {
                    LyWebView.this.loadDataWithBaseURL(UrlUtils.deleteGetUrlParameter(httpUrl, "html_response_json=1"), result.plain(), "text/html", "utf-8", UrlUtils.deleteGetUrlParameter(httpUrl, "html_response_json=1"));
                }
            } catch (Exception unused) {
                LyWebView.this.loadDataWithBaseURL("about:blank", "", "text/html", "utf-8", UrlUtils.deleteGetUrlParameter(httpUrl, "html_response_json=1"));
                if (LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onShowErrorPage();
                }
            }
        }

        @Override
        public void onError() {
            super.onError();
            ((Activity) LyWebView.this.getContext()).runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    LyWebView.this.loadDataWithBaseURL("about:blank", "", "text/html", "utf-8", AnonymousClass3.this.val$finalurl);
                    if (LyWebView.this.loadingListener != null) {
                        LyWebView.this.loadingListener.onShowErrorPage();
                    }
                }
            });
        }
    }

    public void init() {
        setWebViewClient(new MagWebViewClient());
        if (Build.VERSION.SDK_INT >= 19) {
            getSettings().setLoadsImagesAutomatically(true);
        } else {
            getSettings().setLoadsImagesAutomatically(false);
        }
        WebSettings settings = getSettings();
        try {
            settings.setPluginState(WebSettings.PluginState.ON);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (Build.VERSION.SDK_INT >= 21) {
            settings.setMixedContentMode(0);
        }
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setJavaScriptEnabled(true);
        settings.setLoadWithOverviewMode(true);
        settings.setUseWideViewPort(true);
        settings.setDomStorageEnabled(true);
        settings.setDatabaseEnabled(true);
        String path = FileUtil.getExternalFilesDir("webview").getPath();
        settings.setDatabasePath(path);
        FileUtil.getExternalFilesDir("webview").getPath();
        settings.setAllowFileAccess(true);
        settings.setCacheMode(-1);
        this.defaultUserAgent = settings.getUserAgentString();
        settings.setGeolocationEnabled(true);
        settings.setGeolocationDatabasePath(path);
        requestFocus();
        setWebChromeClient(new WebChromeClient() {
            @Override
            public void onGeolocationPermissionsShowPrompt(String str, GeolocationPermissions.Callback callback) {
                if (new PermissionsChecker(LyWebView.this.getContext()).judgePermissions("android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION")) {
                    ActivityCompat.requestPermissions((Activity) LyWebView.this.getContext(), new String[]{"android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"}, 0);
                }
                callback.invoke(str, true, false);
                super.onGeolocationPermissionsShowPrompt(str, callback);
            }

            @Override
            public void onReceivedTitle(WebView webView, String str) {
                super.onReceivedTitle(webView, str);
                if (LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onReceivedTitle(webView, str);
                }
            }

            @Override
            public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
                ((IDialog) Ioc.get(IDialog.class)).showToastShort(LyWebView.this.getContext(), str2);
                jsResult.confirm();
                return true;
            }

            @Override
            public boolean onJsConfirm(WebView webView, String str, String str2, final JsResult jsResult) {
                ((IDialog) Ioc.get(IDialog.class)).showDialog(LyWebView.this.getContext(), "提示", str2, new DialogCallBack() {
                    @Override
                    public void onClick(int i) {
                        if (i == -1) {
                            jsResult.confirm();
                        } else {
                            jsResult.cancel();
                        }
                    }
                });
                return true;
            }

            public void openFileChooser(ValueCallback<Uri> valueCallback, String str, String str2) {
                if (LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onShowFileUploadType(valueCallback, null);
                }
            }

            public void openFileChooser(ValueCallback<Uri> valueCallback, String str) {
                if (LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onShowFileUploadType(valueCallback, null);
                }
            }

            public void openFileChooser(ValueCallback<Uri> valueCallback) {
                if (LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onShowFileUploadType(valueCallback, null);
                }
            }

            @Override
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
                if (LyWebView.this.loadingListener == null) {
                    return true;
                }
                LyWebView.this.loadingListener.onShowFileUploadType(null, valueCallback);
                return true;
            }

            @Override
            public void onProgressChanged(WebView webView, int i) {
                super.onProgressChanged(webView, i);
                if (i > 20 && LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onHideCommonPlaceBg();
                }
                if (i <= 50 || LyWebView.this.loadingListener == null) {
                    return;
                }
                LyWebView.this.loadingListener.onHideProgress();
            }

            @Override
            public View getVideoLoadingProgressView() {
                FrameLayout frameLayout = new FrameLayout(LyWebView.this.getContext());
                frameLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
                return frameLayout;
            }

            @Override
            public void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
                if (LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onShowVideoFull(view, customViewCallback);
                }
            }

            @Override
            public void onHideCustomView() {
                if (LyWebView.this.loadingListener != null) {
                    LyWebView.this.loadingListener.onShowVideoNormal();
                }
            }
        });
    }

    @Override
    public void setNestedScrollingEnabled(boolean z) {
        this.mScrollingChildHelper.setNestedScrollingEnabled(z);
    }

    @Override
    public boolean isNestedScrollingEnabled() {
        return this.mScrollingChildHelper.isNestedScrollingEnabled();
    }

    @Override
    public boolean startNestedScroll(int i) {
        return this.mScrollingChildHelper.startNestedScroll(i);
    }

    @Override
    public void stopNestedScroll() {
        this.mScrollingChildHelper.stopNestedScroll();
    }

    @Override
    public boolean hasNestedScrollingParent() {
        return this.mScrollingChildHelper.hasNestedScrollingParent();
    }

    @Override
    public boolean dispatchNestedScroll(int i, int i2, int i3, int i4, int[] iArr) {
        return this.mScrollingChildHelper.dispatchNestedScroll(i, i2, i3, i4, iArr);
    }

    @Override
    public boolean dispatchNestedPreScroll(int i, int i2, int[] iArr, int[] iArr2) {
        return this.mScrollingChildHelper.dispatchNestedPreScroll(i, i2, iArr, iArr2);
    }

    @Override
    public boolean dispatchNestedFling(float f, float f2, boolean z) {
        return this.mScrollingChildHelper.dispatchNestedFling(f, f2, z);
    }

    @Override
    public boolean dispatchNestedPreFling(float f, float f2) {
        return this.mScrollingChildHelper.dispatchNestedPreFling(f, f2);
    }

    public class MagWebViewClient extends WebViewClient {
        public MagWebViewClient() {
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            if (!str.startsWith("http") && !str.startsWith("https")) {
                UrlScheme.toUrl(LyWebView.this.getContext(), str);
                return true;
            }
            SiteConfig siteConfig = (SiteConfig) Ioc.get(SiteConfig.class);
            if (!TextUtils.isEmpty(siteConfig.seekExp)) {
                Matcher matcher = Pattern.compile(siteConfig.seekExp).matcher(str);
                if (matcher.find()) {
                    String group = matcher.group(1);
                    UrlScheme.toUrl(LyWebView.this.getContext(), "https://app.jpztong.com/mag/circle/v1/forum/threadViewPage?tid=" + group);
                    return true;
                }
            }
            if (!TextUtils.isEmpty(siteConfig.global_thread_regular_expression)) {
                Matcher matcher2 = Pattern.compile(siteConfig.global_thread_regular_expression).matcher(str);
                if (matcher2.find()) {
                    String group2 = matcher2.group(1);
                    UrlScheme.toUrl(LyWebView.this.getContext(), "https://app.jpztong.com/mag/circle/v1/forum/threadViewPage?tid=" + group2);
                    return true;
                }
            }
            if (!TextUtils.isEmpty(siteConfig.homeEep)) {
                Matcher matcher3 = Pattern.compile(siteConfig.homeEep).matcher(str);
                if (matcher3.find()) {
                    String group3 = matcher3.group(1);
                    UrlScheme.toUrl(LyWebView.this.getContext(), Ioc.getApplicationContext().getResources().getString(R.string.app_code) + "://userHome?userId=" + group3);
                    return true;
                }
            }
            if (str.contains(".zip") || str.contains(".rar") || str.contains(".apk")) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.setData(Uri.parse(str));
                LyWebView.this.getContext().startActivity(intent);
                return true;
            }
            if (LyWebView.this.findViewById(R.id.comment_bar) != null && !str.equals(LyWebView.this.getUrl())) {
                UrlScheme.toUrl(LyWebView.this.getContext(), str);
                return true;
            }
            HashMap hashMap = new HashMap();
            hashMap.put("Referer", LyWebView.this.getUrl());
            webView.loadUrl(UrlUtils.deleteGetUrlParameter(str, "html_response_json=1"), hashMap);
            if (LyWebView.this.loadingListener != null) {
                LyWebView.this.loadingListener.onHideNaviAuthor();
            }
            return true;
        }

        @Override
        public void onPageFinished(WebView webView, String str) {
            super.onPageFinished(webView, str);
            if (!LyWebView.this.getSettings().getLoadsImagesAutomatically()) {
                LyWebView.this.getSettings().setLoadsImagesAutomatically(true);
            }
            if (LyWebView.this.loadingListener != null) {
                LyWebView.this.loadingListener.onWebPageLoadFinished();
            }
        }

        @Override
        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            if (LyWebView.this.loadingListener != null) {
                LyWebView.this.loadingListener.onShowProgress();
                LyWebView.this.loadingListener.onClearShareInfo();
            }
        }

        @Override
        public void onReceivedError(WebView webView, int i, String str, String str2) {
            if (LyWebView.this.loadingListener != null) {
                LyWebView.this.loadingListener.onShowErrorPage();
            }
        }

        @Override
        public void onReceivedSslError(WebView webView, final SslErrorHandler sslErrorHandler, SslError sslError) {
            if (BuildConfig.foreignMarket.booleanValue()) {
                ((IDialog) Ioc.get(IDialog.class)).showDialog(LyWebView.this.getContext(), "提示", "该网站https证书存在问题,是否继续?", "停止", "继续", new DialogCallBack() {
                    @Override
                    public void onClick(int i) {
                        if (i == -1) {
                            sslErrorHandler.proceed();
                        } else {
                            sslErrorHandler.cancel();
                        }
                    }
                });
            } else {
                sslErrorHandler.proceed();
            }
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView webView, String str) {
            if (str.endsWith(".js")) {
                if (str.endsWith(Constants.VUEMINJS)) {
                    return new WebResourceResponse("application/x-javascript", "UTF-8", LyWebView.this.getContext().getResources().openRawResource(R.raw.vue));
                }
                if (str.endsWith(Constants.UNDERSCOREMINJS)) {
                    return new WebResourceResponse("application/x-javascript", "UTF-8", LyWebView.this.getContext().getResources().openRawResource(R.raw.underscore));
                }
                if (str.endsWith(Constants.JQUERYMINJS)) {
                    return new WebResourceResponse("application/x-javascript", "UTF-8", LyWebView.this.getContext().getResources().openRawResource(R.raw.jquery));
                }
            }
            return super.shouldInterceptRequest(webView, str);
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
            if (Build.VERSION.SDK_INT >= 21) {
                String uri = webResourceRequest.getUrl().toString();
                if (uri.endsWith(".js")) {
                    if (uri.endsWith(Constants.VUEMINJS)) {
                        return new WebResourceResponse("application/x-javascript", "UTF-8", LyWebView.this.getContext().getResources().openRawResource(R.raw.vue));
                    }
                    if (uri.endsWith(Constants.UNDERSCOREMINJS)) {
                        return new WebResourceResponse("application/x-javascript", "UTF-8", LyWebView.this.getContext().getResources().openRawResource(R.raw.underscore));
                    }
                    if (uri.endsWith(Constants.JQUERYMINJS)) {
                        return new WebResourceResponse("application/x-javascript", "UTF-8", LyWebView.this.getContext().getResources().openRawResource(R.raw.jquery));
                    }
                }
            }
            return super.shouldInterceptRequest(webView, webResourceRequest);
        }
    }

    public void setOnShowLoadingListener(OnLoadingListener onLoadingListener) {
        this.loadingListener = onLoadingListener;
    }
}