package e6;

import B0.RunnableC0014a;
import N1.t0;
import P6.g;
import android.view.View;
import android.view.ViewParent;
import androidx.recyclerview.widget.RecyclerView;
import com.rubensousa.dpadrecyclerview.DpadRecyclerView;
import com.rubensousa.dpadrecyclerview.layoutmanager.PivotLayoutManager;
import d6.p;
import d6.u;
import java.util.ArrayList;

/* JADX INFO: renamed from: e6.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0891c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final PivotLayoutManager f12521a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final i6.c f12522b;

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public DpadRecyclerView f12527g;

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public t0 f12531l;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f12524d = -1;
    public final ArrayList i = new ArrayList();

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final ArrayList f12529j = new ArrayList();

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final RunnableC0014a f12530k = new RunnableC0014a(21, this);

    public C0891c(PivotLayoutManager pivotLayoutManager, i6.c cVar) {
        this.f12521a = pivotLayoutManager;
        this.f12522b = cVar;
    }

    public static RecyclerView c(View view) {
        for (ViewParent parent = view.getParent(); parent != null; parent = parent.getParent()) {
            if (parent instanceof RecyclerView) {
                return (RecyclerView) parent;
            }
        }
        return null;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final void a() {
        DpadRecyclerView dpadRecyclerView = this.f12527g;
        if (dpadRecyclerView == null) {
            return;
        }
        int i = this.f12524d;
        i6.c cVar = this.f12522b;
        PivotLayoutManager pivotLayoutManager = cVar.f13524a;
        View viewD = i == -1 ? null : pivotLayoutManager.D(i);
        t0 t0VarM = viewD != null ? dpadRecyclerView.M(viewD) : null;
        t0 t0Var = this.f12531l;
        ArrayList arrayList = this.i;
        if (t0VarM != t0Var) {
            if (t0Var != 0) {
                if (t0Var instanceof p) {
                }
                for (int size = arrayList.size() - 1; -1 < size; size--) {
                    ((u) arrayList.get(size)).a(dpadRecyclerView, t0Var);
                }
            }
            if (t0VarM instanceof p) {
                ((p) t0VarM).getClass();
            }
        }
        this.f12531l = t0VarM;
        if (t0VarM != null) {
            for (int size2 = arrayList.size() - 1; -1 < size2; size2--) {
                ((u) arrayList.get(size2)).c(dpadRecyclerView, t0VarM, this.f12524d);
            }
        } else {
            for (int size3 = arrayList.size() - 1; -1 < size3; size3--) {
                ((u) arrayList.get(size3)).c(dpadRecyclerView, null, -1);
            }
        }
        if (cVar.f13530g || dpadRecyclerView.isLayoutRequested()) {
            return;
        }
        int I7 = pivotLayoutManager.I();
        for (int i5 = 0; i5 < I7; i5++) {
            View viewH = pivotLayoutManager.H(i5);
            if (viewH != null && viewH.isLayoutRequested()) {
                dpadRecyclerView.postOnAnimation(this.f12530k);
                return;
            }
        }
    }

    public final void b() {
        DpadRecyclerView dpadRecyclerView = this.f12527g;
        if (dpadRecyclerView == null) {
            return;
        }
        int i = this.f12524d;
        View viewD = i == -1 ? null : this.f12522b.f13524a.D(i);
        t0 t0VarM = viewD != null ? dpadRecyclerView.M(viewD) : null;
        if (t0VarM instanceof p) {
            ((p) t0VarM).getClass();
        }
        ArrayList arrayList = this.i;
        if (t0VarM != null) {
            for (int size = arrayList.size() - 1; -1 < size; size--) {
                ((u) arrayList.get(size)).b(dpadRecyclerView, t0VarM, this.f12524d, this.f12525e);
            }
            return;
        }
        for (int size2 = arrayList.size() - 1; -1 < size2; size2--) {
            ((u) arrayList.get(size2)).b(dpadRecyclerView, null, -1, 0);
        }
    }

    public final void d(View view) {
        DpadRecyclerView dpadRecyclerView;
        View viewFindFocus;
        g.e(view, "view");
        view.requestFocus();
        if (this.f12523c || (dpadRecyclerView = this.f12527g) == null || c(view) != dpadRecyclerView) {
            return;
        }
        if (!view.hasFocus() || view.isFocused() || (viewFindFocus = view.findFocus()) == null || c(viewFindFocus) == dpadRecyclerView) {
            View viewD = dpadRecyclerView.D(view);
            if ((viewD == null ? null : dpadRecyclerView.M(viewD)) == null) {
                return;
            }
            ArrayList arrayList = this.f12529j;
            int size = arrayList.size() - 1;
            if (-1 < size) {
                arrayList.get(size).getClass();
                throw new ClassCastException();
            }
            RecyclerView recyclerViewC = c(dpadRecyclerView);
            if (recyclerViewC instanceof DpadRecyclerView) {
                DpadRecyclerView dpadRecyclerView2 = (DpadRecyclerView) recyclerViewC;
                dpadRecyclerView2.getClass();
                PivotLayoutManager pivotLayoutManager = dpadRecyclerView2.f11229j1;
                if (pivotLayoutManager != null) {
                    pivotLayoutManager.f11237I.e(view);
                }
            }
        }
    }

    public final void e(View view) {
        t0 t0VarI;
        g.e(view, "view");
        this.f12532m = null;
        DpadRecyclerView dpadRecyclerView = this.f12527g;
        if (dpadRecyclerView == null || (t0VarI = dpadRecyclerView.I(this.f12524d, false)) == null) {
            return;
        }
        for (ViewParent parent = view.getParent(); parent != null; parent = parent.getParent()) {
            if (parent == t0VarI.f4654a) {
                ArrayList arrayList = this.f12529j;
                int size = arrayList.size() - 1;
                if (-1 >= size) {
                    return;
                }
                arrayList.get(size).getClass();
                throw new ClassCastException();
            }
        }
        this.f12532m = view;
    }

    public final boolean f(int i, int i5) {
        int i8 = this.f12524d;
        int i9 = this.f12525e;
        int iS = this.f12521a.S();
        int iMax = iS == 0 ? -1 : Math.max(0, Math.min(iS - 1, i));
        this.f12524d = iMax;
        this.f12525e = i5;
        return (iMax == i8 && i5 == i9) ? false : true;
    }
}
