292 lines
13 KiB
Java
292 lines
13 KiB
Java
package com.discord.widgets.botuikit;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Parcel;
|
|
import android.os.Parcelable;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
import androidx.annotation.LayoutRes;
|
|
import androidx.fragment.app.Fragment;
|
|
import b.a.d.j;
|
|
import b.a.k.b;
|
|
import b.d.b.a.a;
|
|
import com.discord.R;
|
|
import com.discord.api.botuikit.ActionRowComponent;
|
|
import com.discord.api.botuikit.TextComponent;
|
|
import com.discord.api.botuikit.TextStyle;
|
|
import com.discord.api.interaction.InteractionModalCreate;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.BotUikitTextInputBinding;
|
|
import com.discord.databinding.ViewInteractionModalBinding;
|
|
import com.discord.stores.StoreApplicationCommandsKt;
|
|
import com.discord.stores.StoreApplicationInteractions;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.dimen.DimenUtils;
|
|
import com.discord.utilities.icon.IconUtils;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.facebook.drawee.view.SimpleDraweeView;
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import d0.g;
|
|
import d0.t.o;
|
|
import d0.t.t;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import kotlin.Lazy;
|
|
import kotlin.Pair;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: ModalComponent.kt */
|
|
/* loaded from: classes2.dex */
|
|
public final class ModalComponent extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.b0(ModalComponent.class, "binding", "getBinding()Lcom/discord/databinding/ViewInteractionModalBinding;", 0)};
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String EXTRA_OPTIONS = "extra_options";
|
|
private final Lazy args$delegate;
|
|
private final FragmentViewBindingDelegate binding$delegate;
|
|
private String sentNonce;
|
|
|
|
/* compiled from: ModalComponent.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final void show(Context context, Options options) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(options, "options");
|
|
Intent intent = new Intent();
|
|
intent.putExtra("extra_options", options);
|
|
j.d(context, ModalComponent.class, intent);
|
|
}
|
|
}
|
|
|
|
/* compiled from: ModalComponent.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Options implements Parcelable {
|
|
public static final Parcelable.Creator<Options> CREATOR = new Creator();
|
|
private final InteractionModalCreate modal;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public static class Creator implements Parcelable.Creator<Options> {
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public final Options createFromParcel(Parcel parcel) {
|
|
m.checkNotNullParameter(parcel, "in");
|
|
return new Options((InteractionModalCreate) parcel.readSerializable());
|
|
}
|
|
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // android.os.Parcelable.Creator
|
|
public final Options[] newArray(int i) {
|
|
return new Options[i];
|
|
}
|
|
}
|
|
|
|
public Options(InteractionModalCreate interactionModalCreate) {
|
|
m.checkNotNullParameter(interactionModalCreate, "modal");
|
|
this.modal = interactionModalCreate;
|
|
}
|
|
|
|
public static /* synthetic */ Options copy$default(Options options, InteractionModalCreate interactionModalCreate, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
interactionModalCreate = options.modal;
|
|
}
|
|
return options.copy(interactionModalCreate);
|
|
}
|
|
|
|
public final InteractionModalCreate component1() {
|
|
return this.modal;
|
|
}
|
|
|
|
public final Options copy(InteractionModalCreate interactionModalCreate) {
|
|
m.checkNotNullParameter(interactionModalCreate, "modal");
|
|
return new Options(interactionModalCreate);
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public int describeContents() {
|
|
return 0;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Options) && m.areEqual(this.modal, ((Options) obj).modal);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final InteractionModalCreate getModal() {
|
|
return this.modal;
|
|
}
|
|
|
|
public int hashCode() {
|
|
InteractionModalCreate interactionModalCreate = this.modal;
|
|
if (interactionModalCreate != null) {
|
|
return interactionModalCreate.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder R = a.R("Options(modal=");
|
|
R.append(this.modal);
|
|
R.append(")");
|
|
return R.toString();
|
|
}
|
|
|
|
@Override // android.os.Parcelable
|
|
public void writeToParcel(Parcel parcel, int i) {
|
|
m.checkNotNullParameter(parcel, "parcel");
|
|
parcel.writeSerializable(this.modal);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
|
|
static {
|
|
StoreApplicationInteractions.SentInteractionState.values();
|
|
int[] iArr = new int[3];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
iArr[StoreApplicationInteractions.SentInteractionState.SUCCESS.ordinal()] = 1;
|
|
iArr[StoreApplicationInteractions.SentInteractionState.FAILURE.ordinal()] = 2;
|
|
}
|
|
}
|
|
|
|
public ModalComponent() {
|
|
this(0, 1, null);
|
|
}
|
|
|
|
public ModalComponent(@LayoutRes int i) {
|
|
super(i);
|
|
this.binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, ModalComponent$binding$2.INSTANCE, null, 2, null);
|
|
this.args$delegate = g.lazy(new ModalComponent$$special$$inlined$args$1(this, "extra_options"));
|
|
}
|
|
|
|
public /* synthetic */ ModalComponent(int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this((i2 & 1) != 0 ? R.layout.view_interaction_modal : i);
|
|
}
|
|
|
|
public static final /* synthetic */ ViewInteractionModalBinding access$getBinding$p(ModalComponent modalComponent) {
|
|
return modalComponent.getBinding();
|
|
}
|
|
|
|
public static final /* synthetic */ String access$getSentNonce$p(ModalComponent modalComponent) {
|
|
return modalComponent.sentNonce;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setSentNonce$p(ModalComponent modalComponent, String str) {
|
|
modalComponent.sentNonce = str;
|
|
}
|
|
|
|
private final ViewInteractionModalBinding getBinding() {
|
|
return (ViewInteractionModalBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
public final Options getArgs() {
|
|
return (Options) this.args$delegate.getValue();
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
TextView textView = getBinding().g;
|
|
m.checkNotNullExpressionValue(textView, "binding.title");
|
|
textView.setText(getArgs().getModal().e());
|
|
SimpleDraweeView simpleDraweeView = getBinding().e;
|
|
m.checkNotNullExpressionValue(simpleDraweeView, "binding.icon");
|
|
simpleDraweeView.setContentDescription(getArgs().getModal().a().d());
|
|
SimpleDraweeView simpleDraweeView2 = getBinding().e;
|
|
m.checkNotNullExpressionValue(simpleDraweeView2, "binding.icon");
|
|
IconUtils.setApplicationIcon(simpleDraweeView2, StoreApplicationCommandsKt.toDomainApplication(getArgs().getModal().a()));
|
|
TextView textView2 = getBinding().h;
|
|
m.checkNotNullExpressionValue(textView2, "binding.warning");
|
|
b.n(textView2, R.string.interaction_form_submission_application, new Object[]{getArgs().getModal().a().d()}, null, 4);
|
|
List<ActionRowComponent> filterIsInstance = t.filterIsInstance(getArgs().getModal().b(), ActionRowComponent.class);
|
|
ArrayList arrayList = new ArrayList();
|
|
for (ActionRowComponent actionRowComponent : filterIsInstance) {
|
|
Object orNull = u.getOrNull(actionRowComponent.b(), 0);
|
|
if (!(orNull instanceof TextComponent)) {
|
|
orNull = null;
|
|
}
|
|
TextComponent textComponent = (TextComponent) orNull;
|
|
if (textComponent != null) {
|
|
arrayList.add(textComponent);
|
|
}
|
|
}
|
|
ArrayList arrayList2 = new ArrayList(o.collectionSizeOrDefault(arrayList, 10));
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
TextComponent textComponent2 = (TextComponent) it.next();
|
|
View inflate = LayoutInflater.from(requireContext()).inflate(R.layout.bot_uikit_text_input, (ViewGroup) null, false);
|
|
int i = R.id.edit_text;
|
|
TextInputEditText textInputEditText = (TextInputEditText) inflate.findViewById(R.id.edit_text);
|
|
if (textInputEditText != null) {
|
|
i = R.id.label;
|
|
TextView textView3 = (TextView) inflate.findViewById(R.id.label);
|
|
if (textView3 != null) {
|
|
i = R.id.layout;
|
|
TextInputLayout textInputLayout = (TextInputLayout) inflate.findViewById(R.id.layout);
|
|
if (textInputLayout != null) {
|
|
LinearLayout linearLayout = (LinearLayout) inflate;
|
|
BotUikitTextInputBinding botUikitTextInputBinding = new BotUikitTextInputBinding(linearLayout, textInputEditText, textView3, textInputLayout);
|
|
m.checkNotNullExpressionValue(botUikitTextInputBinding, "BotUikitTextInputBinding…r.from(requireContext()))");
|
|
m.checkNotNullExpressionValue(textView3, "textInput.label");
|
|
textView3.setText(textComponent2.b());
|
|
m.checkNotNullExpressionValue(textInputLayout, "textInput.layout");
|
|
textInputLayout.setCounterMaxLength(textComponent2.c());
|
|
m.checkNotNullExpressionValue(textInputLayout, "textInput.layout");
|
|
ViewExtensions.addBindedTextWatcher(textInputLayout, this, new ModalComponent$onViewBound$components$2$1(botUikitTextInputBinding));
|
|
textInputEditText.setText(textComponent2.h());
|
|
m.checkNotNullExpressionValue(textInputEditText, "textInput.editText");
|
|
textInputEditText.setHint(textComponent2.e());
|
|
if (textComponent2.g() == TextStyle.PARAGRAPH) {
|
|
m.checkNotNullExpressionValue(textInputEditText, "textInput.editText");
|
|
textInputEditText.setMaxLines(5);
|
|
m.checkNotNullExpressionValue(textInputEditText, "textInput.editText");
|
|
textInputEditText.setInputType(131073);
|
|
m.checkNotNullExpressionValue(textInputEditText, "textInput.editText");
|
|
textInputEditText.setMinHeight(DimenUtils.dpToPixels(96));
|
|
} else {
|
|
m.checkNotNullExpressionValue(textInputEditText, "textInput.editText");
|
|
textInputEditText.setMaxLines(1);
|
|
m.checkNotNullExpressionValue(textInputEditText, "textInput.editText");
|
|
textInputEditText.setInputType(1);
|
|
}
|
|
getBinding().c.addView(linearLayout);
|
|
arrayList2.add(new Pair(textComponent2, botUikitTextInputBinding));
|
|
}
|
|
}
|
|
}
|
|
throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i)));
|
|
}
|
|
getBinding().f2191b.setOnClickListener(new ModalComponent$onViewBound$1(this));
|
|
getBinding().f.setOnClickListener(new ModalComponent$onViewBound$2(this, arrayList2, view));
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBoundOrOnResume() {
|
|
super.onViewBoundOrOnResume();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(StoreStream.Companion.getInteractions().observeSentInteractions(), this, null, 2, null), ModalComponent.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new ModalComponent$onViewBoundOrOnResume$1(this), 62, (Object) null);
|
|
}
|
|
}
|