319 lines
12 KiB
Java
319 lines
12 KiB
Java
package com.discord.widgets.channels;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.StringRes;
|
|
import c.d.b.a.a;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.stores.StoreChannels;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
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: WidgetThreadSettingsViewModel.kt */
|
|
public final class WidgetThreadSettingsViewModel extends AppViewModel<ViewState> {
|
|
private final long channelId;
|
|
private final PublishSubject<Event> eventSubject = PublishSubject.k0();
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
/* renamed from: com.discord.widgets.channels.WidgetThreadSettingsViewModel$1 reason: invalid class name */
|
|
public static final class AnonymousClass1 extends o implements Function0<Channel> {
|
|
public final /* synthetic */ StoreChannels $channelStore;
|
|
public final /* synthetic */ WidgetThreadSettingsViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass1(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel, StoreChannels storeChannels) {
|
|
super(0);
|
|
this.this$0 = widgetThreadSettingsViewModel;
|
|
this.$channelStore = storeChannels;
|
|
}
|
|
|
|
@Override // kotlin.jvm.functions.Function0
|
|
/* renamed from: invoke */
|
|
public final Channel mo1invoke() {
|
|
return this.$channelStore.getChannel(this.this$0.getChannelId());
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
/* renamed from: com.discord.widgets.channels.WidgetThreadSettingsViewModel$2 reason: invalid class name */
|
|
public static final class AnonymousClass2 extends o implements Function1<Channel, Unit> {
|
|
public final /* synthetic */ WidgetThreadSettingsViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass2(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel) {
|
|
super(1);
|
|
this.this$0 = widgetThreadSettingsViewModel;
|
|
}
|
|
|
|
/* 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(Channel channel) {
|
|
invoke(channel);
|
|
return Unit.a;
|
|
}
|
|
|
|
public final void invoke(Channel channel) {
|
|
WidgetThreadSettingsViewModel.access$handleStoreState(this.this$0, channel);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static abstract class Event {
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static final class ShowToast extends Event {
|
|
private final int messageStringRes;
|
|
|
|
public ShowToast(@StringRes int i) {
|
|
super(null);
|
|
this.messageStringRes = i;
|
|
}
|
|
|
|
public static /* synthetic */ ShowToast copy$default(ShowToast showToast, int i, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
i = showToast.messageStringRes;
|
|
}
|
|
return showToast.copy(i);
|
|
}
|
|
|
|
public final int component1() {
|
|
return this.messageStringRes;
|
|
}
|
|
|
|
public final ShowToast copy(@StringRes int i) {
|
|
return new ShowToast(i);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof ShowToast) && this.messageStringRes == ((ShowToast) obj).messageStringRes;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final int getMessageStringRes() {
|
|
return this.messageStringRes;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.messageStringRes;
|
|
}
|
|
|
|
public String toString() {
|
|
return a.z(a.L("ShowToast(messageStringRes="), this.messageStringRes, ")");
|
|
}
|
|
}
|
|
|
|
private Event() {
|
|
}
|
|
|
|
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static abstract class ViewState {
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static final class Invalid extends ViewState {
|
|
public static final Invalid INSTANCE = new Invalid();
|
|
|
|
private Invalid() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetThreadSettingsViewModel.kt */
|
|
public static final class Valid extends ViewState {
|
|
private final Channel channel;
|
|
private final String channelNameDraft;
|
|
private final boolean hasUnsavedChanges;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public Valid(Channel channel, String str, boolean z2) {
|
|
super(null);
|
|
m.checkNotNullParameter(channel, "channel");
|
|
this.channel = channel;
|
|
this.channelNameDraft = str;
|
|
this.hasUnsavedChanges = z2;
|
|
}
|
|
|
|
public static /* synthetic */ Valid copy$default(Valid valid, Channel channel, String str, boolean z2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
channel = valid.channel;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
str = valid.channelNameDraft;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
z2 = valid.hasUnsavedChanges;
|
|
}
|
|
return valid.copy(channel, str, z2);
|
|
}
|
|
|
|
public final Channel component1() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final String component2() {
|
|
return this.channelNameDraft;
|
|
}
|
|
|
|
public final boolean component3() {
|
|
return this.hasUnsavedChanges;
|
|
}
|
|
|
|
public final Valid copy(Channel channel, String str, boolean z2) {
|
|
m.checkNotNullParameter(channel, "channel");
|
|
return new Valid(channel, str, z2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof Valid)) {
|
|
return false;
|
|
}
|
|
Valid valid = (Valid) obj;
|
|
return m.areEqual(this.channel, valid.channel) && m.areEqual(this.channelNameDraft, valid.channelNameDraft) && this.hasUnsavedChanges == valid.hasUnsavedChanges;
|
|
}
|
|
|
|
public final Channel getChannel() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final String getChannelNameDraft() {
|
|
return this.channelNameDraft;
|
|
}
|
|
|
|
public final boolean getHasUnsavedChanges() {
|
|
return this.hasUnsavedChanges;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Channel channel = this.channel;
|
|
int i = 0;
|
|
int hashCode = (channel != null ? channel.hashCode() : 0) * 31;
|
|
String str = this.channelNameDraft;
|
|
if (str != null) {
|
|
i = str.hashCode();
|
|
}
|
|
int i2 = (hashCode + i) * 31;
|
|
boolean z2 = this.hasUnsavedChanges;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i3 = z2 ? 1 : 0;
|
|
int i4 = z2 ? 1 : 0;
|
|
int i5 = z2 ? 1 : 0;
|
|
return i2 + i3;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = a.L("Valid(channel=");
|
|
L.append(this.channel);
|
|
L.append(", channelNameDraft=");
|
|
L.append(this.channelNameDraft);
|
|
L.append(", hasUnsavedChanges=");
|
|
return a.G(L, this.hasUnsavedChanges, ")");
|
|
}
|
|
}
|
|
|
|
private ViewState() {
|
|
}
|
|
|
|
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public WidgetThreadSettingsViewModel(long j) {
|
|
super(null, 1, null);
|
|
this.channelId = j;
|
|
StoreChannels channels = StoreStream.Companion.getChannels();
|
|
Observable r = ObservationDeck.connectRx$default(ObservationDeckProvider.get(), new ObservationDeck.UpdateSource[]{channels}, false, null, null, new AnonymousClass1(this, channels), 14, null).r();
|
|
m.checkNotNullExpressionValue(r, "ObservationDeckProvider.… .distinctUntilChanged()");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(r, this, null, 2, null), WidgetThreadSettingsViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass2(this), 62, (Object) null);
|
|
}
|
|
|
|
public static final /* synthetic */ PublishSubject access$getEventSubject$p(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel) {
|
|
return widgetThreadSettingsViewModel.eventSubject;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(WidgetThreadSettingsViewModel widgetThreadSettingsViewModel, Channel channel) {
|
|
widgetThreadSettingsViewModel.handleStoreState(channel);
|
|
}
|
|
|
|
@MainThread
|
|
private final void handleStoreState(Channel channel) {
|
|
String str = null;
|
|
if ((channel != null ? channel.m() : null) == null || !AnimatableValueParser.z1(channel)) {
|
|
updateViewState(ViewState.Invalid.INSTANCE);
|
|
return;
|
|
}
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
str = valid.getChannelNameDraft();
|
|
}
|
|
if (str != null) {
|
|
updateViewState(ViewState.Valid.copy$default(valid, channel, null, false, 6, null));
|
|
} else {
|
|
updateViewState(new ViewState.Valid(channel, channel.m(), false));
|
|
}
|
|
}
|
|
|
|
public final long getChannelId() {
|
|
return this.channelId;
|
|
}
|
|
|
|
public final Observable<Event> observeEvents() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
|
|
return publishSubject;
|
|
}
|
|
|
|
@MainThread
|
|
public final void onChannelNameInputChanged(String str) {
|
|
m.checkNotNullParameter(str, "value");
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null) {
|
|
updateViewState(ViewState.Valid.copy$default(valid, null, str, true, 1, null));
|
|
}
|
|
}
|
|
|
|
public final void saveThread() {
|
|
String channelNameDraft;
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Valid)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Valid valid = (ViewState.Valid) viewState;
|
|
if (valid != null && (channelNameDraft = valid.getChannelNameDraft()) != null) {
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(RestAPI.editTextChannel$default(RestAPI.Companion.getApi(), this.channelId, channelNameDraft, null, null, null, null, null, 124, null), this, null, 2, null), WidgetThreadSettingsViewModel.class, (Context) null, (Function1) null, new WidgetThreadSettingsViewModel$saveThread$2(this), (Function0) null, (Function0) null, new WidgetThreadSettingsViewModel$saveThread$1(this), 54, (Object) null);
|
|
}
|
|
}
|
|
}
|