402 lines
14 KiB
Java
402 lines
14 KiB
Java
package com.discord.widgets.settings.account;
|
|
|
|
import android.content.Context;
|
|
import androidx.annotation.StringRes;
|
|
import b.d.b.a.a;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.models.user.User;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.StoreUser;
|
|
import com.discord.stores.StoreUserRelationships;
|
|
import com.discord.utilities.mg_recycler.MGRecyclerDataPayload;
|
|
import com.discord.utilities.rest.RestAPI;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import d0.f0.q;
|
|
import d0.t.i0;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
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: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public final class WidgetSettingsBlockedUsersViewModel extends AppViewModel<ViewState> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private static final String LOCATION = "Blocked Users List";
|
|
public static final int VIEW_TYPE_BLOCKED_USER_ITEM = 0;
|
|
private final PublishSubject<Event> eventSubject;
|
|
private final RestAPI restAPI;
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* renamed from: com.discord.widgets.settings.account.WidgetSettingsBlockedUsersViewModel$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");
|
|
WidgetSettingsBlockedUsersViewModel.access$handleStoreState(WidgetSettingsBlockedUsersViewModel.this, storeState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final Observable<StoreState> observeStores(StoreUserRelationships storeUserRelationships, StoreUser storeUser) {
|
|
m.checkNotNullParameter(storeUserRelationships, "storeUserRelationships");
|
|
m.checkNotNullParameter(storeUser, "storeUser");
|
|
Observable Y = storeUserRelationships.observe().Y(new WidgetSettingsBlockedUsersViewModel$Companion$observeStores$1(storeUser));
|
|
m.checkNotNullExpressionValue(Y, "storeUserRelationships\n … }\n }");
|
|
return Y;
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static abstract class Event {
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class ShowToast extends Event {
|
|
private final int stringRes;
|
|
|
|
public ShowToast(int i) {
|
|
super(null);
|
|
this.stringRes = i;
|
|
}
|
|
|
|
public static /* synthetic */ ShowToast copy$default(ShowToast showToast, int i, int i2, Object obj) {
|
|
if ((i2 & 1) != 0) {
|
|
i = showToast.stringRes;
|
|
}
|
|
return showToast.copy(i);
|
|
}
|
|
|
|
public final int component1() {
|
|
return this.stringRes;
|
|
}
|
|
|
|
public final ShowToast copy(int i) {
|
|
return new ShowToast(i);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof ShowToast) && this.stringRes == ((ShowToast) obj).stringRes;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final int getStringRes() {
|
|
return this.stringRes;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.stringRes;
|
|
}
|
|
|
|
public String toString() {
|
|
return a.A(a.R("ShowToast(stringRes="), this.stringRes, ")");
|
|
}
|
|
}
|
|
|
|
private Event() {
|
|
}
|
|
|
|
public /* synthetic */ Event(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Item implements MGRecyclerDataPayload {
|
|
private final String key;
|
|
private final int type;
|
|
private final User user;
|
|
|
|
public Item(User user) {
|
|
m.checkNotNullParameter(user, "user");
|
|
this.user = user;
|
|
this.key = String.valueOf(user.getId());
|
|
}
|
|
|
|
public static /* synthetic */ Item copy$default(Item item, User user, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
user = item.user;
|
|
}
|
|
return item.copy(user);
|
|
}
|
|
|
|
public final User component1() {
|
|
return this.user;
|
|
}
|
|
|
|
public final Item copy(User user) {
|
|
m.checkNotNullParameter(user, "user");
|
|
return new Item(user);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Item) && m.areEqual(this.user, ((Item) obj).user);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload, com.discord.utilities.recycler.DiffKeyProvider
|
|
public String getKey() {
|
|
return this.key;
|
|
}
|
|
|
|
@Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload
|
|
public int getType() {
|
|
return this.type;
|
|
}
|
|
|
|
public final User getUser() {
|
|
return this.user;
|
|
}
|
|
|
|
public int hashCode() {
|
|
User user = this.user;
|
|
if (user != null) {
|
|
return user.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder R = a.R("Item(user=");
|
|
R.append(this.user);
|
|
R.append(")");
|
|
return R.toString();
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class StoreState {
|
|
private final Map<Long, User> users;
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public StoreState(Map<Long, ? extends User> map) {
|
|
m.checkNotNullParameter(map, "users");
|
|
this.users = map;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ StoreState copy$default(StoreState storeState, Map map, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
map = storeState.users;
|
|
}
|
|
return storeState.copy(map);
|
|
}
|
|
|
|
public final Map<Long, User> component1() {
|
|
return this.users;
|
|
}
|
|
|
|
public final StoreState copy(Map<Long, ? extends User> map) {
|
|
m.checkNotNullParameter(map, "users");
|
|
return new StoreState(map);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof StoreState) && m.areEqual(this.users, ((StoreState) obj).users);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final Map<Long, User> getUsers() {
|
|
return this.users;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Map<Long, User> map = this.users;
|
|
if (map != null) {
|
|
return map.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
return a.L(a.R("StoreState(users="), this.users, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static abstract class ViewState {
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Empty extends ViewState {
|
|
public static final Empty INSTANCE = new Empty();
|
|
|
|
private Empty() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Loaded extends ViewState {
|
|
private final List<Item> items;
|
|
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
public Loaded(List<Item> list) {
|
|
super(null);
|
|
m.checkNotNullParameter(list, "items");
|
|
this.items = list;
|
|
}
|
|
|
|
/* 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.items;
|
|
}
|
|
return loaded.copy(list);
|
|
}
|
|
|
|
public final List<Item> component1() {
|
|
return this.items;
|
|
}
|
|
|
|
public final Loaded copy(List<Item> list) {
|
|
m.checkNotNullParameter(list, "items");
|
|
return new Loaded(list);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Loaded) && m.areEqual(this.items, ((Loaded) obj).items);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final List<Item> getItems() {
|
|
return this.items;
|
|
}
|
|
|
|
public int hashCode() {
|
|
List<Item> list = this.items;
|
|
if (list != null) {
|
|
return list.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
return a.K(a.R("Loaded(items="), this.items, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSettingsBlockedUsersViewModel.kt */
|
|
/* loaded from: classes2.dex */
|
|
public static final class Uninitialized extends ViewState {
|
|
public static final Uninitialized INSTANCE = new Uninitialized();
|
|
|
|
private Uninitialized() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private ViewState() {
|
|
}
|
|
|
|
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public WidgetSettingsBlockedUsersViewModel() {
|
|
this(null, null, 3, null);
|
|
}
|
|
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
public WidgetSettingsBlockedUsersViewModel(Observable<StoreState> observable, RestAPI restAPI) {
|
|
super(ViewState.Uninitialized.INSTANCE);
|
|
m.checkNotNullParameter(observable, "storeObservable");
|
|
m.checkNotNullParameter(restAPI, "restAPI");
|
|
this.restAPI = restAPI;
|
|
this.eventSubject = PublishSubject.k0();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(observable, this, null, 2, null), WidgetSettingsBlockedUsersViewModel.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 */ WidgetSettingsBlockedUsersViewModel(Observable observable, RestAPI restAPI, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(observable, (i & 2) != 0 ? RestAPI.Companion.getApi() : restAPI);
|
|
if ((i & 1) != 0) {
|
|
Companion companion = Companion;
|
|
StoreStream.Companion companion2 = StoreStream.Companion;
|
|
observable = companion.observeStores(companion2.getUserRelationships(), companion2.getUsers());
|
|
}
|
|
}
|
|
|
|
public static final /* synthetic */ void access$emitShowToastEvent(WidgetSettingsBlockedUsersViewModel widgetSettingsBlockedUsersViewModel, int i) {
|
|
widgetSettingsBlockedUsersViewModel.emitShowToastEvent(i);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(WidgetSettingsBlockedUsersViewModel widgetSettingsBlockedUsersViewModel, StoreState storeState) {
|
|
widgetSettingsBlockedUsersViewModel.handleStoreState(storeState);
|
|
}
|
|
|
|
private final void emitShowToastEvent(@StringRes int i) {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
publishSubject.k.onNext(new Event.ShowToast(i));
|
|
}
|
|
|
|
private final List<Item> getItems(Map<Long, ? extends User> map) {
|
|
return q.toList(q.sortedWith(q.map(i0.asSequence(map), WidgetSettingsBlockedUsersViewModel$getItems$1.INSTANCE), WidgetSettingsBlockedUsersViewModel$getItems$2.INSTANCE));
|
|
}
|
|
|
|
private final void handleStoreState(StoreState storeState) {
|
|
List<Item> items = getItems(storeState.getUsers());
|
|
if (items.isEmpty()) {
|
|
updateViewState(ViewState.Empty.INSTANCE);
|
|
} else {
|
|
updateViewState(new ViewState.Loaded(items));
|
|
}
|
|
}
|
|
|
|
public final RestAPI getRestAPI() {
|
|
return this.restAPI;
|
|
}
|
|
|
|
public final Observable<Event> observeEvents() {
|
|
PublishSubject<Event> publishSubject = this.eventSubject;
|
|
m.checkNotNullExpressionValue(publishSubject, "eventSubject");
|
|
return publishSubject;
|
|
}
|
|
|
|
public final void onClickUnblock(long j) {
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservableExtensionsKt.restSubscribeOn$default(this.restAPI.removeRelationship(LOCATION, j), false, 1, null), this, null, 2, null), WidgetSettingsBlockedUsersViewModel.class, (Context) null, (Function1) null, new WidgetSettingsBlockedUsersViewModel$onClickUnblock$2(this), (Function0) null, (Function0) null, new WidgetSettingsBlockedUsersViewModel$onClickUnblock$1(this), 54, (Object) null);
|
|
}
|
|
}
|