362 lines
16 KiB
Java
362 lines
16 KiB
Java
package com.discord.widgets.search;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.view.View;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentContainerView;
|
|
import c.a.d.l;
|
|
import c.a.k.b;
|
|
import c.d.b.a.a;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.discord.api.channel.Channel;
|
|
import com.discord.app.AppActivity;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.WidgetSearchBinding;
|
|
import com.discord.models.guild.Guild;
|
|
import com.discord.stores.StoreSearch;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.search.strings.ContextSearchStringProvider;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import d0.z.d.m;
|
|
import j0.l.e.j;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
import rx.Observable;
|
|
/* compiled from: WidgetSearch.kt */
|
|
public final class WidgetSearch extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetSearch.class, "binding", "getBinding()Lcom/discord/databinding/WidgetSearchBinding;", 0)};
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final String INTENT_EXTRA_TARGET_ID = "INTENT_EXTRA_TARGET_ID";
|
|
public static final String INTENT_EXTRA_TARGET_TYPE = "INTENT_EXTRA_SEARCH_TYPE";
|
|
private static final int TARGET_TYPE_CHANNEL = 1;
|
|
private static final int TARGET_TYPE_GUILD = 0;
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetSearch$binding$2.INSTANCE, null, 2, null);
|
|
private long targetId;
|
|
private int targetType = -1;
|
|
|
|
/* compiled from: WidgetSearch.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
private final void launch(long j, int i, Context context) {
|
|
Intent putExtra = new Intent().putExtra("INTENT_EXTRA_TARGET_ID", j).putExtra("INTENT_EXTRA_SEARCH_TYPE", i);
|
|
m.checkNotNullExpressionValue(putExtra, "Intent()\n .putE…_TARGET_TYPE, targetType)");
|
|
l.d(context, WidgetSearch.class, putExtra);
|
|
}
|
|
|
|
public final void launchForChannel(long j, Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
launch(j, 1, context);
|
|
}
|
|
|
|
public final void launchForGuild(long j, Context context) {
|
|
m.checkNotNullParameter(context, "context");
|
|
launch(j, 0, context);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetSearch.kt */
|
|
public static final class Model {
|
|
public static final Companion Companion = new Companion(null);
|
|
private final Channel channel;
|
|
private final StoreSearch.DisplayState displayState;
|
|
private final Guild guild;
|
|
private final boolean isQueryValid;
|
|
|
|
/* compiled from: WidgetSearch.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final Observable<Model> get(int i, long j) {
|
|
Observable<Guild> observeGuild = i == 0 ? StoreStream.Companion.getGuilds().observeGuild(j) : new j<>(null);
|
|
Observable<Channel> observePrivateChannel = i == 1 ? StoreStream.Companion.getChannels().observePrivateChannel(j) : new j<>(null);
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
Observable h = Observable.h(observeGuild, observePrivateChannel, companion.getSearch().getDisplayState(), companion.getSearch().getStoreSearchInput().isInputValid(), WidgetSearch$Model$Companion$get$1.INSTANCE);
|
|
m.checkNotNullExpressionValue(h, "Observable\n .… }\n }");
|
|
return ObservableExtensionsKt.computationLatest(h);
|
|
}
|
|
}
|
|
|
|
public Model(Guild guild, Channel channel, StoreSearch.DisplayState displayState, boolean z2) {
|
|
this.guild = guild;
|
|
this.channel = channel;
|
|
this.displayState = displayState;
|
|
this.isQueryValid = z2;
|
|
}
|
|
|
|
public static /* synthetic */ Model copy$default(Model model, Guild guild, Channel channel, StoreSearch.DisplayState displayState, boolean z2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
guild = model.guild;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
channel = model.channel;
|
|
}
|
|
if ((i & 4) != 0) {
|
|
displayState = model.displayState;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
z2 = model.isQueryValid;
|
|
}
|
|
return model.copy(guild, channel, displayState, z2);
|
|
}
|
|
|
|
public final Guild component1() {
|
|
return this.guild;
|
|
}
|
|
|
|
public final Channel component2() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final StoreSearch.DisplayState component3() {
|
|
return this.displayState;
|
|
}
|
|
|
|
public final boolean component4() {
|
|
return this.isQueryValid;
|
|
}
|
|
|
|
public final Model copy(Guild guild, Channel channel, StoreSearch.DisplayState displayState, boolean z2) {
|
|
return new Model(guild, channel, displayState, z2);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof Model)) {
|
|
return false;
|
|
}
|
|
Model model = (Model) obj;
|
|
return m.areEqual(this.guild, model.guild) && m.areEqual(this.channel, model.channel) && m.areEqual(this.displayState, model.displayState) && this.isQueryValid == model.isQueryValid;
|
|
}
|
|
|
|
public final Channel getChannel() {
|
|
return this.channel;
|
|
}
|
|
|
|
public final StoreSearch.DisplayState getDisplayState() {
|
|
return this.displayState;
|
|
}
|
|
|
|
public final Guild getGuild() {
|
|
return this.guild;
|
|
}
|
|
|
|
public int hashCode() {
|
|
Guild guild = this.guild;
|
|
int i = 0;
|
|
int hashCode = (guild != null ? guild.hashCode() : 0) * 31;
|
|
Channel channel = this.channel;
|
|
int hashCode2 = (hashCode + (channel != null ? channel.hashCode() : 0)) * 31;
|
|
StoreSearch.DisplayState displayState = this.displayState;
|
|
if (displayState != null) {
|
|
i = displayState.hashCode();
|
|
}
|
|
int i2 = (hashCode2 + i) * 31;
|
|
boolean z2 = this.isQueryValid;
|
|
if (z2) {
|
|
z2 = true;
|
|
}
|
|
int i3 = z2 ? 1 : 0;
|
|
int i4 = z2 ? 1 : 0;
|
|
int i5 = z2 ? 1 : 0;
|
|
return i2 + i3;
|
|
}
|
|
|
|
public final boolean isQueryValid() {
|
|
return this.isQueryValid;
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder K = a.K("Model(guild=");
|
|
K.append(this.guild);
|
|
K.append(", channel=");
|
|
K.append(this.channel);
|
|
K.append(", displayState=");
|
|
K.append(this.displayState);
|
|
K.append(", isQueryValid=");
|
|
return a.F(K, this.isQueryValid, ")");
|
|
}
|
|
}
|
|
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
|
|
static {
|
|
StoreSearch.DisplayState.values();
|
|
int[] iArr = new int[2];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
iArr[StoreSearch.DisplayState.SUGGESTIONS.ordinal()] = 1;
|
|
iArr[StoreSearch.DisplayState.RESULTS.ordinal()] = 2;
|
|
}
|
|
}
|
|
|
|
public WidgetSearch() {
|
|
super(2131559146);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$configureUI(WidgetSearch widgetSearch, Model model) {
|
|
widgetSearch.configureUI(model);
|
|
}
|
|
|
|
public static final /* synthetic */ WidgetSearchBinding access$getBinding$p(WidgetSearch widgetSearch) {
|
|
return widgetSearch.getBinding();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$sendQuery(WidgetSearch widgetSearch, Context context) {
|
|
widgetSearch.sendQuery(context);
|
|
}
|
|
|
|
private final void configureSearchInput() {
|
|
TextInputLayout textInputLayout = getBinding().f1871c;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.widgetSearchInput");
|
|
ViewExtensions.setOnEditorActionListener(textInputLayout, new WidgetSearch$configureSearchInput$1(this));
|
|
TextInputLayout textInputLayout2 = getBinding().f1871c;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.widgetSearchInput");
|
|
ViewExtensions.addBindedTextWatcher(textInputLayout2, this, WidgetSearch$configureSearchInput$2.INSTANCE);
|
|
Observable F = ObservableExtensionsKt.ui$default(StoreStream.Companion.getSearch().getStoreSearchInput().getForcedInput(), this, null, 2, null).F(new WidgetSearch$configureSearchInput$3(this)).F(WidgetSearch$configureSearchInput$4.INSTANCE);
|
|
m.checkNotNullExpressionValue(F, "StoreStream\n .get… obj.toString()\n }");
|
|
ObservableExtensionsKt.appSubscribe$default(F, WidgetSearch.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetSearch$configureSearchInput$5(this), 62, (Object) null);
|
|
}
|
|
|
|
/* JADX DEBUG: Can't convert new array creation: APUT found in different block: 0x0092: APUT (r2v2 java.lang.Object[]), (0 ??[int, short, byte, char]), (r7v2 java.lang.String) */
|
|
private final void configureUI(Model model) {
|
|
if (model == null) {
|
|
AppActivity appActivity = getAppActivity();
|
|
if (appActivity != null) {
|
|
appActivity.finish();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
int i = this.targetType;
|
|
int i2 = 0;
|
|
if (i == 0) {
|
|
TextInputLayout textInputLayout = getBinding().f1871c;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.widgetSearchInput");
|
|
Object[] objArr = new Object[1];
|
|
Guild guild = model.getGuild();
|
|
objArr[0] = guild != null ? guild.getName() : null;
|
|
ViewExtensions.setSingleLineHint(textInputLayout, b.j(this, 2131893279, objArr, null, 4));
|
|
} else if (i == 1) {
|
|
Channel channel = model.getChannel();
|
|
String z0 = channel != null ? AnimatableValueParser.z0(channel, requireContext(), false) : null;
|
|
TextInputLayout textInputLayout2 = getBinding().f1871c;
|
|
m.checkNotNullExpressionValue(textInputLayout2, "binding.widgetSearchInput");
|
|
Channel channel2 = model.getChannel();
|
|
Integer valueOf = channel2 != null ? Integer.valueOf(channel2.A()) : null;
|
|
ViewExtensions.setSingleLineHint(textInputLayout2, (valueOf != null && valueOf.intValue() == 1) ? b.j(this, 2131893248, new Object[]{z0}, null, 4) : (valueOf != null && valueOf.intValue() == 3) ? b.j(this, 2131893279, new Object[]{z0}, null, 4) : b.j(this, 2131893225, new Object[0], null, 4));
|
|
}
|
|
StoreSearch.DisplayState displayState = model.getDisplayState();
|
|
if (displayState != null) {
|
|
int ordinal = displayState.ordinal();
|
|
if (ordinal == 0) {
|
|
FragmentContainerView fragmentContainerView = getBinding().e;
|
|
m.checkNotNullExpressionValue(fragmentContainerView, "binding.widgetSearchSuggestions");
|
|
fragmentContainerView.setVisibility(0);
|
|
FragmentContainerView fragmentContainerView2 = getBinding().d;
|
|
m.checkNotNullExpressionValue(fragmentContainerView2, "binding.widgetSearchResults");
|
|
fragmentContainerView2.setVisibility(4);
|
|
FloatingActionButton floatingActionButton = getBinding().b;
|
|
m.checkNotNullExpressionValue(floatingActionButton, "binding.searchSendQueryFab");
|
|
if (!model.isQueryValid()) {
|
|
i2 = 8;
|
|
}
|
|
floatingActionButton.setVisibility(i2);
|
|
} else if (ordinal == 1) {
|
|
FragmentContainerView fragmentContainerView3 = getBinding().e;
|
|
m.checkNotNullExpressionValue(fragmentContainerView3, "binding.widgetSearchSuggestions");
|
|
fragmentContainerView3.setVisibility(4);
|
|
FragmentContainerView fragmentContainerView4 = getBinding().d;
|
|
m.checkNotNullExpressionValue(fragmentContainerView4, "binding.widgetSearchResults");
|
|
fragmentContainerView4.setVisibility(0);
|
|
FloatingActionButton floatingActionButton2 = getBinding().b;
|
|
m.checkNotNullExpressionValue(floatingActionButton2, "binding.searchSendQueryFab");
|
|
floatingActionButton2.setVisibility(8);
|
|
}
|
|
}
|
|
}
|
|
|
|
private final WidgetSearchBinding getBinding() {
|
|
return (WidgetSearchBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final void sendQuery(Context context) {
|
|
AppFragment.hideKeyboard$default(this, null, 1, null);
|
|
StoreSearch search = StoreStream.Companion.getSearch();
|
|
TextInputLayout textInputLayout = getBinding().f1871c;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.widgetSearchInput");
|
|
search.loadInitial(ViewExtensions.getTextOrEmpty(textInputLayout), new ContextSearchStringProvider(context));
|
|
}
|
|
|
|
public final long getTargetId() {
|
|
return this.targetId;
|
|
}
|
|
|
|
public final int getTargetType() {
|
|
return this.targetType;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
StoreStream.Companion.getSearch().clear();
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
setRetainInstance(true);
|
|
this.targetId = getMostRecentIntent().getLongExtra("INTENT_EXTRA_TARGET_ID", 0);
|
|
this.targetType = getMostRecentIntent().getIntExtra("INTENT_EXTRA_SEARCH_TYPE", -1);
|
|
if (!isRecreated()) {
|
|
TextInputLayout textInputLayout = getBinding().f1871c;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.widgetSearchInput");
|
|
showKeyboard(textInputLayout);
|
|
}
|
|
int i = this.targetType;
|
|
if (i == 0) {
|
|
StoreStream.Companion.getSearch().initForGuild(this.targetId, new ContextSearchStringProvider(requireContext()));
|
|
} else if (i == 1) {
|
|
StoreStream.Companion.getSearch().initForChannel(this.targetId, new ContextSearchStringProvider(requireContext()));
|
|
}
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBoundOrOnResume() {
|
|
super.onViewBoundOrOnResume();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(Model.Companion.get(this.targetType, this.targetId), this, null, 2, null), WidgetSearch.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetSearch$onViewBoundOrOnResume$1(this), 62, (Object) null);
|
|
configureSearchInput();
|
|
getBinding().b.setOnClickListener(new WidgetSearch$onViewBoundOrOnResume$2(this));
|
|
getBinding().f1871c.setStartIconOnClickListener(new WidgetSearch$onViewBoundOrOnResume$3(this));
|
|
}
|
|
|
|
public final void setTargetId(long j) {
|
|
this.targetId = j;
|
|
}
|
|
|
|
public final void setTargetType(int i) {
|
|
this.targetType = i;
|
|
}
|
|
}
|