package com.tencent.mm.plugin.topstory.ui.webview;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.f;
import com.tencent.mm.ai.m;
import com.tencent.mm.kernel.g;
import com.tencent.mm.plugin.topstory.a.c.b;
import com.tencent.mm.plugin.topstory.a.h;
import com.tencent.mm.plugin.topstory.ui.PluginTopStoryUI;
import com.tencent.mm.plugin.topstory.ui.home.a;
import com.tencent.mm.protocal.protobuf.chn;
import com.tencent.mm.protocal.protobuf.cve;
import com.tencent.mm.sdk.g.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ttpic.baseutils.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public final class c implements f {
    private b sAq;
    public f sEu = new 2(this);
    public f sHA = new 3(this);
    public a sHt;
    private boolean sHu;
    public b sHv;
    public byte[] sHw;
    byte[] sHx;
    byte[] sHy;
    public f sHz = new 1(this);

    public c() {
        AppMethodBeat.i(2153);
        AppMethodBeat.o(2153);
    }

    public final void cHl() {
        AppMethodBeat.i(2154);
        d.post(new a(this, (byte) 0), "TopStory.LoadHtmlDataFromSdcardTask");
        AppMethodBeat.o(2154);
    }

    public final void y(String str, String str2, boolean z) {
        AppMethodBeat.i(2155);
        if (bo.isNullOrNil(str)) {
            AppMethodBeat.o(2155);
            return;
        }
        if (this.sHw != null) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("json", str);
                jSONObject.put("newQuery", true);
                jSONObject.put("isCache", true);
                jSONObject.put("recType", z ? 1 : 0);
                if (!bo.isNullOrNil(str2)) {
                    jSONObject.put("filterDocidList", new JSONArray(str2));
                }
            } catch (Exception e) {
            }
            this.sHw = new String(this.sHw).replace("'###preloadObjFeedsData###'", jSONObject.toString() + IOUtils.LINE_SEPARATOR_UNIX).getBytes();
            ab.i("MicroMsg.TopStory.TopStoryWebData", "attachDataToHtml htmlBytes:%s", new Object[]{Integer.valueOf(this.sHw.length)});
        }
        AppMethodBeat.o(2155);
    }

    public final void a(chn chn, boolean z, boolean z2, int i) {
        AppMethodBeat.i(2156);
        ab.i("MicroMsg.TopStory.TopStoryWebData", "loadDataFromServer directRequest:%s", new Object[]{Boolean.valueOf(z2)});
        if (z2 || this.sAq == null || !chn.cvF.equals(this.sAq.cPu.cvF)) {
            this.sAq = new b(chn, i);
            g.Rg().a(1943, this);
            g.Rg().a(this.sAq, 0);
            this.sHu = z;
            ab.i("MicroMsg.TopStory.TopStoryWebData", "Start new net scene");
            AppMethodBeat.o(2156);
            return;
        }
        this.sHu = z;
        ab.i("MicroMsg.TopStory.TopStoryWebData", "Wait current net scene");
        h.a(chn, "WaitCurrentNetScene", System.currentTimeMillis());
        AppMethodBeat.o(2156);
    }

    public final void onSceneEnd(int i, int i2, String str, m mVar) {
        AppMethodBeat.i(2157);
        if (mVar.equals(this.sAq)) {
            g.Rg().b(1943, this);
            this.sAq = null;
            b bVar = (b) mVar;
            if (i == 0 && i2 == 0) {
                cve cFt = bVar.cFt();
                String str2 = cFt.vOy;
                ((com.tencent.mm.plugin.topstory.a.b) g.M(com.tencent.mm.plugin.topstory.a.b.class)).getRedDotMgr().lC((long) cFt.xri);
                a(bVar.cPu, str2, false);
                if (bVar.cFt().xrh != null && (bVar.cFt().xrh.wSe == 1 || ((PluginTopStoryUI) g.M(PluginTopStoryUI.class)).getTopStoryCommand().sBl)) {
                    d.post(new 4(this, cFt, str2), "TopStory.CacheHomeData");
                }
            } else {
                ab.i("MicroMsg.TopStory.TopStoryWebData", "netscene topstory error");
                a(bVar.cPu, cHm(), true);
                AppMethodBeat.o(2157);
                return;
            }
        }
        AppMethodBeat.o(2157);
    }

    private void a(chn chn, String str, boolean z) {
        AppMethodBeat.i(2158);
        if (this.sHu) {
            if (this.sHt != null) {
                this.sHt.abD(str);
            }
            this.sHu = false;
            AppMethodBeat.o(2158);
        } else if (z || chn.cdf != 100) {
            this.sHv = null;
            AppMethodBeat.o(2158);
        } else {
            this.sHv = new b(this, (byte) 0);
            this.sHv.sHE = chn;
            this.sHv.jKz = System.currentTimeMillis();
            this.sHv.sHD = str;
            AppMethodBeat.o(2158);
        }
    }

    private static String cHm() {
        AppMethodBeat.i(2159);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("ret", -1);
        } catch (JSONException e) {
        }
        String jSONObject2 = jSONObject.toString();
        AppMethodBeat.o(2159);
        return jSONObject2;
    }
}
