187 lines
9.9 KiB
Java
187 lines
9.9 KiB
Java
package com.discord.widgets.botuikit.views;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.ViewGroup;
|
|
import android.widget.Button;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
import androidx.appcompat.widget.AppCompatImageView;
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
import androidx.core.content.res.ResourcesCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
import com.discord.api.botuikit.ButtonStyle;
|
|
import com.discord.api.botuikit.ComponentEmoji;
|
|
import com.discord.api.botuikit.ComponentType;
|
|
import com.discord.databinding.WidgetChatListBotUiButtonComponentBinding;
|
|
import com.discord.models.botuikit.ActionInteractionComponentState;
|
|
import com.discord.models.botuikit.ButtonMessageComponent;
|
|
import com.discord.utilities.dimen.DimenUtils;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.views.typing.TypingDots;
|
|
import com.discord.widgets.botuikit.ComponentProvider;
|
|
import com.facebook.drawee.view.SimpleDraweeView;
|
|
import com.google.android.material.button.MaterialButton;
|
|
import com.google.android.material.textview.MaterialTextView;
|
|
import d0.z.d.m;
|
|
import kotlin.NoWhenBranchMatchedException;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
/* compiled from: ButtonComponentView.kt */
|
|
public final class ButtonComponentView extends ConstraintLayout implements ComponentView<ButtonMessageComponent> {
|
|
public static final Companion Companion = new Companion(null);
|
|
|
|
/* compiled from: ButtonComponentView.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final ButtonComponentView inflateComponent(Context context, ViewGroup viewGroup) {
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(viewGroup, "root");
|
|
WidgetChatListBotUiButtonComponentBinding a = WidgetChatListBotUiButtonComponentBinding.a(LayoutInflater.from(context).inflate(2131558975, viewGroup, false));
|
|
m.checkNotNullExpressionValue(a, "WidgetChatListBotUiButto…om(context), root, false)");
|
|
ButtonComponentView buttonComponentView = a.a;
|
|
m.checkNotNullExpressionValue(buttonComponentView, "WidgetChatListBotUiButto…ntext), root, false).root");
|
|
return buttonComponentView;
|
|
}
|
|
}
|
|
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
|
|
static {
|
|
ButtonStyle.values();
|
|
int[] iArr = new int[6];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
iArr[ButtonStyle.UNKNOWN.ordinal()] = 1;
|
|
iArr[ButtonStyle.PRIMARY.ordinal()] = 2;
|
|
iArr[ButtonStyle.SECONDARY.ordinal()] = 3;
|
|
iArr[ButtonStyle.LINK.ordinal()] = 4;
|
|
iArr[ButtonStyle.DANGER.ordinal()] = 5;
|
|
iArr[ButtonStyle.SUCCESS.ordinal()] = 6;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public ButtonComponentView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(attributeSet, "attrs");
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public ButtonComponentView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(attributeSet, "attrs");
|
|
}
|
|
|
|
private final void configureEmoji(SimpleDraweeView simpleDraweeView, ComponentEmoji componentEmoji, boolean z2) {
|
|
if (componentEmoji == null || !z2) {
|
|
ComponentViewUtils.INSTANCE.setEmojiOrHide(simpleDraweeView, componentEmoji);
|
|
} else {
|
|
simpleDraweeView.setVisibility(4);
|
|
}
|
|
}
|
|
|
|
private final void configureLabelPadding(TextView textView, ButtonMessageComponent buttonMessageComponent) {
|
|
if (buttonMessageComponent.getLabel() == null) {
|
|
textView.setPadding(0, 0, (!ButtonComponentViewKt.hasEmoji(buttonMessageComponent) || !ButtonComponentViewKt.hasIcon(buttonMessageComponent)) ? DimenUtils.dpToPixels(16) : DimenUtils.dpToPixels(8), 0);
|
|
} else {
|
|
textView.setPadding(ButtonComponentViewKt.hasEmoji(buttonMessageComponent) ? DimenUtils.dpToPixels(8) : DimenUtils.dpToPixels(16), 0, ButtonComponentViewKt.hasIcon(buttonMessageComponent) ? DimenUtils.dpToPixels(8) : DimenUtils.dpToPixels(16), 0);
|
|
}
|
|
}
|
|
|
|
private final void configureLinkIcon(ImageView imageView, boolean z2) {
|
|
imageView.setVisibility(z2 ? 0 : 8);
|
|
}
|
|
|
|
public void configure(ButtonMessageComponent buttonMessageComponent, ComponentProvider componentProvider, ComponentActionListener componentActionListener) {
|
|
m.checkNotNullParameter(buttonMessageComponent, "component");
|
|
m.checkNotNullParameter(componentProvider, "componentProvider");
|
|
m.checkNotNullParameter(componentActionListener, "componentActionListener");
|
|
WidgetChatListBotUiButtonComponentBinding a = WidgetChatListBotUiButtonComponentBinding.a(this);
|
|
m.checkNotNullExpressionValue(a, "WidgetChatListBotUiButto…mponentBinding.bind(this)");
|
|
MaterialButton materialButton = a.b;
|
|
m.checkNotNullExpressionValue(materialButton, "binding.button");
|
|
configureStyle(materialButton, buttonMessageComponent.getStyle());
|
|
SimpleDraweeView simpleDraweeView = a.f1757c;
|
|
m.checkNotNullExpressionValue(simpleDraweeView, "binding.emoji");
|
|
configureEmoji(simpleDraweeView, buttonMessageComponent.getEmoji(), buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Loading);
|
|
AppCompatImageView appCompatImageView = a.e;
|
|
m.checkNotNullExpressionValue(appCompatImageView, "binding.linkIcon");
|
|
configureLinkIcon(appCompatImageView, buttonMessageComponent.getStyle() == ButtonStyle.LINK);
|
|
MaterialTextView materialTextView = a.d;
|
|
m.checkNotNullExpressionValue(materialTextView, "binding.label");
|
|
configureLabelPadding(materialTextView, buttonMessageComponent);
|
|
MaterialTextView materialTextView2 = a.d;
|
|
m.checkNotNullExpressionValue(materialTextView2, "binding.label");
|
|
ViewExtensions.setEnabledAlpha(materialTextView2, !(buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Disabled), 0.5f);
|
|
SimpleDraweeView simpleDraweeView2 = a.f1757c;
|
|
m.checkNotNullExpressionValue(simpleDraweeView2, "binding.emoji");
|
|
ViewExtensions.setEnabledAlpha$default(simpleDraweeView2, !(buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Disabled), 0.0f, 2, null);
|
|
AppCompatImageView appCompatImageView2 = a.e;
|
|
m.checkNotNullExpressionValue(appCompatImageView2, "binding.linkIcon");
|
|
ViewExtensions.setEnabledAlpha$default(appCompatImageView2, !(buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Disabled), 0.0f, 2, null);
|
|
MaterialButton materialButton2 = a.b;
|
|
m.checkNotNullExpressionValue(materialButton2, "binding.button");
|
|
materialButton2.setEnabled(!(buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Disabled));
|
|
MaterialTextView materialTextView3 = a.d;
|
|
m.checkNotNullExpressionValue(materialTextView3, "binding.label");
|
|
materialTextView3.setText(buttonMessageComponent.getLabel());
|
|
MaterialTextView materialTextView4 = a.d;
|
|
m.checkNotNullExpressionValue(materialTextView4, "binding.label");
|
|
materialTextView4.setVisibility(buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Loading ? 4 : 0);
|
|
a.b.setOnClickListener(new ButtonComponentView$configure$1(buttonMessageComponent, a, componentActionListener));
|
|
TypingDots typingDots = a.f;
|
|
m.checkNotNullExpressionValue(typingDots, "binding.loadingDots");
|
|
typingDots.setVisibility(buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Loading ? 0 : 8);
|
|
if (buttonMessageComponent.getStateInteraction() instanceof ActionInteractionComponentState.Loading) {
|
|
a.f.a(false);
|
|
MaterialButton materialButton3 = a.b;
|
|
m.checkNotNullExpressionValue(materialButton3, "binding.button");
|
|
materialButton3.setClickable(false);
|
|
return;
|
|
}
|
|
a.f.b();
|
|
MaterialButton materialButton4 = a.b;
|
|
m.checkNotNullExpressionValue(materialButton4, "binding.button");
|
|
materialButton4.setClickable(true);
|
|
}
|
|
|
|
public final void configureStyle(Button button, ButtonStyle buttonStyle) {
|
|
m.checkNotNullParameter(button, "button");
|
|
m.checkNotNullParameter(buttonStyle, "style");
|
|
int ordinal = buttonStyle.ordinal();
|
|
int i = 2131100414;
|
|
if (ordinal != 0) {
|
|
if (ordinal == 1) {
|
|
i = 2131100411;
|
|
} else if (ordinal != 2) {
|
|
if (ordinal == 3) {
|
|
i = 2131100412;
|
|
} else if (ordinal == 4) {
|
|
i = 2131100413;
|
|
} else if (ordinal != 5) {
|
|
throw new NoWhenBranchMatchedException();
|
|
}
|
|
}
|
|
}
|
|
Resources resources = getResources();
|
|
Context context = getContext();
|
|
m.checkNotNullExpressionValue(context, "context");
|
|
ViewCompat.setBackgroundTintList(button, ResourcesCompat.getColorStateList(resources, i, context.getTheme()));
|
|
}
|
|
|
|
@Override // com.discord.widgets.botuikit.views.ComponentView
|
|
public ComponentType type() {
|
|
return ComponentType.BUTTON;
|
|
}
|
|
}
|