discord-jadx/app/src/main/java/com/discord/widgets/chat/list/sheet/WidgetApplicationCommandBottomSheet.java
2021-07-04 01:36:06 +02:00

252 lines
14 KiB
Java

package com.discord.widgets.chat.list.sheet;
import android.content.Context;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentViewModelLazyKt;
import c.a.d.h0;
import c.a.d.j0;
import c.a.l.b;
import c.d.b.a.a;
import com.discord.api.commands.ApplicationCommandData;
import com.discord.api.commands.ApplicationCommandValue;
import com.discord.app.AppBottomSheet;
import com.discord.databinding.WidgetApplicationCommandBottomSheetBinding;
import com.discord.models.commands.Application;
import com.discord.models.experiments.domain.Experiment;
import com.discord.models.member.GuildMember;
import com.discord.models.user.User;
import com.discord.stores.StoreStream;
import com.discord.utilities.color.ColorCompat;
import com.discord.utilities.icon.IconUtils;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
import com.discord.widgets.chat.list.sheet.WidgetApplicationCommandBottomSheetViewModel;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.material.button.MaterialButton;
import d0.z.d.a0;
import d0.z.d.m;
import java.util.List;
import kotlin.Lazy;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.reflect.KProperty;
/* compiled from: WidgetApplicationCommandBottomSheet.kt */
public final class WidgetApplicationCommandBottomSheet extends AppBottomSheet {
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.W(WidgetApplicationCommandBottomSheet.class, "binding", "getBinding()Lcom/discord/databinding/WidgetApplicationCommandBottomSheetBinding;", 0)};
public static final String ARG_MESSAGE_NONCE = "arg_message_nonce";
public static final Companion Companion = new Companion(null);
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetApplicationCommandBottomSheet$binding$2.INSTANCE, null, 2, null);
private final Lazy viewModel$delegate;
/* compiled from: WidgetApplicationCommandBottomSheet.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final void show(FragmentManager fragmentManager, long j, long j2, long j3, Long l, long j4, long j5, String str) {
m.checkNotNullParameter(fragmentManager, "fragmentManager");
boolean z2 = false;
Experiment userExperiment = StoreStream.Companion.getExperiments().getUserExperiment("2021-03_android_app_slash_commands_bottom_sheet_disabled", false);
if (userExperiment != null && userExperiment.getBucket() == 1) {
z2 = true;
}
if (!z2) {
WidgetApplicationCommandBottomSheet widgetApplicationCommandBottomSheet = new WidgetApplicationCommandBottomSheet();
Bundle bundle = new Bundle();
bundle.putLong("com.discord.intent.extra.EXTRA_INTERACTION_ID", j);
bundle.putLong("com.discord.intent.extra.EXTRA_CHANNEL_ID", j3);
bundle.putLong("com.discord.intent.extra.EXTRA_MESSAGE_ID", j2);
if (l != null) {
bundle.putLong("com.discord.intent.extra.EXTRA_GUILD_ID", l.longValue());
}
bundle.putLong("com.discord.intent.extra.EXTRA_USER_ID", j4);
bundle.putLong("com.discord.intent.extra.EXTRA_APPLICATION_ID", j5);
bundle.putString("arg_message_nonce", str);
widgetApplicationCommandBottomSheet.setArguments(bundle);
widgetApplicationCommandBottomSheet.show(fragmentManager, WidgetApplicationCommandBottomSheet.class.getName());
}
}
}
public WidgetApplicationCommandBottomSheet() {
super(false, 1, null);
WidgetApplicationCommandBottomSheet$viewModel$2 widgetApplicationCommandBottomSheet$viewModel$2 = new WidgetApplicationCommandBottomSheet$viewModel$2(this);
h0 h0Var = new h0(this);
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(WidgetApplicationCommandBottomSheetViewModel.class), new WidgetApplicationCommandBottomSheet$appViewModels$$inlined$viewModels$1(h0Var), new j0(widgetApplicationCommandBottomSheet$viewModel$2));
}
public static final /* synthetic */ void access$configureUI(WidgetApplicationCommandBottomSheet widgetApplicationCommandBottomSheet, WidgetApplicationCommandBottomSheetViewModel.ViewState viewState) {
widgetApplicationCommandBottomSheet.configureUI(viewState);
}
public static final /* synthetic */ Bundle access$getArgumentsOrDefault$p(WidgetApplicationCommandBottomSheet widgetApplicationCommandBottomSheet) {
return widgetApplicationCommandBottomSheet.getArgumentsOrDefault();
}
/* JADX DEBUG: Can't convert new array creation: APUT found in different block: 0x006c: APUT (r8v1 java.lang.Object[]), (0 ??[int, short, byte, char]), (r2v1 java.lang.String) */
private final void configureCommandTitle(WidgetApplicationCommandBottomSheetViewModel.ViewState.Loaded loaded) {
String nick;
StringBuilder J = a.J('/');
J.append(loaded.getApplicationCommandData().a());
String sb = J.toString();
Application application = loaded.getApplication();
String str = null;
String name = application != null ? application.getName() : null;
int themedColor = ColorCompat.getThemedColor(requireContext(), 2130968989);
Application application2 = loaded.getApplication();
int i = 0;
if (application2 != null) {
SimpleDraweeView simpleDraweeView = getBinding().b;
m.checkNotNullExpressionValue(simpleDraweeView, "binding.commandBottomSheetCommandAvatar");
IconUtils.setApplicationIcon$default(simpleDraweeView, application2, false, 4, null);
}
TextView textView = getBinding().f;
m.checkNotNullExpressionValue(textView, "binding.commandBottomSheetCommandTitle");
Object[] objArr = new Object[2];
GuildMember interactionUser = loaded.getInteractionUser();
if (interactionUser == null || (nick = interactionUser.getNick()) == null) {
User user = loaded.getUser();
if (user != null) {
str = user.getUsername();
}
} else {
str = nick;
}
objArr[0] = str;
boolean z2 = true;
objArr[1] = sb;
CharSequence c2 = b.c(textView, 2131893828, objArr, new WidgetApplicationCommandBottomSheet$configureCommandTitle$content$1(this, loaded, themedColor));
TextView textView2 = getBinding().f;
m.checkNotNullExpressionValue(textView2, "binding.commandBottomSheetCommandTitle");
textView2.setMovementMethod(LinkMovementMethod.getInstance());
TextView textView3 = getBinding().f;
m.checkNotNullExpressionValue(textView3, "binding.commandBottomSheetCommandTitle");
textView3.setText(c2);
TextView textView4 = getBinding().g;
m.checkNotNullExpressionValue(textView4, "binding.commandBottomShe…mmandTitleApplicationName");
if (name == null) {
z2 = false;
}
if (!z2) {
i = 8;
}
textView4.setVisibility(i);
TextView textView5 = getBinding().g;
m.checkNotNullExpressionValue(textView5, "binding.commandBottomShe…mmandTitleApplicationName");
textView5.setText(name);
}
private final Spannable configureSlashCommandString(WidgetApplicationCommandBottomSheetViewModel.ViewState.Loaded loaded, ApplicationCommandValue applicationCommandValue) {
List<ApplicationCommandValue> b = applicationCommandValue.b();
if (b == null || b.isEmpty()) {
return configureSlashCommandStringOptions(loaded, applicationCommandValue);
}
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
SpannableStringBuilder append = spannableStringBuilder.append((CharSequence) (applicationCommandValue.a() + ' '));
List<ApplicationCommandValue> b2 = applicationCommandValue.b();
if (b2 != null) {
for (ApplicationCommandValue applicationCommandValue2 : b2) {
append.append((CharSequence) configureSlashCommandString(loaded, applicationCommandValue2));
}
}
return append;
}
private final void configureSlashCommandString(WidgetApplicationCommandBottomSheetViewModel.ViewState.Loaded loaded) {
ApplicationCommandData applicationCommandData = loaded.getApplicationCommandData();
List<ApplicationCommandValue> b = loaded.getApplicationCommandData().b();
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
StringBuilder J = a.J('/');
J.append(applicationCommandData.a());
J.append(' ');
spannableStringBuilder.append((CharSequence) J.toString());
if (b != null) {
for (ApplicationCommandValue applicationCommandValue : b) {
spannableStringBuilder.append((CharSequence) configureSlashCommandString(loaded, applicationCommandValue));
}
}
TextView textView = getBinding().f1667c;
m.checkNotNullExpressionValue(textView, "binding.commandBottomSheetCommandContent");
textView.setText(spannableStringBuilder);
}
private final Spannable configureSlashCommandStringOptions(WidgetApplicationCommandBottomSheetViewModel.ViewState.Loaded loaded, ApplicationCommandValue applicationCommandValue) {
Integer valueColor;
int themedColor = ColorCompat.getThemedColor(this, 2130968932);
WidgetApplicationCommandBottomSheetViewModel.SlashCommandParam slashCommandParam = loaded.getCommandValues().get(applicationCommandValue.a());
String str = null;
if ((slashCommandParam != null ? slashCommandParam.getValueColor() : null) != null && ((valueColor = slashCommandParam.getValueColor()) == null || valueColor.intValue() != 0)) {
themedColor = slashCommandParam.getValueColor().intValue();
}
if (slashCommandParam != null) {
str = slashCommandParam.getValue();
}
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
SpannableStringBuilder append = spannableStringBuilder.append((CharSequence) (applicationCommandValue.a() + ": "));
m.checkNotNullExpressionValue(append, "SpannableStringBuilder()…ppend(\"${option.name}: \")");
ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(themedColor);
int length = append.length();
append.append((CharSequence) (str + ' '));
append.setSpan(foregroundColorSpan, length, append.length(), 17);
return append;
}
private final void configureUI(WidgetApplicationCommandBottomSheetViewModel.ViewState viewState) {
boolean z2 = viewState instanceof WidgetApplicationCommandBottomSheetViewModel.ViewState.Loading;
ProgressBar progressBar = getBinding().e;
m.checkNotNullExpressionValue(progressBar, "binding.commandBottomSheetCommandLoader");
progressBar.setVisibility(z2 ? 0 : 8);
MaterialButton materialButton = getBinding().d;
m.checkNotNullExpressionValue(materialButton, "binding.commandBottomSheetCommandCopyButton");
materialButton.setEnabled(!z2);
if (viewState instanceof WidgetApplicationCommandBottomSheetViewModel.ViewState.Loaded) {
MaterialButton materialButton2 = getBinding().d;
m.checkNotNullExpressionValue(materialButton2, "binding.commandBottomSheetCommandCopyButton");
materialButton2.setEnabled(true);
configureLoaded((WidgetApplicationCommandBottomSheetViewModel.ViewState.Loaded) viewState);
} else if (viewState instanceof WidgetApplicationCommandBottomSheetViewModel.ViewState.Failed) {
dismiss();
}
}
private final WidgetApplicationCommandBottomSheetBinding getBinding() {
return (WidgetApplicationCommandBottomSheetBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
private final WidgetApplicationCommandBottomSheetViewModel getViewModel() {
return (WidgetApplicationCommandBottomSheetViewModel) this.viewModel$delegate.getValue();
}
public final void configureLoaded(WidgetApplicationCommandBottomSheetViewModel.ViewState.Loaded loaded) {
m.checkNotNullParameter(loaded, "viewState");
configureCommandTitle(loaded);
configureSlashCommandString(loaded);
getBinding().d.setOnClickListener(new WidgetApplicationCommandBottomSheet$configureLoaded$1(this, loaded));
}
@Override // com.discord.app.AppBottomSheet
public int getContentViewResId() {
return 2131558842;
}
@Override // com.discord.app.AppBottomSheet, androidx.fragment.app.Fragment
public void onResume() {
super.onResume();
AppBottomSheet.hideKeyboard$default(this, null, 1, null);
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(getViewModel().observeViewState(), this), WidgetApplicationCommandBottomSheet.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetApplicationCommandBottomSheet$onResume$1(this), 62, (Object) null);
}
}