112 lines
4.5 KiB
Java
112 lines
4.5 KiB
Java
package com.discord.utilities.mg_recycler;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import androidx.recyclerview.widget.SimpleItemAnimator;
|
|
import c.a.k.b;
|
|
import com.discord.R;
|
|
import com.discord.utilities.recycler.SelfHealingLinearLayoutManager;
|
|
import d0.z.d.m;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.subscriptions.CompositeSubscription;
|
|
/* compiled from: MGRecyclerAdapter.kt */
|
|
public abstract class MGRecyclerAdapter<D> extends RecyclerView.Adapter<MGRecyclerViewHolder<?, D>> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private final CompositeSubscription cellSubscriptions = new CompositeSubscription();
|
|
private RecyclerView recycler;
|
|
|
|
/* compiled from: MGRecyclerAdapter.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final <D, T extends MGRecyclerAdapter<D>> T configure(T t) {
|
|
m.checkNotNullParameter(t, "adapter");
|
|
try {
|
|
RecyclerView recycler = t.getRecycler();
|
|
RecyclerView.LayoutManager layoutManager = t.getRecycler().getLayoutManager();
|
|
RecyclerView.ItemAnimator itemAnimator = null;
|
|
if (!(layoutManager instanceof LinearLayoutManager)) {
|
|
layoutManager = null;
|
|
}
|
|
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
|
|
SelfHealingLinearLayoutManager selfHealingLinearLayoutManager = new SelfHealingLinearLayoutManager(t.getRecycler(), t, linearLayoutManager != null ? linearLayoutManager.getOrientation() : 1, false);
|
|
selfHealingLinearLayoutManager.setSmoothScrollbarEnabled(true);
|
|
recycler.setLayoutManager(selfHealingLinearLayoutManager);
|
|
recycler.setAdapter(t);
|
|
recycler.setHasFixedSize(true);
|
|
RecyclerView.ItemAnimator itemAnimator2 = recycler.getItemAnimator();
|
|
if (itemAnimator2 instanceof SimpleItemAnimator) {
|
|
itemAnimator = itemAnimator2;
|
|
}
|
|
SimpleItemAnimator simpleItemAnimator = (SimpleItemAnimator) itemAnimator;
|
|
if (simpleItemAnimator != null) {
|
|
simpleItemAnimator.setSupportsChangeAnimations(false);
|
|
}
|
|
return t;
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public MGRecyclerAdapter(RecyclerView recyclerView) {
|
|
m.checkNotNullParameter(recyclerView, "recycler");
|
|
this.recycler = recyclerView;
|
|
}
|
|
|
|
public static final <D, T extends MGRecyclerAdapter<D>> T configure(T t) {
|
|
return (T) Companion.configure(t);
|
|
}
|
|
|
|
public final void dispose() {
|
|
this.cellSubscriptions.b();
|
|
}
|
|
|
|
public final CompositeSubscription getCellSubscriptions() {
|
|
return this.cellSubscriptions;
|
|
}
|
|
|
|
public final Context getContext() {
|
|
Context context = getRecycler().getContext();
|
|
m.checkNotNullExpressionValue(context, "recycler.context");
|
|
return context;
|
|
}
|
|
|
|
public abstract D getItem(int i);
|
|
|
|
public RecyclerView getRecycler() {
|
|
return this.recycler;
|
|
}
|
|
|
|
@SuppressLint({"StringFormatMatches"})
|
|
public final IllegalArgumentException invalidViewTypeException(int i) {
|
|
Context context = getRecycler().getContext();
|
|
CharSequence charSequence = null;
|
|
if (context != null) {
|
|
charSequence = b.h(context, R.string.android_unknown_view_holder, new Object[]{Integer.valueOf(i)}, null, 4);
|
|
}
|
|
return new IllegalArgumentException(String.valueOf(charSequence));
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public /* bridge */ /* synthetic */ void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
|
|
onBindViewHolder((MGRecyclerViewHolder) ((MGRecyclerViewHolder) viewHolder), i);
|
|
}
|
|
|
|
public void onBindViewHolder(MGRecyclerViewHolder<?, D> mGRecyclerViewHolder, int i) {
|
|
m.checkNotNullParameter(mGRecyclerViewHolder, "holder");
|
|
mGRecyclerViewHolder.onBindViewHolder(i);
|
|
}
|
|
|
|
public void setRecycler(RecyclerView recyclerView) {
|
|
m.checkNotNullParameter(recyclerView, "<set-?>");
|
|
this.recycler = recyclerView;
|
|
}
|
|
}
|