discord-jadx/app/src/main/java/com/discord/widgets/chat/input/gifpicker/GifLoadingView.java

161 lines
6.9 KiB
Java

package com.discord.widgets.chat.input.gifpicker;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.discord.R;
import com.discord.databinding.LoadingGifItemViewBinding;
import com.discord.utilities.dimen.DimenUtils;
import com.discord.utilities.recycler.GridColumnSpaceItemDecoration;
import d0.t.n;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: GifLoadingView.kt */
public final class GifLoadingView extends RecyclerView {
private boolean isStaggered;
private final LoadingGifAdapter loadingGifAdapter;
/* compiled from: GifLoadingView.kt */
public static final class LoadingGifAdapter extends RecyclerView.Adapter<LoadingGifViewHolder> {
private List<Integer> heightsDp = n.emptyList();
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public int getItemCount() {
return this.heightsDp.size();
}
public void onBindViewHolder(LoadingGifViewHolder loadingGifViewHolder, int i) {
m.checkNotNullParameter(loadingGifViewHolder, "holder");
loadingGifViewHolder.configure(this.heightsDp.get(i).intValue());
}
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
public LoadingGifViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
m.checkNotNullParameter(viewGroup, "parent");
View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(2131558548, viewGroup, false);
Objects.requireNonNull(inflate, "rootView");
LoadingGifItemViewBinding loadingGifItemViewBinding = new LoadingGifItemViewBinding((CardView) inflate);
m.checkNotNullExpressionValue(loadingGifItemViewBinding, "LoadingGifItemViewBindin….context), parent, false)");
return new LoadingGifViewHolder(loadingGifItemViewBinding);
}
public final void setData(List<Integer> list) {
m.checkNotNullParameter(list, "heightsDp");
this.heightsDp = list;
notifyDataSetChanged();
}
}
/* compiled from: GifLoadingView.kt */
public static final class LoadingGifViewHolder extends RecyclerView.ViewHolder {
private final LoadingGifItemViewBinding binding;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public LoadingGifViewHolder(LoadingGifItemViewBinding loadingGifItemViewBinding) {
super(loadingGifItemViewBinding.a);
m.checkNotNullParameter(loadingGifItemViewBinding, "binding");
this.binding = loadingGifItemViewBinding;
}
public final void configure(int i) {
CardView cardView = this.binding.a;
m.checkNotNullExpressionValue(cardView, "binding.root");
ViewGroup.LayoutParams layoutParams = cardView.getLayoutParams();
CardView cardView2 = this.binding.a;
m.checkNotNullExpressionValue(cardView2, "binding.root");
Resources resources = cardView2.getResources();
m.checkNotNullExpressionValue(resources, "binding.root.resources");
layoutParams.height = (int) (((float) i) * resources.getDisplayMetrics().density);
CardView cardView3 = this.binding.a;
m.checkNotNullExpressionValue(cardView3, "binding.root");
cardView3.setLayoutParams(layoutParams);
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public GifLoadingView(Context context) {
super(context);
m.checkNotNullParameter(context, "context");
this.loadingGifAdapter = new LoadingGifAdapter();
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public GifLoadingView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
m.checkNotNullParameter(context, "context");
this.loadingGifAdapter = new LoadingGifAdapter();
initialize(attributeSet);
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public GifLoadingView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
m.checkNotNullParameter(context, "context");
this.loadingGifAdapter = new LoadingGifAdapter();
initialize(attributeSet);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ GifLoadingView(Context context, AttributeSet attributeSet, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this(context, (i2 & 2) != 0 ? null : attributeSet, (i2 & 4) != 0 ? 0 : i);
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ GifLoadingView(Context context, AttributeSet attributeSet, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(context, (i & 2) != 0 ? null : attributeSet);
}
/* JADX INFO: finally extract failed */
private final void initialize(AttributeSet attributeSet) {
TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.a.GifLoadingView, 0, 0);
m.checkNotNullExpressionValue(obtainStyledAttributes, "context.obtainStyledAttr…ble.GifLoadingView, 0, 0)");
try {
this.isStaggered = obtainStyledAttributes.getBoolean(0, false);
obtainStyledAttributes.recycle();
setAdapter(this.loadingGifAdapter);
} catch (Throwable th) {
obtainStyledAttributes.recycle();
throw th;
}
}
public static /* synthetic */ void updateView$default(GifLoadingView gifLoadingView, int i, int i2, int i3, Object obj) {
if ((i3 & 2) != 0) {
i2 = 4;
}
gifLoadingView.updateView(i, i2);
}
public final void updateView(int i, int i2) {
int i3 = 1;
setLayoutManager(new StaggeredGridLayoutManager(i, 1));
addItemDecoration(new GridColumnSpaceItemDecoration(DimenUtils.dpToPixels(8), i));
int i4 = i2 * i;
ArrayList arrayList = new ArrayList();
if (this.isStaggered) {
arrayList.add(96);
int i5 = i4 - 1;
while (i3 < i5) {
arrayList.add(Integer.valueOf((i3 % 2 != 0 || i3 >= i) ? 160 : 96));
i3++;
}
arrayList.add(96);
} else {
for (int i6 = 0; i6 < i4; i6++) {
arrayList.add(96);
}
}
this.loadingGifAdapter.setData(arrayList);
}
}