232 lines
12 KiB
Java
232 lines
12 KiB
Java
package com.discord.widgets.settings.premium;
|
|
|
|
import android.content.ClipData;
|
|
import android.content.ClipboardManager;
|
|
import android.content.Context;
|
|
import android.content.res.ColorStateList;
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
import androidx.annotation.ColorInt;
|
|
import androidx.core.content.ContextCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentKt;
|
|
import androidx.fragment.app.FragmentManager;
|
|
import androidx.fragment.app.FragmentViewModelLazyKt;
|
|
import androidx.transition.AutoTransition;
|
|
import androidx.transition.TransitionManager;
|
|
import c.a.d.h0;
|
|
import c.a.d.j0;
|
|
import c.a.k.b;
|
|
import c.d.b.a.a;
|
|
import com.discord.app.AppDialog;
|
|
import com.discord.app.AppViewFlipper;
|
|
import com.discord.databinding.WidgetClaimOutboundPromoBinding;
|
|
import com.discord.utilities.KotlinExtensionsKt;
|
|
import com.discord.utilities.color.ColorCompat;
|
|
import com.discord.utilities.dimen.DimenUtils;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.uri.UriHandler;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.discord.widgets.settings.premium.ClaimOutboundPromoViewModel;
|
|
import com.discord.widgets.settings.premium.ClaimStatus;
|
|
import com.google.android.material.button.MaterialButton;
|
|
import com.google.android.material.shape.MaterialShapeDrawable;
|
|
import com.google.android.material.shape.ShapeAppearanceModel;
|
|
import d0.z.d.a0;
|
|
import d0.z.d.m;
|
|
import java.util.Objects;
|
|
import kotlin.Lazy;
|
|
import kotlin.NoWhenBranchMatchedException;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: WidgetClaimOutboundPromo.kt */
|
|
public final class WidgetClaimOutboundPromo extends AppDialog {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetClaimOutboundPromo.class, "binding", "getBinding()Lcom/discord/databinding/WidgetClaimOutboundPromoBinding;", 0)};
|
|
private static final String ARG_CLAIM_STATUS = "ARG_CLAIM_STATUS";
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final int INDEX_FAILURE = 2;
|
|
private static final int INDEX_LOADING = 0;
|
|
private static final int INDEX_SUCCESS = 1;
|
|
private static final String KEY_PROMO_CLAIMED = "KEY_PROMO_CLAIMED";
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetClaimOutboundPromo$binding$2.INSTANCE, null, 2, null);
|
|
private final MaterialShapeDrawable codeBoxBackground;
|
|
private final Lazy viewModel$delegate;
|
|
|
|
/* compiled from: WidgetClaimOutboundPromo.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final void showAndRegisterForClaimResult(ClaimStatus claimStatus, Fragment fragment, Function1<? super ClaimStatus.Claimed, Unit> function1) {
|
|
m.checkNotNullParameter(claimStatus, "claimStatus");
|
|
m.checkNotNullParameter(fragment, "fragment");
|
|
m.checkNotNullParameter(function1, "onPromoClaimed");
|
|
if (fragment.getParentFragmentManager().findFragmentByTag("javaClass") == null) {
|
|
if (claimStatus instanceof ClaimStatus.Unclaimed) {
|
|
FragmentKt.setFragmentResultListener(fragment, "KEY_PROMO_CLAIMED", new WidgetClaimOutboundPromo$Companion$showAndRegisterForClaimResult$2(function1));
|
|
}
|
|
WidgetClaimOutboundPromo widgetClaimOutboundPromo = new WidgetClaimOutboundPromo();
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("ARG_CLAIM_STATUS", claimStatus);
|
|
widgetClaimOutboundPromo.setArguments(bundle);
|
|
FragmentManager parentFragmentManager = fragment.getParentFragmentManager();
|
|
m.checkNotNullExpressionValue(parentFragmentManager, "fragment.parentFragmentManager");
|
|
widgetClaimOutboundPromo.show(parentFragmentManager, "javaClass");
|
|
}
|
|
}
|
|
}
|
|
|
|
public WidgetClaimOutboundPromo() {
|
|
super(2131558986);
|
|
WidgetClaimOutboundPromo$viewModel$2 widgetClaimOutboundPromo$viewModel$2 = new WidgetClaimOutboundPromo$viewModel$2(this);
|
|
h0 h0Var = new h0(this);
|
|
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(ClaimOutboundPromoViewModel.class), new WidgetClaimOutboundPromo$appViewModels$$inlined$viewModels$1(h0Var), new j0(widgetClaimOutboundPromo$viewModel$2));
|
|
MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable(new ShapeAppearanceModel.Builder().setAllCornerSizes((float) DimenUtils.dpToPixels(4)).build());
|
|
materialShapeDrawable.setFillColor(ColorStateList.valueOf(0));
|
|
this.codeBoxBackground = materialShapeDrawable;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$configureUi(WidgetClaimOutboundPromo widgetClaimOutboundPromo, ClaimOutboundPromoViewModel.ViewState viewState) {
|
|
widgetClaimOutboundPromo.configureUi(viewState);
|
|
}
|
|
|
|
public static final /* synthetic */ ClaimStatus access$getClaimStatus$p(WidgetClaimOutboundPromo widgetClaimOutboundPromo) {
|
|
return widgetClaimOutboundPromo.getClaimStatus();
|
|
}
|
|
|
|
public static final /* synthetic */ ClaimOutboundPromoViewModel access$getViewModel$p(WidgetClaimOutboundPromo widgetClaimOutboundPromo) {
|
|
return widgetClaimOutboundPromo.getViewModel();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleEvent(WidgetClaimOutboundPromo widgetClaimOutboundPromo, ClaimOutboundPromoViewModel.Event event) {
|
|
widgetClaimOutboundPromo.handleEvent(event);
|
|
}
|
|
|
|
private final void configureUi(ClaimOutboundPromoViewModel.ViewState viewState) {
|
|
View view = getView();
|
|
if (!(view instanceof ViewGroup)) {
|
|
view = null;
|
|
}
|
|
ViewGroup viewGroup = (ViewGroup) view;
|
|
if (viewGroup != null) {
|
|
AutoTransition autoTransition = new AutoTransition();
|
|
autoTransition.setOrdering(0);
|
|
autoTransition.setDuration(200L);
|
|
TransitionManager.beginDelayedTransition(viewGroup, autoTransition);
|
|
}
|
|
if (viewState instanceof ClaimOutboundPromoViewModel.ViewState.ClaimInProgress) {
|
|
AppViewFlipper appViewFlipper = getBinding().g;
|
|
m.checkNotNullExpressionValue(appViewFlipper, "binding.claimPromoFlipper");
|
|
appViewFlipper.setDisplayedChild(0);
|
|
} else if (viewState instanceof ClaimOutboundPromoViewModel.ViewState.Claimed) {
|
|
TextView textView = getBinding().b;
|
|
m.checkNotNullExpressionValue(textView, "binding.claimPromoBody");
|
|
ClaimOutboundPromoViewModel.ViewState.Claimed claimed = (ClaimOutboundPromoViewModel.ViewState.Claimed) viewState;
|
|
textView.setText(claimed.getClaimedStatus().getBody());
|
|
TextView textView2 = getBinding().f1764c;
|
|
m.checkNotNullExpressionValue(textView2, "binding.claimPromoCode");
|
|
textView2.setText(claimed.getClaimedStatus().getCode());
|
|
AppViewFlipper appViewFlipper2 = getBinding().g;
|
|
m.checkNotNullExpressionValue(appViewFlipper2, "binding.claimPromoFlipper");
|
|
appViewFlipper2.setDisplayedChild(1);
|
|
setCancelable(true);
|
|
} else if (viewState instanceof ClaimOutboundPromoViewModel.ViewState.ClaimFailed) {
|
|
AppViewFlipper appViewFlipper3 = getBinding().g;
|
|
m.checkNotNullExpressionValue(appViewFlipper3, "binding.claimPromoFlipper");
|
|
appViewFlipper3.setMeasureAllChildren(false);
|
|
AppViewFlipper appViewFlipper4 = getBinding().g;
|
|
m.checkNotNullExpressionValue(appViewFlipper4, "binding.claimPromoFlipper");
|
|
appViewFlipper4.setDisplayedChild(2);
|
|
setCancelable(true);
|
|
}
|
|
}
|
|
|
|
private final WidgetClaimOutboundPromoBinding getBinding() {
|
|
return (WidgetClaimOutboundPromoBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final ClaimStatus getClaimStatus() {
|
|
Parcelable parcelable = getArgumentsOrDefault().getParcelable("ARG_CLAIM_STATUS");
|
|
m.checkNotNull(parcelable);
|
|
return (ClaimStatus) parcelable;
|
|
}
|
|
|
|
private final ClaimOutboundPromoViewModel getViewModel() {
|
|
return (ClaimOutboundPromoViewModel) this.viewModel$delegate.getValue();
|
|
}
|
|
|
|
private final void handleEvent(ClaimOutboundPromoViewModel.Event event) {
|
|
Unit unit;
|
|
if (event instanceof ClaimOutboundPromoViewModel.Event.Claimed) {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("KEY_PROMO_CLAIMED", ((ClaimOutboundPromoViewModel.Event.Claimed) event).getClaimedStatus());
|
|
unit = Unit.a;
|
|
FragmentKt.setFragmentResult(this, "KEY_PROMO_CLAIMED", bundle);
|
|
} else if (event instanceof ClaimOutboundPromoViewModel.Event.CopyCode) {
|
|
Object systemService = requireContext().getSystemService("clipboard");
|
|
Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.content.ClipboardManager");
|
|
((ClipboardManager) systemService).setPrimaryClip(ClipData.newPlainText("Promo Code", ((ClaimOutboundPromoViewModel.Event.CopyCode) event).getCode()));
|
|
MaterialButton materialButton = getBinding().e;
|
|
m.checkNotNullExpressionValue(materialButton, "binding.claimPromoCopyButton");
|
|
b.m(materialButton, 2131887625, new Object[0], null, 4);
|
|
setCodeBoxColor(ContextCompat.getColor(requireContext(), 2131100249));
|
|
unit = Unit.a;
|
|
} else if (event instanceof ClaimOutboundPromoViewModel.Event.OpenRedemptionUrl) {
|
|
UriHandler uriHandler = UriHandler.INSTANCE;
|
|
Context requireContext = requireContext();
|
|
m.checkNotNullExpressionValue(requireContext, "requireContext()");
|
|
UriHandler.handle$default(uriHandler, requireContext, ((ClaimOutboundPromoViewModel.Event.OpenRedemptionUrl) event).getUrl(), null, 4, null);
|
|
dismiss();
|
|
unit = Unit.a;
|
|
} else if (event instanceof ClaimOutboundPromoViewModel.Event.Dismiss) {
|
|
dismiss();
|
|
unit = Unit.a;
|
|
} else {
|
|
throw new NoWhenBranchMatchedException();
|
|
}
|
|
KotlinExtensionsKt.getExhaustive(unit);
|
|
}
|
|
|
|
private final void setCodeBoxColor(@ColorInt int i) {
|
|
this.codeBoxBackground.setStroke((float) DimenUtils.dpToPixels(1), i);
|
|
getBinding().d.invalidate();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.DialogFragment, androidx.fragment.app.Fragment
|
|
public void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
setCancelable(false);
|
|
}
|
|
|
|
@Override // com.discord.app.AppDialog
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
ViewCompat.setBackground(getBinding().d, this.codeBoxBackground);
|
|
setCodeBoxColor(ColorCompat.getThemedColor(view, 2130968949));
|
|
getBinding().e.setOnClickListener(new WidgetClaimOutboundPromo$onViewBound$1(this));
|
|
getBinding().i.setOnClickListener(new WidgetClaimOutboundPromo$onViewBound$2(this));
|
|
getBinding().h.setOnClickListener(new WidgetClaimOutboundPromo$onViewBound$3(this));
|
|
getBinding().f.setOnClickListener(new WidgetClaimOutboundPromo$onViewBound$4(this));
|
|
}
|
|
|
|
@Override // com.discord.app.AppDialog
|
|
public void onViewBoundOrOnResume() {
|
|
super.onViewBoundOrOnResume();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(getViewModel().observeViewState(), this), WidgetClaimOutboundPromo.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetClaimOutboundPromo$onViewBoundOrOnResume$1(this), 62, (Object) null);
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(getViewModel().observeEvents(), this), WidgetClaimOutboundPromo.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetClaimOutboundPromo$onViewBoundOrOnResume$2(this), 62, (Object) null);
|
|
}
|
|
}
|