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

922 lines
46 KiB
Java

package com.discord.widgets.settings.premium;
import android.content.Context;
import androidx.annotation.MainThread;
import androidx.annotation.StringRes;
import b.d.b.a.a;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.SkuDetails;
import com.discord.R;
import com.discord.app.AppViewModel;
import com.discord.models.domain.ModelEntitlement;
import com.discord.models.domain.ModelGuildBoostSlot;
import com.discord.models.domain.ModelPaymentSource;
import com.discord.models.domain.ModelSubscription;
import com.discord.models.domain.billing.ModelInvoicePreview;
import com.discord.models.domain.premium.SubscriptionPlanType;
import com.discord.restapi.RestAPIParams;
import com.discord.stores.StoreEntitlements;
import com.discord.stores.StoreExperiments;
import com.discord.stores.StoreGooglePlayPurchases;
import com.discord.stores.StoreGooglePlaySkuDetails;
import com.discord.stores.StoreGuildBoost;
import com.discord.stores.StorePaymentSources;
import com.discord.stores.StoreStream;
import com.discord.stores.StoreSubscriptions;
import com.discord.utilities.billing.GooglePlayBillingManager;
import com.discord.utilities.rest.RestAPI;
import com.discord.utilities.rx.ObservableExtensionsKt;
import d0.g0.t;
import d0.t.n;
import d0.t.n0;
import d0.z.d.m;
import d0.z.d.o;
import j0.l.a.d;
import j0.l.e.k;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.subjects.PublishSubject;
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public final class SettingsPremiumViewModel extends AppViewModel<ViewState> {
public static final Companion Companion = new Companion(null);
private final PublishSubject<Event> eventSubject;
private final RestAPI restAPI;
private final StoreEntitlements storeEntitlements;
private final StoreGuildBoost storeGuildBoost;
private final StorePaymentSources storePaymentsSources;
private final StoreSubscriptions storeSubscriptions;
/* compiled from: SettingsPremiumViewModel.kt */
/* renamed from: com.discord.widgets.settings.premium.SettingsPremiumViewModel$1 reason: invalid class name */
/* loaded from: classes2.dex */
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
public AnonymousClass1() {
super(1);
}
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(StoreState storeState) {
invoke2(storeState);
return Unit.a;
}
/* renamed from: invoke reason: avoid collision after fix types in other method */
public final void invoke2(StoreState storeState) {
m.checkNotNullParameter(storeState, "storeState");
SettingsPremiumViewModel.access$handleStoreState(SettingsPremiumViewModel.this, storeState);
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public static final /* synthetic */ Observable access$getSubscriptionsAndInvoicePreview(Companion companion, RestAPI restAPI, StoreSubscriptions.SubscriptionsState subscriptionsState, boolean z2) {
return companion.getSubscriptionsAndInvoicePreview(restAPI, subscriptionsState, z2);
}
public static final /* synthetic */ Observable access$observeStores(Companion companion, StorePaymentSources storePaymentSources, StoreSubscriptions storeSubscriptions, StoreEntitlements storeEntitlements, StoreGuildBoost storeGuildBoost, StoreGooglePlaySkuDetails storeGooglePlaySkuDetails, StoreGooglePlayPurchases storeGooglePlayPurchases, StoreExperiments storeExperiments, RestAPI restAPI) {
return companion.observeStores(storePaymentSources, storeSubscriptions, storeEntitlements, storeGuildBoost, storeGooglePlaySkuDetails, storeGooglePlayPurchases, storeExperiments, restAPI);
}
private final Observable<SubscriptionAndInvoice> getSubscriptionsAndInvoicePreview(RestAPI restAPI, StoreSubscriptions.SubscriptionsState subscriptionsState, boolean z2) {
Object obj;
String id2;
boolean z3;
if (subscriptionsState instanceof StoreSubscriptions.SubscriptionsState.Loaded) {
Iterator<T> it = ((StoreSubscriptions.SubscriptionsState.Loaded) subscriptionsState).getSubscriptions().iterator();
while (true) {
if (!it.hasNext()) {
obj = null;
break;
}
obj = it.next();
if (((ModelSubscription) obj).getType() == ModelSubscription.Type.PREMIUM) {
z3 = true;
continue;
} else {
z3 = false;
continue;
}
if (z3) {
break;
}
}
ModelSubscription modelSubscription = (ModelSubscription) obj;
if (modelSubscription == null || (id2 = modelSubscription.getId()) == null) {
k kVar = new k(new SubscriptionAndInvoice(subscriptionsState, new InvoicePreviewFetch.Invoice(null)));
m.checkNotNullExpressionValue(kVar, "Observable.just(\n …nvoice(null))\n )");
return kVar;
}
Observable<SubscriptionAndInvoice> L = ObservableExtensionsKt.restSubscribeOn$default(restAPI.getInvoicePreview(new RestAPIParams.InvoicePreviewBody(id2, true, z2 && !modelSubscription.isGoogleSubscription())), false, 1, null).F(new SettingsPremiumViewModel$Companion$getSubscriptionsAndInvoicePreview$1(subscriptionsState)).L(new SettingsPremiumViewModel$Companion$getSubscriptionsAndInvoicePreview$2(subscriptionsState));
m.checkNotNullExpressionValue(L, "restAPI\n .g…ch.Error)\n }");
return L;
}
Observable observable = d.k;
m.checkNotNullExpressionValue(observable, "Observable.never()");
return observable;
}
private final Observable<StoreState> observeStores(StorePaymentSources storePaymentSources, StoreSubscriptions storeSubscriptions, StoreEntitlements storeEntitlements, StoreGuildBoost storeGuildBoost, StoreGooglePlaySkuDetails storeGooglePlaySkuDetails, StoreGooglePlayPurchases storeGooglePlayPurchases, StoreExperiments storeExperiments, RestAPI restAPI) {
Observable<StoreState> e = Observable.e(storePaymentSources.observePaymentSourcesState(), storeSubscriptions.observeSubscriptions().Y(new SettingsPremiumViewModel$Companion$observeStores$1(restAPI)), storeSubscriptions.observeSubscriptions().Y(new SettingsPremiumViewModel$Companion$observeStores$2(restAPI)), storeEntitlements.observeEntitlementState(), StoreGuildBoost.observeGuildBoostState$default(storeGuildBoost, null, 1, null), storeGooglePlaySkuDetails.observeState(), storeGooglePlayPurchases.observeState(), SettingsPremiumViewModel$Companion$observeStores$3.INSTANCE);
m.checkNotNullExpressionValue(e, "Observable\n .co… )\n }");
return e;
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static abstract class Event {
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class ErrorToast extends Event {
private final int errorStringResId;
public ErrorToast(@StringRes int i) {
super(null);
this.errorStringResId = i;
}
public static /* synthetic */ ErrorToast copy$default(ErrorToast errorToast, int i, int i2, Object obj) {
if ((i2 & 1) != 0) {
i = errorToast.errorStringResId;
}
return errorToast.copy(i);
}
public final int component1() {
return this.errorStringResId;
}
public final ErrorToast copy(@StringRes int i) {
return new ErrorToast(i);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof ErrorToast) && this.errorStringResId == ((ErrorToast) obj).errorStringResId;
}
return true;
}
public final int getErrorStringResId() {
return this.errorStringResId;
}
public int hashCode() {
return this.errorStringResId;
}
public String toString() {
return a.A(a.R("ErrorToast(errorStringResId="), this.errorStringResId, ")");
}
}
private Event() {
}
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static abstract class InvoicePreviewFetch {
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class Error extends InvoicePreviewFetch {
public static final Error INSTANCE = new Error();
private Error() {
super(null);
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class Invoice extends InvoicePreviewFetch {
private final ModelInvoicePreview modelInvoicePreview;
public Invoice(ModelInvoicePreview modelInvoicePreview) {
super(null);
this.modelInvoicePreview = modelInvoicePreview;
}
public static /* synthetic */ Invoice copy$default(Invoice invoice, ModelInvoicePreview modelInvoicePreview, int i, Object obj) {
if ((i & 1) != 0) {
modelInvoicePreview = invoice.modelInvoicePreview;
}
return invoice.copy(modelInvoicePreview);
}
public final ModelInvoicePreview component1() {
return this.modelInvoicePreview;
}
public final Invoice copy(ModelInvoicePreview modelInvoicePreview) {
return new Invoice(modelInvoicePreview);
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof Invoice) && m.areEqual(this.modelInvoicePreview, ((Invoice) obj).modelInvoicePreview);
}
return true;
}
public final ModelInvoicePreview getModelInvoicePreview() {
return this.modelInvoicePreview;
}
public int hashCode() {
ModelInvoicePreview modelInvoicePreview = this.modelInvoicePreview;
if (modelInvoicePreview != null) {
return modelInvoicePreview.hashCode();
}
return 0;
}
public String toString() {
StringBuilder R = a.R("Invoice(modelInvoicePreview=");
R.append(this.modelInvoicePreview);
R.append(")");
return R.toString();
}
}
private InvoicePreviewFetch() {
}
public /* synthetic */ InvoicePreviewFetch(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class StoreState {
private final InvoicePreviewFetch currentInvoicePreviewFetch;
private final StoreEntitlements.State entitlementState;
private final StoreGuildBoost.State guildBoostState;
private final StorePaymentSources.PaymentSourcesState paymentSourcesState;
private final StoreGooglePlayPurchases.State purchaseState;
private final InvoicePreviewFetch renewalInvoicePreviewFetch;
private final StoreGooglePlaySkuDetails.State skuDetailsState;
private final StoreSubscriptions.SubscriptionsState subscriptionsState;
public StoreState(StorePaymentSources.PaymentSourcesState paymentSourcesState, StoreSubscriptions.SubscriptionsState subscriptionsState, StoreEntitlements.State state, StoreGuildBoost.State state2, InvoicePreviewFetch invoicePreviewFetch, InvoicePreviewFetch invoicePreviewFetch2, StoreGooglePlaySkuDetails.State state3, StoreGooglePlayPurchases.State state4) {
m.checkNotNullParameter(paymentSourcesState, "paymentSourcesState");
m.checkNotNullParameter(subscriptionsState, "subscriptionsState");
m.checkNotNullParameter(state, "entitlementState");
m.checkNotNullParameter(state2, "guildBoostState");
m.checkNotNullParameter(invoicePreviewFetch, "renewalInvoicePreviewFetch");
m.checkNotNullParameter(invoicePreviewFetch2, "currentInvoicePreviewFetch");
m.checkNotNullParameter(state3, "skuDetailsState");
m.checkNotNullParameter(state4, "purchaseState");
this.paymentSourcesState = paymentSourcesState;
this.subscriptionsState = subscriptionsState;
this.entitlementState = state;
this.guildBoostState = state2;
this.renewalInvoicePreviewFetch = invoicePreviewFetch;
this.currentInvoicePreviewFetch = invoicePreviewFetch2;
this.skuDetailsState = state3;
this.purchaseState = state4;
}
public static /* synthetic */ StoreState copy$default(StoreState storeState, StorePaymentSources.PaymentSourcesState paymentSourcesState, StoreSubscriptions.SubscriptionsState subscriptionsState, StoreEntitlements.State state, StoreGuildBoost.State state2, InvoicePreviewFetch invoicePreviewFetch, InvoicePreviewFetch invoicePreviewFetch2, StoreGooglePlaySkuDetails.State state3, StoreGooglePlayPurchases.State state4, int i, Object obj) {
return storeState.copy((i & 1) != 0 ? storeState.paymentSourcesState : paymentSourcesState, (i & 2) != 0 ? storeState.subscriptionsState : subscriptionsState, (i & 4) != 0 ? storeState.entitlementState : state, (i & 8) != 0 ? storeState.guildBoostState : state2, (i & 16) != 0 ? storeState.renewalInvoicePreviewFetch : invoicePreviewFetch, (i & 32) != 0 ? storeState.currentInvoicePreviewFetch : invoicePreviewFetch2, (i & 64) != 0 ? storeState.skuDetailsState : state3, (i & 128) != 0 ? storeState.purchaseState : state4);
}
public final StorePaymentSources.PaymentSourcesState component1() {
return this.paymentSourcesState;
}
public final StoreSubscriptions.SubscriptionsState component2() {
return this.subscriptionsState;
}
public final StoreEntitlements.State component3() {
return this.entitlementState;
}
public final StoreGuildBoost.State component4() {
return this.guildBoostState;
}
public final InvoicePreviewFetch component5() {
return this.renewalInvoicePreviewFetch;
}
public final InvoicePreviewFetch component6() {
return this.currentInvoicePreviewFetch;
}
public final StoreGooglePlaySkuDetails.State component7() {
return this.skuDetailsState;
}
public final StoreGooglePlayPurchases.State component8() {
return this.purchaseState;
}
public final StoreState copy(StorePaymentSources.PaymentSourcesState paymentSourcesState, StoreSubscriptions.SubscriptionsState subscriptionsState, StoreEntitlements.State state, StoreGuildBoost.State state2, InvoicePreviewFetch invoicePreviewFetch, InvoicePreviewFetch invoicePreviewFetch2, StoreGooglePlaySkuDetails.State state3, StoreGooglePlayPurchases.State state4) {
m.checkNotNullParameter(paymentSourcesState, "paymentSourcesState");
m.checkNotNullParameter(subscriptionsState, "subscriptionsState");
m.checkNotNullParameter(state, "entitlementState");
m.checkNotNullParameter(state2, "guildBoostState");
m.checkNotNullParameter(invoicePreviewFetch, "renewalInvoicePreviewFetch");
m.checkNotNullParameter(invoicePreviewFetch2, "currentInvoicePreviewFetch");
m.checkNotNullParameter(state3, "skuDetailsState");
m.checkNotNullParameter(state4, "purchaseState");
return new StoreState(paymentSourcesState, subscriptionsState, state, state2, invoicePreviewFetch, invoicePreviewFetch2, state3, state4);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof StoreState)) {
return false;
}
StoreState storeState = (StoreState) obj;
return m.areEqual(this.paymentSourcesState, storeState.paymentSourcesState) && m.areEqual(this.subscriptionsState, storeState.subscriptionsState) && m.areEqual(this.entitlementState, storeState.entitlementState) && m.areEqual(this.guildBoostState, storeState.guildBoostState) && m.areEqual(this.renewalInvoicePreviewFetch, storeState.renewalInvoicePreviewFetch) && m.areEqual(this.currentInvoicePreviewFetch, storeState.currentInvoicePreviewFetch) && m.areEqual(this.skuDetailsState, storeState.skuDetailsState) && m.areEqual(this.purchaseState, storeState.purchaseState);
}
public final InvoicePreviewFetch getCurrentInvoicePreviewFetch() {
return this.currentInvoicePreviewFetch;
}
public final StoreEntitlements.State getEntitlementState() {
return this.entitlementState;
}
public final StoreGuildBoost.State getGuildBoostState() {
return this.guildBoostState;
}
public final StorePaymentSources.PaymentSourcesState getPaymentSourcesState() {
return this.paymentSourcesState;
}
public final StoreGooglePlayPurchases.State getPurchaseState() {
return this.purchaseState;
}
public final InvoicePreviewFetch getRenewalInvoicePreviewFetch() {
return this.renewalInvoicePreviewFetch;
}
public final StoreGooglePlaySkuDetails.State getSkuDetailsState() {
return this.skuDetailsState;
}
public final StoreSubscriptions.SubscriptionsState getSubscriptionsState() {
return this.subscriptionsState;
}
public int hashCode() {
StorePaymentSources.PaymentSourcesState paymentSourcesState = this.paymentSourcesState;
int i = 0;
int hashCode = (paymentSourcesState != null ? paymentSourcesState.hashCode() : 0) * 31;
StoreSubscriptions.SubscriptionsState subscriptionsState = this.subscriptionsState;
int hashCode2 = (hashCode + (subscriptionsState != null ? subscriptionsState.hashCode() : 0)) * 31;
StoreEntitlements.State state = this.entitlementState;
int hashCode3 = (hashCode2 + (state != null ? state.hashCode() : 0)) * 31;
StoreGuildBoost.State state2 = this.guildBoostState;
int hashCode4 = (hashCode3 + (state2 != null ? state2.hashCode() : 0)) * 31;
InvoicePreviewFetch invoicePreviewFetch = this.renewalInvoicePreviewFetch;
int hashCode5 = (hashCode4 + (invoicePreviewFetch != null ? invoicePreviewFetch.hashCode() : 0)) * 31;
InvoicePreviewFetch invoicePreviewFetch2 = this.currentInvoicePreviewFetch;
int hashCode6 = (hashCode5 + (invoicePreviewFetch2 != null ? invoicePreviewFetch2.hashCode() : 0)) * 31;
StoreGooglePlaySkuDetails.State state3 = this.skuDetailsState;
int hashCode7 = (hashCode6 + (state3 != null ? state3.hashCode() : 0)) * 31;
StoreGooglePlayPurchases.State state4 = this.purchaseState;
if (state4 != null) {
i = state4.hashCode();
}
return hashCode7 + i;
}
public String toString() {
StringBuilder R = a.R("StoreState(paymentSourcesState=");
R.append(this.paymentSourcesState);
R.append(", subscriptionsState=");
R.append(this.subscriptionsState);
R.append(", entitlementState=");
R.append(this.entitlementState);
R.append(", guildBoostState=");
R.append(this.guildBoostState);
R.append(", renewalInvoicePreviewFetch=");
R.append(this.renewalInvoicePreviewFetch);
R.append(", currentInvoicePreviewFetch=");
R.append(this.currentInvoicePreviewFetch);
R.append(", skuDetailsState=");
R.append(this.skuDetailsState);
R.append(", purchaseState=");
R.append(this.purchaseState);
R.append(")");
return R.toString();
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class SubscriptionAndInvoice {
private final InvoicePreviewFetch invoicePreviewFetch;
private final StoreSubscriptions.SubscriptionsState subscriptionsState;
public SubscriptionAndInvoice(StoreSubscriptions.SubscriptionsState subscriptionsState, InvoicePreviewFetch invoicePreviewFetch) {
m.checkNotNullParameter(subscriptionsState, "subscriptionsState");
m.checkNotNullParameter(invoicePreviewFetch, "invoicePreviewFetch");
this.subscriptionsState = subscriptionsState;
this.invoicePreviewFetch = invoicePreviewFetch;
}
public static /* synthetic */ SubscriptionAndInvoice copy$default(SubscriptionAndInvoice subscriptionAndInvoice, StoreSubscriptions.SubscriptionsState subscriptionsState, InvoicePreviewFetch invoicePreviewFetch, int i, Object obj) {
if ((i & 1) != 0) {
subscriptionsState = subscriptionAndInvoice.subscriptionsState;
}
if ((i & 2) != 0) {
invoicePreviewFetch = subscriptionAndInvoice.invoicePreviewFetch;
}
return subscriptionAndInvoice.copy(subscriptionsState, invoicePreviewFetch);
}
public final StoreSubscriptions.SubscriptionsState component1() {
return this.subscriptionsState;
}
public final InvoicePreviewFetch component2() {
return this.invoicePreviewFetch;
}
public final SubscriptionAndInvoice copy(StoreSubscriptions.SubscriptionsState subscriptionsState, InvoicePreviewFetch invoicePreviewFetch) {
m.checkNotNullParameter(subscriptionsState, "subscriptionsState");
m.checkNotNullParameter(invoicePreviewFetch, "invoicePreviewFetch");
return new SubscriptionAndInvoice(subscriptionsState, invoicePreviewFetch);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SubscriptionAndInvoice)) {
return false;
}
SubscriptionAndInvoice subscriptionAndInvoice = (SubscriptionAndInvoice) obj;
return m.areEqual(this.subscriptionsState, subscriptionAndInvoice.subscriptionsState) && m.areEqual(this.invoicePreviewFetch, subscriptionAndInvoice.invoicePreviewFetch);
}
public final InvoicePreviewFetch getInvoicePreviewFetch() {
return this.invoicePreviewFetch;
}
public final StoreSubscriptions.SubscriptionsState getSubscriptionsState() {
return this.subscriptionsState;
}
public int hashCode() {
StoreSubscriptions.SubscriptionsState subscriptionsState = this.subscriptionsState;
int i = 0;
int hashCode = (subscriptionsState != null ? subscriptionsState.hashCode() : 0) * 31;
InvoicePreviewFetch invoicePreviewFetch = this.invoicePreviewFetch;
if (invoicePreviewFetch != null) {
i = invoicePreviewFetch.hashCode();
}
return hashCode + i;
}
public String toString() {
StringBuilder R = a.R("SubscriptionAndInvoice(subscriptionsState=");
R.append(this.subscriptionsState);
R.append(", invoicePreviewFetch=");
R.append(this.invoicePreviewFetch);
R.append(")");
return R.toString();
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static abstract class ViewState {
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class Failure extends ViewState {
public static final Failure INSTANCE = new Failure();
private Failure() {
super(null);
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class Loaded extends ViewState {
private final ModelInvoicePreview currentInvoicePreview;
private final List<ModelEntitlement> entitlements;
private final Map<Long, ModelGuildBoostSlot> guildSubscriptions;
private final boolean hasAnyGuildBoosts;
private final boolean isBusy;
private final int pastDueGracePeriodDays;
private final List<ModelPaymentSource> paymentSources;
private final ModelSubscription premiumSubscription;
private final List<Purchase> purchases;
private final ModelInvoicePreview renewalInvoicePreview;
private final Map<String, SkuDetails> skuDetails;
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
/* JADX WARN: Multi-variable type inference failed */
public Loaded(ModelSubscription modelSubscription, List<? extends ModelPaymentSource> list, boolean z2, List<ModelEntitlement> list2, Map<Long, ModelGuildBoostSlot> map, boolean z3, ModelInvoicePreview modelInvoicePreview, ModelInvoicePreview modelInvoicePreview2, Map<String, ? extends SkuDetails> map2, List<? extends Purchase> list3, int i) {
super(null);
m.checkNotNullParameter(list, "paymentSources");
m.checkNotNullParameter(list2, "entitlements");
m.checkNotNullParameter(map, "guildSubscriptions");
m.checkNotNullParameter(map2, "skuDetails");
m.checkNotNullParameter(list3, "purchases");
this.premiumSubscription = modelSubscription;
this.paymentSources = list;
this.isBusy = z2;
this.entitlements = list2;
this.guildSubscriptions = map;
this.hasAnyGuildBoosts = z3;
this.renewalInvoicePreview = modelInvoicePreview;
this.currentInvoicePreview = modelInvoicePreview2;
this.skuDetails = map2;
this.purchases = list3;
this.pastDueGracePeriodDays = i;
}
public static /* synthetic */ Loaded copy$default(Loaded loaded, ModelSubscription modelSubscription, List list, boolean z2, List list2, Map map, boolean z3, ModelInvoicePreview modelInvoicePreview, ModelInvoicePreview modelInvoicePreview2, Map map2, List list3, int i, int i2, Object obj) {
return loaded.copy((i2 & 1) != 0 ? loaded.premiumSubscription : modelSubscription, (i2 & 2) != 0 ? loaded.paymentSources : list, (i2 & 4) != 0 ? loaded.isBusy : z2, (i2 & 8) != 0 ? loaded.entitlements : list2, (i2 & 16) != 0 ? loaded.guildSubscriptions : map, (i2 & 32) != 0 ? loaded.hasAnyGuildBoosts : z3, (i2 & 64) != 0 ? loaded.renewalInvoicePreview : modelInvoicePreview, (i2 & 128) != 0 ? loaded.currentInvoicePreview : modelInvoicePreview2, (i2 & 256) != 0 ? loaded.skuDetails : map2, (i2 & 512) != 0 ? loaded.purchases : list3, (i2 & 1024) != 0 ? loaded.pastDueGracePeriodDays : i);
}
public final ModelSubscription component1() {
return this.premiumSubscription;
}
public final List<Purchase> component10() {
return this.purchases;
}
public final int component11() {
return this.pastDueGracePeriodDays;
}
public final List<ModelPaymentSource> component2() {
return this.paymentSources;
}
public final boolean component3() {
return this.isBusy;
}
public final List<ModelEntitlement> component4() {
return this.entitlements;
}
public final Map<Long, ModelGuildBoostSlot> component5() {
return this.guildSubscriptions;
}
public final boolean component6() {
return this.hasAnyGuildBoosts;
}
public final ModelInvoicePreview component7() {
return this.renewalInvoicePreview;
}
public final ModelInvoicePreview component8() {
return this.currentInvoicePreview;
}
public final Map<String, SkuDetails> component9() {
return this.skuDetails;
}
public final Loaded copy(ModelSubscription modelSubscription, List<? extends ModelPaymentSource> list, boolean z2, List<ModelEntitlement> list2, Map<Long, ModelGuildBoostSlot> map, boolean z3, ModelInvoicePreview modelInvoicePreview, ModelInvoicePreview modelInvoicePreview2, Map<String, ? extends SkuDetails> map2, List<? extends Purchase> list3, int i) {
m.checkNotNullParameter(list, "paymentSources");
m.checkNotNullParameter(list2, "entitlements");
m.checkNotNullParameter(map, "guildSubscriptions");
m.checkNotNullParameter(map2, "skuDetails");
m.checkNotNullParameter(list3, "purchases");
return new Loaded(modelSubscription, list, z2, list2, map, z3, modelInvoicePreview, modelInvoicePreview2, map2, list3, i);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Loaded)) {
return false;
}
Loaded loaded = (Loaded) obj;
return m.areEqual(this.premiumSubscription, loaded.premiumSubscription) && m.areEqual(this.paymentSources, loaded.paymentSources) && this.isBusy == loaded.isBusy && m.areEqual(this.entitlements, loaded.entitlements) && m.areEqual(this.guildSubscriptions, loaded.guildSubscriptions) && this.hasAnyGuildBoosts == loaded.hasAnyGuildBoosts && m.areEqual(this.renewalInvoicePreview, loaded.renewalInvoicePreview) && m.areEqual(this.currentInvoicePreview, loaded.currentInvoicePreview) && m.areEqual(this.skuDetails, loaded.skuDetails) && m.areEqual(this.purchases, loaded.purchases) && this.pastDueGracePeriodDays == loaded.pastDueGracePeriodDays;
}
public final ModelInvoicePreview getCurrentInvoicePreview() {
return this.currentInvoicePreview;
}
public final List<ModelEntitlement> getEntitlements() {
return this.entitlements;
}
public final Map<Long, ModelGuildBoostSlot> getGuildSubscriptions() {
return this.guildSubscriptions;
}
public final boolean getHasAnyGuildBoosts() {
return this.hasAnyGuildBoosts;
}
public final int getPastDueGracePeriodDays() {
return this.pastDueGracePeriodDays;
}
public final List<ModelPaymentSource> getPaymentSources() {
return this.paymentSources;
}
public final ModelSubscription getPremiumSubscription() {
return this.premiumSubscription;
}
public final List<Purchase> getPurchases() {
return this.purchases;
}
public final ModelInvoicePreview getRenewalInvoicePreview() {
return this.renewalInvoicePreview;
}
public final Map<String, SkuDetails> getSkuDetails() {
return this.skuDetails;
}
public int hashCode() {
ModelSubscription modelSubscription = this.premiumSubscription;
int i = 0;
int hashCode = (modelSubscription != null ? modelSubscription.hashCode() : 0) * 31;
List<ModelPaymentSource> list = this.paymentSources;
int hashCode2 = (hashCode + (list != null ? list.hashCode() : 0)) * 31;
boolean z2 = this.isBusy;
int i2 = 1;
if (z2) {
z2 = true;
}
int i3 = z2 ? 1 : 0;
int i4 = z2 ? 1 : 0;
int i5 = z2 ? 1 : 0;
int i6 = (hashCode2 + i3) * 31;
List<ModelEntitlement> list2 = this.entitlements;
int hashCode3 = (i6 + (list2 != null ? list2.hashCode() : 0)) * 31;
Map<Long, ModelGuildBoostSlot> map = this.guildSubscriptions;
int hashCode4 = (hashCode3 + (map != null ? map.hashCode() : 0)) * 31;
boolean z3 = this.hasAnyGuildBoosts;
if (!z3) {
i2 = z3 ? 1 : 0;
}
int i7 = (hashCode4 + i2) * 31;
ModelInvoicePreview modelInvoicePreview = this.renewalInvoicePreview;
int hashCode5 = (i7 + (modelInvoicePreview != null ? modelInvoicePreview.hashCode() : 0)) * 31;
ModelInvoicePreview modelInvoicePreview2 = this.currentInvoicePreview;
int hashCode6 = (hashCode5 + (modelInvoicePreview2 != null ? modelInvoicePreview2.hashCode() : 0)) * 31;
Map<String, SkuDetails> map2 = this.skuDetails;
int hashCode7 = (hashCode6 + (map2 != null ? map2.hashCode() : 0)) * 31;
List<Purchase> list3 = this.purchases;
if (list3 != null) {
i = list3.hashCode();
}
return ((hashCode7 + i) * 31) + this.pastDueGracePeriodDays;
}
public final boolean isBusy() {
return this.isBusy;
}
public String toString() {
StringBuilder R = a.R("Loaded(premiumSubscription=");
R.append(this.premiumSubscription);
R.append(", paymentSources=");
R.append(this.paymentSources);
R.append(", isBusy=");
R.append(this.isBusy);
R.append(", entitlements=");
R.append(this.entitlements);
R.append(", guildSubscriptions=");
R.append(this.guildSubscriptions);
R.append(", hasAnyGuildBoosts=");
R.append(this.hasAnyGuildBoosts);
R.append(", renewalInvoicePreview=");
R.append(this.renewalInvoicePreview);
R.append(", currentInvoicePreview=");
R.append(this.currentInvoicePreview);
R.append(", skuDetails=");
R.append(this.skuDetails);
R.append(", purchases=");
R.append(this.purchases);
R.append(", pastDueGracePeriodDays=");
return a.A(R, this.pastDueGracePeriodDays, ")");
}
}
/* compiled from: SettingsPremiumViewModel.kt */
/* loaded from: classes2.dex */
public static final class Loading extends ViewState {
public static final Loading INSTANCE = new Loading();
private Loading() {
super(null);
}
}
private ViewState() {
}
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public SettingsPremiumViewModel() {
this(null, null, null, null, null, null, 63, null);
}
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
public SettingsPremiumViewModel(StorePaymentSources storePaymentSources, StoreSubscriptions storeSubscriptions, StoreEntitlements storeEntitlements, StoreGuildBoost storeGuildBoost, RestAPI restAPI, Observable<StoreState> observable) {
super(ViewState.Loading.INSTANCE);
m.checkNotNullParameter(storePaymentSources, "storePaymentsSources");
m.checkNotNullParameter(storeSubscriptions, "storeSubscriptions");
m.checkNotNullParameter(storeEntitlements, "storeEntitlements");
m.checkNotNullParameter(storeGuildBoost, "storeGuildBoost");
m.checkNotNullParameter(restAPI, "restAPI");
m.checkNotNullParameter(observable, "storeObservable");
this.storePaymentsSources = storePaymentSources;
this.storeSubscriptions = storeSubscriptions;
this.storeEntitlements = storeEntitlements;
this.storeGuildBoost = storeGuildBoost;
this.restAPI = restAPI;
this.eventSubject = PublishSubject.k0();
fetchData();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(observable), this, null, 2, null), SettingsPremiumViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(), 62, (Object) null);
}
/* JADX WARN: Illegal instructions before constructor call */
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
public /* synthetic */ SettingsPremiumViewModel(StorePaymentSources storePaymentSources, StoreSubscriptions storeSubscriptions, StoreEntitlements storeEntitlements, StoreGuildBoost storeGuildBoost, RestAPI restAPI, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
this(r0, r1, r2, r3, r4, r5);
Observable observable2;
StorePaymentSources paymentSources = (i & 1) != 0 ? StoreStream.Companion.getPaymentSources() : storePaymentSources;
StoreSubscriptions subscriptions = (i & 2) != 0 ? StoreStream.Companion.getSubscriptions() : storeSubscriptions;
StoreEntitlements entitlements = (i & 4) != 0 ? StoreStream.Companion.getEntitlements() : storeEntitlements;
StoreGuildBoost guildBoosts = (i & 8) != 0 ? StoreStream.Companion.getGuildBoosts() : storeGuildBoost;
RestAPI api = (i & 16) != 0 ? RestAPI.Companion.getApi() : restAPI;
if ((i & 32) != 0) {
Companion companion = Companion;
StoreStream.Companion companion2 = StoreStream.Companion;
observable2 = Companion.access$observeStores(companion, companion2.getPaymentSources(), companion2.getSubscriptions(), companion2.getEntitlements(), companion2.getGuildBoosts(), companion2.getGooglePlaySkuDetails(), companion2.getGooglePlayPurchases(), companion2.getExperiments(), RestAPI.Companion.getApi());
} else {
observable2 = observable;
}
}
public static final /* synthetic */ void access$fetchData(SettingsPremiumViewModel settingsPremiumViewModel) {
settingsPremiumViewModel.fetchData();
}
public static final /* synthetic */ void access$handleStoreState(SettingsPremiumViewModel settingsPremiumViewModel, StoreState storeState) {
settingsPremiumViewModel.handleStoreState(storeState);
}
public static final /* synthetic */ void access$onCancelError(SettingsPremiumViewModel settingsPremiumViewModel) {
settingsPremiumViewModel.onCancelError();
}
private final void fetchData() {
this.storePaymentsSources.fetchPaymentSources();
this.storeSubscriptions.fetchSubscriptions();
this.storeEntitlements.fetchMyEntitlementsForApplication(521842831262875670L);
this.storeGuildBoost.fetchUserGuildBoostState();
GooglePlayBillingManager.INSTANCE.querySkuDetails();
}
private final int getPastDueGracePeriodDays(ModelSubscription modelSubscription) {
if (modelSubscription != null && !modelSubscription.isMobileManaged()) {
String paymentSourceId = modelSubscription.getPaymentSourceId();
if (!(paymentSourceId == null || t.isBlank(paymentSourceId))) {
return 7;
}
}
return 3;
}
private final void handleStoreState(StoreState storeState) {
Object obj;
Object obj2;
boolean z2;
StorePaymentSources.PaymentSourcesState paymentSourcesState = storeState.getPaymentSourcesState();
StoreSubscriptions.SubscriptionsState subscriptionsState = storeState.getSubscriptionsState();
StoreEntitlements.State entitlementState = storeState.getEntitlementState();
StoreGuildBoost.State guildBoostState = storeState.getGuildBoostState();
InvoicePreviewFetch renewalInvoicePreviewFetch = storeState.getRenewalInvoicePreviewFetch();
InvoicePreviewFetch currentInvoicePreviewFetch = storeState.getCurrentInvoicePreviewFetch();
StoreGooglePlaySkuDetails.State skuDetailsState = storeState.getSkuDetailsState();
StoreGooglePlayPurchases.State purchaseState = storeState.getPurchaseState();
if (!(paymentSourcesState instanceof StorePaymentSources.PaymentSourcesState.Loaded) || !(subscriptionsState instanceof StoreSubscriptions.SubscriptionsState.Loaded) || !(entitlementState instanceof StoreEntitlements.State.Loaded) || !(guildBoostState instanceof StoreGuildBoost.State.Loaded) || !(renewalInvoicePreviewFetch instanceof InvoicePreviewFetch.Invoice) || !(currentInvoicePreviewFetch instanceof InvoicePreviewFetch.Invoice) || !(skuDetailsState instanceof StoreGooglePlaySkuDetails.State.Loaded) || !(purchaseState instanceof StoreGooglePlayPurchases.State.Loaded)) {
obj = ((paymentSourcesState instanceof StorePaymentSources.PaymentSourcesState.Failure) || (subscriptionsState instanceof StoreSubscriptions.SubscriptionsState.Failure) || (guildBoostState instanceof StoreGuildBoost.State.Failure) || (renewalInvoicePreviewFetch instanceof InvoicePreviewFetch.Error) || (skuDetailsState instanceof StoreGooglePlaySkuDetails.State.Failure)) ? ViewState.Failure.INSTANCE : ViewState.Loading.INSTANCE;
} else {
Iterator<T> it = ((StoreSubscriptions.SubscriptionsState.Loaded) subscriptionsState).getSubscriptions().iterator();
while (true) {
if (!it.hasNext()) {
obj2 = null;
break;
}
obj2 = it.next();
if (((ModelSubscription) obj2).getType() == ModelSubscription.Type.PREMIUM) {
z2 = true;
continue;
} else {
z2 = false;
continue;
}
if (z2) {
break;
}
}
ModelSubscription modelSubscription = (ModelSubscription) obj2;
boolean hasAnyOfPlans = modelSubscription != null ? modelSubscription.hasAnyOfPlans(n0.setOf((Object[]) new Long[]{Long.valueOf(SubscriptionPlanType.PREMIUM_GUILD_MONTH.getPlanId()), Long.valueOf(SubscriptionPlanType.PREMIUM_GUILD_3_MONTH.getPlanId()), Long.valueOf(SubscriptionPlanType.PREMIUM_GUILD_6_MONTH.getPlanId()), Long.valueOf(SubscriptionPlanType.PREMIUM_GUILD_YEAR.getPlanId())})) : false;
List<ModelPaymentSource> paymentSources = ((StorePaymentSources.PaymentSourcesState.Loaded) paymentSourcesState).getPaymentSources();
List<ModelEntitlement> list = ((StoreEntitlements.State.Loaded) entitlementState).getOwnedEntitlements().get(521842831262875670L);
if (list == null) {
list = n.emptyList();
}
obj = new ViewState.Loaded(modelSubscription, paymentSources, false, list, ((StoreGuildBoost.State.Loaded) guildBoostState).getBoostSlotMap(), hasAnyOfPlans, ((InvoicePreviewFetch.Invoice) renewalInvoicePreviewFetch).getModelInvoicePreview(), ((InvoicePreviewFetch.Invoice) currentInvoicePreviewFetch).getModelInvoicePreview(), ((StoreGooglePlaySkuDetails.State.Loaded) skuDetailsState).getSkuDetails(), ((StoreGooglePlayPurchases.State.Loaded) purchaseState).getPurchases(), getPastDueGracePeriodDays(modelSubscription));
}
updateViewState(obj);
}
private final void markBusy() {
ViewState viewState = getViewState();
if (!(viewState instanceof ViewState.Loaded)) {
viewState = null;
}
ViewState.Loaded loaded = (ViewState.Loaded) viewState;
if (loaded != null) {
updateViewState(ViewState.Loaded.copy$default(loaded, null, null, true, null, null, false, null, null, null, null, 0, 2043, null));
}
}
private final void onCancelError() {
if (getViewState() instanceof ViewState.Loaded) {
PublishSubject<Event> publishSubject = this.eventSubject;
publishSubject.k.onNext(new Event.ErrorToast(R.string.premium_alert_error_title));
}
}
@MainThread
public final void cancelSubscription() {
ModelSubscription premiumSubscription;
ViewState viewState = getViewState();
if (!(viewState instanceof ViewState.Loaded)) {
viewState = null;
}
ViewState.Loaded loaded = (ViewState.Loaded) viewState;
if (loaded != null && (premiumSubscription = loaded.getPremiumSubscription()) != null) {
markBusy();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(this.restAPI.deleteSubscription(premiumSubscription.getId()), false, 1, null), this, null, 2, null), SettingsPremiumViewModel.class, (Context) null, (Function1) null, new SettingsPremiumViewModel$cancelSubscription$2(this), (Function0) null, (Function0) null, new SettingsPremiumViewModel$cancelSubscription$1(this), 54, (Object) null);
}
}
@MainThread
public final Observable<Event> getEventSubject() {
PublishSubject<Event> publishSubject = this.eventSubject;
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
return publishSubject;
}
@MainThread
public final void onRetryClicked() {
fetchData();
}
}