discord-jadx/app/src/main/java/com/lytefast/flexinput/utils/SelectionAggregator.java

270 lines
11 KiB
Java

package com.lytefast.flexinput.utils;
import android.os.Parcelable;
import android.util.Log;
import androidx.recyclerview.widget.RecyclerView;
import com.lytefast.flexinput.adapters.AttachmentPreviewAdapter;
import com.lytefast.flexinput.model.Attachment;
import com.lytefast.flexinput.utils.SelectionCoordinator;
import d0.z.d.e0;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Objects;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: SelectionAggregator.kt */
public class SelectionAggregator<T extends Attachment<? extends Object>> {
public static final Companion Companion = new Companion(null);
private static final String TAG;
private final AttachmentPreviewAdapter<T> adapter;
private final ArrayList<T> attachments;
private final ArrayList<SelectionCoordinator<T, ?>> childSelectionCoordinators;
private ArrayList<SelectionCoordinator.ItemSelectionListener<T>> itemSelectionListeners;
/* compiled from: SelectionAggregator.kt */
public static final class Companion {
public Companion() {
}
public Companion(DefaultConstructorMarker defaultConstructorMarker) {
}
}
/* compiled from: SelectionAggregator.kt */
public static final class a implements SelectionCoordinator.ItemSelectionListener<T> {
public final /* synthetic */ SelectionAggregator a;
public final /* synthetic */ SelectionCoordinator b;
public a(SelectionAggregator selectionAggregator, SelectionCoordinator selectionCoordinator) {
this.a = selectionAggregator;
this.b = selectionCoordinator;
}
@Override // com.lytefast.flexinput.utils.SelectionCoordinator.ItemSelectionListener
public void onItemSelected(Object obj) {
Attachment attachment = (Attachment) obj;
m.checkNotNullParameter(attachment, "item");
SelectionAggregator.access$addItem(this.a, attachment);
}
@Override // com.lytefast.flexinput.utils.SelectionCoordinator.ItemSelectionListener
public void onItemUnselected(Object obj) {
Attachment attachment = (Attachment) obj;
m.checkNotNullParameter(attachment, "item");
SelectionAggregator.access$removeItem(this.a, attachment);
}
@Override // com.lytefast.flexinput.utils.SelectionCoordinator.ItemSelectionListener
public void unregister() {
this.a.getChildSelectionCoordinators().remove(this.b);
}
}
static {
String canonicalName = SelectionAggregator.class.getCanonicalName();
m.checkNotNull(canonicalName);
TAG = canonicalName;
}
public SelectionAggregator(AttachmentPreviewAdapter<T> attachmentPreviewAdapter) {
this(attachmentPreviewAdapter, null, null, null, 14, null);
}
public SelectionAggregator(AttachmentPreviewAdapter<T> attachmentPreviewAdapter, ArrayList<T> arrayList) {
this(attachmentPreviewAdapter, arrayList, null, null, 12, null);
}
public SelectionAggregator(AttachmentPreviewAdapter<T> attachmentPreviewAdapter, ArrayList<T> arrayList, ArrayList<SelectionCoordinator<T, ?>> arrayList2) {
this(attachmentPreviewAdapter, arrayList, arrayList2, null, 8, null);
}
public SelectionAggregator(AttachmentPreviewAdapter<T> attachmentPreviewAdapter, ArrayList<T> arrayList, ArrayList<SelectionCoordinator<T, ?>> arrayList2, ArrayList<SelectionCoordinator.ItemSelectionListener<T>> arrayList3) {
m.checkNotNullParameter(attachmentPreviewAdapter, "adapter");
m.checkNotNullParameter(arrayList, "attachments");
m.checkNotNullParameter(arrayList2, "childSelectionCoordinators");
m.checkNotNullParameter(arrayList3, "itemSelectionListeners");
this.adapter = attachmentPreviewAdapter;
this.attachments = arrayList;
this.childSelectionCoordinators = arrayList2;
this.itemSelectionListeners = arrayList3;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ SelectionAggregator(AttachmentPreviewAdapter attachmentPreviewAdapter, ArrayList arrayList, ArrayList arrayList2, ArrayList arrayList3, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(attachmentPreviewAdapter, (i & 2) != 0 ? new ArrayList() : arrayList, (i & 4) != 0 ? new ArrayList(4) : arrayList2, (i & 8) != 0 ? new ArrayList(4) : arrayList3);
}
public static final /* synthetic */ void access$addItem(SelectionAggregator selectionAggregator, Attachment attachment) {
selectionAggregator.addItem(attachment);
}
public static final /* synthetic */ String access$getTAG$cp() {
return TAG;
}
public static final /* synthetic */ boolean access$removeItem(SelectionAggregator selectionAggregator, Attachment attachment) {
return selectionAggregator.removeItem(attachment);
}
private final void addItem(T t) {
if (!this.attachments.contains(t)) {
this.attachments.add(t);
this.adapter.notifyItemInserted(this.attachments.size() - 1);
Iterator<T> it = this.itemSelectionListeners.iterator();
while (it.hasNext()) {
((SelectionCoordinator.ItemSelectionListener) it.next()).onItemSelected(t);
}
}
}
private final boolean removeItem(T t) {
int indexOf = this.attachments.indexOf(t);
boolean remove = this.attachments.remove(t);
if (remove) {
this.adapter.notifyItemRemoved(indexOf);
}
Iterator<T> it = this.itemSelectionListeners.iterator();
while (it.hasNext()) {
((SelectionCoordinator.ItemSelectionListener) it.next()).onItemUnselected(t);
}
return remove;
}
public final SelectionAggregator<T> addItemSelectionListener(SelectionCoordinator.ItemSelectionListener<? super T> itemSelectionListener) {
m.checkNotNullParameter(itemSelectionListener, "itemSelectionListener");
if (!this.itemSelectionListeners.contains(itemSelectionListener)) {
this.itemSelectionListeners.add(itemSelectionListener);
}
return this;
}
public final void clear() {
this.attachments.clear();
Iterator<T> it = this.childSelectionCoordinators.iterator();
while (it.hasNext()) {
SelectionCoordinator selectionCoordinator = (SelectionCoordinator) it.next();
Objects.requireNonNull(selectionCoordinator);
ArrayList arrayList = new ArrayList(selectionCoordinator.b.values());
selectionCoordinator.b.clear();
RecyclerView.Adapter<?> adapter = selectionCoordinator.a;
if (adapter != null) {
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
Integer num = (Integer) it2.next();
m.checkNotNullExpressionValue(num, "position");
adapter.notifyItemChanged(num.intValue());
}
}
}
}
public final T get(int i) {
T t = this.attachments.get(i);
m.checkNotNullExpressionValue(t, "attachments[position]");
return t;
}
public final AttachmentPreviewAdapter<T> getAdapter() {
return this.adapter;
}
public final ArrayList<T> getAttachments() {
return this.attachments;
}
public final ArrayList<SelectionCoordinator<T, ?>> getChildSelectionCoordinators() {
return this.childSelectionCoordinators;
}
public final ArrayList<SelectionCoordinator.ItemSelectionListener<T>> getItemSelectionListeners() {
return this.itemSelectionListeners;
}
public final int getSize() {
return this.attachments.size();
}
public final SelectionAggregator<T> initFrom(SelectionAggregator<T> selectionAggregator) {
if (selectionAggregator != null) {
this.attachments.addAll(selectionAggregator.attachments);
Iterator<SelectionCoordinator<T, ?>> it = selectionAggregator.childSelectionCoordinators.iterator();
while (it.hasNext()) {
SelectionCoordinator<T, ?> next = it.next();
m.checkNotNullExpressionValue(next, "coordinator");
registerSelectionCoordinatorInternal(next);
}
this.itemSelectionListeners.addAll(selectionAggregator.itemSelectionListeners);
}
return this;
}
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: com.lytefast.flexinput.utils.SelectionAggregator<T extends com.lytefast.flexinput.model.Attachment<? extends java.lang.Object>> */
/* JADX WARN: Multi-variable type inference failed */
public final SelectionAggregator<T> initFrom(ArrayList<? super Parcelable> arrayList) {
m.checkNotNullParameter(arrayList, "savedAttachments");
ArrayList<Attachment> arrayList2 = new ArrayList();
for (Object obj : arrayList) {
if (!(obj instanceof Attachment)) {
obj = null;
}
Attachment attachment = (Attachment) obj;
if (attachment != null) {
arrayList2.add(attachment);
}
}
for (Attachment attachment2 : arrayList2) {
toggleItemInternal(attachment2);
}
return this;
}
public final void registerSelectionCoordinator(SelectionCoordinator<T, ?> selectionCoordinator) {
m.checkNotNullParameter(selectionCoordinator, "selectionCoordinator");
registerSelectionCoordinatorInternal(selectionCoordinator);
try {
selectionCoordinator.b(this.attachments);
} catch (SelectionCoordinator.RestorationException e) {
Log.d(TAG, "selections could not be synced", e);
}
}
public void registerSelectionCoordinatorInternal(SelectionCoordinator<T, ?> selectionCoordinator) {
m.checkNotNullParameter(selectionCoordinator, "selectionCoordinator");
a aVar = new a(this, selectionCoordinator);
Objects.requireNonNull(selectionCoordinator);
m.checkNotNullParameter(aVar, "<set-?>");
selectionCoordinator.f2389c = aVar;
this.childSelectionCoordinators.add(selectionCoordinator);
}
public final void removeItemSelectionListener(SelectionCoordinator.ItemSelectionListener<?> itemSelectionListener) {
m.checkNotNullParameter(itemSelectionListener, "itemSelectionListener");
ArrayList<SelectionCoordinator.ItemSelectionListener<T>> arrayList = this.itemSelectionListeners;
Objects.requireNonNull(arrayList, "null cannot be cast to non-null type kotlin.collections.MutableCollection<T>");
e0.asMutableCollection(arrayList).remove(itemSelectionListener);
}
public final void setItemSelectionListeners(ArrayList<SelectionCoordinator.ItemSelectionListener<T>> arrayList) {
m.checkNotNullParameter(arrayList, "<set-?>");
this.itemSelectionListeners = arrayList;
}
public final boolean toggleItemInternal(T t) {
m.checkNotNullParameter(t, "item");
boolean removeItem = removeItem(t);
if (!removeItem) {
addItem(t);
}
return removeItem;
}
public final void unselectItem(T t) {
m.checkNotNullParameter(t, "item");
Iterator<T> it = this.childSelectionCoordinators.iterator();
while (it.hasNext()) {
((SelectionCoordinator) it.next()).d(t);
}
removeItem(t);
}
}