package s3;

import M.J;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.material.chip.ChipGroup;
import com.martsnew.tv.R;
import java.lang.reflect.Field;

/* JADX INFO: loaded from: classes.dex */
public abstract class d extends ViewGroup {

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

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

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

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

    public int getItemSpacing() {
        return this.f16832r;
    }

    public int getLineSpacing() {
        return this.f16831q;
    }

    public int getRowCount() {
        return this.f16834t;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z8, int i, int i5, int i8, int i9) {
        int marginEnd;
        int marginStart;
        if (getChildCount() == 0) {
            this.f16834t = 0;
            return;
        }
        this.f16834t = 1;
        Field field = J.f4065a;
        boolean z9 = getLayoutDirection() == 1;
        int paddingRight = z9 ? getPaddingRight() : getPaddingLeft();
        int paddingLeft = z9 ? getPaddingLeft() : getPaddingRight();
        int paddingTop = getPaddingTop();
        int i10 = (i8 - i) - paddingLeft;
        int measuredWidth = paddingRight;
        int i11 = paddingTop;
        for (int i12 = 0; i12 < getChildCount(); i12++) {
            View childAt = getChildAt(i12);
            if (childAt.getVisibility() == 8) {
                childAt.setTag(R.id.row_index_key, -1);
            } else {
                ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
                if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
                    ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
                    marginStart = marginLayoutParams.getMarginStart();
                    marginEnd = marginLayoutParams.getMarginEnd();
                } else {
                    marginEnd = 0;
                    marginStart = 0;
                }
                int measuredWidth2 = childAt.getMeasuredWidth() + measuredWidth + marginStart;
                if (!this.f16833s && measuredWidth2 > i10) {
                    i11 = this.f16831q + paddingTop;
                    this.f16834t++;
                    measuredWidth = paddingRight;
                }
                childAt.setTag(R.id.row_index_key, Integer.valueOf(this.f16834t - 1));
                int i13 = measuredWidth + marginStart;
                int measuredWidth3 = childAt.getMeasuredWidth() + i13;
                int measuredHeight = childAt.getMeasuredHeight() + i11;
                if (z9) {
                    childAt.layout(i10 - measuredWidth3, i11, (i10 - measuredWidth) - marginStart, measuredHeight);
                } else {
                    childAt.layout(i13, i11, measuredWidth3, measuredHeight);
                }
                measuredWidth += childAt.getMeasuredWidth() + marginStart + marginEnd + this.f16832r;
                paddingTop = measuredHeight;
            }
        }
    }

    @Override // android.view.View
    public final void onMeasure(int i, int i5) {
        int i8;
        int i9;
        int i10;
        int size = View.MeasureSpec.getSize(i);
        int mode = View.MeasureSpec.getMode(i);
        int size2 = View.MeasureSpec.getSize(i5);
        int mode2 = View.MeasureSpec.getMode(i5);
        int i11 = (mode == Integer.MIN_VALUE || mode == 1073741824) ? size : Integer.MAX_VALUE;
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = i11 - getPaddingRight();
        int i12 = paddingTop;
        int i13 = 0;
        for (int i14 = 0; i14 < getChildCount(); i14++) {
            View childAt = getChildAt(i14);
            if (childAt.getVisibility() != 8) {
                measureChild(childAt, i, i5);
                ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
                if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
                    ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
                    i10 = marginLayoutParams.leftMargin;
                    i9 = marginLayoutParams.rightMargin;
                } else {
                    i9 = 0;
                    i10 = 0;
                }
                int i15 = i9;
                if (childAt.getMeasuredWidth() + paddingLeft + i10 > paddingRight && !((ChipGroup) this).f16833s) {
                    paddingLeft = getPaddingLeft();
                    i12 = paddingTop + this.f16831q;
                }
                int measuredWidth = childAt.getMeasuredWidth() + paddingLeft + i10;
                int measuredHeight = childAt.getMeasuredHeight() + i12;
                if (measuredWidth > i13) {
                    i13 = measuredWidth;
                }
                int measuredWidth2 = childAt.getMeasuredWidth() + i10 + i15 + this.f16832r + paddingLeft;
                if (i14 == getChildCount() - 1) {
                    i13 += i15;
                }
                paddingLeft = measuredWidth2;
                paddingTop = measuredHeight;
            }
        }
        int paddingRight2 = getPaddingRight() + i13;
        int paddingBottom = getPaddingBottom() + paddingTop;
        if (mode != Integer.MIN_VALUE) {
            i8 = 1073741824;
            if (mode != 1073741824) {
                size = paddingRight2;
            }
        } else {
            i8 = 1073741824;
            size = Math.min(paddingRight2, size);
        }
        if (mode2 == Integer.MIN_VALUE) {
            size2 = Math.min(paddingBottom, size2);
        } else if (mode2 != i8) {
            size2 = paddingBottom;
        }
        setMeasuredDimension(size, size2);
    }

    public void setItemSpacing(int i) {
        this.f16832r = i;
    }

    public void setLineSpacing(int i) {
        this.f16831q = i;
    }

    public void setSingleLine(boolean z8) {
        this.f16833s = z8;
    }
}
