discord-jadx/app/src/main/java/com/discord/widgets/settings/premium/WidgetChoosePlan.java

268 lines
15 KiB
Java

package com.discord.widgets.settings.premium;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentViewModelLazyKt;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import c.a.a.c.c;
import c.a.a.e.f;
import c.a.a.e.g;
import c.a.d.f0;
import c.a.d.h0;
import c.a.d.j;
import c.a.k.b;
import c.d.b.a.a;
import com.discord.R;
import com.discord.app.AppFragment;
import com.discord.databinding.WidgetChoosePlanBinding;
import com.discord.stores.StoreGooglePlayPurchases;
import com.discord.utilities.analytics.AnalyticsTracker;
import com.discord.utilities.analytics.Traits;
import com.discord.utilities.billing.GooglePlayBillingManager;
import com.discord.utilities.billing.GooglePlaySku;
import com.discord.utilities.dimmer.DimmerView;
import com.discord.utilities.mg_recycler.MGRecyclerAdapter;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.view.text.LinkifiedTextView;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
import com.discord.widgets.settings.premium.ChoosePlanViewModel;
import d0.z.d.a0;
import d0.z.d.m;
import java.io.Serializable;
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: WidgetChoosePlan.kt */
public final class WidgetChoosePlan extends AppFragment {
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.a0(WidgetChoosePlan.class, "binding", "getBinding()Lcom/discord/databinding/WidgetChoosePlanBinding;", 0)};
public static final Companion Companion = new Companion(null);
public static final String RESULT_EXTRA_LOCATION_TRAIT = "result_extra_location_trait";
public static final String RESULT_EXTRA_OLD_SKU_NAME = "result_extra_current_sku_name";
public static final String RESULT_VIEW_TYPE = "result_view_type";
private WidgetChoosePlanAdapter adapter;
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetChoosePlan$binding$2.INSTANCE, null, 2, null);
private LinearLayoutManager planLayoutManager;
private final Lazy viewModel$delegate;
/* compiled from: WidgetChoosePlan.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static /* synthetic */ void launch$default(Companion companion, Context context, ActivityResultLauncher activityResultLauncher, ViewType viewType, String str, Traits.Location location, Traits.Subscription subscription, int i, Object obj) {
companion.launch(context, (i & 2) != 0 ? null : activityResultLauncher, viewType, (i & 8) != 0 ? null : str, location, (i & 32) != 0 ? null : subscription);
}
public final void launch(Context context, ActivityResultLauncher<Intent> activityResultLauncher, ViewType viewType, String str, Traits.Location location, Traits.Subscription subscription) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(viewType, "viewType");
m.checkNotNullParameter(location, "locationTrait");
Intent intent = new Intent();
intent.putExtra(WidgetChoosePlan.RESULT_EXTRA_OLD_SKU_NAME, str);
intent.putExtra(WidgetChoosePlan.RESULT_EXTRA_LOCATION_TRAIT, location);
intent.putExtra(WidgetChoosePlan.RESULT_VIEW_TYPE, viewType);
AnalyticsTracker.paymentFlowStarted$default(AnalyticsTracker.INSTANCE, location, subscription, null, null, 12, null);
if (activityResultLauncher != null) {
j.g.f(context, activityResultLauncher, WidgetChoosePlan.class, intent);
} else {
j.d(context, WidgetChoosePlan.class, intent);
}
}
public final ActivityResultLauncher<Intent> registerForResult(AppFragment appFragment, Function0<Unit> function0) {
m.checkNotNullParameter(appFragment, "fragment");
m.checkNotNullParameter(function0, "callback");
ActivityResultLauncher<Intent> registerForActivityResult = appFragment.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new WidgetChoosePlan$Companion$registerForResult$1(function0));
m.checkNotNullExpressionValue(registerForActivityResult, "fragment.registerForActi…k()\n }\n }");
return registerForActivityResult;
}
}
/* compiled from: WidgetChoosePlan.kt */
public enum ViewType {
BUY_PREMIUM_TIER_2,
BUY_PREMIUM_TIER_1,
BUY_PREMIUM_GUILD,
SWITCH_PLANS
}
public final /* synthetic */ class WhenMappings {
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
static {
GooglePlaySku.Type.values();
int[] iArr = new int[5];
$EnumSwitchMapping$0 = iArr;
iArr[GooglePlaySku.Type.PREMIUM_TIER_1.ordinal()] = 1;
iArr[GooglePlaySku.Type.PREMIUM_TIER_2.ordinal()] = 2;
iArr[GooglePlaySku.Type.PREMIUM_TIER_1_AND_PREMIUM_GUILD.ordinal()] = 3;
iArr[GooglePlaySku.Type.PREMIUM_TIER_2_AND_PREMIUM_GUILD.ordinal()] = 4;
iArr[GooglePlaySku.Type.PREMIUM_GUILD.ordinal()] = 5;
}
}
public WidgetChoosePlan() {
super(R.layout.widget_choose_plan);
WidgetChoosePlan$viewModel$2 widgetChoosePlan$viewModel$2 = new WidgetChoosePlan$viewModel$2(this);
f0 f0Var = new f0(this);
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(ChoosePlanViewModel.class), new WidgetChoosePlan$appViewModels$$inlined$viewModels$1(f0Var), new h0(widgetChoosePlan$viewModel$2));
}
public static final /* synthetic */ Unit access$configureUI(WidgetChoosePlan widgetChoosePlan, ChoosePlanViewModel.ViewState viewState) {
return widgetChoosePlan.configureUI(viewState);
}
public static final /* synthetic */ ChoosePlanViewModel access$getViewModel$p(WidgetChoosePlan widgetChoosePlan) {
return widgetChoosePlan.getViewModel();
}
public static final /* synthetic */ void access$handleEvent(WidgetChoosePlan widgetChoosePlan, ChoosePlanViewModel.Event event) {
widgetChoosePlan.handleEvent(event);
}
private final Unit configureUI(ChoosePlanViewModel.ViewState viewState) {
if (viewState instanceof ChoosePlanViewModel.ViewState.Loading) {
return null;
}
if (viewState instanceof ChoosePlanViewModel.ViewState.Loaded) {
WidgetChoosePlanAdapter widgetChoosePlanAdapter = this.adapter;
if (widgetChoosePlanAdapter == null) {
m.throwUninitializedPropertyAccessException("adapter");
}
ChoosePlanViewModel.ViewState.Loaded loaded = (ChoosePlanViewModel.ViewState.Loaded) viewState;
widgetChoosePlanAdapter.setData(loaded.getItems());
LinearLayout linearLayout = getBinding().b;
m.checkNotNullExpressionValue(linearLayout, "binding.choosePlanEmptyContainer");
linearLayout.setVisibility(loaded.isEmpty() ? 0 : 8);
if (m.areEqual(loaded.getPurchasesQueryState(), StoreGooglePlayPurchases.QueryState.InProgress.INSTANCE)) {
DimmerView.setDimmed$default(getBinding().e, true, false, 2, null);
return Unit.a;
}
DimmerView.setDimmed$default(getBinding().e, false, false, 2, null);
return Unit.a;
}
throw new NoWhenBranchMatchedException();
}
private final WidgetChoosePlanBinding getBinding() {
return (WidgetChoosePlanBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
private final ChoosePlanViewModel getViewModel() {
return (ChoosePlanViewModel) this.viewModel$delegate.getValue();
}
private final void handleEvent(ChoosePlanViewModel.Event event) {
if (event instanceof ChoosePlanViewModel.Event.ErrorSkuPurchase) {
c.a.d.m.i(this, ((ChoosePlanViewModel.Event.ErrorSkuPurchase) event).getMessage(), 0, 4);
} else if (event instanceof ChoosePlanViewModel.Event.StartSkuPurchase) {
GooglePlayBillingManager.INSTANCE.launchBillingFlow(requireAppActivity(), ((ChoosePlanViewModel.Event.StartSkuPurchase) event).getBillingParams());
} else if (event instanceof ChoosePlanViewModel.Event.CompleteSkuPurchase) {
ChoosePlanViewModel.Event.CompleteSkuPurchase completeSkuPurchase = (ChoosePlanViewModel.Event.CompleteSkuPurchase) event;
GooglePlaySku fromSkuName = GooglePlaySku.Companion.fromSkuName(completeSkuPurchase.getSkuName());
if (fromSkuName != null) {
WidgetChoosePlan$handleEvent$onDismiss$1 widgetChoosePlan$handleEvent$onDismiss$1 = new WidgetChoosePlan$handleEvent$onDismiss$1(this);
int ordinal = fromSkuName.getType().ordinal();
if (ordinal == 0) {
f.a aVar = f.j;
FragmentManager parentFragmentManager = getParentFragmentManager();
m.checkNotNullExpressionValue(parentFragmentManager, "parentFragmentManager");
aVar.a(parentFragmentManager, widgetChoosePlan$handleEvent$onDismiss$1, false);
} else if (ordinal == 1) {
f.a aVar2 = f.j;
FragmentManager parentFragmentManager2 = getParentFragmentManager();
m.checkNotNullExpressionValue(parentFragmentManager2, "parentFragmentManager");
aVar2.a(parentFragmentManager2, widgetChoosePlan$handleEvent$onDismiss$1, true);
} else if (ordinal == 2 || ordinal == 3) {
g.a aVar3 = g.j;
FragmentManager parentFragmentManager3 = getParentFragmentManager();
m.checkNotNullExpressionValue(parentFragmentManager3, "parentFragmentManager");
String planName = completeSkuPurchase.getPlanName();
Objects.requireNonNull(aVar3);
m.checkNotNullParameter(parentFragmentManager3, "fragmentManager");
m.checkNotNullParameter(widgetChoosePlan$handleEvent$onDismiss$1, "onDismiss");
m.checkNotNullParameter(planName, "planName");
g gVar = new g();
gVar.k = widgetChoosePlan$handleEvent$onDismiss$1;
Bundle bundle = new Bundle();
bundle.putString("extra_plan_text", planName);
gVar.setArguments(bundle);
gVar.show(parentFragmentManager3, g.class.getSimpleName());
} else if (ordinal == 4) {
c.a aVar4 = c.k;
FragmentManager parentFragmentManager4 = getParentFragmentManager();
m.checkNotNullExpressionValue(parentFragmentManager4, "parentFragmentManager");
aVar4.a(parentFragmentManager4, requireContext(), null, fromSkuName.getPremiumSubscriptionCount(), false, widgetChoosePlan$handleEvent$onDismiss$1);
}
}
}
}
private final void setUpRecycler() {
RecyclerView recyclerView = getBinding().d;
m.checkNotNullExpressionValue(recyclerView, "binding.choosePlanRecycler");
this.planLayoutManager = new LinearLayoutManager(recyclerView.getContext(), 1, false);
RecyclerView recyclerView2 = getBinding().d;
MGRecyclerAdapter.Companion companion = MGRecyclerAdapter.Companion;
m.checkNotNullExpressionValue(recyclerView2, "it");
this.adapter = (WidgetChoosePlanAdapter) companion.configure(new WidgetChoosePlanAdapter(recyclerView2));
Serializable serializableExtra = getMostRecentIntent().getSerializableExtra(RESULT_EXTRA_LOCATION_TRAIT);
Objects.requireNonNull(serializableExtra, "null cannot be cast to non-null type com.discord.utilities.analytics.Traits.Location");
Traits.Location location = (Traits.Location) serializableExtra;
WidgetChoosePlanAdapter widgetChoosePlanAdapter = this.adapter;
if (widgetChoosePlanAdapter == null) {
m.throwUninitializedPropertyAccessException("adapter");
}
widgetChoosePlanAdapter.setOnClickPlan(new WidgetChoosePlan$setUpRecycler$2(this, location));
RecyclerView recyclerView3 = getBinding().d;
m.checkNotNullExpressionValue(recyclerView3, "binding.choosePlanRecycler");
LinearLayoutManager linearLayoutManager = this.planLayoutManager;
if (linearLayoutManager == null) {
m.throwUninitializedPropertyAccessException("planLayoutManager");
}
recyclerView3.setLayoutManager(linearLayoutManager);
RecyclerView recyclerView4 = getBinding().d;
m.checkNotNullExpressionValue(recyclerView4, "binding.choosePlanRecycler");
WidgetChoosePlanAdapter widgetChoosePlanAdapter2 = this.adapter;
if (widgetChoosePlanAdapter2 == null) {
m.throwUninitializedPropertyAccessException("adapter");
}
recyclerView4.setAdapter(widgetChoosePlanAdapter2);
}
@Override // com.discord.app.AppFragment
public void onViewBound(View view) {
m.checkNotNullParameter(view, "view");
super.onViewBound(view);
setUpRecycler();
LinkifiedTextView linkifiedTextView = getBinding().f1802c;
m.checkNotNullExpressionValue(linkifiedTextView, "binding.choosePlanEmptyDescription");
b.n(linkifiedTextView, R.string.premium_no_plans_body, new Object[]{c.a.d.f.a.a(360055386693L, null)}, null, 4);
}
@Override // com.discord.app.AppFragment
public void onViewBoundOrOnResume() {
super.onViewBoundOrOnResume();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(getViewModel().observeEvents(), this, null, 2, null), WidgetChoosePlan.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetChoosePlan$onViewBoundOrOnResume$1(this), 62, (Object) null);
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(getViewModel().observeViewState(), this, null, 2, null), WidgetChoosePlan.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetChoosePlan$onViewBoundOrOnResume$2(this), 62, (Object) null);
}
}