451 lines
20 KiB
Java
451 lines
20 KiB
Java
package com.discord.widgets.chat.input.gifpicker;
|
|
|
|
import android.content.Context;
|
|
import com.discord.app.AppViewModel;
|
|
import com.discord.models.gifpicker.dto.ModelGif;
|
|
import com.discord.stores.StoreAnalytics;
|
|
import com.discord.stores.StoreGifPicker;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.analytics.SearchType;
|
|
import com.discord.utilities.analytics.Traits;
|
|
import com.discord.utilities.rx.LeadingEdgeThrottle;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.widgets.chat.MessageManager;
|
|
import com.discord.widgets.chat.input.gifpicker.GifAdapterItem;
|
|
import d0.g;
|
|
import d0.z.d.m;
|
|
import d0.z.d.o;
|
|
import j0.l.a.r;
|
|
import j0.p.a;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
import kotlin.Lazy;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Observable;
|
|
import rx.subjects.BehaviorSubject;
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public final class GifSearchViewModel extends AppViewModel<ViewState> {
|
|
public static final Companion Companion = new Companion(null);
|
|
private final MessageManager messageManager;
|
|
private final BehaviorSubject<String> searchSubject;
|
|
private final StoreAnalytics storeAnalytics;
|
|
private final StoreGifPicker storeGifPicker;
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
/* renamed from: com.discord.widgets.chat.input.gifpicker.GifSearchViewModel$1 reason: invalid class name */
|
|
public static final class AnonymousClass1 extends o implements Function1<StoreState, Unit> {
|
|
public final /* synthetic */ GifSearchViewModel this$0;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public AnonymousClass1(GifSearchViewModel gifSearchViewModel) {
|
|
super(1);
|
|
this.this$0 = gifSearchViewModel;
|
|
}
|
|
|
|
/* 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");
|
|
GifSearchViewModel.access$handleStoreState(this.this$0, storeState);
|
|
}
|
|
}
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public static final /* synthetic */ Observable access$observeQueryState(Companion companion, BehaviorSubject behaviorSubject, StoreAnalytics storeAnalytics, StoreGifPicker storeGifPicker, List list) {
|
|
return companion.observeQueryState(behaviorSubject, storeAnalytics, storeGifPicker, list);
|
|
}
|
|
|
|
public static final /* synthetic */ Observable access$observeStoreState(Companion companion, BehaviorSubject behaviorSubject, StoreAnalytics storeAnalytics, StoreGifPicker storeGifPicker) {
|
|
return companion.observeStoreState(behaviorSubject, storeAnalytics, storeGifPicker);
|
|
}
|
|
|
|
private final Observable<StoreState> observeQueryState(BehaviorSubject<String> behaviorSubject, StoreAnalytics storeAnalytics, StoreGifPicker storeGifPicker, List<String> list) {
|
|
Observable<String> r = behaviorSubject.I(a.c()).r();
|
|
Observable<StoreState> Y = Observable.h0(new r(r.i, new LeadingEdgeThrottle(1000, TimeUnit.MILLISECONDS, a.c()))).t(new GifSearchViewModel$Companion$observeQueryState$1(storeAnalytics)).Y(new GifSearchViewModel$Companion$observeQueryState$2(list, storeGifPicker));
|
|
m.checkNotNullExpressionValue(Y, "searchSubject\n … }\n }");
|
|
return Y;
|
|
}
|
|
|
|
private final Observable<StoreState> observeStoreState(BehaviorSubject<String> behaviorSubject, StoreAnalytics storeAnalytics, StoreGifPicker storeGifPicker) {
|
|
Observable<R> Y = storeGifPicker.observeGifTrendingSearchTerms().Y(new GifSearchViewModel$Companion$observeStoreState$1(behaviorSubject, storeAnalytics, storeGifPicker));
|
|
m.checkNotNullExpressionValue(Y, "storeGifPicker.observeGi…fPicker, terms)\n }");
|
|
return Y;
|
|
}
|
|
}
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public static abstract class StoreState {
|
|
private final List<String> trendingSearchTerms;
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public static final class SearchResults extends StoreState {
|
|
private final List<ModelGif> gifs;
|
|
private final String searchQuery;
|
|
private final List<String> suggested;
|
|
private final List<String> trending;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public SearchResults(List<ModelGif> list, List<String> list2, List<String> list3, String str) {
|
|
super(list3, null);
|
|
m.checkNotNullParameter(list, "gifs");
|
|
m.checkNotNullParameter(list2, "suggested");
|
|
m.checkNotNullParameter(list3, "trending");
|
|
this.gifs = list;
|
|
this.suggested = list2;
|
|
this.trending = list3;
|
|
this.searchQuery = str;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.chat.input.gifpicker.GifSearchViewModel$StoreState$SearchResults */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ SearchResults copy$default(SearchResults searchResults, List list, List list2, List list3, String str, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
list = searchResults.gifs;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
list2 = searchResults.suggested;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
list3 = searchResults.trending;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
str = searchResults.searchQuery;
|
|
}
|
|
return searchResults.copy(list, list2, list3, str);
|
|
}
|
|
|
|
public final List<ModelGif> component1() {
|
|
return this.gifs;
|
|
}
|
|
|
|
public final List<String> component2() {
|
|
return this.suggested;
|
|
}
|
|
|
|
public final List<String> component3() {
|
|
return this.trending;
|
|
}
|
|
|
|
public final String component4() {
|
|
return this.searchQuery;
|
|
}
|
|
|
|
public final SearchResults copy(List<ModelGif> list, List<String> list2, List<String> list3, String str) {
|
|
m.checkNotNullParameter(list, "gifs");
|
|
m.checkNotNullParameter(list2, "suggested");
|
|
m.checkNotNullParameter(list3, "trending");
|
|
return new SearchResults(list, list2, list3, str);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof SearchResults)) {
|
|
return false;
|
|
}
|
|
SearchResults searchResults = (SearchResults) obj;
|
|
return m.areEqual(this.gifs, searchResults.gifs) && m.areEqual(this.suggested, searchResults.suggested) && m.areEqual(this.trending, searchResults.trending) && m.areEqual(this.searchQuery, searchResults.searchQuery);
|
|
}
|
|
|
|
public final List<ModelGif> getGifs() {
|
|
return this.gifs;
|
|
}
|
|
|
|
public final String getSearchQuery() {
|
|
return this.searchQuery;
|
|
}
|
|
|
|
public final List<String> getSuggested() {
|
|
return this.suggested;
|
|
}
|
|
|
|
public final List<String> getTrending() {
|
|
return this.trending;
|
|
}
|
|
|
|
public int hashCode() {
|
|
List<ModelGif> list = this.gifs;
|
|
int i = 0;
|
|
int hashCode = (list != null ? list.hashCode() : 0) * 31;
|
|
List<String> list2 = this.suggested;
|
|
int hashCode2 = (hashCode + (list2 != null ? list2.hashCode() : 0)) * 31;
|
|
List<String> list3 = this.trending;
|
|
int hashCode3 = (hashCode2 + (list3 != null ? list3.hashCode() : 0)) * 31;
|
|
String str = this.searchQuery;
|
|
if (str != null) {
|
|
i = str.hashCode();
|
|
}
|
|
return hashCode3 + i;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder L = c.d.b.a.a.L("SearchResults(gifs=");
|
|
L.append(this.gifs);
|
|
L.append(", suggested=");
|
|
L.append(this.suggested);
|
|
L.append(", trending=");
|
|
L.append(this.trending);
|
|
L.append(", searchQuery=");
|
|
return c.d.b.a.a.D(L, this.searchQuery, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public static final class TrendingSearchTermsResults extends StoreState {
|
|
private final List<String> trending;
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public TrendingSearchTermsResults(List<String> list) {
|
|
super(list, null);
|
|
m.checkNotNullParameter(list, "trending");
|
|
this.trending = list;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.chat.input.gifpicker.GifSearchViewModel$StoreState$TrendingSearchTermsResults */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static /* synthetic */ TrendingSearchTermsResults copy$default(TrendingSearchTermsResults trendingSearchTermsResults, List list, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
list = trendingSearchTermsResults.trending;
|
|
}
|
|
return trendingSearchTermsResults.copy(list);
|
|
}
|
|
|
|
public final List<String> component1() {
|
|
return this.trending;
|
|
}
|
|
|
|
public final TrendingSearchTermsResults copy(List<String> list) {
|
|
m.checkNotNullParameter(list, "trending");
|
|
return new TrendingSearchTermsResults(list);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof TrendingSearchTermsResults) && m.areEqual(this.trending, ((TrendingSearchTermsResults) obj).trending);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final List<String> getTrending() {
|
|
return this.trending;
|
|
}
|
|
|
|
public int hashCode() {
|
|
List<String> list = this.trending;
|
|
if (list != null) {
|
|
return list.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
return c.d.b.a.a.E(c.d.b.a.a.L("TrendingSearchTermsResults(trending="), this.trending, ")");
|
|
}
|
|
}
|
|
|
|
private StoreState(List<String> list) {
|
|
this.trendingSearchTerms = list;
|
|
}
|
|
|
|
public /* synthetic */ StoreState(List list, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(list);
|
|
}
|
|
|
|
public final List<String> getTrendingSearchTerms() {
|
|
return this.trendingSearchTerms;
|
|
}
|
|
}
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public static abstract class ViewState {
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public static final class Loaded extends ViewState {
|
|
private final List<GifAdapterItem> adapterItems;
|
|
private final Lazy gifCount$delegate = g.lazy(new GifSearchViewModel$ViewState$Loaded$gifCount$2(this));
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.util.List<? extends com.discord.widgets.chat.input.gifpicker.GifAdapterItem> */
|
|
/* 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 GifAdapterItem> list) {
|
|
super(null);
|
|
m.checkNotNullParameter(list, "adapterItems");
|
|
this.adapterItems = list;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: com.discord.widgets.chat.input.gifpicker.GifSearchViewModel$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.adapterItems;
|
|
}
|
|
return loaded.copy(list);
|
|
}
|
|
|
|
public final List<GifAdapterItem> component1() {
|
|
return this.adapterItems;
|
|
}
|
|
|
|
public final Loaded copy(List<? extends GifAdapterItem> list) {
|
|
m.checkNotNullParameter(list, "adapterItems");
|
|
return new Loaded(list);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this != obj) {
|
|
return (obj instanceof Loaded) && m.areEqual(this.adapterItems, ((Loaded) obj).adapterItems);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public final List<GifAdapterItem> getAdapterItems() {
|
|
return this.adapterItems;
|
|
}
|
|
|
|
public final int getGifCount() {
|
|
return ((Number) this.gifCount$delegate.getValue()).intValue();
|
|
}
|
|
|
|
public int hashCode() {
|
|
List<GifAdapterItem> list = this.adapterItems;
|
|
if (list != null) {
|
|
return list.hashCode();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public String toString() {
|
|
return c.d.b.a.a.E(c.d.b.a.a.L("Loaded(adapterItems="), this.adapterItems, ")");
|
|
}
|
|
}
|
|
|
|
/* compiled from: GifSearchViewModel.kt */
|
|
public static final class LoadingSearchResults extends ViewState {
|
|
public static final LoadingSearchResults INSTANCE = new LoadingSearchResults();
|
|
|
|
private LoadingSearchResults() {
|
|
super(null);
|
|
}
|
|
}
|
|
|
|
private ViewState() {
|
|
}
|
|
|
|
public /* synthetic */ ViewState(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public GifSearchViewModel(Context context, BehaviorSubject<String> behaviorSubject, StoreGifPicker storeGifPicker, StoreAnalytics storeAnalytics, MessageManager messageManager, Observable<StoreState> observable) {
|
|
super(null);
|
|
m.checkNotNullParameter(context, "context");
|
|
m.checkNotNullParameter(behaviorSubject, "searchSubject");
|
|
m.checkNotNullParameter(storeGifPicker, "storeGifPicker");
|
|
m.checkNotNullParameter(storeAnalytics, "storeAnalytics");
|
|
m.checkNotNullParameter(messageManager, "messageManager");
|
|
m.checkNotNullParameter(observable, "storeStateObservable");
|
|
this.searchSubject = behaviorSubject;
|
|
this.storeGifPicker = storeGifPicker;
|
|
this.storeAnalytics = storeAnalytics;
|
|
this.messageManager = messageManager;
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(observable, this, null, 2, null), GifSearchViewModel.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new AnonymousClass1(this), 62, (Object) null);
|
|
}
|
|
|
|
/* JADX WARNING: Illegal instructions before constructor call */
|
|
public /* synthetic */ GifSearchViewModel(Context context, BehaviorSubject behaviorSubject, StoreGifPicker storeGifPicker, StoreAnalytics storeAnalytics, MessageManager messageManager, Observable observable, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(context, r0, r1, r2, (i & 16) != 0 ? new MessageManager(context, null, null, null, null, null, null, null, null, 510, null) : messageManager, (i & 32) != 0 ? Companion.access$observeStoreState(Companion, r0, r2, r1) : observable);
|
|
BehaviorSubject behaviorSubject2;
|
|
if ((i & 2) != 0) {
|
|
behaviorSubject2 = BehaviorSubject.l0("");
|
|
m.checkNotNullExpressionValue(behaviorSubject2, "BehaviorSubject.create(\"\")");
|
|
} else {
|
|
behaviorSubject2 = behaviorSubject;
|
|
}
|
|
StoreGifPicker gifPicker = (i & 4) != 0 ? StoreStream.Companion.getGifPicker() : storeGifPicker;
|
|
StoreAnalytics analytics = (i & 8) != 0 ? StoreStream.Companion.getAnalytics() : storeAnalytics;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleStoreState(GifSearchViewModel gifSearchViewModel, StoreState storeState) {
|
|
gifSearchViewModel.handleStoreState(storeState);
|
|
}
|
|
|
|
private final void handleStoreState(StoreState storeState) {
|
|
ArrayList arrayList = new ArrayList();
|
|
List<String> trendingSearchTerms = storeState.getTrendingSearchTerms();
|
|
boolean z2 = storeState instanceof StoreState.SearchResults;
|
|
if (z2) {
|
|
StoreState.SearchResults searchResults = (StoreState.SearchResults) storeState;
|
|
List<ModelGif> gifs = searchResults.getGifs();
|
|
ArrayList arrayList2 = new ArrayList(d0.t.o.collectionSizeOrDefault(gifs, 10));
|
|
for (ModelGif modelGif : gifs) {
|
|
arrayList2.add(new GifAdapterItem.GifItem(modelGif, searchResults.getSearchQuery()));
|
|
}
|
|
arrayList.addAll(arrayList2);
|
|
List<String> suggested = searchResults.getSuggested();
|
|
boolean z3 = true;
|
|
boolean z4 = arrayList.size() > 0;
|
|
boolean z5 = searchResults.getSuggested().size() > 0;
|
|
String n0 = this.searchSubject.n0();
|
|
m.checkNotNullExpressionValue(n0, "searchSubject.value");
|
|
if (n0.length() <= 0) {
|
|
z3 = false;
|
|
}
|
|
arrayList.add(z4 ? new GifAdapterItem.SuggestedTermsItem.SuggestedTermsNonEmptyResults(suggested, 2131888974) : (!z3 || z5) ? (!z3 || !z5) ? new GifAdapterItem.SuggestedTermsItem.SuggestedTermsEmptyResults(suggested, 2131888972) : new GifAdapterItem.SuggestedTermsItem.SuggestedTermsEmptyResults(suggested, 2131891459) : new GifAdapterItem.SuggestedTermsItem.SuggestedTermsEmptyResults(suggested, 2131891460));
|
|
} else if (storeState instanceof StoreState.TrendingSearchTermsResults) {
|
|
arrayList.add(new GifAdapterItem.SuggestedTermsItem.SuggestedTermsEmptyResults(trendingSearchTerms, 2131888972));
|
|
}
|
|
ViewState.Loaded loaded = new ViewState.Loaded(arrayList);
|
|
if (z2) {
|
|
StoreAnalytics.trackSearchResultViewed$default(this.storeAnalytics, SearchType.GIF, loaded.getGifCount(), null, null, false, 28, null);
|
|
}
|
|
updateViewState(loaded);
|
|
}
|
|
|
|
public final void selectGif(GifAdapterItem.GifItem gifItem) {
|
|
m.checkNotNullParameter(gifItem, "gifItem");
|
|
ViewState viewState = getViewState();
|
|
if (!(viewState instanceof ViewState.Loaded)) {
|
|
viewState = null;
|
|
}
|
|
ViewState.Loaded loaded = (ViewState.Loaded) viewState;
|
|
if (loaded != null) {
|
|
StoreAnalytics.trackSearchResultSelected$default(this.storeAnalytics, SearchType.GIF, loaded.getGifCount(), null, new Traits.Source(null, null, "GIF Picker", null, null, 27, null), 4, null);
|
|
}
|
|
MessageManager.sendMessage$default(this.messageManager, gifItem.getGif().getTenorGifUrl(), null, null, null, null, false, null, null, null, 510, null);
|
|
}
|
|
|
|
public final void setSearchText(String str) {
|
|
m.checkNotNullParameter(str, "searchText");
|
|
boolean z2 = true;
|
|
if (!m.areEqual(this.searchSubject.n0(), str)) {
|
|
if (str.length() <= 0) {
|
|
z2 = false;
|
|
}
|
|
if (z2) {
|
|
updateViewState(ViewState.LoadingSearchResults.INSTANCE);
|
|
}
|
|
}
|
|
this.searchSubject.onNext(str);
|
|
}
|
|
}
|