143 lines
6.7 KiB
Java
143 lines
6.7 KiB
Java
package com.discord.utilities.mg_recycler;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.utilities.mg_recycler.MGRecyclerDataPayload;
|
|
import com.discord.utilities.recycler.DiffCreator;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import d0.o;
|
|
import d0.t.g0;
|
|
import d0.t.n;
|
|
import d0.z.d.m;
|
|
import j0.p.a;
|
|
import java.util.List;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function2;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.Subscription;
|
|
/* compiled from: MGRecyclerAdapterSimple.kt */
|
|
public abstract class MGRecyclerAdapterSimple<D extends MGRecyclerDataPayload> extends MGRecyclerAdapter<D> {
|
|
private final boolean deferredDiffs;
|
|
private final DiffCreator<List<D>, MGRecyclerViewHolder<MGRecyclerAdapterSimple<D>, D>> diffCreator;
|
|
private Subscription diffingSubscription;
|
|
private List<? extends D> internalData;
|
|
private Function2<? super List<? extends D>, ? super List<? extends D>, Unit> onUpdated;
|
|
|
|
public MGRecyclerAdapterSimple(RecyclerView recyclerView) {
|
|
this(recyclerView, false, 2, null);
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public MGRecyclerAdapterSimple(RecyclerView recyclerView, boolean z2) {
|
|
super(recyclerView);
|
|
m.checkNotNullParameter(recyclerView, "recycler");
|
|
this.deferredDiffs = z2;
|
|
this.internalData = n.emptyList();
|
|
this.diffCreator = new DiffCreator<>(null);
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ MGRecyclerAdapterSimple(RecyclerView recyclerView, boolean z2, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(recyclerView, (i & 2) != 0 ? true : z2);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$dispatchUpdates(MGRecyclerAdapterSimple mGRecyclerAdapterSimple, DiffUtil.DiffResult diffResult, List list, List list2) {
|
|
mGRecyclerAdapterSimple.dispatchUpdates(diffResult, list, list2);
|
|
}
|
|
|
|
public static final /* synthetic */ DiffCreator access$getDiffCreator$p(MGRecyclerAdapterSimple mGRecyclerAdapterSimple) {
|
|
return mGRecyclerAdapterSimple.diffCreator;
|
|
}
|
|
|
|
public static final /* synthetic */ Subscription access$getDiffingSubscription$p(MGRecyclerAdapterSimple mGRecyclerAdapterSimple) {
|
|
return mGRecyclerAdapterSimple.diffingSubscription;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleError(MGRecyclerAdapterSimple mGRecyclerAdapterSimple, Throwable th) {
|
|
mGRecyclerAdapterSimple.handleError(th);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setDiffingSubscription$p(MGRecyclerAdapterSimple mGRecyclerAdapterSimple, Subscription subscription) {
|
|
mGRecyclerAdapterSimple.diffingSubscription = subscription;
|
|
}
|
|
|
|
@SuppressLint({"NotifyDataSetChanged"})
|
|
private final void dispatchUpdates(DiffUtil.DiffResult diffResult, List<? extends D> list, List<? extends D> list2) {
|
|
this.internalData = list2;
|
|
if (diffResult != null) {
|
|
diffResult.dispatchUpdatesTo(this);
|
|
} else {
|
|
notifyDataSetChanged();
|
|
}
|
|
Function2<? super List<? extends D>, ? super List<? extends D>, Unit> function2 = this.onUpdated;
|
|
if (function2 != null) {
|
|
function2.invoke(list, list2);
|
|
}
|
|
}
|
|
|
|
private final void handleError(Throwable th) {
|
|
AppLog.g.e("Unable to configure recycler.", th, g0.mapOf(o.to("adapterClass", getClass().getSimpleName())));
|
|
}
|
|
|
|
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: java.util.List<? extends D extends com.discord.utilities.mg_recycler.MGRecyclerDataPayload>, java.util.List<D extends com.discord.utilities.mg_recycler.MGRecyclerDataPayload> */
|
|
public final List<D> getInternalData() {
|
|
return (List<? extends D>) this.internalData;
|
|
}
|
|
|
|
@Override // com.discord.utilities.mg_recycler.MGRecyclerAdapter
|
|
public D getItem(int i) {
|
|
return (D) ((MGRecyclerDataPayload) this.internalData.get(i));
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public int getItemCount() {
|
|
return this.internalData.size();
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public int getItemViewType(int i) {
|
|
return getItem(i).getType();
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r1v2, resolved type: com.discord.utilities.recycler.DiffCreator<java.util.List<D extends com.discord.utilities.mg_recycler.MGRecyclerDataPayload>, com.discord.utilities.mg_recycler.MGRecyclerViewHolder<com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple<D extends com.discord.utilities.mg_recycler.MGRecyclerDataPayload>, D extends com.discord.utilities.mg_recycler.MGRecyclerDataPayload>> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public void setData(List<? extends D> list) {
|
|
m.checkNotNullParameter(list, "data");
|
|
unsubscribeFromUpdates();
|
|
List<? extends D> list2 = this.internalData;
|
|
if (list2.isEmpty()) {
|
|
dispatchUpdates(null, list2, list);
|
|
} else if (this.deferredDiffs) {
|
|
Observable X = Observable.C(new MGRecyclerAdapterSimple$setData$1(this, list2, list)).X(a.a());
|
|
m.checkNotNullExpressionValue(X, "Observable\n .…Schedulers.computation())");
|
|
Observable ui = ObservableExtensionsKt.ui(X);
|
|
Class<?> cls = getClass();
|
|
MGRecyclerAdapterSimple$setData$2 mGRecyclerAdapterSimple$setData$2 = new MGRecyclerAdapterSimple$setData$2(this, list2, list);
|
|
ObservableExtensionsKt.appSubscribe$default(ui, cls, (Context) null, new MGRecyclerAdapterSimple$setData$4(this), new MGRecyclerAdapterSimple$setData$3(this), (Function0) null, (Function0) null, mGRecyclerAdapterSimple$setData$2, 50, (Object) null);
|
|
} else {
|
|
try {
|
|
dispatchUpdates(this.diffCreator.calculateDiffResult(list2, list), list2, list);
|
|
} catch (Throwable th) {
|
|
handleError(th);
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void setOnUpdated(Function2<? super List<? extends D>, ? super List<? extends D>, Unit> function2) {
|
|
m.checkNotNullParameter(function2, "onUpdated");
|
|
this.onUpdated = function2;
|
|
}
|
|
|
|
public final void unsubscribeFromUpdates() {
|
|
Subscription subscription = this.diffingSubscription;
|
|
if (subscription != null) {
|
|
subscription.unsubscribe();
|
|
}
|
|
this.diffingSubscription = null;
|
|
}
|
|
}
|