package com.ss.android.ugc.aweme.search.theme.dark.tint;

import X.0CB;
import X.0CN;
import X.1hK;
import X.2fL;
import X.3Hc;
import X.7he;
import X.8ER;
import X.C3811SfH;
import X.C3815SfL;
import X.C3858Sg2;
import X.C3865Sg9;
import X.C3945ShR;
import X.C3994SiE;
import X.C4009SiT;
import X.C4017Sib;
import X.C4189SlN;
import X.C4418Sp4;
import X.C4421Sp7;
import X.Cb5;
import X.Cb6;
import X.Crj;
import X.EvA;
import X.M12;
import X.SXY;
import android.content.Context;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.search.theme.dark.ThemeViewModel;
import java.util.concurrent.ConcurrentHashMap;
import kotlin.h.b.n;

public final class TintThemeController implements View.OnAttachStateChangeListener, C4189SlN, C4421Sp7, 2fL {
    public static final C4418Sp4 LJ = new C4418Sp4((byte) 0);
    public Cb6 LIZ;
    public final 1hK LIZIZ;
    public final RecyclerView LIZJ;
    public final 8ER LIZLLL;
    public final Crj LJFF = 7he.LIZ(new C4017Sib(this));
    public final Crj LJI = 7he.LIZ(new C4009SiT(this));
    public final Crj LJII = 7he.LIZ(new C3858Sg2(this));
    public final Crj LJIIIIZZ = 7he.LIZ(new C3994SiE(this));
    public boolean LJIIIZ;
    public boolean LJIIJ;
    public Cb6 LJIIJJI;

    static {
        Covode.recordClassIndex(104694);
    }

    private final Cb5 LJII() {
        return (Cb5) this.LJIIIIZZ.getValue();
    }

    public final void LIZ(float f) {
    }

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

    public final C3811SfH LIZJ() {
        return (C3811SfH) this.LJI.getValue();
    }

    public final ThemeViewModel LIZLLL() {
        return (ThemeViewModel) this.LJII.getValue();
    }

    public final void onViewAttachedToWindow(View view) {
    }

    @0CN(LIZ = 0CB.ON_CREATE)
    public final void onCreate() {
        EvA.onCreate(this);
    }

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

    @0CN(LIZ = 0CB.ON_RESUME)
    public final void onResume() {
        EvA.onResume(this);
    }

    @0CN(LIZ = 0CB.ON_START)
    public final void onStart() {
        EvA.onStart(this);
    }

    @0CN(LIZ = 0CB.ON_STOP)
    public final void onStop() {
        EvA.onStop(this);
    }

    public final void LIZ() {
        LIZLLL().LIZ(SXY.LIZIZ(this.LIZIZ));
    }

    public final void LJFF() {
        LJII().LIZ(this.LJIIJJI);
    }

    public final void LJI() {
        Cb6 cb6 = this.LIZ;
        if (cb6 != null) {
            LJII().LIZ(cb6);
        }
    }

    private void LJIIIIZZ() {
        this.LIZJ.removeOnAttachStateChangeListener(this);
        LIZIZ().LJ();
        LIZJ().LIZIZ();
    }

    private final Cb6 LJIIIZ() {
        if (n.LIZ(LIZLLL().LJFF(), "dark")) {
            return SXY.LIZJ(this.LIZIZ);
        }
        return SXY.LIZLLL(this.LIZIZ);
    }

    public final void LJ() {
        this.LIZ = null;
        LJIIIIZZ();
        this.LJIIIZ = false;
        LIZLLL().LIZ(this.LJIIJJI);
        LIZLLL().LIZLLL().setValue(this.LJIIJJI);
    }

    public final void onDestroy() {
        Integer num;
        EvA.onDestroy(this);
        C3865Sg9 sg9 = C3865Sg9.LIZ;
        Fragment LJII2 = this.LIZLLL.LJII();
        if (LJII2 != null) {
            num = Integer.valueOf(LJII2.hashCode());
        } else {
            num = null;
        }
        ConcurrentHashMap concurrentHashMap = sg9.LIZ().get(num);
        if (concurrentHashMap != null) {
            concurrentHashMap.clear();
        }
    }

    public final void onViewDetachedFromWindow(View view) {
        LJIIIIZZ();
    }

    public final void LIZ(boolean z) {
        if (z) {
            LIZIZ(true);
        } else {
            LIZJ(true);
        }
    }

    public final void LIZLLL(boolean z) {
        this.LJIIJ = z;
        if (z && this.LJIIIZ) {
            this.LJIIIZ = false;
            Cb6 cb6 = this.LIZ;
            if (cb6 != null) {
                LIZLLL().LIZ(cb6);
            }
        }
    }

    public final void LIZ(Cb6 cb6) {
        M12.LIZ(cb6);
        this.LIZ = cb6;
        if (this.LJIIJ) {
            LIZLLL().LIZ(cb6);
        } else {
            this.LJIIIZ = true;
        }
        LIZLLL().LIZIZ().observe(this.LIZIZ, new C3815SfL(this));
    }

    public final void LIZIZ(boolean z) {
        Cb6 cb6;
        LIZJ().LIZ();
        if (this.LIZ == null) {
            this.LIZ = LJIIIZ();
        }
        if (LIZJ().LIZ()) {
            cb6 = this.LIZ;
            if (cb6 == null) {
                n.LIZIZ();
            }
        } else {
            cb6 = this.LJIIJJI;
        }
        if (z) {
            LJII().LIZ(cb6);
        } else {
            LIZLLL().LIZ(cb6);
        }
    }

    public final void LIZJ(boolean z) {
        LIZJ().LIZ();
        if (z) {
            LJII().LIZ(LJIIIZ());
        } else {
            LIZLLL().LIZ(LJIIIZ());
        }
    }

    public final void LJ(boolean z) {
        Cb6 LIZIZ2;
        if (z) {
            LIZIZ2 = SXY.LIZ((Context) this.LIZIZ);
        } else {
            LIZIZ2 = SXY.LIZIZ(this.LIZIZ);
        }
        this.LJIIJJI = LIZIZ2;
    }

    public TintThemeController(1hK r2, RecyclerView recyclerView, 8ER r4, Cb6 cb6) {
        M12.LIZ(r2, recyclerView, r4, cb6);
        this.LIZIZ = r2;
        this.LIZJ = recyclerView;
        this.LIZLLL = r4;
        this.LJIIJJI = cb6;
        3Hc.LIZ(r2, this);
    }
}
