package cj;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.util.AttributeSet;
import android.view.View;
import androidx.core.view.s0;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.internal.o;
import ij.c;
import vi.b;
import vi.d;
import vi.k;
import vi.l;

/* loaded from: classes3.dex */
public class a extends RecyclerView.o {

    /* renamed from: i, reason: collision with root package name */
    private static final int f11976i = k.f39911z;

    /* renamed from: a, reason: collision with root package name */
    private Drawable f11977a;

    /* renamed from: b, reason: collision with root package name */
    private int f11978b;

    /* renamed from: c, reason: collision with root package name */
    private int f11979c;

    /* renamed from: d, reason: collision with root package name */
    private int f11980d;

    /* renamed from: e, reason: collision with root package name */
    private int f11981e;

    /* renamed from: f, reason: collision with root package name */
    private int f11982f;

    /* renamed from: g, reason: collision with root package name */
    private boolean f11983g;

    /* renamed from: h, reason: collision with root package name */
    private final Rect f11984h;

    public a(Context context, int i10) {
        this(context, null, i10);
    }

    private void j(Canvas canvas, RecyclerView recyclerView) {
        int height;
        int i10;
        canvas.save();
        if (recyclerView.getClipToPadding()) {
            i10 = recyclerView.getPaddingTop();
            height = recyclerView.getHeight() - recyclerView.getPaddingBottom();
            canvas.clipRect(recyclerView.getPaddingLeft(), i10, recyclerView.getWidth() - recyclerView.getPaddingRight(), height);
        } else {
            height = recyclerView.getHeight();
            i10 = 0;
        }
        int i11 = i10 + this.f11981e;
        int i12 = height - this.f11982f;
        int childCount = recyclerView.getChildCount();
        for (int i13 = 0; i13 < childCount; i13++) {
            View childAt = recyclerView.getChildAt(i13);
            recyclerView.getLayoutManager().Z(childAt, this.f11984h);
            int round = this.f11984h.right + Math.round(childAt.getTranslationX());
            this.f11977a.setBounds((round - this.f11977a.getIntrinsicWidth()) - this.f11978b, i11, round, i12);
            this.f11977a.draw(canvas);
        }
        canvas.restore();
    }

    private void k(Canvas canvas, RecyclerView recyclerView) {
        int width;
        int i10;
        canvas.save();
        if (recyclerView.getClipToPadding()) {
            i10 = recyclerView.getPaddingLeft();
            width = recyclerView.getWidth() - recyclerView.getPaddingRight();
            canvas.clipRect(i10, recyclerView.getPaddingTop(), width, recyclerView.getHeight() - recyclerView.getPaddingBottom());
        } else {
            width = recyclerView.getWidth();
            i10 = 0;
        }
        boolean z10 = s0.z(recyclerView) == 1;
        int i11 = i10 + (z10 ? this.f11982f : this.f11981e);
        int i12 = width - (z10 ? this.f11981e : this.f11982f);
        int childCount = recyclerView.getChildCount();
        if (!this.f11983g) {
            childCount--;
        }
        for (int i13 = 0; i13 < childCount; i13++) {
            View childAt = recyclerView.getChildAt(i13);
            recyclerView.i0(childAt, this.f11984h);
            int round = this.f11984h.bottom + Math.round(childAt.getTranslationY());
            this.f11977a.setBounds(i11, (round - this.f11977a.getIntrinsicHeight()) - this.f11978b, i12, round);
            this.f11977a.draw(canvas);
        }
        canvas.restore();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public void e(Rect rect, View view, RecyclerView recyclerView, RecyclerView.b0 b0Var) {
        rect.set(0, 0, 0, 0);
        if (this.f11980d == 1) {
            rect.bottom = this.f11977a.getIntrinsicHeight() + this.f11978b;
        } else {
            rect.right = this.f11977a.getIntrinsicWidth() + this.f11978b;
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public void g(Canvas canvas, RecyclerView recyclerView, RecyclerView.b0 b0Var) {
        if (recyclerView.getLayoutManager() == null) {
            return;
        }
        if (this.f11980d == 1) {
            k(canvas, recyclerView);
        } else {
            j(canvas, recyclerView);
        }
    }

    public void l(int i10) {
        this.f11979c = i10;
        Drawable l10 = androidx.core.graphics.drawable.a.l(this.f11977a);
        this.f11977a = l10;
        androidx.core.graphics.drawable.a.h(l10, i10);
    }

    public void m(boolean z10) {
        this.f11983g = z10;
    }

    public void n(int i10) {
        if (i10 == 0 || i10 == 1) {
            this.f11980d = i10;
            return;
        }
        throw new IllegalArgumentException("Invalid orientation: " + i10 + ". It should be either HORIZONTAL or VERTICAL");
    }

    public a(Context context, AttributeSet attributeSet, int i10) {
        this(context, attributeSet, b.E, i10);
    }

    public a(Context context, AttributeSet attributeSet, int i10, int i11) {
        this.f11984h = new Rect();
        TypedArray h10 = o.h(context, attributeSet, l.f40037m4, i10, f11976i, new int[0]);
        this.f11979c = c.a(context, h10, l.f40047n4).getDefaultColor();
        this.f11978b = h10.getDimensionPixelSize(l.f40077q4, context.getResources().getDimensionPixelSize(d.f39789u));
        this.f11981e = h10.getDimensionPixelOffset(l.f40067p4, 0);
        this.f11982f = h10.getDimensionPixelOffset(l.f40057o4, 0);
        this.f11983g = h10.getBoolean(l.f40087r4, true);
        h10.recycle();
        this.f11977a = new ShapeDrawable();
        l(this.f11979c);
        n(i11);
    }
}
