package com.bytedance.ies.powerlist.page;

import X.0CB;
import X.0CH;
import X.1Bj;
import X.2Pr;
import X.2cN;
import X.4r1;
import X.7AW;
import X.7he;
import X.8dV;
import X.A4l;
import X.A4m;
import X.A4o;
import X.A4p;
import X.AbV;
import X.C0295Crj;
import X.C0436Cwu;
import X.C0746D8s;
import X.C0782DAc;
import X.C0791DAl;
import X.C1481DaP;
import X.C1488DaW;
import X.C1491DaZ;
import X.C1631Dcp;
import X.C1644Dd2;
import X.C1645Dd3;
import X.C1646Dd4;
import X.C1647Dd5;
import X.C1648Dd6;
import X.C1652DdA;
import X.C1654DdC;
import X.C1663DdL;
import X.C1664DdM;
import X.C1669DdR;
import X.C1673DdV;
import X.C1676DdY;
import X.C1679Ddb;
import X.Cv9;
import X.DAU;
import X.DBT;
import X.DCZ;
import X.Lel;
import X.LsC;
import X.M12;
import X.PgU;
import android.os.Handler;
import com.bytedance.covode.number.Covode;
import java.util.List;
import kotlin.h.b.n;

public final class PowerPageLoader<T> implements 1Bj, C1679Ddb<T>, Cv9 {
    public AbV LIZ;
    public C0436Cwu<? extends T, ? extends T> LIZIZ;
    public DCZ<? super A4l<T>> LIZJ;
    public DCZ<? super A4l<T>> LIZLLL;
    public final C1647Dd5<T> LJ;
    public final C1676DdY<C1481DaP> LJFF;
    public final LsC<C1631Dcp, 2Pr> LJI;
    public final DBT LJII = C0791DAl.LIZ((DBT) null);
    public 2cN LJIIIIZZ;
    public final C0295Crj LJIIIZ;
    public final C0295Crj LJIIJ;
    public final 0CH LJIIJJI;

    static {
        Covode.recordClassIndex(30264);
    }

    public final Handler LIZ() {
        return (Handler) this.LJIIIZ.getValue();
    }

    public final C1652DdA LIZIZ() {
        return (C1652DdA) this.LJIIJ.getValue();
    }

    public final void LIZLLL() {
        LJFF();
    }

    public final C0746D8s getCoroutineContext() {
        return 8dV.LIZ.plus(this.LJII);
    }

    public final void LIZJ() {
        AbV abV = this.LIZ;
        if (abV == null) {
            n.LIZ("");
        }
        if (abV.LIZIZ) {
            LJFF();
        }
    }

    public final void LJ() {
        this.LJII.LJIIJ();
        this.LJIIIIZZ.dispose();
        this.LJIIJJI.getLifecycle().LIZIZ(this);
    }

    private final void LJFF() {
        DCZ<? super A4l<T>> dcz = this.LIZJ;
        if (dcz != null) {
            boolean unused = dcz.LIZIZ((Throwable) null);
        }
        DCZ<? super A4l<T>> dcz2 = this.LIZLLL;
        if (dcz2 != null) {
            boolean unused2 = dcz2.LIZIZ((Throwable) null);
        }
        C1663DdL ddL = C1663DdL.Refresh;
        LIZIZ().LIZ(C1669DdR.Loading, ddL, (Object) null);
        DBT unused3 = C0782DAc.LIZ(this, (C0746D8s) null, (DAU) null, new C1644Dd2(this, ddL, (4r1) null), 3);
    }

    public final void LIZ(T t) {
        LIZJ(t);
    }

    public final void LIZIZ(T t) {
        LIZLLL(t);
    }

    public static final /* synthetic */ AbV LIZ(PowerPageLoader powerPageLoader) {
        AbV abV = powerPageLoader.LIZ;
        if (abV == null) {
            n.LIZ("");
        }
        return abV;
    }

    public final void LIZLLL(T t) {
        DCZ<? super A4l<T>> dcz = this.LIZLLL;
        if (dcz != null) {
            boolean unused = dcz.LIZIZ((Throwable) null);
        }
        C1663DdL ddL = C1663DdL.Next;
        LIZIZ().LIZ(C1669DdR.Loading, ddL, (Object) null);
        DBT unused2 = C0782DAc.LIZ(this, (C0746D8s) null, (DAU) null, new C1645Dd3(this, t, ddL, (4r1) null), 3);
    }

    public final void LIZ(C1663DdL ddL) {
        M12.LIZ(ddL);
        int i = C1664DdM.LIZJ[ddL.ordinal()];
        if (i == 1) {
            LIZLLL((Object) null);
        } else if (i == 2) {
            LIZJ((Object) null);
        } else if (i == 3) {
            LJFF();
        }
    }

    public final void LIZJ(T t) {
        DCZ<? super A4l<T>> dcz = this.LIZJ;
        if (dcz != null) {
            boolean unused = dcz.LIZIZ((Throwable) null);
        }
        C1663DdL ddL = C1663DdL.Prev;
        LIZIZ().LIZ(C1669DdR.Loading, ddL, (Object) null);
        DBT unused2 = C0782DAc.LIZ(this, (C0746D8s) null, (DAU) null, new C1646Dd4(this, t, ddL, (4r1) null), 3);
    }

    public final boolean LIZ(DCZ<?> dcz) {
        if (dcz == null || dcz.LIZJ() || dcz.LIZIZ()) {
            return true;
        }
        return false;
    }

    public final void onStateChanged(0CH r2, 0CB r3) {
        M12.LIZ(r2, r3);
        if (r3 == 0CB.ON_DESTROY) {
            LJ();
        }
    }

    public final void LIZ(C1663DdL ddL, A4l<T> a4l, boolean z) {
        C0436Cwu<? extends T, ? extends T> cwu;
        List list;
        M12.LIZ(ddL, a4l);
        if (z) {
            if (a4l instanceof A4p) {
                list = ((A4p) a4l).LIZLLL;
            } else if (a4l instanceof A4o) {
                list = ((A4o) a4l).LIZIZ;
            } else {
                list = Lel.INSTANCE;
            }
            int i = C1664DdM.LIZ[ddL.ordinal()];
            if (i == 1) {
                this.LJFF.LIZ(list);
            } else if (i == 2) {
                this.LJFF.LIZ(0, list);
            } else if (i == 3) {
                this.LJFF.LIZIZ(list);
            }
        }
        if (a4l instanceof A4p) {
            int i2 = C1664DdM.LIZIZ[ddL.ordinal()];
            if (i2 == 1) {
                A4p a4p = (A4p) a4l;
                cwu = new C0436Cwu<>(a4p.LIZIZ, a4p.LIZJ);
            } else if (i2 == 2) {
                cwu = C0436Cwu.copy$default(this.LIZIZ, ((A4p) a4l).LIZIZ, (Object) null, 2, (Object) null);
            } else if (i2 == 3) {
                cwu = C0436Cwu.copy$default(this.LIZIZ, (Object) null, ((A4p) a4l).LIZJ, 1, (Object) null);
            } else {
                throw new 7AW();
            }
            this.LIZIZ = cwu;
            A4p a4p2 = (A4p) a4l;
            LIZIZ().LIZ(C1669DdR.Loaded, ddL, new C1673DdV(a4p2.LIZIZ, a4p2.LIZJ));
        } else if (a4l instanceof A4m) {
            LIZIZ().LIZ(C1669DdR.Error, ddL, ((A4m) a4l).LIZIZ);
        } else if (a4l instanceof A4o) {
            LIZIZ().LIZ(C1669DdR.End, ddL, (Object) null);
        }
    }

    public PowerPageLoader(C1647Dd5<T> dd5, PgU<AbV> pgU, 0CH r7, C1676DdY<C1481DaP> ddY, LsC<? super C1631Dcp, 2Pr> lsC) {
        C1648Dd6<T> dd6;
        M12.LIZ(dd5, pgU, r7, ddY, lsC);
        this.LJ = dd5;
        this.LJIIJJI = r7;
        this.LJFF = ddY;
        this.LJI = lsC;
        2cN LIZLLL2 = pgU.LIZLLL(new C1491DaZ(this));
        n.LIZ(LIZLLL2, "");
        this.LJIIIIZZ = LIZLLL2;
        this.LIZIZ = new C0436Cwu<>(null, null);
        this.LJIIIZ = 7he.LIZ(C1488DaW.LIZ);
        this.LJIIJ = 7he.LIZ(new C1654DdC(this));
        M12.LIZ(this);
        C1679Ddb<T> ddb = dd5.LIZLLL;
        dd5.LIZLLL = this;
        if (n.LIZ(ddb, dd5.LIZ()) && (dd6 = dd5.LIZJ) != null) {
            dd5.LIZLLL.LIZ(dd6.LIZ, dd6.LIZIZ, dd6.LIZJ);
        }
        r7.getLifecycle().LIZ(this);
    }
}
