323 lines
15 KiB
Java
323 lines
15 KiB
Java
package com.discord.widgets.settings.billing;
|
|
|
|
import android.content.Context;
|
|
import c.d.b.a.a;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.models.domain.ModelPaymentSource;
|
|
import com.discord.models.domain.ModelSubscription;
|
|
import com.discord.stores.StorePaymentSources;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreSubscriptions;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.widgets.settings.billing.PaymentSourceAdapter;
|
|
import d0.t.n;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.functions.Func2;
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
public final class SettingsBillingViewModel extends AppViewModel<ViewState> {
|
|
private final StorePaymentSources storePaymentSources;
|
|
private final StoreSubscriptions storeSubscriptions;
|
|
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
/* renamed from: com.discord.widgets.settings.billing.SettingsBillingViewModel$1 reason: invalid class name */
|
|
public static final class AnonymousClass1<T1, T2, R> implements Func2<StorePaymentSources.PaymentSourcesState, StoreSubscriptions.SubscriptionsState, StoreState> {
|
|
public static final AnonymousClass1 INSTANCE = new AnonymousClass1();
|
|
|
|
public final StoreState call(StorePaymentSources.PaymentSourcesState paymentSourcesState, StoreSubscriptions.SubscriptionsState subscriptionsState) {
|
|
m.checkNotNullExpressionValue(paymentSourcesState, "paymentSourcesState");
|
|
m.checkNotNullExpressionValue(subscriptionsState, "subscriptionsState");
|
|
return new StoreState(paymentSourcesState, subscriptionsState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
/* renamed from: com.discord.widgets.settings.billing.SettingsBillingViewModel$2 reason: invalid class name */
|
|
public static final class AnonymousClass2 extends o implements Function1<StoreState, Unit> {
|
|
public final /* synthetic */ SettingsBillingViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass2(SettingsBillingViewModel settingsBillingViewModel) {
|
|
super(1);
|
|
this.this$0 = settingsBillingViewModel;
|
|
}
|
|
|
|
/* Return type fixed from 'java.lang.Object' to match base method */
|
|
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
|
|
@Override // kotlin.jvm.functions.Function1
|
|
public /* bridge */ /* synthetic */ Unit invoke(StoreState storeState) {
|
|
invoke(storeState);
|
|
return Unit.a;
|
|
}
|
|
|
|
public final void invoke(StoreState storeState) {
|
|
m.checkNotNullParameter(storeState, "storeState");
|
|
SettingsBillingViewModel.access$handleStoreState(this.this$0, storeState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
public static final class StoreState {
|
|
private final StorePaymentSources.PaymentSourcesState paymentSourceState;
|
|
private final StoreSubscriptions.SubscriptionsState subscriptionsState;
|
|
|
|
public StoreState(StorePaymentSources.PaymentSourcesState paymentSourcesState, StoreSubscriptions.SubscriptionsState subscriptionsState) {
|
|
m.checkNotNullParameter(paymentSourcesState, "paymentSourceState");
|
|
m.checkNotNullParameter(subscriptionsState, "subscriptionsState");
|
|
this.paymentSourceState = paymentSourcesState;
|
|
this.subscriptionsState = subscriptionsState;
|
|
}
|
|
|
|
public static /* synthetic */ StoreState copy$default(StoreState storeState, StorePaymentSources.PaymentSourcesState paymentSourcesState, StoreSubscriptions.SubscriptionsState subscriptionsState, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
paymentSourcesState = storeState.paymentSourceState;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
subscriptionsState = storeState.subscriptionsState;
|
|
}
|
|
return storeState.copy(paymentSourcesState, subscriptionsState);
|
|
}
|
|
|
|
public final StorePaymentSources.PaymentSourcesState component1() {
|
|
return this.paymentSourceState;
|
|
}
|
|
|
|
public final StoreSubscriptions.SubscriptionsState component2() {
|
|
return this.subscriptionsState;
|
|
}
|
|
|
|
public final StoreState copy(StorePaymentSources.PaymentSourcesState paymentSourcesState, StoreSubscriptions.SubscriptionsState subscriptionsState) {
|
|
m.checkNotNullParameter(paymentSourcesState, "paymentSourceState");
|
|
m.checkNotNullParameter(subscriptionsState, "subscriptionsState");
|
|
return new StoreState(paymentSourcesState, subscriptionsState);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof StoreState)) {
|
|
return false;
|
|
}
|
|
StoreState storeState = (StoreState) obj;
|
|
return m.areEqual(this.paymentSourceState, storeState.paymentSourceState) && m.areEqual(this.subscriptionsState, storeState.subscriptionsState);
|
|
}
|
|
|
|
public final StorePaymentSources.PaymentSourcesState getPaymentSourceState() {
|
|
return this.paymentSourceState;
|
|
}
|
|
|
|
public final StoreSubscriptions.SubscriptionsState getSubscriptionsState() {
|
|
return this.subscriptionsState;
|
|
}
|
|
|
|
public int hashCode() {
|
|
StorePaymentSources.PaymentSourcesState paymentSourcesState = this.paymentSourceState;
|
|
int i = 0;
|
|
int hashCode = (paymentSourcesState != null ? paymentSourcesState.hashCode() : 0) * 31;
|
|
StoreSubscriptions.SubscriptionsState subscriptionsState = this.subscriptionsState;
|
|
if (subscriptionsState != null) {
|
|
i = subscriptionsState.hashCode();
|
|
}
|
|
return hashCode + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("StoreState(paymentSourceState=");
|
|
L.append(this.paymentSourceState);
|
|
L.append(", subscriptionsState=");
|
|
L.append(this.subscriptionsState);
|
|
L.append(")");
|
|
return L.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
public static abstract class ViewState {
|
|
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
public static final class Failure extends ViewState {
|
|
public static final Failure INSTANCE = new Failure();
|
|
|
|
private Failure() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
public static final class Loaded extends ViewState {
|
|
private final List<PaymentSourceAdapter.Item> paymentSourceItems;
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.util.List<? extends com.discord.widgets.settings.billing.PaymentSourceAdapter$Item> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Loaded(List<? extends PaymentSourceAdapter.Item> list) {
|
|
super(null);
|
|
m.checkNotNullParameter(list, "paymentSourceItems");
|
|
this.paymentSourceItems = list;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.settings.billing.SettingsBillingViewModel$ViewState$Loaded */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ Loaded copy$default(Loaded loaded, List list, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
list = loaded.paymentSourceItems;
|
|
}
|
|
return loaded.copy(list);
|
|
}
|
|
|
|
public final List<PaymentSourceAdapter.Item> component1() {
|
|
return this.paymentSourceItems;
|
|
}
|
|
|
|
public final Loaded copy(List<? extends PaymentSourceAdapter.Item> list) {
|
|
m.checkNotNullParameter(list, "paymentSourceItems");
|
|
return new Loaded(list);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Loaded) && m.areEqual(this.paymentSourceItems, ((Loaded) obj).paymentSourceItems);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final List<PaymentSourceAdapter.Item> getPaymentSourceItems() {
|
|
return this.paymentSourceItems;
|
|
}
|
|
|
|
public int hashCode() {
|
|
List<PaymentSourceAdapter.Item> list = this.paymentSourceItems;
|
|
if (list != null) {
|
|
return list.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
return a.E(a.L("Loaded(paymentSourceItems="), this.paymentSourceItems, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: SettingsBillingViewModel.kt */
|
|
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 SettingsBillingViewModel() {
|
|
this(null, null, null, 7, null);
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public SettingsBillingViewModel(StorePaymentSources storePaymentSources, StoreSubscriptions storeSubscriptions, Observable<StoreState> observable) {
|
|
super(ViewState.Loading.INSTANCE);
|
|
m.checkNotNullParameter(storePaymentSources, "storePaymentSources");
|
|
m.checkNotNullParameter(storeSubscriptions, "storeSubscriptions");
|
|
m.checkNotNullParameter(observable, "storeObservable");
|
|
this.storePaymentSources = storePaymentSources;
|
|
this.storeSubscriptions = storeSubscriptions;
|
|
fetchData();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.computationLatest(observable), this, null, 2, null), SettingsBillingViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass2(this), 62, (Object) null);
|
|
}
|
|
|
|
/* JADX WARNING: Illegal instructions before constructor call */
|
|
public /* synthetic */ SettingsBillingViewModel(StorePaymentSources storePaymentSources, StoreSubscriptions storeSubscriptions, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(storePaymentSources, storeSubscriptions, observable);
|
|
storePaymentSources = (i & 1) != 0 ? StoreStream.Companion.getPaymentSources() : storePaymentSources;
|
|
storeSubscriptions = (i & 2) != 0 ? StoreStream.Companion.getSubscriptions() : storeSubscriptions;
|
|
if ((i & 4) != 0) {
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
observable = Observable.j(companion.getPaymentSources().observePaymentSourcesState(), companion.getSubscriptions().observeSubscriptions(), AnonymousClass1.INSTANCE);
|
|
m.checkNotNullExpressionValue(observable, "Observable\n .combin…nsState\n )\n }");
|
|
}
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(SettingsBillingViewModel settingsBillingViewModel, StoreState storeState) {
|
|
settingsBillingViewModel.handleStoreState(storeState);
|
|
}
|
|
|
|
private final void fetchData() {
|
|
this.storePaymentSources.fetchPaymentSources();
|
|
this.storeSubscriptions.fetchSubscriptions();
|
|
}
|
|
|
|
private final List<PaymentSourceAdapter.Item> generateListItems(List<? extends ModelPaymentSource> list, ModelSubscription modelSubscription) {
|
|
ArrayList arrayList = new ArrayList();
|
|
if (!list.isEmpty()) {
|
|
int i = 0;
|
|
for (Object obj : list) {
|
|
int i2 = i + 1;
|
|
if (i < 0) {
|
|
n.throwIndexOverflow();
|
|
}
|
|
ModelPaymentSource modelPaymentSource = (ModelPaymentSource) obj;
|
|
String str = null;
|
|
PaymentSourceAdapter.PaymentSourceHeader.Type type = i != 0 ? i != 1 ? null : PaymentSourceAdapter.PaymentSourceHeader.Type.OTHER : PaymentSourceAdapter.PaymentSourceHeader.Type.DEFAULT;
|
|
PaymentSourceAdapter.PaymentSourceHeader paymentSourceHeader = type != null ? new PaymentSourceAdapter.PaymentSourceHeader(type) : null;
|
|
if (paymentSourceHeader != null) {
|
|
arrayList.add(paymentSourceHeader);
|
|
}
|
|
String id2 = modelPaymentSource.getId();
|
|
if (modelSubscription != null) {
|
|
str = modelSubscription.getPaymentSourceId();
|
|
}
|
|
arrayList.add(new PaymentSourceAdapter.PaymentSourceItem(modelPaymentSource, m.areEqual(id2, str) && !modelSubscription.getStatus().isCanceled()));
|
|
i = i2;
|
|
}
|
|
arrayList.add(new PaymentSourceAdapter.PaymentSourceAddItem());
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
private final void handleStoreState(StoreState storeState) {
|
|
Object obj;
|
|
boolean z2;
|
|
StorePaymentSources.PaymentSourcesState paymentSourceState = storeState.getPaymentSourceState();
|
|
StoreSubscriptions.SubscriptionsState subscriptionsState = storeState.getSubscriptionsState();
|
|
if ((paymentSourceState instanceof StorePaymentSources.PaymentSourcesState.Loaded) && (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) {
|
|
z2 = true;
|
|
continue;
|
|
} else {
|
|
z2 = false;
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
break;
|
|
}
|
|
}
|
|
updateViewState(new ViewState.Loaded(generateListItems(((StorePaymentSources.PaymentSourcesState.Loaded) paymentSourceState).getPaymentSources(), (ModelSubscription) obj)));
|
|
} else if ((paymentSourceState instanceof StorePaymentSources.PaymentSourcesState.Failure) || (subscriptionsState instanceof StoreSubscriptions.SubscriptionsState.Failure)) {
|
|
updateViewState(ViewState.Failure.INSTANCE);
|
|
} else {
|
|
updateViewState(ViewState.Loading.INSTANCE);
|
|
}
|
|
}
|
|
}
|