70 lines
2.8 KiB
Java
70 lines
2.8 KiB
Java
package com.discord.utilities.view.recycler;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.content.res.TypedArray;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.discord.utils.R;
|
|
import d0.a0.a;
|
|
import d0.z.d.m;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
/* compiled from: MaxHeightRecyclerView.kt */
|
|
public final class MaxHeightRecyclerView extends RecyclerView {
|
|
private int maxHeight;
|
|
|
|
public MaxHeightRecyclerView(Context context) {
|
|
this(context, null, 0, 6, null);
|
|
}
|
|
|
|
public MaxHeightRecyclerView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0, 4, null);
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public MaxHeightRecyclerView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
m.checkNotNullParameter(context, "context");
|
|
this.maxHeight = getHeightMaximum(context, attributeSet, 0);
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ MaxHeightRecyclerView(Context context, AttributeSet attributeSet, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(context, (i2 & 2) != 0 ? null : attributeSet, (i2 & 4) != 0 ? 0 : i);
|
|
}
|
|
|
|
private final int getHeightMaximum(Context context, AttributeSet attributeSet, int i) {
|
|
if (attributeSet == null) {
|
|
return 0;
|
|
}
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.b.MaxHeightRecyclerView, i, 0);
|
|
m.checkNotNullExpressionValue(obtainStyledAttributes, "obtainStyledAttributes(a…lerView, defStyleAttr, 0)");
|
|
int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(R.b.MaxHeightRecyclerView_max_height, 0);
|
|
float f = obtainStyledAttributes.getFloat(R.b.MaxHeightRecyclerView_max_height_screen_ratio, 0.0f);
|
|
obtainStyledAttributes.recycle();
|
|
if (f <= 0.0f || f >= 1.0f) {
|
|
return dimensionPixelSize;
|
|
}
|
|
Resources resources = context.getResources();
|
|
m.checkNotNullExpressionValue(resources, "resources");
|
|
return a.roundToInt(((float) resources.getDisplayMetrics().heightPixels) * f);
|
|
}
|
|
|
|
public final int getMaxHeight() {
|
|
return this.maxHeight;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView, android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
int i3 = this.maxHeight;
|
|
if (i3 > 0) {
|
|
i2 = View.MeasureSpec.makeMeasureSpec(i3, Integer.MIN_VALUE);
|
|
}
|
|
super.onMeasure(i, i2);
|
|
}
|
|
|
|
public final void setMaxHeight(int i) {
|
|
this.maxHeight = i;
|
|
}
|
|
}
|