package com.tencent.mm.plugin.topstory;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.compatible.util.q;
import com.tencent.mm.plugin.topstory.a.b.b;
import com.tencent.mm.plugin.websearch.api.aa;
import com.tencent.mm.protocal.protobuf.bsj;
import com.tencent.mm.protocal.protobuf.chv;
import com.tencent.mm.protocal.protobuf.chw;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ytcommon.BuildConfig;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

class c$a implements Runnable {
    long createTime;
    final /* synthetic */ c sAx;
    HashSet<b> sAy;
    chv sAz;

    private c$a(c cVar) {
        this.sAx = cVar;
        AppMethodBeat.i(65494);
        this.sAy = new HashSet();
        AppMethodBeat.o(65494);
    }

    /* synthetic */ c$a(c cVar, byte b) {
        this(cVar);
    }

    public final void run() {
        AppMethodBeat.i(65495);
        ab.i("MicroMsg.TopStory.TopStoryReporterImpl", "Star to run ReportExposeTask");
        this.sAx.sAw.remove(Long.valueOf(this.sAz.xgG));
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(this.sAy);
        int i = 0;
        while (true) {
            List subList;
            int i2 = i + 20;
            if (i2 >= arrayList.size()) {
                subList = arrayList.subList(i, arrayList.size());
            } else {
                subList = arrayList.subList(i, i2);
            }
            String a = a(subList, this.sAz);
            if (!bo.isNullOrNil(a)) {
                bsj bsj = new bsj();
                bsj.wUu = a;
                ab.i("MicroMsg.TopStory.TopStoryReporterImpl", "build14057VideoInfoExposeString %d report string: %s", new Object[]{Integer.valueOf(subList.size()), bsj.wUu});
                al.d(new 1(this, bsj));
            }
            if (i2 >= arrayList.size()) {
                AppMethodBeat.o(65495);
                return;
            }
            i = i2;
        }
    }

    private static String a(List<b> list, chv chv) {
        AppMethodBeat.i(65496);
        if (list.size() == 0) {
            AppMethodBeat.o(65496);
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder(BuildConfig.FLAVOR);
        stringBuilder.append("isexpose=1&content=");
        StringBuilder stringBuilder2 = new StringBuilder(BuildConfig.FLAVOR);
        for (b bVar : list) {
            chw chw = bVar.sAX;
            stringBuilder2.append(chw.ctk);
            stringBuilder2.append(":");
            stringBuilder2.append(chw.ubA);
            stringBuilder2.append(":");
            stringBuilder2.append(bVar.mLr);
            stringBuilder2.append(":");
            stringBuilder2.append(chw.xgV);
            stringBuilder2.append(";");
        }
        try {
            stringBuilder.append(q.encode(stringBuilder2.toString(), "utf-8"));
        } catch (Exception e) {
            ab.printErrStackTrace("MicroMsg.TopStory.TopStoryReporterImpl", e, BuildConfig.FLAVOR, new Object[0]);
        }
        try {
            chw chw2;
            stringBuilder.append("&resulttype=");
            for (b bVar2 : list) {
                chw2 = bVar2.sAX;
                stringBuilder.append(chw2.ctk);
                stringBuilder.append(":");
                stringBuilder.append(chw2.xgZ);
                stringBuilder.append(";");
            }
            stringBuilder.append("&expand=");
            stringBuilder2 = new StringBuilder(BuildConfig.FLAVOR);
            for (b bVar22 : list) {
                chw2 = bVar22.sAX;
                stringBuilder2.append(chw2.ctk);
                stringBuilder2.append(":");
                stringBuilder2.append(chw2.xgX);
                stringBuilder2.append(";");
            }
            try {
                stringBuilder.append(q.encode(stringBuilder2.toString(), "utf-8"));
            } catch (UnsupportedEncodingException e2) {
                ab.printErrStackTrace("MicroMsg.TopStory.TopStoryReporterImpl", e2, BuildConfig.FLAVOR, new Object[0]);
            }
            stringBuilder.append("&itemtype=");
            stringBuilder2 = new StringBuilder(BuildConfig.FLAVOR);
            for (b bVar222 : list) {
                stringBuilder2.append(bVar222.sAX.xgW);
                stringBuilder2.append(";");
            }
            stringBuilder.append(stringBuilder2);
            if (chv != null) {
                stringBuilder.append("&");
                stringBuilder.append("searchid=");
                stringBuilder.append(chv.hlm);
                stringBuilder.append("&");
                stringBuilder.append("query=");
                try {
                    stringBuilder.append(q.encode(chv.ctj, "utf-8"));
                } catch (Exception e3) {
                    ab.printErrStackTrace("MicroMsg.TopStory.TopStoryReporterImpl", e3, BuildConfig.FLAVOR, new Object[0]);
                }
                stringBuilder.append("&");
                stringBuilder.append("ishomepage=0");
                stringBuilder.append("&");
                stringBuilder.append("sessionid=");
                stringBuilder.append(aa.HP(chv.scene));
                stringBuilder.append("&");
                stringBuilder.append("scene=");
                stringBuilder.append(chv.scene);
                stringBuilder.append("&rec_category=");
                stringBuilder.append(chv.xgG);
            }
            String stringBuilder3 = stringBuilder.toString();
            AppMethodBeat.o(65496);
            return stringBuilder3;
        } catch (Exception e32) {
            ab.printErrStackTrace("MicroMsg.TopStory.TopStoryReporterImpl", e32, "build14057VideoInfoExposeString error: %s", new Object[]{e32.getMessage()});
            AppMethodBeat.o(65496);
            return null;
        }
    }
}
