package com.ss.android.ugc.aweme.inbox.widget.multi;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0E3;
import X.2GO;
import X.2HZ;
import X.3PM;
import X.7he;
import X.C0295Crj;
import X.C1805Dfd;
import X.C1870Dgg;
import X.C2576Ds4;
import X.C2583DsB;
import X.C2588DsG;
import X.C2595DsN;
import X.C2596DsO;
import X.C2598DsQ;
import X.C2600DsS;
import X.C2605DsX;
import X.C2638Dt4;
import X.C2641Dt7;
import X.C2644DtA;
import X.C2645DtB;
import X.C2646DtC;
import X.C2647DtD;
import X.C2648DtE;
import X.C2649DtF;
import X.C2708DuC;
import X.C3112E1s;
import X.C4068Eb2;
import X.E3G;
import X.ISm;
import X.M12;
import X.MHK;
import X.PgU;
import X.PgX;
import X.Pkb;
import X.Rc9;
import android.content.Context;
import android.os.Handler;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LiveData;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.IAppWidgetService;
import com.ss.android.ugc.aweme.inbox.widget.InboxAdapterWidget;
import com.ss.android.ugc.aweme.inbox.widget.multi.vm.InboxTopHorizontalListVM;
import com.ss.android.ugc.aweme.main.TabChangeManager;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.ThreadMode;

public final class MultiAdapterWidget extends InboxAdapterWidget implements C2583DsB<List<? extends C2588DsG>>, C2583DsB, 2HZ, 2GO {
    public boolean LIZ;
    public C2645DtB LIZIZ;
    public String LIZJ;
    public final boolean LIZLLL;
    public final C0295Crj LJ;
    public final C0295Crj LJFF;
    public final C0295Crj LJI;
    public boolean LJII;
    public boolean LJIILIIL;
    public boolean LJIILJJIL;
    public final C0295Crj LJIILL;
    public final C0295Crj LJIILLIIL;
    public final C0295Crj LJIIZILJ;

    static {
        Covode.recordClassIndex(88092);
    }

    private final Handler LJIIIZ() {
        return (Handler) this.LJI.getValue();
    }

    private final InboxTopHorizontalListVM LJIIJ() {
        return (InboxTopHorizontalListVM) this.LJIILL.getValue();
    }

    public final MultiViewModel LIZ() {
        return (MultiViewModel) this.LJ.getValue();
    }

    public final C2576Ds4 LIZIZ() {
        return (C2576Ds4) this.LJFF.getValue();
    }

    public final void LJII() {
    }

    public final Pkb<List<C2588DsG>> LJIIIIZZ() {
        return (Pkb) this.LJIIZILJ.getValue();
    }

    public final Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(468, new Rc9(MultiAdapterWidget.class, "onRedPointUpdate", C4068Eb2.class, ThreadMode.MAIN, 0, true));
        hashMap.put(488, new Rc9(MultiAdapterWidget.class, "onNoticeDeleted", C2648DtE.class, ThreadMode.MAIN, 0, false));
        hashMap.put(489, new Rc9(MultiAdapterWidget.class, "onFollowRequestFinished", E3G.class, ThreadMode.MAIN, 0, false));
        hashMap.put(180, new Rc9(MultiAdapterWidget.class, "onNoticeCountChangedEvent", C3112E1s.class, ThreadMode.MAIN, 0, true));
        return hashMap;
    }

    @0CN(LIZ = 0CB.ON_PAUSE)
    public final void onPause() {
        this.LJIILJJIL = false;
    }

    public final void onStateChanged(0CH r2, 0CB r3) {
        super.onStateChanged(r2, r3);
        if (r3 == 0CB.ON_CREATE) {
            onCreate();
        } else if (r3 == 0CB.ON_RESUME) {
            onResume();
        } else if (r3 == 0CB.ON_PAUSE) {
            onPause();
        } else if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    public final 0E3<?> LIZJ() {
        return LIZIZ();
    }

    public final LiveData<C1805Dfd> LJFF() {
        return LIZ().LIZLLL;
    }

    public final LiveData<Boolean> cO_() {
        return LIZ().LJ;
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public final void onDestroy() {
        EventBus.LIZ().LIZIZ(this);
    }

    public final PgU<List<C2588DsG>> LJI() {
        PgU<List<C2588DsG>> LIZ2 = LJIIIIZZ().LIZJ().LIZ(PgX.LIZ);
        n.LIZIZ(LIZ2, "");
        return LIZ2;
    }

    @0CN(LIZ = 0CB.ON_CREATE)
    public final void onCreate() {
        LIZ().LIZIZ.observe(this, new C2644DtA(this));
        EventBus.LIZ(EventBus.LIZ(), this);
        this.LJII = true;
        C2708DuC.LIZJ.LIZ();
        LIZ().LIZIZ(2);
    }

    public final void LIZLLL() {
        3PM.LIZIZ("MultiAdapterWidget", "onRefresh isTabChange=" + this.LIZ + ", hasNewNotice=" + this.LJIILIIL + ", isRefreshByTabChange=" + C2649DtF.LIZIZ.LIZIZ());
        C2708DuC.LIZJ.LIZ();
        if (this.LIZ) {
            if (this.LJIILIIL) {
                LIZ().LIZ(this.LIZ, false);
            } else if (C2649DtF.LIZIZ.LIZIZ() || C2649DtF.LIZ(LIZ().LJJI)) {
                LIZ().LIZIZ(2);
            }
            this.LIZ = false;
            this.LJIILIIL = false;
            return;
        }
        LIZ().LIZIZ(2);
    }

    @0CN(LIZ = 0CB.ON_RESUME)
    public final void onResume() {
        boolean z;
        Context context;
        boolean z2 = true;
        this.LJIILJJIL = true;
        LIZ().LJIJJ = true;
        if (this.LJII) {
            this.LJII = false;
            3PM.LIZIZ("MultiAdapterWidget", "onResume by created");
        } else if (!n.LIZ(TabChangeManager.LJII.LIZ(this.LJIIIZ.getActivity()).LIZ(), this.LJIIIZ)) {
            3PM.LIZIZ("MultiAdapterWidget", "onResume but not in inbox tab");
        } else {
            InboxTopHorizontalListVM LJIIJ = LJIIJ();
            if (LJIIJ.LJ != null) {
                z = true;
            } else {
                z = false;
            }
            LJIIJ.LJ = null;
            3PM.LIZIZ("MultiAdapterWidget", "onResume hasNewNotice=" + this.LJIILIIL + ", backFromStoryPlayer=" + z + ", noticeDeleted=" + LIZ().LJJII);
            if (z && (context = this.LJIIIZ.getContext()) != null) {
                n.LIZIZ(context, "");
                ((IAppWidgetService) this.LJIILLIIL.getValue()).LIZIZ(context);
            }
            if (this.LJIILIIL) {
                this.LJIILIIL = false;
                C2708DuC.LIZJ.LIZ();
                LIZ().LIZ(false, z);
            } else if (LIZ().LJJII) {
                LIZ().LIZIZ(2);
            } else {
                long j = LIZ().LJJI;
                long currentTimeMillis = System.currentTimeMillis();
                if (currentTimeMillis - j < C2649DtF.LIZIZ.LIZJ()) {
                    z2 = false;
                }
                3PM.LIZIZ("InboxRefreshSettings", "expiredByTabChange " + currentTimeMillis + " - " + j + " >= " + C2649DtF.LIZIZ.LIZJ() + " = " + z2);
                if (z2) {
                    C2708DuC.LIZJ.LIZ();
                    if (z) {
                        LIZ().LIZIZ(34);
                    } else {
                        LIZ().LIZIZ(2);
                    }
                } else {
                    LIZ().LJFF();
                    LJIIJ().LIZIZ();
                }
            }
        }
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onFollowRequestFinished(E3G e3g) {
        M12.LIZ(e3g);
        LIZ().LJJIFFI++;
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onNoticeDeleted(C2648DtE dtE) {
        M12.LIZ(dtE);
        LIZ().LJJII = true;
    }

    public final int LIZ(int i) {
        List list = (List) LIZ().LIZIZ.getValue();
        if (list == null) {
            return -1;
        }
        n.LIZIZ(list, "");
        if (i < 0) {
            return -1;
        }
        int size = list.size();
        while (i < size) {
            if (((C2638Dt4) list.get(i)).isUnread()) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public final void LIZ(C2645DtB dtB) {
        LIZ().LJIJJLI = dtB;
        this.LIZIZ = dtB;
    }

    @ISm(LIZ = ThreadMode.MAIN, LIZIZ = true)
    public final void onNoticeCountChangedEvent(C3112E1s e1s) {
        M12.LIZ(e1s);
        if (e1s.LIZIZ == 2) {
            if (e1s.LIZJ == 301) {
                3PM.LIZIZ("MultiAdapterWidget", "refactor notice count init finish");
                LIZ().LJII();
            } else if (e1s.LIZJ == 201) {
                3PM.LIZIZ("MultiAdapterWidget", "onRedPointUpdate isResume=" + this.LJIILJJIL);
                if (!this.LJIILJJIL || (!n.LIZ(TabChangeManager.LJII.LIZ(this.LJIIIZ.getActivity()).LIZ(), this.LJIIIZ))) {
                    this.LJIILIIL = true;
                    return;
                }
                3PM.LIZIZ("MultiAdapterWidget", "onRedPointUpdate need refresh");
                this.LJIILIIL = false;
                LJIIIZ().post(new C2646DtC(this));
            }
        }
    }

    @ISm(LIZ = ThreadMode.MAIN, LIZIZ = true)
    public final void onRedPointUpdate(C4068Eb2 eb2) {
        M12.LIZ(eb2);
        if (!MHK.LIZ.LIZIZ()) {
            if (eb2.LIZ == -3 && eb2.LIZLLL == 2) {
                3PM.LIZIZ("MultiAdapterWidget", "notice count init finish");
                LIZ().LJII();
            } else if (eb2.LIZ == -3 && eb2.LIZLLL == 1) {
                3PM.LIZIZ("MultiAdapterWidget", "onRedPointUpdate isResume=" + this.LJIILJJIL);
                if (!this.LJIILJJIL || (!n.LIZ(TabChangeManager.LJII.LIZ(this.LJIIIZ.getActivity()).LIZ(), this.LJIIIZ))) {
                    this.LJIILIIL = true;
                    return;
                }
                3PM.LIZIZ("MultiAdapterWidget", "onRedPointUpdate need refresh");
                this.LJIILIIL = false;
                LJIIIZ().post(new C2647DtD(this));
            }
        }
    }

    public /* synthetic */ MultiAdapterWidget(Fragment fragment, LiveData liveData) {
        this(fragment, liveData, false);
    }

    public final void LIZ(int i, C1870Dgg dgg) {
        M12.LIZ(dgg);
        if (!this.LIZLLL) {
            C2576Ds4 LIZIZ2 = LIZIZ();
            M12.LIZ(dgg);
            LIZIZ2.LIZIZ.put(i, dgg);
        }
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public MultiAdapterWidget(Fragment fragment, LiveData<C1805Dfd> liveData, boolean z) {
        super(fragment, liveData);
        M12.LIZ(fragment, liveData);
        this.LIZLLL = z;
        this.LJ = 7he.LIZ(new C2595DsN(fragment));
        this.LJFF = 7he.LIZ(new C2596DsO(fragment));
        this.LJI = 7he.LIZ(C2600DsS.LIZ);
        this.LJIILL = 7he.LIZ(new C2605DsX(this));
        this.LJIILLIIL = 7he.LIZ(C2641Dt7.LIZ);
        this.LJIIZILJ = 7he.LIZ(C2598DsQ.LIZ);
    }
}
