package com.bytedance.android.livesdk.feed.repository;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0aJ;
import X.0b0;
import X.2K7;
import X.2cN;
import X.6Is;
import X.C3497GtG;
import X.C3572GuT;
import X.C3610Gv5;
import X.C3725Gww;
import X.C3747GxI;
import X.C3748GxJ;
import X.C3839Gym;
import X.Mjy;
import X.OJw;
import android.os.SystemClock;
import android.text.TextUtils;
import com.bytedance.android.livesdk.feed.feed.FeedDataKey;
import com.bytedance.android.livesdk.model.FeedItem;
import com.bytedance.covode.number.Covode;

public abstract class BaseFeedRepository implements C3610Gv5, C3747GxI<FeedItem>, 6Is {
    public C3839Gym LIZ;
    public final 0aJ<FeedDataKey, FeedItem> LIZIZ;
    public OJw<C3748GxJ> LIZJ = new OJw<>();
    public OJw<C3748GxJ> LIZLLL = new OJw<>();
    public C3725Gww LJ;
    public final Mjy LJFF = new Mjy();
    public C3497GtG LJI;

    static {
        Covode.recordClassIndex(16158);
    }

    public abstract FeedDataKey LJII();

    public void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_CREATE) {
            registerFeedRepository();
        } else if (r3 == 0CB.ON_DESTROY) {
            unRegisterFeedRepository();
        }
    }

    public static boolean LIZ() {
        try {
            return 2K7.LIZ.LIZJ();
        } catch (Exception unused) {
            return false;
        }
    }

    @0CN(LIZ = 0CB.ON_CREATE)
    public void registerFeedRepository() {
        if (LJII() != null) {
            this.LJ.LIZ(LJII(), (C3747GxI) this);
        }
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void unRegisterFeedRepository() {
        if (this.LJ.LIZ(LJII())) {
            LJFF();
            this.LJFF.LIZ();
        }
    }

    public final void LIZ(2cN r2) {
        this.LJFF.LIZ(r2);
    }

    public final void LIZ(0CH r2) {
        if (r2 != null) {
            r2.getLifecycle().LIZ(this);
        }
    }

    public BaseFeedRepository(C3725Gww gww, 0aJ<FeedDataKey, FeedItem> r3) {
        this.LJ = gww;
        this.LIZ = null;
        this.LIZIZ = r3;
    }

    public final void LIZIZ(C3572GuT guT, String str) {
        if (guT == C3572GuT.REFRESH) {
            this.LIZJ.onNext(C3748GxJ.SUCCESS);
            if (this.LIZ != null) {
                LJII();
                TextUtils.equals(str, "enter_auto");
            }
            C3497GtG gtG = this.LJI;
            if (gtG != null) {
                gtG.LIZ("refresh");
            }
        } else if (guT == C3572GuT.LOAD_MORE) {
            this.LIZLLL.onNext(C3748GxJ.SUCCESS);
            if (this.LIZ != null) {
                LJII();
            }
            C3497GtG gtG2 = this.LJI;
            if (gtG2 != null) {
                gtG2.LIZ("load_more");
            }
        }
    }

    public final void LIZ(C3572GuT guT, String str) {
        C3497GtG gtG = new C3497GtG();
        this.LJI = gtG;
        gtG.LIZ = SystemClock.uptimeMillis();
        if (guT == C3572GuT.REFRESH) {
            this.LIZJ.onNext(C3748GxJ.START);
            if (this.LIZ != null) {
                LJII();
                TextUtils.equals(str, "enter_auto");
            }
        } else if (guT == C3572GuT.LOAD_MORE) {
            this.LIZLLL.onNext(C3748GxJ.START);
            C3497GtG gtG2 = this.LJI;
            if (gtG2 != null) {
                gtG2.LIZ = SystemClock.uptimeMillis();
            }
            if (this.LIZ != null) {
                LJII();
            }
        }
    }

    public final void LIZ(C3572GuT guT, String str, Throwable th) {
        if (guT == C3572GuT.REFRESH) {
            this.LIZJ.onNext(C3748GxJ.FAIL);
            if (this.LIZ != null) {
                LJII();
                TextUtils.equals(str, "enter_auto");
            }
            if (this.LJI != null) {
                0b0.LJ();
                if (LIZ()) {
                    this.LJI.LIZ("refresh", th);
                }
            }
        } else if (guT == C3572GuT.LOAD_MORE) {
            this.LIZLLL.onNext(C3748GxJ.FAIL);
            if (this.LIZ != null) {
                LJII();
            }
            if (this.LJI != null) {
                0b0.LJ();
                if (LIZ()) {
                    this.LJI.LIZ("load_more", th);
                }
            }
        }
    }
}
