374 lines
16 KiB
Java
374 lines
16 KiB
Java
package com.discord.widgets.guild_role_subscriptions.setup;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.MainThread;
|
|
import c.d.b.a.a;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.stores.StoreGuildRoleSubscriptions;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.error.Error;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.widgets.guild_role_subscriptions.GuildRoleSubscriptionUtils;
|
|
import com.discord.widgets.guild_role_subscriptions.tier.model.GuildRoleSubscriptionTier;
|
|
import d0.g0.t;
|
|
import d0.z.d.m;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.subjects.PublishSubject;
|
|
/* compiled from: GuildRoleSubscriptionPlanSetupViewModel.kt */
|
|
public final class GuildRoleSubscriptionPlanSetupViewModel extends AppViewModel<ViewState> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final int DETAILS_STEP = 0;
|
|
private static final int TIER_CHANNEL_BENEFITS_STEP = 2;
|
|
private static final int TIER_DESIGN_STEP = 4;
|
|
private static final int TIER_DETAILS_STEP = 1;
|
|
private static final int TIER_INTANGIBLE_BENEFITS_STEP = 3;
|
|
private final PublishSubject<Event> eventSubject;
|
|
private final long guildId;
|
|
private final RestAPI restApi;
|
|
private final StoreGuildRoleSubscriptions storeGuildRoleSubscriptions;
|
|
|
|
/* compiled from: GuildRoleSubscriptionPlanSetupViewModel.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: GuildRoleSubscriptionPlanSetupViewModel.kt */
|
|
public static abstract class Event {
|
|
|
|
/* compiled from: GuildRoleSubscriptionPlanSetupViewModel.kt */
|
|
public static final class SubmitFailure extends Event {
|
|
private final Error error;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public SubmitFailure(Error error) {
|
|
super(null);
|
|
m.checkNotNullParameter(error, "error");
|
|
this.error = error;
|
|
}
|
|
|
|
public static /* synthetic */ SubmitFailure copy$default(SubmitFailure submitFailure, Error error, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
error = submitFailure.error;
|
|
}
|
|
return submitFailure.copy(error);
|
|
}
|
|
|
|
public final Error component1() {
|
|
return this.error;
|
|
}
|
|
|
|
public final SubmitFailure copy(Error error) {
|
|
m.checkNotNullParameter(error, "error");
|
|
return new SubmitFailure(error);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof SubmitFailure) && m.areEqual(this.error, ((SubmitFailure) obj).error);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final Error getError() {
|
|
return this.error;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Error error = this.error;
|
|
if (error != null) {
|
|
return error.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder O = a.O("SubmitFailure(error=");
|
|
O.append(this.error);
|
|
O.append(")");
|
|
return O.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: GuildRoleSubscriptionPlanSetupViewModel.kt */
|
|
public static final class SubmitSuccess extends Event {
|
|
public static final SubmitSuccess INSTANCE = new SubmitSuccess();
|
|
|
|
private SubmitSuccess() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private Event() {
|
|
}
|
|
|
|
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: GuildRoleSubscriptionPlanSetupViewModel.kt */
|
|
public static final class ViewState {
|
|
private final boolean canProceedToNextStep;
|
|
private final String coverImage;
|
|
private final int currentStep;
|
|
private final GuildRoleSubscriptionTier guildRoleSubscriptionTier;
|
|
private final boolean isSubmitting;
|
|
private final String planDescription;
|
|
|
|
public ViewState() {
|
|
this(0, false, false, null, null, null, 63, null);
|
|
}
|
|
|
|
public ViewState(int i, boolean z2, boolean z3, String str, String str2, GuildRoleSubscriptionTier guildRoleSubscriptionTier) {
|
|
m.checkNotNullParameter(guildRoleSubscriptionTier, "guildRoleSubscriptionTier");
|
|
this.currentStep = i;
|
|
this.isSubmitting = z2;
|
|
this.canProceedToNextStep = z3;
|
|
this.coverImage = str;
|
|
this.planDescription = str2;
|
|
this.guildRoleSubscriptionTier = guildRoleSubscriptionTier;
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ ViewState(int i, boolean z2, boolean z3, String str, String str2, GuildRoleSubscriptionTier guildRoleSubscriptionTier, int i2, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this((i2 & 1) != 0 ? 0 : i, (i2 & 2) != 0 ? false : z2, (i2 & 4) == 0 ? z3 : false, (i2 & 8) != 0 ? null : str, (i2 & 16) == 0 ? str2 : null, (i2 & 32) != 0 ? new GuildRoleSubscriptionTier(null, null, null, null, null, null, null, null, null, null, null, null, null, 8191, null) : guildRoleSubscriptionTier);
|
|
}
|
|
|
|
public static /* synthetic */ ViewState copy$default(ViewState viewState, int i, boolean z2, boolean z3, String str, String str2, GuildRoleSubscriptionTier guildRoleSubscriptionTier, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
i = viewState.currentStep;
|
|
}
|
|
if ((i2 & 2) != 0) {
|
|
z2 = viewState.isSubmitting;
|
|
}
|
|
if ((i2 & 4) != 0) {
|
|
z3 = viewState.canProceedToNextStep;
|
|
}
|
|
if ((i2 & 8) != 0) {
|
|
str = viewState.coverImage;
|
|
}
|
|
if ((i2 & 16) != 0) {
|
|
str2 = viewState.planDescription;
|
|
}
|
|
if ((i2 & 32) != 0) {
|
|
guildRoleSubscriptionTier = viewState.guildRoleSubscriptionTier;
|
|
}
|
|
return viewState.copy(i, z2, z3, str, str2, guildRoleSubscriptionTier);
|
|
}
|
|
|
|
public final int component1() {
|
|
return this.currentStep;
|
|
}
|
|
|
|
public final boolean component2() {
|
|
return this.isSubmitting;
|
|
}
|
|
|
|
public final boolean component3() {
|
|
return this.canProceedToNextStep;
|
|
}
|
|
|
|
public final String component4() {
|
|
return this.coverImage;
|
|
}
|
|
|
|
public final String component5() {
|
|
return this.planDescription;
|
|
}
|
|
|
|
public final GuildRoleSubscriptionTier component6() {
|
|
return this.guildRoleSubscriptionTier;
|
|
}
|
|
|
|
public final ViewState copy(int i, boolean z2, boolean z3, String str, String str2, GuildRoleSubscriptionTier guildRoleSubscriptionTier) {
|
|
m.checkNotNullParameter(guildRoleSubscriptionTier, "guildRoleSubscriptionTier");
|
|
return new ViewState(i, z2, z3, str, str2, guildRoleSubscriptionTier);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof ViewState)) {
|
|
return false;
|
|
}
|
|
ViewState viewState = (ViewState) obj;
|
|
return this.currentStep == viewState.currentStep && this.isSubmitting == viewState.isSubmitting && this.canProceedToNextStep == viewState.canProceedToNextStep && m.areEqual(this.coverImage, viewState.coverImage) && m.areEqual(this.planDescription, viewState.planDescription) && m.areEqual(this.guildRoleSubscriptionTier, viewState.guildRoleSubscriptionTier);
|
|
}
|
|
|
|
public final boolean getCanProceedToNextStep() {
|
|
return this.canProceedToNextStep;
|
|
}
|
|
|
|
public final String getCoverImage() {
|
|
return this.coverImage;
|
|
}
|
|
|
|
public final int getCurrentStep() {
|
|
return this.currentStep;
|
|
}
|
|
|
|
public final GuildRoleSubscriptionTier getGuildRoleSubscriptionTier() {
|
|
return this.guildRoleSubscriptionTier;
|
|
}
|
|
|
|
public final String getPlanDescription() {
|
|
return this.planDescription;
|
|
}
|
|
|
|
public int hashCode() {
|
|
int i = this.currentStep * 31;
|
|
boolean z2 = this.isSubmitting;
|
|
int i2 = 1;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i3 = z2 ? 1 : 0;
|
|
int i4 = z2 ? 1 : 0;
|
|
int i5 = z2 ? 1 : 0;
|
|
int i6 = (i + i3) * 31;
|
|
boolean z3 = this.canProceedToNextStep;
|
|
if (!z3) {
|
|
i2 = z3 ? 1 : 0;
|
|
}
|
|
int i7 = (i6 + i2) * 31;
|
|
String str = this.coverImage;
|
|
int i8 = 0;
|
|
int hashCode = (i7 + (str != null ? str.hashCode() : 0)) * 31;
|
|
String str2 = this.planDescription;
|
|
int hashCode2 = (hashCode + (str2 != null ? str2.hashCode() : 0)) * 31;
|
|
GuildRoleSubscriptionTier guildRoleSubscriptionTier = this.guildRoleSubscriptionTier;
|
|
if (guildRoleSubscriptionTier != null) {
|
|
i8 = guildRoleSubscriptionTier.hashCode();
|
|
}
|
|
return hashCode2 + i8;
|
|
}
|
|
|
|
public final boolean isSubmitting() {
|
|
return this.isSubmitting;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder O = a.O("ViewState(currentStep=");
|
|
O.append(this.currentStep);
|
|
O.append(", isSubmitting=");
|
|
O.append(this.isSubmitting);
|
|
O.append(", canProceedToNextStep=");
|
|
O.append(this.canProceedToNextStep);
|
|
O.append(", coverImage=");
|
|
O.append(this.coverImage);
|
|
O.append(", planDescription=");
|
|
O.append(this.planDescription);
|
|
O.append(", guildRoleSubscriptionTier=");
|
|
O.append(this.guildRoleSubscriptionTier);
|
|
O.append(")");
|
|
return O.toString();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public GuildRoleSubscriptionPlanSetupViewModel(long j, RestAPI restAPI, StoreGuildRoleSubscriptions storeGuildRoleSubscriptions) {
|
|
super(new ViewState(0, false, false, null, null, null, 63, null));
|
|
m.checkNotNullParameter(restAPI, "restApi");
|
|
m.checkNotNullParameter(storeGuildRoleSubscriptions, "storeGuildRoleSubscriptions");
|
|
this.guildId = j;
|
|
this.restApi = restAPI;
|
|
this.storeGuildRoleSubscriptions = storeGuildRoleSubscriptions;
|
|
this.eventSubject = PublishSubject.k0();
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ GuildRoleSubscriptionPlanSetupViewModel(long j, RestAPI restAPI, StoreGuildRoleSubscriptions storeGuildRoleSubscriptions, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(j, (i & 2) != 0 ? RestAPI.Companion.getApi() : restAPI, (i & 4) != 0 ? StoreStream.Companion.getGuildRoleSubscriptions() : storeGuildRoleSubscriptions);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$emitEvent(GuildRoleSubscriptionPlanSetupViewModel guildRoleSubscriptionPlanSetupViewModel, Event event) {
|
|
guildRoleSubscriptionPlanSetupViewModel.emitEvent(event);
|
|
}
|
|
|
|
public static final /* synthetic */ ViewState access$requireViewState(GuildRoleSubscriptionPlanSetupViewModel guildRoleSubscriptionPlanSetupViewModel) {
|
|
return guildRoleSubscriptionPlanSetupViewModel.requireViewState();
|
|
}
|
|
|
|
private final boolean computeCanProceedToNextStep(ViewState viewState) {
|
|
GuildRoleSubscriptionTier guildRoleSubscriptionTier = viewState.getGuildRoleSubscriptionTier();
|
|
int currentStep = viewState.getCurrentStep();
|
|
if (currentStep == 0) {
|
|
String coverImage = viewState.getCoverImage();
|
|
if (coverImage == null || t.isBlank(coverImage)) {
|
|
return false;
|
|
}
|
|
String planDescription = viewState.getPlanDescription();
|
|
if (planDescription == null || t.isBlank(planDescription)) {
|
|
return false;
|
|
}
|
|
} else if (currentStep == 1) {
|
|
String name = guildRoleSubscriptionTier.getName();
|
|
if ((name == null || t.isBlank(name)) || guildRoleSubscriptionTier.getPriceTier() == null) {
|
|
return false;
|
|
}
|
|
String image = guildRoleSubscriptionTier.getImage();
|
|
if (image == null || t.isBlank(image)) {
|
|
return false;
|
|
}
|
|
} else if (currentStep != 2 && currentStep != 3 && (currentStep != 4 || guildRoleSubscriptionTier.getMemberColor() == null)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@MainThread
|
|
private final void emitEvent(Event event) {
|
|
this.eventSubject.j.onNext(event);
|
|
}
|
|
|
|
public final void goToNextStep() {
|
|
ViewState requireViewState = requireViewState();
|
|
updateViewState(ViewState.copy$default(requireViewState, requireViewState.getCurrentStep() + 1, false, false, null, null, null, 62, null));
|
|
}
|
|
|
|
public final void goToPreviousStep() {
|
|
ViewState requireViewState = requireViewState();
|
|
updateViewState(ViewState.copy$default(requireViewState, requireViewState.getCurrentStep() - 1, false, false, null, null, null, 62, null));
|
|
}
|
|
|
|
public final Observable<Event> observeEvents() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
|
|
return publishSubject;
|
|
}
|
|
|
|
public final void onSubscriptionPlanUpdated(String str, String str2) {
|
|
updateViewState(ViewState.copy$default(requireViewState(), 0, false, false, str, str2, null, 39, null));
|
|
}
|
|
|
|
public final void onTierUpdated(GuildRoleSubscriptionTier guildRoleSubscriptionTier) {
|
|
m.checkNotNullParameter(guildRoleSubscriptionTier, "guildRoleSubscriptionTier");
|
|
updateViewState(ViewState.copy$default(requireViewState(), 0, false, false, null, null, guildRoleSubscriptionTier, 31, null));
|
|
}
|
|
|
|
public final void submit() {
|
|
ViewState requireViewState = requireViewState();
|
|
GuildRoleSubscriptionTier guildRoleSubscriptionTier = requireViewState.getGuildRoleSubscriptionTier();
|
|
String name = guildRoleSubscriptionTier.getName();
|
|
if (!(name == null || t.isBlank(name)) && guildRoleSubscriptionTier.getPriceTier() != null && guildRoleSubscriptionTier.getMemberColor() != null) {
|
|
updateViewState(ViewState.copy$default(requireViewState, 0, true, false, null, null, null, 61, null));
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(GuildRoleSubscriptionUtils.INSTANCE.createGuildRoleSubscriptionGroupListing(this.restApi, this.storeGuildRoleSubscriptions, this.guildId, requireViewState.getCoverImage(), requireViewState.getPlanDescription(), guildRoleSubscriptionTier.getName(), guildRoleSubscriptionTier.getDescription(), guildRoleSubscriptionTier.getPriceTier().intValue(), guildRoleSubscriptionTier.getImage(), guildRoleSubscriptionTier.getMemberColor().intValue(), guildRoleSubscriptionTier.getMemberIcon(), guildRoleSubscriptionTier.getChannelBenefits(), guildRoleSubscriptionTier.getIntangibleBenefits()), this, null, 2, null), GuildRoleSubscriptionPlanSetupViewModel.class, (Context) null, (Function1) null, new GuildRoleSubscriptionPlanSetupViewModel$submit$2(this), (Function0) null, (Function0) null, new GuildRoleSubscriptionPlanSetupViewModel$submit$1(this), 54, (Object) null);
|
|
}
|
|
}
|
|
|
|
public void updateViewState(ViewState viewState) {
|
|
m.checkNotNullParameter(viewState, "viewState");
|
|
super.updateViewState((GuildRoleSubscriptionPlanSetupViewModel) ViewState.copy$default(viewState, 0, false, computeCanProceedToNextStep(viewState), null, null, null, 59, null));
|
|
}
|
|
}
|