package androidx.recyclerview.widget;

import android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.annotation.Nullable;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final int[] f3867d = {R.attr.listDivider};

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f3869b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Rect f3870c = new Rect();

    public r(Context context) {
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(f3867d);
        this.f3868a = typedArrayObtainStyledAttributes.getDrawable(0);
        typedArrayObtainStyledAttributes.recycle();
        this.f3869b = 1;
    }

    @Nullable
    public Drawable getDrawable() {
        return this.f3868a;
    }

    @Override // androidx.recyclerview.widget.m1
    public final void getItemOffsets(Rect rect, View view, RecyclerView recyclerView, f2 f2Var) {
        Drawable drawable = this.f3868a;
        if (drawable == null) {
            rect.set(0, 0, 0, 0);
        } else if (this.f3869b == 1) {
            rect.set(0, 0, 0, drawable.getIntrinsicHeight());
        } else {
            rect.set(0, 0, drawable.getIntrinsicWidth(), 0);
        }
    }

    @Override // androidx.recyclerview.widget.m1
    public final void onDraw(Canvas canvas, RecyclerView recyclerView, f2 f2Var) {
        Drawable drawable;
        int height;
        int paddingTop;
        int width;
        int paddingLeft;
        if (recyclerView.getLayoutManager() == null || (drawable = this.f3868a) == null) {
            return;
        }
        int i10 = this.f3869b;
        Rect rect = this.f3870c;
        int i11 = 0;
        if (i10 == 1) {
            canvas.save();
            if (recyclerView.getClipToPadding()) {
                paddingLeft = recyclerView.getPaddingLeft();
                width = recyclerView.getWidth() - recyclerView.getPaddingRight();
                canvas.clipRect(paddingLeft, recyclerView.getPaddingTop(), width, recyclerView.getHeight() - recyclerView.getPaddingBottom());
            } else {
                width = recyclerView.getWidth();
                paddingLeft = 0;
            }
            int childCount = recyclerView.getChildCount();
            while (i11 < childCount) {
                View childAt = recyclerView.getChildAt(i11);
                recyclerView.getDecoratedBoundsWithMargins(childAt, rect);
                int iRound = Math.round(childAt.getTranslationY()) + rect.bottom;
                drawable.setBounds(paddingLeft, iRound - drawable.getIntrinsicHeight(), width, iRound);
                drawable.draw(canvas);
                i11++;
            }
            canvas.restore();
            return;
        }
        canvas.save();
        if (recyclerView.getClipToPadding()) {
            paddingTop = recyclerView.getPaddingTop();
            height = recyclerView.getHeight() - recyclerView.getPaddingBottom();
            canvas.clipRect(recyclerView.getPaddingLeft(), paddingTop, recyclerView.getWidth() - recyclerView.getPaddingRight(), height);
        } else {
            height = recyclerView.getHeight();
            paddingTop = 0;
        }
        int childCount2 = recyclerView.getChildCount();
        while (i11 < childCount2) {
            View childAt2 = recyclerView.getChildAt(i11);
            recyclerView.getLayoutManager().getDecoratedBoundsWithMargins(childAt2, rect);
            int iRound2 = Math.round(childAt2.getTranslationX()) + rect.right;
            drawable.setBounds(iRound2 - drawable.getIntrinsicWidth(), paddingTop, iRound2, height);
            drawable.draw(canvas);
            i11++;
        }
        canvas.restore();
    }
}
