178 lines
8.8 KiB
Java
178 lines
8.8 KiB
Java
package com.discord.widgets.chat.input.applicationcommands;
|
|
|
|
import android.view.ViewGroup;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.discord.models.commands.Application;
|
|
import com.discord.models.commands.ApplicationCommand;
|
|
import com.discord.models.commands.ApplicationCommandOption;
|
|
import com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple;
|
|
import com.discord.utilities.mg_recycler.MGRecyclerViewHolder;
|
|
import d0.t.n;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
/* compiled from: SelectedApplicationCommandAdapter.kt */
|
|
public final class SelectedApplicationCommandAdapter extends MGRecyclerAdapterSimple<SelectedApplicationCommandItem> {
|
|
private ApplicationCommand currentCommand;
|
|
private ApplicationCommandOption highlightedCommandOption;
|
|
private final Function1<ApplicationCommandOption, Unit> onClickApplicationCommandOption;
|
|
private final Map<String, Integer> paramPositions = new LinkedHashMap();
|
|
private RecyclerView.SmoothScroller scroller = new SelectedApplicationCommandAdapter$scroller$1(this, getContext());
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: kotlin.jvm.functions.Function1<? super com.discord.models.commands.ApplicationCommandOption, kotlin.Unit> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public SelectedApplicationCommandAdapter(RecyclerView recyclerView, Function1<? super ApplicationCommandOption, Unit> function1) {
|
|
super(recyclerView, false);
|
|
m.checkNotNullParameter(recyclerView, "recyclerView");
|
|
m.checkNotNullParameter(function1, "onClickApplicationCommandOption");
|
|
this.onClickApplicationCommandOption = function1;
|
|
}
|
|
|
|
public static final /* synthetic */ RecyclerView.SmoothScroller access$getScroller$p(SelectedApplicationCommandAdapter selectedApplicationCommandAdapter) {
|
|
return selectedApplicationCommandAdapter.scroller;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setScroller$p(SelectedApplicationCommandAdapter selectedApplicationCommandAdapter, RecyclerView.SmoothScroller smoothScroller) {
|
|
selectedApplicationCommandAdapter.scroller = smoothScroller;
|
|
}
|
|
|
|
private final void configureVerified() {
|
|
}
|
|
|
|
public final void clear() {
|
|
setData(n.emptyList());
|
|
this.paramPositions.clear();
|
|
this.currentCommand = null;
|
|
this.highlightedCommandOption = null;
|
|
}
|
|
|
|
public final void clearParamOptionHighlight() {
|
|
if (getItemCount() != 0) {
|
|
Map<String, Integer> map = this.paramPositions;
|
|
ApplicationCommandOption applicationCommandOption = this.highlightedCommandOption;
|
|
Integer num = map.get(applicationCommandOption != null ? applicationCommandOption.getName() : null);
|
|
if (num != null) {
|
|
int intValue = num.intValue();
|
|
getItem(intValue).setHighlighted(false);
|
|
notifyItemChanged(intValue);
|
|
}
|
|
}
|
|
}
|
|
|
|
public final Function1<ApplicationCommandOption, Unit> getOnClickApplicationCommandOption() {
|
|
return this.onClickApplicationCommandOption;
|
|
}
|
|
|
|
public final void highlightOption(ApplicationCommandOption applicationCommandOption) {
|
|
Integer num;
|
|
m.checkNotNullParameter(applicationCommandOption, "commandOption");
|
|
if (!m.areEqual(this.highlightedCommandOption, applicationCommandOption)) {
|
|
clearParamOptionHighlight();
|
|
this.highlightedCommandOption = applicationCommandOption;
|
|
if (getItemCount() != 0 && (num = this.paramPositions.get(applicationCommandOption.getName())) != null) {
|
|
int intValue = num.intValue();
|
|
this.highlightedCommandOption = applicationCommandOption;
|
|
getItem(intValue).setHighlighted(true);
|
|
notifyItemChanged(intValue);
|
|
getRecycler().post(new SelectedApplicationCommandAdapter$highlightOption$$inlined$let$lambda$1(intValue, this, applicationCommandOption));
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public MGRecyclerViewHolder<SelectedApplicationCommandAdapter, SelectedApplicationCommandItem> onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
m.checkNotNullParameter(viewGroup, "parent");
|
|
if (i == 0) {
|
|
return new SelectedAppCommandTitleAdapterItem(this);
|
|
}
|
|
if (i == 1) {
|
|
return new SelectedAppCommandOptionAdapterItem(this);
|
|
}
|
|
if (i == 2) {
|
|
return new SelectedAppCommandSectionHeadingAdapterItem(this);
|
|
}
|
|
throw invalidViewTypeException(i);
|
|
}
|
|
|
|
public final void onParamClicked(ApplicationCommandOption applicationCommandOption) {
|
|
m.checkNotNullParameter(applicationCommandOption, "option");
|
|
this.onClickApplicationCommandOption.invoke(applicationCommandOption);
|
|
}
|
|
|
|
public final void setApplicationCommand(ApplicationCommand applicationCommand, Application application) {
|
|
m.checkNotNullParameter(applicationCommand, "command");
|
|
m.checkNotNullParameter(application, "application");
|
|
ApplicationCommand applicationCommand2 = this.currentCommand;
|
|
if (!m.areEqual(applicationCommand2 != null ? applicationCommand2.getId() : null, applicationCommand.getId())) {
|
|
this.currentCommand = applicationCommand;
|
|
ArrayList arrayList = new ArrayList();
|
|
arrayList.add(new SelectedApplicationCommandItem(application, null, false, false, false, applicationCommand.getName(), null, 94, null));
|
|
List<ApplicationCommandOption> options = applicationCommand.getOptions();
|
|
ArrayList arrayList2 = new ArrayList();
|
|
for (Object obj : options) {
|
|
if (((ApplicationCommandOption) obj).getRequired()) {
|
|
arrayList2.add(obj);
|
|
}
|
|
}
|
|
int i = 0;
|
|
int i2 = 0;
|
|
for (Object obj2 : arrayList2) {
|
|
int i3 = i2 + 1;
|
|
if (i2 < 0) {
|
|
n.throwIndexOverflow();
|
|
}
|
|
ApplicationCommandOption applicationCommandOption = (ApplicationCommandOption) obj2;
|
|
this.paramPositions.put(applicationCommandOption.getName(), Integer.valueOf(arrayList.size()));
|
|
arrayList.add(new SelectedApplicationCommandItem(null, applicationCommandOption, false, false, false, null, null, 125, null));
|
|
i2 = i3;
|
|
}
|
|
List<ApplicationCommandOption> options2 = applicationCommand.getOptions();
|
|
if (!(options2 instanceof Collection) || !options2.isEmpty()) {
|
|
for (ApplicationCommandOption applicationCommandOption2 : options2) {
|
|
if ((!applicationCommandOption2.getRequired()) && (i = i + 1) < 0) {
|
|
n.throwCountOverflow();
|
|
}
|
|
}
|
|
}
|
|
if (i != 0) {
|
|
arrayList.add(new SelectedApplicationCommandItem(null, null, false, false, false, null, getRecycler().getResources().getString(2131887463), 63, null));
|
|
}
|
|
List<ApplicationCommandOption> options3 = applicationCommand.getOptions();
|
|
ArrayList<ApplicationCommandOption> arrayList3 = new ArrayList();
|
|
for (Object obj3 : options3) {
|
|
if (!((ApplicationCommandOption) obj3).getRequired()) {
|
|
arrayList3.add(obj3);
|
|
}
|
|
}
|
|
for (ApplicationCommandOption applicationCommandOption3 : arrayList3) {
|
|
this.paramPositions.put(applicationCommandOption3.getName(), Integer.valueOf(arrayList.size()));
|
|
arrayList.add(new SelectedApplicationCommandItem(null, applicationCommandOption3, false, false, false, null, null, 125, null));
|
|
}
|
|
setData(arrayList);
|
|
}
|
|
}
|
|
|
|
public final void setVerified(Map<ApplicationCommandOption, Boolean> map, Set<ApplicationCommandOption> set) {
|
|
m.checkNotNullParameter(map, "verifiedInputs");
|
|
m.checkNotNullParameter(set, "showOptionErrorSet");
|
|
if (getItemCount() != 0) {
|
|
for (ApplicationCommandOption applicationCommandOption : map.keySet()) {
|
|
Integer num = this.paramPositions.get(applicationCommandOption.getName());
|
|
if (num != null) {
|
|
int intValue = num.intValue();
|
|
getItem(intValue).setCompleted(m.areEqual(map.get(applicationCommandOption), Boolean.TRUE));
|
|
getItem(intValue).setError(set.contains(applicationCommandOption));
|
|
}
|
|
}
|
|
configureVerified();
|
|
}
|
|
}
|
|
}
|