package com.ss.android.ugc.aweme.bullet.business;

import X.C0339K0c;
import X.C0762KGj;
import X.C1165KVw;
import X.C1897Kk4;
import X.C2140Knz;
import X.C2277KqC;
import X.C2621Kvk;
import X.C2623Kvm;
import X.KWQ;
import X.M12;
import android.app.Activity;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;

public final class AdLynxStatBusiness extends BulletBusinessService$Business {
    public long LIZ = -1;
    public boolean LIZIZ;
    public boolean LIZJ;
    public final List<String> LIZLLL = new ArrayList();
    public boolean LJ;
    public long LJFF;

    static {
        Covode.recordClassIndex(55163);
    }

    private final KWQ LIZLLL() {
        C1897Kk4 kk4 = this.LJIIJ.LIZ;
        if (!(kk4 instanceof KWQ)) {
            kk4 = null;
        }
        return (KWQ) kk4;
    }

    public final void LIZ() {
        this.LIZIZ = false;
        this.LIZJ = false;
        this.LIZLLL.clear();
        LIZJ();
    }

    public final void LIZJ() {
        this.LJ = false;
        this.LJFF = System.currentTimeMillis();
    }

    public final void LIZIZ() {
        Object obj;
        C1165KVw kVw;
        KWQ LIZLLL2 = LIZLLL();
        if (LIZLLL2 == null || (kVw = LIZLLL2.LJJLL) == null) {
            obj = null;
        } else {
            obj = kVw.LIZIZ();
        }
        if (!(!n.LIZ(obj, true))) {
            this.LIZIZ = true;
            LIZJ("load_finish");
        }
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public AdLynxStatBusiness(C2140Knz knz) {
        super(knz);
        M12.LIZ((Object) knz);
    }

    public final void LIZ(String str) {
        Object obj;
        C1165KVw kVw;
        KWQ LIZLLL2 = LIZLLL();
        if (LIZLLL2 == null || (kVw = LIZLLL2.LJJLL) == null) {
            obj = null;
        } else {
            obj = kVw.LIZIZ();
        }
        if (!(!n.LIZ(obj, true))) {
            this.LIZIZ = true;
            this.LIZJ = true;
            if (str != null) {
                this.LIZLLL.add(str);
            }
        }
    }

    public final void LIZ(boolean z) {
        Object obj;
        Activity LIZ2;
        C1165KVw kVw;
        KWQ LIZLLL2 = LIZLLL();
        if (LIZLLL2 == null || (kVw = LIZLLL2.LJJLL) == null) {
            obj = null;
        } else {
            obj = kVw.LIZIZ();
        }
        if (!(!n.LIZ(obj, true)) && (LIZ2 = this.LJIIJ.LIZ()) != null) {
            if (!this.LJ) {
                LIZJ("stay_page");
            }
            if (!z && !LIZ2.isFinishing()) {
                return;
            }
            if (!this.LIZIZ) {
                LIZJ("load");
            } else if (this.LIZJ) {
                LIZ("load_fail", this.LIZLLL.toString());
            }
        }
    }

    public final void LIZIZ(String str) {
        Object obj;
        C1165KVw kVw;
        KWQ LIZLLL2 = LIZLLL();
        if (LIZLLL2 == null || (kVw = LIZLLL2.LJJLL) == null) {
            obj = null;
        } else {
            obj = kVw.LIZIZ();
        }
        if (!(!n.LIZ(obj, true))) {
            LIZ("init_fail", str);
        }
    }

    private final void LIZJ(String str) {
        String str2;
        C2277KqC kqC = this.LJIIJ.LIZIZ;
        if (kqC != null) {
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            linkedHashMap.put("render_type", "lynx");
            if (n.LIZ("load_finish", str)) {
                linkedHashMap.put("duration", Long.valueOf(this.LIZ));
            } else if (n.LIZ("stay_page", str)) {
                long currentTimeMillis = System.currentTimeMillis() - this.LJFF;
                this.LJFF = 0;
                if (currentTimeMillis > 0) {
                    linkedHashMap.put("stay_time", Long.valueOf(currentTimeMillis));
                    this.LJ = true;
                } else {
                    return;
                }
            }
            KWQ LIZLLL2 = LIZLLL();
            if (LIZLLL2 != null) {
                str2 = LIZLLL2.LIZIZ();
            } else {
                str2 = null;
            }
            linkedHashMap.put("channel_name", str2);
            String LIZIZ2 = kqC.LJJLIL.LIZIZ();
            if (LIZIZ2 == null) {
                LIZIZ2 = "";
            }
            linkedHashMap.put("page_id", LIZIZ2);
            linkedHashMap.put("first_page", 1);
            linkedHashMap.put("ix_to_externalurl", 0);
            C2621Kvk LIZ2 = C2623Kvm.LIZ();
            LIZ2.LIZ = "ad_wap_stat";
            LIZ2.LIZIZ = str;
            LIZ2.LIZ(Long.valueOf(kqC.LIZIZ()));
            LIZ2.LIZJ(kqC.LIZLLL());
            LIZ2.LIZLLL = kqC.LIZJ();
            LIZ2.LIZ((Object) linkedHashMap);
            LIZ2.LIZJ();
            HashMap hashMap = new HashMap();
            for (Map.Entry entry : linkedHashMap.entrySet()) {
                Object value = entry.getValue();
                if (value != null) {
                    hashMap.put(entry.getKey(), value);
                }
            }
            C0762KGj LIZ3 = C0339K0c.LIZ("ad_wap_stat", str, String.valueOf(kqC.LIZIZ()), kqC.LIZLLL(), kqC.LIZJ());
            LIZ3.LIZ(hashMap);
            LIZ3.LIZJ();
        }
    }

    private final void LIZ(String str, String str2) {
        String str3;
        C2277KqC kqC = this.LJIIJ.LIZIZ;
        if (kqC != null) {
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            KWQ LIZLLL2 = LIZLLL();
            if (LIZLLL2 != null) {
                str3 = LIZLLL2.LIZIZ();
            } else {
                str3 = null;
            }
            linkedHashMap.put("channel_name", str3);
            linkedHashMap.put("status", str);
            if (str2 == null) {
                str2 = "";
            }
            linkedHashMap.put("message", str2);
            C2621Kvk LIZ2 = C2623Kvm.LIZ();
            LIZ2.LIZ = "lynx_landing_page";
            LIZ2.LIZIZ = "fallback";
            LIZ2.LIZ(Long.valueOf(kqC.LIZIZ()));
            LIZ2.LIZJ(kqC.LIZLLL());
            LIZ2.LIZLLL = kqC.LIZJ();
            LIZ2.LIZ((Object) linkedHashMap);
            LIZ2.LIZJ();
            HashMap hashMap = new HashMap();
            for (Map.Entry entry : linkedHashMap.entrySet()) {
                Object value = entry.getValue();
                if (value != null) {
                    hashMap.put(entry.getKey(), value);
                }
            }
            C0762KGj LIZ3 = C0339K0c.LIZ("lynx_landing_page", "fallback", String.valueOf(kqC.LIZIZ()), kqC.LIZLLL(), kqC.LIZJ());
            LIZ3.LIZ(hashMap);
            LIZ3.LIZJ();
        }
    }
}
