148 lines
4.5 KiB
Java
148 lines
4.5 KiB
Java
package com.lytefast.flexinput.utils;
|
|
|
|
import androidx.collection.ArrayMap;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import c.b.a.g.b;
|
|
import d0.z.d.e0;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.Objects;
|
|
/* compiled from: SelectionCoordinator.kt */
|
|
public class SelectionCoordinator<I, T extends I> {
|
|
public RecyclerView.Adapter<?> a;
|
|
public final ArrayMap<T, Integer> b;
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public ItemSelectionListener<? super I> f2389c;
|
|
|
|
/* compiled from: SelectionCoordinator.kt */
|
|
public interface ItemSelectionListener<I> {
|
|
void onItemSelected(I i);
|
|
|
|
void onItemUnselected(I i);
|
|
|
|
void unregister();
|
|
}
|
|
|
|
/* compiled from: SelectionCoordinator.kt */
|
|
public static final class RestorationException extends Exception {
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public RestorationException(String str) {
|
|
super(str);
|
|
m.checkNotNullParameter(str, "msg");
|
|
}
|
|
}
|
|
|
|
/* compiled from: SelectionCoordinator.kt */
|
|
public static final class a<T> {
|
|
public final T a;
|
|
public final boolean b;
|
|
|
|
public a(T t, boolean z2) {
|
|
this.a = t;
|
|
this.b = z2;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof a)) {
|
|
return false;
|
|
}
|
|
a aVar = (a) obj;
|
|
return m.areEqual(this.a, aVar.a) && this.b == aVar.b;
|
|
}
|
|
|
|
public int hashCode() {
|
|
T t = this.a;
|
|
int hashCode = (t != null ? t.hashCode() : 0) * 31;
|
|
boolean z2 = this.b;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i = z2 ? 1 : 0;
|
|
int i2 = z2 ? 1 : 0;
|
|
int i3 = z2 ? 1 : 0;
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = c.d.b.a.a.L("SelectionEvent(item=");
|
|
L.append((Object) this.a);
|
|
L.append(", isSelected=");
|
|
return c.d.b.a.a.G(L, this.b, ")");
|
|
}
|
|
}
|
|
|
|
public SelectionCoordinator() {
|
|
this(null, null, 3);
|
|
}
|
|
|
|
public SelectionCoordinator(ArrayMap arrayMap, ItemSelectionListener itemSelectionListener, int i) {
|
|
b bVar = null;
|
|
ArrayMap<T, Integer> arrayMap2 = (i & 1) != 0 ? new ArrayMap<>(4) : null;
|
|
bVar = (i & 2) != 0 ? new b() : bVar;
|
|
m.checkNotNullParameter(arrayMap2, "selectedItemPositionMap");
|
|
m.checkNotNullParameter(bVar, "itemSelectionListener");
|
|
this.b = arrayMap2;
|
|
this.f2389c = bVar;
|
|
}
|
|
|
|
public final boolean a(T t, int i) {
|
|
Integer num = this.b.get(t);
|
|
if (num == null) {
|
|
return false;
|
|
}
|
|
if (i == num.intValue()) {
|
|
return true;
|
|
}
|
|
this.b.put(t, Integer.valueOf(i));
|
|
return true;
|
|
}
|
|
|
|
public final void b(ArrayList<? extends I> arrayList) throws RestorationException {
|
|
m.checkNotNullParameter(arrayList, "selectedItems");
|
|
if (this.a == null) {
|
|
Iterator<? extends I> it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
Object next = it.next();
|
|
if (!(next instanceof Object)) {
|
|
next = null;
|
|
}
|
|
if (next != null) {
|
|
((ArrayMap<T, Integer>) this.b).put(next, -1);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
throw new RestorationException("cannot restoreSelections after adapter set: prevents mismatches");
|
|
}
|
|
|
|
public final void c(T t, int i) {
|
|
this.b.put(t, Integer.valueOf(i));
|
|
RecyclerView.Adapter<?> adapter = this.a;
|
|
if (adapter != null) {
|
|
adapter.notifyItemChanged(i, new a(t, true));
|
|
}
|
|
this.f2389c.onItemSelected(t);
|
|
}
|
|
|
|
public final boolean d(I i) {
|
|
ArrayMap<T, Integer> arrayMap = this.b;
|
|
Objects.requireNonNull(arrayMap, "null cannot be cast to non-null type kotlin.collections.MutableMap<K, V>");
|
|
Integer num = (Integer) e0.asMutableMap(arrayMap).remove(i);
|
|
if (num == null) {
|
|
return false;
|
|
}
|
|
int intValue = num.intValue();
|
|
RecyclerView.Adapter<?> adapter = this.a;
|
|
if (adapter != null) {
|
|
adapter.notifyItemChanged(intValue, new a(i, false));
|
|
}
|
|
this.f2389c.onItemUnselected(i);
|
|
return true;
|
|
}
|
|
}
|