package defpackage;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.ComponentCallbacks2;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.os.Bundle;
import android.transition.Scene;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import androidx.leanback.widget.BrowseFrameLayout;
import androidx.leanback.widget.ScaleFrameLayout;
import androidx.leanback.widget.VerticalGridView;
import androidx.leanback.widget.ci;
import androidx.leanback.widget.cp;
import androidx.leanback.widget.p0;
import androidx.recyclerview.widget.RecyclerView;
import com.strmr.ps.R;
import defpackage.bo7;
import defpackage.c88;
import defpackage.k14;
import defpackage.m49;
import java.util.HashMap;

/* JADX INFO: loaded from: classes.dex */
@Deprecated
public class if0 extends l70 {
    public static final String bd = if0.class.getCanonicalName() + ".title";
    public static final String be = if0.class.getCanonicalName() + ".headersState";
    public final p ab;
    public n ac;
    public Fragment ad;
    public k14 ae;
    public r af;
    public int ag;
    public BrowseFrameLayout ah;
    public ScaleFrameLayout ai;
    public final boolean aj;
    public String ak;
    public boolean al;
    public boolean am;
    public int an;
    public int ao;
    public final boolean ap;
    public int aq;
    public float ar;
    public boolean as;
    public Object at;
    public boolean au;
    public final t av;
    public Scene aw;
    public g ax;
    public final BrowseFrameLayout.b ay;
    public final BrowseFrameLayout.a az;
    public final k14.e ba;
    public final k14.f bb;
    public final RecyclerView.t bc;
    public final m49.c x = new d();
    public final m49.b y = new m49.b("headerFragmentViewCreated");
    public final m49.b z = new m49.b("mainFragmentViewCreated");
    public final m49.b aa = new m49.b("screenDataReady");

    public class a implements k14.e {
        public a() {
        }
    }

    public class b implements k14.f {
        public b() {
        }

        public final void a() {
            if0 if0Var = if0.this;
            int i = if0Var.ae.e;
            if (if0Var.al) {
                if0Var.n(i);
            }
        }
    }

    public class c extends RecyclerView.t {
        public c() {
        }

        @Override // androidx.recyclerview.widget.RecyclerView.t
        public final void onScrollStateChanged(RecyclerView recyclerView, int i) {
            if (i == 0) {
                recyclerView.removeOnScrollListener(this);
                if0 if0Var = if0.this;
                if (if0Var.au) {
                    return;
                }
                if0Var.k();
            }
        }
    }

    public class d extends m49.c {
        public d() {
            super("SET_ENTRANCE_START_STATE");
        }

        @Override // m49.c
        public final void c() {
            if0 if0Var = if0.this;
            if0Var.o(false);
            View viewA = if0Var.d.a();
            if (viewA != null) {
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) viewA.getLayoutParams();
                marginLayoutParams.setMarginStart(-if0Var.an);
                viewA.setLayoutParams(marginLayoutParams);
            }
        }
    }

    public class e implements BrowseFrameLayout.b {
        public e() {
        }

        @Override // androidx.leanback.widget.BrowseFrameLayout.b
        public final View a(int i, View view) {
            Fragment fragment;
            if0 if0Var = if0.this;
            View view2 = if0Var.c;
            if (view2 != null && view != view2 && i == 33) {
                return view2;
            }
            if (view2 != null && view2.hasFocus() && i == 130) {
                return (if0Var.am && if0Var.al) ? if0Var.ae.b : if0Var.ad.getView();
            }
            boolean z = view.getLayoutDirection() == 1;
            int i2 = z ? 66 : 17;
            int i3 = z ? 17 : 66;
            if (if0Var.am && i == i2) {
                if (if0Var.ae.b.getScrollState() == 0) {
                    if0Var.ac.a();
                }
                return view;
            }
            if (i == i3) {
                if (if0Var.ae.b.getScrollState() == 0 && !if0Var.ac.a() && (fragment = if0Var.ad) != null && fragment.getView() != null) {
                    return if0Var.ad.getView();
                }
            } else if (i != 130 || !if0Var.al) {
                return null;
            }
            return view;
        }
    }

    public class f implements BrowseFrameLayout.a {
        public f() {
        }

        @Override // androidx.leanback.widget.BrowseFrameLayout.a
        public final boolean a(int i, Rect rect) {
            k14 k14Var;
            if0 if0Var = if0.this;
            if (if0Var.getChildFragmentManager().isDestroyed()) {
                return true;
            }
            if (if0Var.am && if0Var.al && (k14Var = if0Var.ae) != null && k14Var.getView() != null && if0Var.ae.getView().requestFocus(i, rect)) {
                return true;
            }
            Fragment fragment = if0Var.ad;
            if (fragment != null && fragment.getView() != null && if0Var.ad.getView().requestFocus(i, rect)) {
                return true;
            }
            View view = if0Var.c;
            return view != null && view.requestFocus(i, rect);
        }

        @Override // androidx.leanback.widget.BrowseFrameLayout.a
        public final void b(View view) {
            if0 if0Var = if0.this;
            if (!if0Var.getChildFragmentManager().isDestroyed() && if0Var.am) {
                int id = view.getId();
                if (id == R.id.browse_container_dock && if0Var.al) {
                    if0Var.getFragmentManager().isDestroyed();
                } else {
                    if (id != R.id.browse_headers_dock || if0Var.al) {
                        return;
                    }
                    if0Var.getFragmentManager().isDestroyed();
                }
            }
        }
    }

    public final class g implements FragmentManager.OnBackStackChangedListener {
        public int a;
        public int b = -1;

        public g() {
            this.a = if0.this.getFragmentManager().getBackStackEntryCount();
        }

        @Override // android.app.FragmentManager.OnBackStackChangedListener
        public final void onBackStackChanged() {
            if0 if0Var = if0.this;
            if (if0Var.getFragmentManager() == null) {
                Log.w("BrowseFragment", "getFragmentManager() is null, stack:", new Exception());
                return;
            }
            int backStackEntryCount = if0Var.getFragmentManager().getBackStackEntryCount();
            int i = this.a;
            if (backStackEntryCount > i) {
                int i2 = backStackEntryCount - 1;
                if (if0Var.ak.equals(if0Var.getFragmentManager().getBackStackEntryAt(i2).getName())) {
                    this.b = i2;
                }
            } else if (backStackEntryCount < i && this.b >= backStackEntryCount) {
                if0Var.getClass();
                if0Var.getFragmentManager().beginTransaction().addToBackStack(if0Var.ak).commit();
                return;
            }
            this.a = backStackEntryCount;
        }
    }

    @Deprecated
    public static class h {
    }

    public class i implements ViewTreeObserver.OnPreDrawListener {
        @Override // android.view.ViewTreeObserver.OnPreDrawListener
        public final boolean onPreDraw() {
            throw null;
        }
    }

    @Deprecated
    public static abstract class j<T extends Fragment> {
        public abstract c88 a();
    }

    @Deprecated
    public interface k {
    }

    public final class l implements k {
        public boolean a = true;

        public l() {
        }
    }

    @Deprecated
    public static class m extends j<c88> {
        @Override // if0.j
        public final c88 a() {
            return new c88();
        }
    }

    @Deprecated
    public static class n<T extends Fragment> {
        public boolean a;
        public final Fragment b;
        public l c;

        public n(c88 c88Var) {
            this.b = c88Var;
        }

        public boolean a() {
            return false;
        }

        public void b() {
        }

        public void c() {
        }

        public void d() {
        }

        public void e(int i) {
        }

        public void f(boolean z) {
        }

        public void g(boolean z) {
        }
    }

    @Deprecated
    public interface o {
        c88.b b();
    }

    @Deprecated
    public static final class p {
        public static final m a = new m();
    }

    public class q implements nv6 {
        public final r a;

        public q(r rVar) {
            this.a = rVar;
        }

        @Override // androidx.leanback.widget.o
        public final void b(ci.a aVar, Object obj, cp.b bVar, Object obj2) {
            if0.this.n(this.a.a());
        }
    }

    @Deprecated
    public static class r<T extends Fragment> {
        public final c88 a;

        public r(c88 c88Var) {
            this.a = c88Var;
        }

        public int a() {
            return 0;
        }

        public void b() {
        }

        public void c() {
        }

        public void d(nv6 nv6Var) {
        }

        public void e(int i, boolean z) {
        }
    }

    @Deprecated
    public interface s {
        c88.c a();
    }

    public final class t implements Runnable {
        public int a = -1;
        public int b = -1;
        public boolean c = false;

        public t() {
        }

        @Override // java.lang.Runnable
        public final void run() {
            int i = this.a;
            boolean z = this.c;
            if (i != -1) {
                if0 if0Var = if0.this;
                if0Var.aq = i;
                k14 k14Var = if0Var.ae;
                if (k14Var != null && if0Var.ac != null) {
                    if (k14Var.e != i) {
                        k14Var.e = i;
                        VerticalGridView verticalGridView = k14Var.b;
                        if (verticalGridView != null && !k14Var.i.a) {
                            if (z) {
                                verticalGridView.setSelectedPositionSmooth(i);
                            } else {
                                verticalGridView.setSelectedPosition(i);
                            }
                        }
                    }
                    if (if0Var.l(i)) {
                        RecyclerView.t tVar = if0Var.bc;
                        if (!if0Var.au) {
                            VerticalGridView verticalGridView2 = if0Var.ae.b;
                            if (!if0Var.al || verticalGridView2 == null || verticalGridView2.getScrollState() == 0) {
                                if0Var.k();
                            } else {
                                if0Var.getChildFragmentManager().beginTransaction().replace(R.id.scale_frame, new Fragment()).commit();
                                verticalGridView2.removeOnScrollListener(tVar);
                                verticalGridView2.addOnScrollListener(tVar);
                            }
                        }
                        if0Var.m((if0Var.am && if0Var.al) ? false : true);
                    }
                    r rVar = if0Var.af;
                    if (rVar != null) {
                        rVar.e(i, z);
                    }
                    if0Var.t();
                }
            }
            this.a = -1;
            this.b = -1;
            this.c = false;
        }
    }

    public if0() {
        p pVar = new p();
        new HashMap().put(mb5.class, p.a);
        this.ab = pVar;
        this.ag = 1;
        this.aj = true;
        this.al = true;
        this.am = true;
        this.ap = true;
        this.aq = -1;
        this.au = true;
        this.av = new t();
        this.ay = new e();
        this.az = new f();
        this.ba = new a();
        this.bb = new b();
        this.bc = new c();
    }

    @Override // defpackage.l70
    public final Object d() {
        return ju9.e(getContext(), R.transition.lb_browse_entrance_transition);
    }

    @Override // defpackage.l70
    public final void e() {
        super.e();
        this.u.a(this.x);
    }

    @Override // defpackage.l70
    public final void f() {
        super.f();
        this.u.getClass();
        m49.c cVar = this.j;
        m49.d(cVar, this.x, this.y);
        m49.d(cVar, this.k, this.z);
        m49.d(cVar, this.l, this.aa);
    }

    @Override // defpackage.l70
    public final void g() {
        n nVar = this.ac;
        if (nVar != null) {
            nVar.b();
        }
        k14 k14Var = this.ae;
        if (k14Var != null) {
            k14Var.f();
        }
    }

    @Override // defpackage.l70
    public final void h() {
        this.ae.g();
        this.ac.f(false);
        this.ac.c();
    }

    @Override // defpackage.l70
    public final void i() {
        VerticalGridView verticalGridView;
        k14 k14Var = this.ae;
        VerticalGridView verticalGridView2 = k14Var.b;
        if (verticalGridView2 != null) {
            verticalGridView2.setPruneChild(false);
            k14Var.b.setLayoutFrozen(true);
            k14Var.b.setFocusSearchDisabled(true);
        }
        if (!k14Var.m && (verticalGridView = k14Var.b) != null) {
            verticalGridView.setDescendantFocusability(131072);
            if (verticalGridView.hasFocus()) {
                verticalGridView.requestFocus();
            }
        }
        this.ac.d();
    }

    @Override // defpackage.l70
    public final void j(Object obj) {
        ju9.f(this.aw, obj);
    }

    public final void k() {
        FragmentManager childFragmentManager = getChildFragmentManager();
        if (childFragmentManager.findFragmentById(R.id.scale_frame) != this.ad) {
            childFragmentManager.beginTransaction().replace(R.id.scale_frame, this.ad).commit();
        }
    }

    public final boolean l(int i2) {
        if (!this.am) {
            boolean z = this.as;
            this.as = false;
            this.at = null;
            z = this.ad == null || z;
            if (z) {
                this.ab.getClass();
                this.ad = p.a.a();
                p();
            }
        }
        return z;
    }

    public final void m(boolean z) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.ai.getLayoutParams();
        marginLayoutParams.setMarginStart(!z ? this.an : 0);
        this.ai.setLayoutParams(marginLayoutParams);
        this.ac.g(z);
        q();
        float f2 = (!z && this.ap && this.ac.a) ? this.ar : 1.0f;
        this.ai.setLayoutScaleY(f2);
        this.ai.setChildScale(f2);
    }

    public final void n(int i2) {
        t tVar = this.av;
        if0 if0Var = if0.this;
        if (tVar.b <= 0) {
            tVar.a = i2;
            tVar.b = 0;
            tVar.c = true;
            if0Var.ah.removeCallbacks(tVar);
            if (if0Var.au) {
                return;
            }
            if0Var.ah.post(tVar);
        }
    }

    public final void o(boolean z) {
        View view = this.ae.getView();
        if (view == null) {
            return;
        }
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        marginLayoutParams.setMarginStart(z ? 0 : -this.an);
        view.setLayoutParams(marginLayoutParams);
    }

    @Override // defpackage.l70, android.app.Fragment
    public final void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        TypedArray typedArrayObtainStyledAttributes = getContext().obtainStyledAttributes(bo7.n.b);
        this.an = (int) typedArrayObtainStyledAttributes.getDimension(6, r0.getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_start));
        this.ao = (int) typedArrayObtainStyledAttributes.getDimension(7, r0.getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_top));
        typedArrayObtainStyledAttributes.recycle();
        Bundle arguments = getArguments();
        if (arguments != null) {
            String str = bd;
            if (arguments.containsKey(str)) {
                String string = arguments.getString(str);
                this.b = string;
                p0 p0Var = this.d;
                if (p0Var != null) {
                    p0Var.f(string);
                }
            }
            String str2 = be;
            if (arguments.containsKey(str2)) {
                int i2 = arguments.getInt(str2);
                if (i2 < 1 || i2 > 3) {
                    throw new IllegalArgumentException(n41.k("Invalid headers state: ", i2));
                }
                if (i2 != this.ag) {
                    this.ag = i2;
                    if (i2 == 1) {
                        this.am = true;
                        this.al = true;
                    } else if (i2 == 2) {
                        this.am = true;
                        this.al = false;
                    } else if (i2 != 3) {
                        n41.x(i2, "Unknown headers state: ", "BrowseFragment");
                    } else {
                        this.am = false;
                        this.al = false;
                    }
                    k14 k14Var = this.ae;
                    if (k14Var != null) {
                        k14Var.n = !this.am;
                        k14Var.k();
                    }
                }
            }
        }
        if (this.am) {
            if (this.aj) {
                this.ak = "lbHeadersBackStack_" + this;
                this.ax = new g();
                getFragmentManager().addOnBackStackChangedListener(this.ax);
                g gVar = this.ax;
                if0 if0Var = if0.this;
                if (bundle != null) {
                    int i3 = bundle.getInt("headerStackIndex", -1);
                    gVar.b = i3;
                    if0Var.al = i3 == -1;
                } else if (!if0Var.al) {
                    if0Var.getFragmentManager().beginTransaction().addToBackStack(if0Var.ak).commit();
                }
            } else if (bundle != null) {
                this.al = bundle.getBoolean("headerShow");
            }
        }
        this.ar = getResources().getFraction(R.fraction.lb_browse_rows_scale, 1, 1);
    }

    @Override // android.app.Fragment
    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        if (getChildFragmentManager().findFragmentById(R.id.scale_frame) == null) {
            this.ae = new k14();
            l(this.aq);
            FragmentTransaction fragmentTransactionReplace = getChildFragmentManager().beginTransaction().replace(R.id.browse_headers_dock, this.ae);
            Fragment fragment = this.ad;
            if (fragment != null) {
                fragmentTransactionReplace.replace(R.id.scale_frame, fragment);
            } else {
                n nVar = new n(null);
                this.ac = nVar;
                nVar.c = new l();
            }
            fragmentTransactionReplace.commit();
        } else {
            this.ae = (k14) getChildFragmentManager().findFragmentById(R.id.browse_headers_dock);
            this.ad = getChildFragmentManager().findFragmentById(R.id.scale_frame);
            this.as = bundle != null && bundle.getBoolean("isPageRow", false);
            this.aq = bundle != null ? bundle.getInt("currentSelectedPosition", 0) : 0;
            p();
        }
        k14 k14Var = this.ae;
        k14Var.n = true ^ this.am;
        k14Var.k();
        this.ae.h(null);
        k14 k14Var2 = this.ae;
        k14Var2.k = this.bb;
        k14Var2.l = this.ba;
        View viewInflate = layoutInflater.inflate(R.layout.lb_browse_fragment, viewGroup, false);
        this.w.b = (ViewGroup) viewInflate;
        BrowseFrameLayout browseFrameLayout = (BrowseFrameLayout) viewInflate.findViewById(R.id.browse_frame);
        this.ah = browseFrameLayout;
        browseFrameLayout.setOnChildFocusListener(this.az);
        this.ah.setOnFocusSearchListener(this.ay);
        a(layoutInflater, this.ah, bundle);
        ScaleFrameLayout scaleFrameLayout = (ScaleFrameLayout) viewInflate.findViewById(R.id.scale_frame);
        this.ai = scaleFrameLayout;
        scaleFrameLayout.setPivotX(0.0f);
        this.ai.setPivotY(this.ao);
        ju9.c(this.ah, new lf0(this));
        ju9.c(this.ah, new mf0(this));
        this.aw = ju9.c(this.ah, new nf0(this));
        return viewInflate;
    }

    @Override // android.app.Fragment
    public final void onDestroy() {
        if (this.ax != null) {
            getFragmentManager().removeOnBackStackChangedListener(this.ax);
        }
        super.onDestroy();
    }

    @Override // defpackage.l70, defpackage.qe0, android.app.Fragment
    public final void onDestroyView() {
        r(null);
        this.at = null;
        this.ac = null;
        this.ad = null;
        this.ae = null;
        this.ah = null;
        this.ai = null;
        this.aw = null;
        super.onDestroyView();
    }

    @Override // defpackage.qe0, android.app.Fragment
    public final void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putInt("currentSelectedPosition", this.aq);
        bundle.putBoolean("isPageRow", this.as);
        g gVar = this.ax;
        if (gVar != null) {
            bundle.putInt("headerStackIndex", gVar.b);
        } else {
            bundle.putBoolean("headerShow", this.al);
        }
    }

    @Override // defpackage.qe0, android.app.Fragment
    public final void onStart() {
        Fragment fragment;
        k14 k14Var;
        super.onStart();
        k14 k14Var2 = this.ae;
        int i2 = this.ao;
        VerticalGridView verticalGridView = k14Var2.b;
        if (verticalGridView != null) {
            verticalGridView.setItemAlignmentOffset(0);
            k14Var2.b.setItemAlignmentOffsetPercent(-1.0f);
            k14Var2.b.setWindowAlignmentOffset(i2);
            k14Var2.b.setWindowAlignmentOffsetPercent(-1.0f);
            k14Var2.b.setWindowAlignment(0);
        }
        q();
        if (this.am && this.al && (k14Var = this.ae) != null && k14Var.getView() != null) {
            this.ae.getView().requestFocus();
        } else if ((!this.am || !this.al) && (fragment = this.ad) != null && fragment.getView() != null) {
            this.ad.getView().requestFocus();
        }
        if (this.am) {
            s(this.al);
        }
        this.u.e(this.y);
        this.au = false;
        k();
        t tVar = this.av;
        if (tVar.b != -1) {
            if0.this.ah.post(tVar);
        }
    }

    @Override // android.app.Fragment
    public final void onStop() {
        this.au = true;
        t tVar = this.av;
        if0.this.ah.removeCallbacks(tVar);
        super.onStop();
    }

    public final void p() {
        c88.b bVarB = ((o) this.ad).b();
        this.ac = bVarB;
        bVarB.c = new l();
        if (this.as) {
            r(null);
            return;
        }
        ComponentCallbacks2 componentCallbacks2 = this.ad;
        if (componentCallbacks2 instanceof s) {
            r(((s) componentCallbacks2).a());
        } else {
            r(null);
        }
        this.as = this.af == null;
    }

    public final void q() {
        int i2 = this.ao;
        if (this.ap && this.ac.a && this.al) {
            i2 = (int) ((i2 / this.ar) + 0.5f);
        }
        this.ac.e(i2);
    }

    public final void r(r rVar) {
        r rVar2 = this.af;
        if (rVar == rVar2) {
            return;
        }
        if (rVar2 != null) {
            rVar2.b();
        }
        this.af = rVar;
        if (rVar != null) {
            rVar.d(new q(rVar));
            this.af.c();
        }
        r rVar3 = this.af;
        if (rVar3 != null) {
            rVar3.b();
        }
    }

    public final void s(boolean z) {
        k14 k14Var = this.ae;
        k14Var.m = z;
        k14Var.k();
        o(z);
        m(!z);
    }

    public final void t() {
        n nVar;
        n nVar2;
        if (!this.al) {
            if (!((!this.as || (nVar2 = this.ac) == null) ? true : nVar2.c.a)) {
                c(false);
                return;
            }
            p0 p0Var = this.d;
            if (p0Var != null) {
                p0Var.g(6);
            }
            c(true);
            return;
        }
        int i2 = ((!this.as || (nVar = this.ac) == null) ? true : nVar.c.a ? 2 : 0) | 4;
        if (i2 == 0) {
            c(false);
            return;
        }
        p0 p0Var2 = this.d;
        if (p0Var2 != null) {
            p0Var2.g(i2);
        }
        c(true);
    }
}
