package com.ss.android.ugc.aweme.following.ui.controller;

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0CB;
import X.0CD;
import X.0CH;
import X.1Bj;
import X.1hK;
import X.2GD;
import X.2Pr;
import X.C1445DZp;
import X.C1620Dce;
import X.C1990Dic;
import X.C2043DjT;
import X.C2132Dku;
import X.Ls2;
import X.M12;
import X.OQg;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.following.ui.viewmodel.TopRecommendVM;
import kotlin.h.b.n;

public final class RecommendController implements ViewTreeObserver.OnGlobalLayoutListener, 1Bj, 0CH {
    public static final C2043DjT LJIIJJI = new C2043DjT((byte) 0);
    public boolean LIZ;
    public boolean LIZIZ;
    public C1620Dce LIZJ;
    public LinearLayout LIZLLL;
    public C1445DZp LJ;
    public C1990Dic LJFF;
    public View LJI;
    public Ls2<2Pr> LJII;
    public OQg LJIIIIZZ;
    public boolean LJIIIZ;
    public final Fragment LJIIJ;

    static {
        Covode.recordClassIndex(80929);
    }

    public final void LIZIZ() {
        View view = this.LJI;
        if (view != null) {
            view.setVisibility(8);
        }
        this.LIZIZ = true;
    }

    public final 0CD getLifecycle() {
        0CD lifecycle = this.LJIIJ.getLifecycle();
        n.LIZIZ(lifecycle, "");
        return lifecycle;
    }

    public final TopRecommendVM LIZJ() {
        if (LIZ(this.LJIIJ)) {
            return LIZ(this.LJIIJ.requireActivity()).LIZ(TopRecommendVM.class);
        }
        return null;
    }

    public final void LIZ() {
        this.LIZ = true;
        TopRecommendVM LIZJ2 = LIZJ();
        if (LIZJ2 != null) {
            LIZJ2.LIZ = true;
        }
    }

    public final void onGlobalLayout() {
        LinearLayout linearLayout = this.LIZLLL;
        if (linearLayout == null) {
            n.LIZ("");
        }
        if (linearLayout.getGlobalVisibleRect(new Rect())) {
            C2132Dku dku = C2132Dku.LIZJ;
            Integer num = C2132Dku.LIZ.LIZIZ;
            if (num != null) {
                int intValue = num.intValue();
                int i = dku.LIZ().getInt("following_exp_ff_c", 0) + 1;
                if (i >= intValue) {
                    dku.LIZ().storeLong("following_h_ff_t", System.currentTimeMillis());
                } else {
                    dku.LIZ().storeInt("following_exp_ff_c", i);
                }
            }
            LinearLayout linearLayout2 = this.LIZLLL;
            if (linearLayout2 == null) {
                n.LIZ("");
            }
            linearLayout2.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    }

    public RecommendController(Fragment fragment) {
        M12.LIZ(fragment);
        this.LJIIJ = fragment;
    }

    public static 0Bx LIZ(1hK r2) {
        0Bx LIZ2 = 0By.LIZ(r2, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ2, r2);
        }
        return LIZ2;
    }

    private final boolean LIZ(Fragment fragment) {
        if (fragment.getActivity() == null || fragment.isDetached() || !fragment.isAdded()) {
            return false;
        }
        return true;
    }

    public final void onStateChanged(0CH r3, 0CB r4) {
        M12.LIZ(r3, r4);
        if (r4 == 0CB.ON_DESTROY) {
            r3.getLifecycle().LIZIZ(this);
        }
    }
}
