package androidx.leanback.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.debridstream.tv.R;

/* JADX INFO: loaded from: classes.dex */
public class ThumbsBar extends LinearLayout {

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

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

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

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

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

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

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

    public ThumbsBar(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, 0);
        this.f11945a = -1;
        new SparseArray();
        this.f11951j = false;
        this.f11946b = context.getResources().getDimensionPixelSize(R.dimen.lb_playback_transport_thumbs_width);
        this.f11947c = context.getResources().getDimensionPixelSize(R.dimen.lb_playback_transport_thumbs_height);
        this.f11949e = context.getResources().getDimensionPixelSize(R.dimen.lb_playback_transport_hero_thumbs_width);
        this.f11948d = context.getResources().getDimensionPixelSize(R.dimen.lb_playback_transport_hero_thumbs_height);
        this.f11950f = context.getResources().getDimensionPixelSize(R.dimen.lb_playback_transport_thumbs_margin);
    }

    public final void a() {
        int i6;
        int i7;
        while (getChildCount() > this.f11945a) {
            removeView(getChildAt(getChildCount() - 1));
        }
        while (true) {
            int childCount = getChildCount();
            int i8 = this.f11945a;
            i6 = this.f11947c;
            i7 = this.f11946b;
            if (childCount >= i8) {
                break;
            } else {
                addView(new ImageView(getContext()), new LinearLayout.LayoutParams(i7, i6));
            }
        }
        int heroIndex = getHeroIndex();
        for (int i9 = 0; i9 < getChildCount(); i9++) {
            View childAt = getChildAt(i9);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childAt.getLayoutParams();
            if (heroIndex == i9) {
                layoutParams.width = this.f11948d;
                layoutParams.height = this.f11949e;
            } else {
                layoutParams.width = i7;
                layoutParams.height = i6;
            }
            childAt.setLayoutParams(layoutParams);
        }
    }

    public int getHeroIndex() {
        return getChildCount() / 2;
    }

    @Override // android.widget.LinearLayout, android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z6, int i6, int i7, int i8, int i9) {
        super.onLayout(z6, i6, i7, i8, i9);
        int heroIndex = getHeroIndex();
        View childAt = getChildAt(heroIndex);
        int width = (getWidth() / 2) - (childAt.getMeasuredWidth() / 2);
        int measuredWidth = (childAt.getMeasuredWidth() / 2) + (getWidth() / 2);
        childAt.layout(width, getPaddingTop(), measuredWidth, childAt.getMeasuredHeight() + getPaddingTop());
        int measuredHeight = (childAt.getMeasuredHeight() / 2) + getPaddingTop();
        for (int i10 = heroIndex - 1; i10 >= 0; i10--) {
            int i11 = width - this.f11950f;
            View childAt2 = getChildAt(i10);
            childAt2.layout(i11 - childAt2.getMeasuredWidth(), measuredHeight - (childAt2.getMeasuredHeight() / 2), i11, (childAt2.getMeasuredHeight() / 2) + measuredHeight);
            width = i11 - childAt2.getMeasuredWidth();
        }
        while (true) {
            heroIndex++;
            if (heroIndex >= this.f11945a) {
                return;
            }
            int i12 = measuredWidth + this.f11950f;
            View childAt3 = getChildAt(heroIndex);
            childAt3.layout(i12, measuredHeight - (childAt3.getMeasuredHeight() / 2), childAt3.getMeasuredWidth() + i12, (childAt3.getMeasuredHeight() / 2) + measuredHeight);
            measuredWidth = i12 + childAt3.getMeasuredWidth();
        }
    }

    @Override // android.widget.LinearLayout, android.view.View
    public final void onMeasure(int i6, int i7) {
        super.onMeasure(i6, i7);
        int measuredWidth = getMeasuredWidth();
        if (this.f11951j) {
            return;
        }
        int i8 = measuredWidth - this.f11948d;
        int i9 = ((i8 + r3) - 1) / (this.f11946b + this.f11950f);
        if (i9 < 2) {
            i9 = 2;
        } else if ((i9 & 1) != 0) {
            i9++;
        }
        int i10 = i9 + 1;
        if (this.f11945a != i10) {
            this.f11945a = i10;
            a();
        }
    }

    public void setNumberOfThumbs(int i6) {
        this.f11951j = true;
        this.f11945a = i6;
        a();
    }

    public void setThumbSpace(int i6) {
        this.f11950f = i6;
        requestLayout();
    }
}
