mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-18 11:57:18 +01:00
179 lines
6.3 KiB
Java
179 lines
6.3 KiB
Java
package com.google.android.material.internal;
|
|
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.annotation.IdRes;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.UiThread;
|
|
import com.google.android.material.internal.MaterialCheckable;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
|
|
@UiThread
|
|
/* loaded from: classes7.dex */
|
|
public class CheckableGroup<T extends MaterialCheckable<T>> {
|
|
private final Map<Integer, T> checkables = new HashMap();
|
|
private final Set<Integer> checkedIds = new HashSet();
|
|
private OnCheckedStateChangeListener onCheckedStateChangeListener;
|
|
private boolean selectionRequired;
|
|
private boolean singleSelection;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public interface OnCheckedStateChangeListener {
|
|
void onCheckedStateChanged(@NonNull Set<Integer> set);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public boolean checkInternal(@NonNull MaterialCheckable<T> materialCheckable) {
|
|
int id = materialCheckable.getId();
|
|
if (this.checkedIds.contains(Integer.valueOf(id))) {
|
|
return false;
|
|
}
|
|
T t = this.checkables.get(Integer.valueOf(getSingleCheckedId()));
|
|
if (t != null) {
|
|
uncheckInternal(t, false);
|
|
}
|
|
boolean add = this.checkedIds.add(Integer.valueOf(id));
|
|
if (!materialCheckable.isChecked()) {
|
|
materialCheckable.setChecked(true);
|
|
}
|
|
return add;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void onCheckedStateChanged() {
|
|
OnCheckedStateChangeListener onCheckedStateChangeListener = this.onCheckedStateChangeListener;
|
|
if (onCheckedStateChangeListener != null) {
|
|
onCheckedStateChangeListener.onCheckedStateChanged(getCheckedIds());
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public boolean uncheckInternal(@NonNull MaterialCheckable<T> materialCheckable, boolean z) {
|
|
int id = materialCheckable.getId();
|
|
if (!this.checkedIds.contains(Integer.valueOf(id))) {
|
|
return false;
|
|
}
|
|
if (z && this.checkedIds.size() == 1 && this.checkedIds.contains(Integer.valueOf(id))) {
|
|
materialCheckable.setChecked(true);
|
|
return false;
|
|
}
|
|
boolean remove = this.checkedIds.remove(Integer.valueOf(id));
|
|
if (materialCheckable.isChecked()) {
|
|
materialCheckable.setChecked(false);
|
|
}
|
|
return remove;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public void addCheckable(T t) {
|
|
this.checkables.put(Integer.valueOf(t.getId()), t);
|
|
if (t.isChecked()) {
|
|
checkInternal(t);
|
|
}
|
|
t.setInternalOnCheckedChangeListener(new MaterialCheckable.OnCheckedChangeListener<T>() { // from class: com.google.android.material.internal.CheckableGroup.1
|
|
@Override // com.google.android.material.internal.MaterialCheckable.OnCheckedChangeListener
|
|
public void onCheckedChanged(T t2, boolean z) {
|
|
CheckableGroup checkableGroup = CheckableGroup.this;
|
|
if (z) {
|
|
if (!checkableGroup.checkInternal(t2)) {
|
|
return;
|
|
}
|
|
} else if (!checkableGroup.uncheckInternal(t2, checkableGroup.selectionRequired)) {
|
|
return;
|
|
}
|
|
CheckableGroup.this.onCheckedStateChanged();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void check(@IdRes int i) {
|
|
T t = this.checkables.get(Integer.valueOf(i));
|
|
if (t != null && checkInternal(t)) {
|
|
onCheckedStateChanged();
|
|
}
|
|
}
|
|
|
|
public void clearCheck() {
|
|
boolean isEmpty = this.checkedIds.isEmpty();
|
|
Iterator<T> it2 = this.checkables.values().iterator();
|
|
while (it2.hasNext()) {
|
|
uncheckInternal(it2.next(), false);
|
|
}
|
|
if (isEmpty) {
|
|
return;
|
|
}
|
|
onCheckedStateChanged();
|
|
}
|
|
|
|
@NonNull
|
|
public Set<Integer> getCheckedIds() {
|
|
return new HashSet(this.checkedIds);
|
|
}
|
|
|
|
@NonNull
|
|
public List<Integer> getCheckedIdsSortedByChildOrder(@NonNull ViewGroup viewGroup) {
|
|
Set<Integer> checkedIds = getCheckedIds();
|
|
ArrayList arrayList = new ArrayList();
|
|
for (int i = 0; i < viewGroup.getChildCount(); i++) {
|
|
View childAt = viewGroup.getChildAt(i);
|
|
if ((childAt instanceof MaterialCheckable) && checkedIds.contains(Integer.valueOf(childAt.getId()))) {
|
|
arrayList.add(Integer.valueOf(childAt.getId()));
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
@IdRes
|
|
public int getSingleCheckedId() {
|
|
if (!this.singleSelection || this.checkedIds.isEmpty()) {
|
|
return -1;
|
|
}
|
|
return this.checkedIds.iterator().next().intValue();
|
|
}
|
|
|
|
public boolean isSelectionRequired() {
|
|
return this.selectionRequired;
|
|
}
|
|
|
|
public boolean isSingleSelection() {
|
|
return this.singleSelection;
|
|
}
|
|
|
|
public void removeCheckable(T t) {
|
|
t.setInternalOnCheckedChangeListener(null);
|
|
this.checkables.remove(Integer.valueOf(t.getId()));
|
|
this.checkedIds.remove(Integer.valueOf(t.getId()));
|
|
}
|
|
|
|
public void setOnCheckedStateChangeListener(@Nullable OnCheckedStateChangeListener onCheckedStateChangeListener) {
|
|
this.onCheckedStateChangeListener = onCheckedStateChangeListener;
|
|
}
|
|
|
|
public void setSelectionRequired(boolean z) {
|
|
this.selectionRequired = z;
|
|
}
|
|
|
|
public void setSingleSelection(boolean z) {
|
|
if (this.singleSelection != z) {
|
|
this.singleSelection = z;
|
|
clearCheck();
|
|
}
|
|
}
|
|
|
|
public void uncheck(@IdRes int i) {
|
|
T t = this.checkables.get(Integer.valueOf(i));
|
|
if (t != null && uncheckInternal(t, this.selectionRequired)) {
|
|
onCheckedStateChanged();
|
|
}
|
|
}
|
|
}
|