package androidx.leanback.app;

import D1.RunnableC0077b;
import N1.C0220v;
import O1.C0225a;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.transition.Scene;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.transition.TransitionManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.leanback.widget.AbstractC0458c0;
import androidx.leanback.widget.AbstractC0470i0;
import androidx.leanback.widget.BrowseFrameLayout;
import androidx.leanback.widget.C0468h0;
import androidx.leanback.widget.F;
import androidx.leanback.widget.L0;
import androidx.leanback.widget.N;
import androidx.leanback.widget.N0;
import androidx.leanback.widget.ScaleFrameLayout;
import androidx.leanback.widget.VerticalGridView;
import androidx.leanback.widget.Z;
import com.google.android.gms.internal.measurement.B1;
import com.martsnew.tv.R;
import d5.AbstractC0844a;
import h0.C1001a;
import h0.ComponentCallbacksC1023x;
import h0.P;
import y5.AbstractC1757b;

/* JADX INFO: loaded from: classes.dex */
public class r extends g {

    /* JADX INFO: renamed from: w1, reason: collision with root package name */
    public static final String f8245w1 = r.class.getCanonicalName() + ".title";

    /* JADX INFO: renamed from: x1, reason: collision with root package name */
    public static final String f8246x1 = r.class.getCanonicalName() + ".headersState";

    /* JADX INFO: renamed from: O0, reason: collision with root package name */
    public B1 f8251O0;

    /* JADX INFO: renamed from: P0, reason: collision with root package name */
    public ComponentCallbacksC1023x f8252P0;

    /* JADX INFO: renamed from: Q0, reason: collision with root package name */
    public w f8253Q0;

    /* JADX INFO: renamed from: R0, reason: collision with root package name */
    public p f8254R0;

    /* JADX INFO: renamed from: S0, reason: collision with root package name */
    public y f8255S0;

    /* JADX INFO: renamed from: T0, reason: collision with root package name */
    public N f8256T0;

    /* JADX INFO: renamed from: U0, reason: collision with root package name */
    public Z f8257U0;
    public BrowseFrameLayout W0;

    /* JADX INFO: renamed from: X0, reason: collision with root package name */
    public ScaleFrameLayout f8259X0;

    /* JADX INFO: renamed from: Z0, reason: collision with root package name */
    public String f8261Z0;

    /* JADX INFO: renamed from: c1, reason: collision with root package name */
    public int f8263c1;

    /* JADX INFO: renamed from: d1, reason: collision with root package name */
    public int f8264d1;

    /* JADX INFO: renamed from: f1, reason: collision with root package name */
    public AbstractC1757b f8266f1;

    /* JADX INFO: renamed from: g1, reason: collision with root package name */
    public AbstractC1757b f8267g1;

    /* JADX INFO: renamed from: i1, reason: collision with root package name */
    public float f8269i1;

    /* JADX INFO: renamed from: j1, reason: collision with root package name */
    public boolean f8270j1;

    /* JADX INFO: renamed from: m1, reason: collision with root package name */
    public Scene f8273m1;

    /* JADX INFO: renamed from: n1, reason: collision with root package name */
    public Scene f8274n1;

    /* JADX INFO: renamed from: o1, reason: collision with root package name */
    public Scene f8275o1;
    public Transition p1;

    /* JADX INFO: renamed from: q1, reason: collision with root package name */
    public m f8276q1;

    /* JADX INFO: renamed from: J0, reason: collision with root package name */
    public final j f8247J0 = new j(this, 0);
    public final B3.f K0 = new B3.f(7, "headerFragmentViewCreated");

    /* JADX INFO: renamed from: L0, reason: collision with root package name */
    public final B3.f f8248L0 = new B3.f(7, "mainFragmentViewCreated");

    /* JADX INFO: renamed from: M0, reason: collision with root package name */
    public final B3.f f8249M0 = new B3.f(7, "screenDataReady");

    /* JADX INFO: renamed from: N0, reason: collision with root package name */
    public final p f8250N0 = new p();

    /* JADX INFO: renamed from: V0, reason: collision with root package name */
    public int f8258V0 = 1;

    /* JADX INFO: renamed from: Y0, reason: collision with root package name */
    public final boolean f8260Y0 = true;
    public boolean a1 = true;

    /* JADX INFO: renamed from: b1, reason: collision with root package name */
    public boolean f8262b1 = true;

    /* JADX INFO: renamed from: e1, reason: collision with root package name */
    public final boolean f8265e1 = true;

    /* JADX INFO: renamed from: h1, reason: collision with root package name */
    public int f8268h1 = -1;

    /* JADX INFO: renamed from: k1, reason: collision with root package name */
    public boolean f8271k1 = true;

    /* JADX INFO: renamed from: l1, reason: collision with root package name */
    public final q f8272l1 = new q(this);

    /* JADX INFO: renamed from: r1, reason: collision with root package name */
    public final i f8277r1 = new i(this);

    /* JADX INFO: renamed from: s1, reason: collision with root package name */
    public final i f8278s1 = new i(this);

    /* JADX INFO: renamed from: t1, reason: collision with root package name */
    public final i f8279t1 = new i(this);

    /* JADX INFO: renamed from: u1, reason: collision with root package name */
    public final i f8280u1 = new i(this);

    /* JADX INFO: renamed from: v1, reason: collision with root package name */
    public final C0220v f8281v1 = new C0220v(1, this);

    public final void A0() {
        int i = this.f8264d1;
        if (this.f8265e1 && this.f8251O0.f9558a && this.a1) {
            i = (int) ((i / this.f8269i1) + 0.5f);
        }
        this.f8251O0.f(i);
    }

    public final void B0(p pVar) {
        C0468h0 c0468h0K;
        p pVar2 = this.f8254R0;
        if (pVar == pVar2) {
            return;
        }
        if (pVar2 != null) {
            C c3 = (C) pVar2.f8240a;
            if (c3.f8193o0 != null) {
                c3.f8193o0 = null;
                c3.p0();
            }
        }
        this.f8254R0 = pVar;
        if (pVar != null) {
            C0225a c0225a = new C0225a(this, 17, pVar);
            C c8 = (C) pVar.f8240a;
            c8.f8170E0 = c0225a;
            VerticalGridView verticalGridView = c8.f8194p0;
            if (verticalGridView != null) {
                int childCount = verticalGridView.getChildCount();
                for (int i = 0; i < childCount; i++) {
                    F f3 = (F) verticalGridView.M(verticalGridView.getChildAt(i));
                    if (f3 == null) {
                        c0468h0K = null;
                    } else {
                        ((AbstractC0470i0) f3.f8367u).getClass();
                        c0468h0K = AbstractC0470i0.k(f3.f8368v);
                    }
                    c0468h0K.f8654l = c8.f8170E0;
                }
            }
            p pVar3 = this.f8254R0;
            AbstractC1757b abstractC1757b = this.f8267g1;
            C c9 = (C) pVar3.f8240a;
            c9.f8171F0 = abstractC1757b;
            if (c9.f8166A0) {
                throw new IllegalStateException("Item clicked listener must be set before views are created");
            }
        }
        F0();
    }

    public final void C0(boolean z8) {
        View searchAffordanceView = ((L0) this.f8222r0).f8469a.getSearchAffordanceView();
        if (searchAffordanceView != null) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) searchAffordanceView.getLayoutParams();
            marginLayoutParams.setMarginStart(z8 ? 0 : -this.f8263c1);
            searchAffordanceView.setLayoutParams(marginLayoutParams);
        }
    }

    public final void D0(boolean z8) {
        w wVar = this.f8253Q0;
        wVar.f8293y0 = z8;
        wVar.n0();
        x0(z8);
        s0(!z8);
    }

    public final void E0(boolean z8) {
        N n8;
        if (this.f13265K.f13060J || (n8 = this.f8256T0) == null || n8.d() == 0) {
            return;
        }
        this.a1 = z8;
        this.f8251O0.d();
        this.f8251O0.e();
        RunnableC0077b runnableC0077b = new RunnableC0077b(this, z8, 1);
        if (!z8) {
            runnableC0077b.run();
            return;
        }
        B1 b12 = this.f8251O0;
        View view = this.X;
        n nVar = new n(this, runnableC0077b, b12, view);
        view.getViewTreeObserver().addOnPreDrawListener(nVar);
        b12.h(false);
        view.invalidate();
        nVar.f8236s = 0;
    }

    @Override // androidx.leanback.app.g, h0.ComponentCallbacksC1023x
    public void F(Bundle bundle) {
        super.F(bundle);
        TypedArray typedArrayObtainStyledAttributes = o().obtainStyledAttributes(k0.a.f13741b);
        this.f8263c1 = (int) typedArrayObtainStyledAttributes.getDimension(6, r0.getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_start));
        this.f8264d1 = (int) typedArrayObtainStyledAttributes.getDimension(7, r0.getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_top));
        typedArrayObtainStyledAttributes.recycle();
        Bundle bundle2 = this.f13298v;
        if (bundle2 != null) {
            String str = f8245w1;
            if (bundle2.containsKey(str)) {
                String string = bundle2.getString(str);
                this.f8221p0 = string;
                N0 n02 = this.f8222r0;
                if (n02 != null) {
                    ((L0) n02).f8469a.setTitle(string);
                }
            }
            String str2 = f8246x1;
            if (bundle2.containsKey(str2)) {
                y0(bundle2.getInt(str2));
            }
        }
        if (this.f8262b1) {
            if (this.f8260Y0) {
                this.f8261Z0 = "lbHeadersBackStack_" + this;
                m mVar = new m(this);
                this.f8276q1 = mVar;
                this.f13265K.f13079n.add(mVar);
                m mVar2 = this.f8276q1;
                r rVar = mVar2.f8233c;
                if (bundle != null) {
                    int i = bundle.getInt("headerStackIndex", -1);
                    mVar2.f8232b = i;
                    rVar.a1 = i == -1;
                } else if (!rVar.a1) {
                    P p3 = rVar.f13265K;
                    p3.getClass();
                    C1001a c1001a = new C1001a(p3);
                    c1001a.c(rVar.f8261Z0);
                    c1001a.f();
                }
            } else if (bundle != null) {
                this.a1 = bundle.getBoolean("headerShow");
            }
        }
        this.f8269i1 = s().getFraction(R.fraction.lb_browse_rows_scale, 1, 1);
    }

    public final void F0() {
        y yVar = this.f8255S0;
        if (yVar != null) {
            yVar.f8297c.f8479a.unregisterObserver(yVar.f8299e);
            this.f8255S0 = null;
        }
        if (this.f8254R0 != null) {
            N n8 = this.f8256T0;
            y yVar2 = n8 != null ? new y(n8) : null;
            this.f8255S0 = yVar2;
            C c3 = (C) this.f8254R0.f8240a;
            if (c3.f8193o0 != yVar2) {
                c3.f8193o0 = yVar2;
                c3.p0();
            }
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        if (n().C(R.id.scale_frame) == null) {
            this.f8253Q0 = new w();
            r0(this.f8256T0, this.f8268h1);
            P pN = n();
            pN.getClass();
            C1001a c1001a = new C1001a(pN);
            c1001a.j(R.id.browse_headers_dock, this.f8253Q0);
            ComponentCallbacksC1023x componentCallbacksC1023x = this.f8252P0;
            if (componentCallbacksC1023x != null) {
                c1001a.j(R.id.scale_frame, componentCallbacksC1023x);
            } else {
                B1 b12 = new B1((ComponentCallbacksC1023x) null);
                this.f8251O0 = b12;
                b12.f9560c = new K.g(this);
            }
            c1001a.f();
        } else {
            this.f8253Q0 = (w) n().C(R.id.browse_headers_dock);
            this.f8252P0 = n().C(R.id.scale_frame);
            this.f8270j1 = bundle != null && bundle.getBoolean("isPageRow", false);
            this.f8268h1 = bundle != null ? bundle.getInt("currentSelectedPosition", 0) : 0;
            z0();
        }
        w wVar = this.f8253Q0;
        wVar.f8294z0 = !this.f8262b1;
        wVar.n0();
        w wVar2 = this.f8253Q0;
        N n8 = this.f8256T0;
        if (wVar2.f8193o0 != n8) {
            wVar2.f8193o0 = n8;
            wVar2.m0();
        }
        w wVar3 = this.f8253Q0;
        wVar3.f8291w0 = this.f8280u1;
        wVar3.f8292x0 = this.f8279t1;
        View viewInflate = layoutInflater.inflate(R.layout.lb_browse_fragment, viewGroup, false);
        this.f8212I0.f846s = (ViewGroup) viewInflate;
        BrowseFrameLayout browseFrameLayout = (BrowseFrameLayout) viewInflate.findViewById(R.id.browse_frame);
        this.W0 = browseFrameLayout;
        browseFrameLayout.setOnChildFocusListener(this.f8278s1);
        this.W0.setOnFocusSearchListener(this.f8277r1);
        f0(layoutInflater, this.W0);
        ScaleFrameLayout scaleFrameLayout = (ScaleFrameLayout) viewInflate.findViewById(R.id.scale_frame);
        this.f8259X0 = scaleFrameLayout;
        scaleFrameLayout.setPivotX(0.0f);
        this.f8259X0.setPivotY(this.f8264d1);
        this.f8273m1 = android.support.v4.media.session.a.d(this.W0, new l(this, 0));
        this.f8274n1 = android.support.v4.media.session.a.d(this.W0, new l(this, 1));
        this.f8275o1 = android.support.v4.media.session.a.d(this.W0, new l(this, 2));
        return viewInflate;
    }

    public final void G0() {
        B1 b12;
        B1 b13;
        if (!this.a1) {
            if ((!this.f8270j1 || (b13 = this.f8251O0) == null) ? v0(this.f8268h1) : ((K.g) b13.f9560c).f3523a) {
                h0(6);
                return;
            } else {
                i0(false);
                return;
            }
        }
        boolean zV0 = (!this.f8270j1 || (b12 = this.f8251O0) == null) ? v0(this.f8268h1) : ((K.g) b12.f9560c).f3523a;
        int i = this.f8268h1;
        N n8 = this.f8256T0;
        boolean z8 = true;
        if (n8 != null && n8.d() != 0 && this.f8256T0.d() > 0) {
            ((AbstractC0458c0) this.f8256T0.a(0)).getClass();
            if (i != 0) {
                z8 = false;
            }
        }
        int i5 = zV0 ? 2 : 0;
        if (z8) {
            i5 |= 4;
        }
        if (i5 != 0) {
            h0(i5);
        } else {
            i0(false);
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void I() {
        m mVar = this.f8276q1;
        if (mVar != null) {
            this.f13265K.f13079n.remove(mVar);
        }
        this.f13276V = true;
    }

    @Override // androidx.leanback.app.g, androidx.leanback.app.h, h0.ComponentCallbacksC1023x
    public final void J() {
        B0(null);
        this.f8251O0 = null;
        this.f8252P0 = null;
        this.f8253Q0 = null;
        this.W0 = null;
        this.f8259X0 = null;
        this.f8275o1 = null;
        this.f8273m1 = null;
        this.f8274n1 = null;
        super.J();
    }

    @Override // androidx.leanback.app.h, h0.ComponentCallbacksC1023x
    public final void R(Bundle bundle) {
        bundle.putBoolean("titleShow", this.f8220o0);
        bundle.putInt("currentSelectedPosition", this.f8268h1);
        bundle.putBoolean("isPageRow", this.f8270j1);
        m mVar = this.f8276q1;
        if (mVar != null) {
            bundle.putInt("headerStackIndex", mVar.f8232b);
        } else {
            bundle.putBoolean("headerShow", this.a1);
        }
    }

    @Override // androidx.leanback.app.h, h0.ComponentCallbacksC1023x
    public final void S() {
        ComponentCallbacksC1023x componentCallbacksC1023x;
        View view;
        w wVar;
        View view2;
        super.S();
        w wVar2 = this.f8253Q0;
        int i = this.f8264d1;
        VerticalGridView verticalGridView = wVar2.f8194p0;
        if (verticalGridView != null) {
            verticalGridView.setItemAlignmentOffset(0);
            wVar2.f8194p0.setItemAlignmentOffsetPercent(-1.0f);
            wVar2.f8194p0.setWindowAlignmentOffset(i);
            wVar2.f8194p0.setWindowAlignmentOffsetPercent(-1.0f);
            wVar2.f8194p0.setWindowAlignment(0);
        }
        A0();
        boolean z8 = this.f8262b1;
        if (z8 && this.a1 && (wVar = this.f8253Q0) != null && (view2 = wVar.X) != null) {
            view2.requestFocus();
        } else if ((!z8 || !this.a1) && (componentCallbacksC1023x = this.f8252P0) != null && (view = componentCallbacksC1023x.X) != null) {
            view.requestFocus();
        }
        if (this.f8262b1) {
            D0(this.a1);
        }
        this.f8210G0.s(this.K0);
        this.f8271k1 = false;
        q0();
        q qVar = this.f8272l1;
        if (qVar.f8242r != -1) {
            qVar.f8244t.W0.post(qVar);
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void T() {
        this.f8271k1 = true;
        q qVar = this.f8272l1;
        qVar.f8244t.W0.removeCallbacks(qVar);
        this.f13276V = true;
    }

    @Override // androidx.leanback.app.g
    public final Transition j0() {
        return TransitionInflater.from(o()).inflateTransition(R.transition.lb_browse_entrance_transition);
    }

    @Override // androidx.leanback.app.g
    public final void k0() {
        super.k0();
        this.f8210G0.l(this.f8247J0);
    }

    @Override // androidx.leanback.app.g
    public final void l0() {
        super.l0();
        this.f8210G0.getClass();
        C0451d c0451d = this.f8215v0;
        com.google.android.material.datepicker.c.m(c0451d, this.f8247J0, this.K0);
        com.google.android.material.datepicker.c.m(c0451d, this.f8216w0, this.f8248L0);
        com.google.android.material.datepicker.c.m(c0451d, this.f8217x0, this.f8249M0);
    }

    @Override // androidx.leanback.app.g
    public final void m0() {
        B1 b12 = this.f8251O0;
        if (b12 != null) {
            b12.c();
        }
        w wVar = this.f8253Q0;
        if (wVar != null) {
            wVar.i0();
        }
    }

    @Override // androidx.leanback.app.g
    public final void n0() {
        this.f8253Q0.j0();
        this.f8251O0.g(false);
        this.f8251O0.d();
    }

    @Override // androidx.leanback.app.g
    public final void o0() {
        this.f8253Q0.l0();
        this.f8251O0.e();
    }

    @Override // androidx.leanback.app.g
    public final void p0(Object obj) {
        TransitionManager.go(this.f8275o1, (Transition) obj);
    }

    public final void q0() {
        P pN = n();
        if (pN.C(R.id.scale_frame) != this.f8252P0) {
            C1001a c1001a = new C1001a(pN);
            c1001a.j(R.id.scale_frame, this.f8252P0);
            c1001a.f();
        }
    }

    public final boolean r0(N n8, int i) {
        Object objA;
        boolean z8 = true;
        if (!this.f8262b1) {
            objA = null;
        } else {
            if (n8 == null || n8.d() == 0) {
                return false;
            }
            if (i < 0) {
                i = 0;
            } else if (i >= n8.d()) {
                throw new IllegalArgumentException(String.format("Invalid position %d requested", Integer.valueOf(i)));
            }
            objA = n8.a(i);
        }
        boolean z9 = this.f8270j1;
        this.f8270j1 = false;
        if (this.f8252P0 != null && !z9) {
            z8 = false;
        }
        if (z8) {
            p pVar = this.f8250N0;
            pVar.getClass();
            if (objA != null) {
            }
            this.f8252P0 = new C();
            z0();
        }
        return z8;
    }

    public final void s0(boolean z8) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.f8259X0.getLayoutParams();
        marginLayoutParams.setMarginStart(!z8 ? this.f8263c1 : 0);
        this.f8259X0.setLayoutParams(marginLayoutParams);
        this.f8251O0.h(z8);
        A0();
        float f3 = (!z8 && this.f8265e1 && this.f8251O0.f9558a) ? this.f8269i1 : 1.0f;
        this.f8259X0.setLayoutScaleY(f3);
        this.f8259X0.setChildScale(f3);
    }

    public final C t0() {
        ComponentCallbacksC1023x componentCallbacksC1023x = this.f8252P0;
        if (componentCallbacksC1023x instanceof C) {
            return (C) componentCallbacksC1023x;
        }
        return null;
    }

    public final C0468h0 u0() {
        F f3;
        p pVar = this.f8254R0;
        if (pVar != null) {
            C c3 = (C) pVar.f8240a;
            int i = c3.f8196s0;
            VerticalGridView verticalGridView = c3.f8194p0;
            if (verticalGridView == null || (f3 = (F) verticalGridView.H(i)) == null) {
                return null;
            }
            ((AbstractC0470i0) f3.f8367u).getClass();
            return AbstractC0470i0.k(f3.f8368v);
        }
        return null;
    }

    public final boolean v0(int i) {
        N n8 = this.f8256T0;
        if (n8 == null || n8.d() == 0 || this.f8256T0.d() <= 0) {
            return true;
        }
        ((AbstractC0458c0) this.f8256T0.a(0)).getClass();
        return i == 0;
    }

    public final void w0(int i) {
        q qVar = this.f8272l1;
        if (qVar.f8242r <= 0) {
            qVar.f8241q = i;
            qVar.f8242r = 0;
            qVar.f8243s = true;
            r rVar = qVar.f8244t;
            rVar.W0.removeCallbacks(qVar);
            if (rVar.f8271k1) {
                return;
            }
            rVar.W0.post(qVar);
        }
    }

    public final void x0(boolean z8) {
        View view = this.f8253Q0.X;
        if (view == null) {
            return;
        }
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        marginLayoutParams.setMarginStart(z8 ? 0 : -this.f8263c1);
        view.setLayoutParams(marginLayoutParams);
    }

    public final void y0(int i) {
        if (i < 1 || i > 3) {
            throw new IllegalArgumentException(AbstractC0844a.j("Invalid headers state: ", i));
        }
        if (i != this.f8258V0) {
            this.f8258V0 = i;
            if (i == 1) {
                this.f8262b1 = true;
                this.a1 = true;
            } else if (i == 2) {
                this.f8262b1 = true;
                this.a1 = false;
            } else if (i != 3) {
                Log.w("BrowseSupportFragment", "Unknown headers state: " + i);
            } else {
                this.f8262b1 = false;
                this.a1 = false;
            }
            w wVar = this.f8253Q0;
            if (wVar != null) {
                wVar.f8294z0 = true ^ this.f8262b1;
                wVar.n0();
            }
        }
    }

    public final void z0() {
        ComponentCallbacksC1023x componentCallbacksC1023x = this.f8252P0;
        C c3 = (C) componentCallbacksC1023x;
        if (c3.f8175w0 == null) {
            A a3 = new A(c3);
            a3.f9558a = true;
            c3.f8175w0 = a3;
        }
        A a8 = c3.f8175w0;
        this.f8251O0 = a8;
        a8.f9560c = new K.g(this);
        if (this.f8270j1) {
            B0(null);
            return;
        }
        if (componentCallbacksC1023x instanceof C) {
            C c8 = (C) componentCallbacksC1023x;
            if (c8.f8176x0 == null) {
                c8.f8176x0 = new p(c8);
            }
            B0(c8.f8176x0);
        } else {
            B0(null);
        }
        this.f8270j1 = this.f8254R0 == null;
    }
}
