4399游戏盒 v7.2.1.31版本的 MD5 值为:951717f45e3fda95c8a358caf4ca93e1

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


package com.m4399.gamecenter.plugin.main.controllers.web;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Keep;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;
import com.dialog.DialogResult;
import com.dialog.c;
import com.framework.config.Config;
import com.framework.rxbus.RxBus;
import com.framework.rxbus.annotation.Subscribe;
import com.framework.rxbus.annotation.Tag;
import com.framework.utils.JSONUtils;
import com.m4399.gamecenter.plugin.main.R;
import com.m4399.gamecenter.plugin.main.config.GameCenterConfigKey;
import com.m4399.gamecenter.plugin.main.controllers.gamedetail.GameDetailActivity;
import com.m4399.gamecenter.plugin.main.helpers.k;
import com.m4399.gamecenter.plugin.main.helpers.l;
import com.m4399.gamecenter.plugin.main.helpers.t;
import com.m4399.gamecenter.plugin.main.views.CommonDeleteDialog;
import com.m4399.gamecenter.plugin.main.widget.web.BaseWebViewLayout;
import com.m4399.support.widget.dialog.CommonLoadingDialog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONObject;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

public class GameCommentJsInterface extends CommentJsInterface {
    private HashMap<String, String> aNd;
    private CommonLoadingDialog cgJ;
    private RxBusHandler cgK;
    private boolean cgL;
    private boolean cgM;
    private c cgN;
    private String cgO;
    private ArrayList<Bundle> cgP;
    private a cgQ;
    private String mFrom;

    public static abstract class a {
        public void onDeleteComment() {
        }
    }

    public interface b {
        void onCancel(String str);

        void onConfirm(String str);
    }

    public interface c {
        void hideGameInfo(int i);
    }

    public HashMap<String, String> getStatParamsOnDestoryMap() {
        if (this.aNd == null) {
            this.aNd = new HashMap<>();
        }
        return this.aNd;
    }

    public void setIsLoadTemplate(boolean z) {
        this.cgL = z;
    }

    public void setFrom(String str) {
        this.mFrom = str;
    }

    public void setHideGameInfoListener(c cVar) {
        this.cgN = cVar;
    }

    public GameCommentJsInterface(BaseWebViewLayout baseWebViewLayout, Context context) {
        super(baseWebViewLayout, context);
        this.cgL = false;
        this.cgM = false;
        this.cgP = new ArrayList<>();
        this.aNd = null;
    }

    @Override
    public void init(BaseWebViewLayout baseWebViewLayout, Context context) {
        super.init(baseWebViewLayout, context);
        this.cgK = new RxBusHandler(this);
    }

    @Override
    public void onDestroy() {
        RxBusHandler rxBusHandler = this.cgK;
        if (rxBusHandler != null) {
            rxBusHandler.unregister();
            this.cgK = null;
        }
        super.onDestroy();
        this.aNd = null;
    }

    @JavascriptInterface
    public void statParamsOnDestory(String str, String str2) {
        JSONObject parseJSONObjectFromString = JSONUtils.parseJSONObjectFromString(str2);
        Iterator<String> keys = parseJSONObjectFromString.keys();
        if (keys == null || !keys.hasNext()) {
            return;
        }
        while (keys.hasNext()) {
            String next = keys.next();
            String string = JSONUtils.getString(next, parseJSONObjectFromString);
            if (!TextUtils.isEmpty(next) && !TextUtils.isEmpty(string)) {
                getStatParamsOnDestoryMap().put(next, string);
            }
        }
    }

    @JavascriptInterface
    public void modifyCmtInfo(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        JSONObject parseJSONObjectFromString = JSONUtils.parseJSONObjectFromString(str);
        if (parseJSONObjectFromString.length() == 0) {
            return;
        }
        RxBus.get().post("tag.modify.comment.info", parseJSONObjectFromString);
    }

    @JavascriptInterface
    public void updateGameInfo(final String str) {
        Observable.just("").observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<String>() {
            @Override
            public void call(String str2) {
                if (GameCommentJsInterface.this.mContext == null || !(GameCommentJsInterface.this.mContext instanceof GameDetailActivity)) {
                    return;
                }
                JSONObject parseJSONObjectFromString = JSONUtils.parseJSONObjectFromString(str);
                int i = JSONUtils.getInt("counts", parseJSONObjectFromString);
                String string = JSONUtils.getString("score", parseJSONObjectFromString);
                GameDetailActivity gameDetailActivity = (GameDetailActivity) GameCommentJsInterface.this.mContext;
                gameDetailActivity.updateComments(i);
                gameDetailActivity.updateScore(string);
            }
        });
    }

    @JavascriptInterface
    public void dialogBottomDelete(String str) {
        dialogBottomDelete(this.mContext, str, new b() {
            @Override
            public void onConfirm(String str2) {
                if (GameCommentJsInterface.this.cgQ != null) {
                    GameCommentJsInterface.this.cgQ.onDeleteComment();
                }
                GameCommentJsInterface.this.mWebView.loadJs(GameCommentJsInterface.this.mContext.getString(R.string.js_prefix, str2 + "()"));
            }

            @Override
            public void onCancel(String str2) {
                GameCommentJsInterface.this.mWebView.loadJs(GameCommentJsInterface.this.mContext.getString(R.string.js_prefix, str2 + "()"));
            }
        });
    }

    @Keep
    @JavascriptInterface
    public void onPraiseSuccess(int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("intent.extra.comment.id", i);
        bundle.putString("intent.extra.from.key", this.mFrom);
        RxBus.get().post("tag.common.comment.praise", bundle);
    }

    public static void dialogBottomDelete(Context context, String str, final b bVar) {
        JSONObject parseJSONObjectFromString = JSONUtils.parseJSONObjectFromString(str);
        final String string = JSONUtils.getString("cancel", parseJSONObjectFromString);
        final String string2 = JSONUtils.getString("confirm", parseJSONObjectFromString);
        CommonDeleteDialog commonDeleteDialog = new CommonDeleteDialog(context);
        commonDeleteDialog.setOnDialogTwoHorizontalBtnsClickListener(new c.b() {
            @Override
            public DialogResult onLeftBtnClick() {
                b bVar2 = b.this;
                if (bVar2 != null) {
                    bVar2.onConfirm(string2);
                }
                return DialogResult.OK;
            }

            @Override
            public DialogResult onRightBtnClick() {
                b bVar2 = b.this;
                if (bVar2 != null) {
                    bVar2.onCancel(string);
                }
                return DialogResult.Cancel;
            }
        });
        commonDeleteDialog.show(context.getString(R.string.delete_confirm_title, context.getString(R.string.comment)));
    }

    private boolean k(Bundle bundle) {
        if (bundle == null || TextUtils.isEmpty(this.mFrom)) {
            return false;
        }
        String string = bundle.getString("from");
        if (TextUtils.isEmpty(string)) {
            return false;
        }
        return this.mFrom.equals(string);
    }

    public void onNetworkRequestLifecycle(Bundle bundle) {
        if (this.mContext == null || !k(bundle)) {
            return;
        }
        if ("onBefore".equals(bundle.getString("state"))) {
            String string = bundle.getString("requestTips");
            if (TextUtils.isEmpty(string)) {
                return;
            }
            if (this.cgJ == null) {
                this.cgJ = new CommonLoadingDialog(this.mContext);
            }
            this.cgJ.show(string);
            return;
        }
        CommonLoadingDialog commonLoadingDialog = this.cgJ;
        if (commonLoadingDialog != null) {
            commonLoadingDialog.dismiss();
            this.cgJ = null;
        }
    }

    public void doCacheCommentAction() {
        ArrayList<Bundle> arrayList = this.cgP;
        if (arrayList == null || arrayList.size() <= 0) {
            return;
        }
        Iterator it = new ArrayList(this.cgP).iterator();
        while (it.hasNext()) {
            commentAction((Bundle) it.next());
        }
        this.cgP.clear();
    }

    public void commentAction(Bundle bundle) {
        if (bundle == null || this.mContext == null || this.mWebView == null || TextUtils.isEmpty(this.mFrom) || this.mFrom.equals(bundle.getString("intent.extra.comment.action.from")) || !l.ACTION_STATE_SUCCESS.equals(bundle.getString("intent.extra.comment.action.state"))) {
            return;
        }
        if (this.cgL || ((Boolean) Config.getValue(GameCenterConfigKey.WEB_VIEW_DEBUG_MODE)).booleanValue()) {
            String string = bundle.getString("intent.extra.comment.action.info");
            k.executeJs(this.mWebView, this.mContext.getString(R.string.js_prefix, "m_comment.localUpdate(" + string + ")"));
            return;
        }
        if ("like".equals(bundle.getString("intent.extra.comment.action"))) {
            return;
        }
        this.cgP.add(bundle);
    }

    @Keep
    @JavascriptInterface
    public boolean isScrollToCommentCalled() {
        return this.cgM;
    }

    @Keep
    @JavascriptInterface
    public String getAllCommentTabType() {
        String str = this.cgO;
        this.cgO = null;
        return str;
    }

    public void setAllCommentTabType(String str) {
        this.cgO = str;
    }

    @JavascriptInterface
    @Deprecated
    public void onJsHideGameInfo(int i) {
        c cVar = this.cgN;
        if (cVar != null) {
            cVar.hideGameInfo(i);
        }
    }

    public static class RxBusHandler {
        private GameCommentJsInterface cgT;

        public RxBusHandler(GameCommentJsInterface gameCommentJsInterface) {
            this.cgT = gameCommentJsInterface;
            RxBus.register(this);
        }

        public void unregister() {
            RxBus.unregister(this);
            this.cgT = null;
        }

        @Keep
        @Subscribe(tags = {@Tag("tag.comment.reply.request"), @Tag("tag.weekly.comment,reply.request")})
        public void onNetworkRequestLifecycle(Bundle bundle) {
            this.cgT.onNetworkRequestLifecycle(bundle);
        }

        @Keep
        @Subscribe(tags = {@Tag("tag.comment.action")})
        public void commentAction(Bundle bundle) {
            this.cgT.commentAction(bundle);
        }
    }

    public void scrollToCommentList() {
        invoke("window.m_comment.scrollToCommentList()");
        this.cgM = true;
    }

    public void startGetComment() {
        invoke("window.startGetComments");
    }

    public void setActionListener(a aVar) {
        this.cgQ = aVar;
    }

    public void commentShow(boolean z) {
        if (this.mWebView != null) {
            this.mWebView.loadUrl("javascript:window.m_comment.commentPageShow(" + z + ")");
        }
    }

    @Override
    @Keep
    @JavascriptInterface
    public void userFollow(String str) {
        super.userFollow(str);
        t.onEvent("focus_click", "trace", "游戏评论详情页");
    }

    @Keep
    @JavascriptInterface
    public void requestDisallowInterceptTouchEvent(boolean z) {
        if (this.mWebView != null) {
            this.mWebView.disallowIntercept(z);
        }
    }
}