170 lines
9.2 KiB
Java
170 lines
9.2 KiB
Java
package com.discord.widgets.directories;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.text.Editable;
|
|
import android.view.View;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentViewModelLazyKt;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import c.a.d.f0;
|
|
import c.a.d.h0;
|
|
import c.a.k.b;
|
|
import c.d.b.a.a;
|
|
import com.discord.R;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.databinding.WidgetDirectoriesSearchBinding;
|
|
import com.discord.stores.utilities.Loading;
|
|
import com.discord.utilities.hubs.HubUtilsKt;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.view.text.LinkifiedTextView;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.discord.widgets.directories.DirectoryChannelItem;
|
|
import com.discord.widgets.directories.WidgetDirectoriesSearchViewModel;
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import d0.g;
|
|
import d0.g0.t;
|
|
import d0.t.o;
|
|
import d0.z.d.a0;
|
|
import d0.z.d.m;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import kotlin.Lazy;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: WidgetDirectoriesSearch.kt */
|
|
public final class WidgetDirectoriesSearch extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.W(WidgetDirectoriesSearch.class, "binding", "getBinding()Lcom/discord/databinding/WidgetDirectoriesSearchBinding;", 0)};
|
|
private final ActivityResultLauncher<Intent> activityResult;
|
|
private final WidgetDirectoryChannelAdapter adapter;
|
|
private final Lazy args$delegate = g.lazy(new WidgetDirectoriesSearch$$special$$inlined$args$1(this, "intent_args_key"));
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetDirectoriesSearch$binding$2.INSTANCE, null, 2, null);
|
|
private final Lazy viewModel$delegate;
|
|
|
|
public WidgetDirectoriesSearch() {
|
|
super(R.layout.widget_directories_search);
|
|
WidgetDirectoriesSearch$viewModel$2 widgetDirectoriesSearch$viewModel$2 = WidgetDirectoriesSearch$viewModel$2.INSTANCE;
|
|
f0 f0Var = new f0(this);
|
|
this.viewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(WidgetDirectoriesSearchViewModel.class), new WidgetDirectoriesSearch$appViewModels$$inlined$viewModels$1(f0Var), new h0(widgetDirectoriesSearch$viewModel$2));
|
|
this.activityResult = HubUtilsKt.getAddServerActivityResultHandler(this);
|
|
this.adapter = new WidgetDirectoryChannelAdapter(new WidgetDirectoriesSearch$adapter$1(this));
|
|
}
|
|
|
|
public static final /* synthetic */ void access$configureUI(WidgetDirectoriesSearch widgetDirectoriesSearch, WidgetDirectoriesSearchViewModel.ViewState viewState) {
|
|
widgetDirectoriesSearch.configureUI(viewState);
|
|
}
|
|
|
|
public static final /* synthetic */ ActivityResultLauncher access$getActivityResult$p(WidgetDirectoriesSearch widgetDirectoriesSearch) {
|
|
return widgetDirectoriesSearch.activityResult;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$searchForDirectories(WidgetDirectoriesSearch widgetDirectoriesSearch) {
|
|
widgetDirectoriesSearch.searchForDirectories();
|
|
}
|
|
|
|
private final void configureUI(WidgetDirectoriesSearchViewModel.ViewState viewState) {
|
|
WidgetDirectoryChannelAdapter widgetDirectoryChannelAdapter = this.adapter;
|
|
List<DirectoryEntryData> directoryEntryData = viewState.getDirectoryEntryData();
|
|
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(directoryEntryData, 10));
|
|
for (DirectoryEntryData directoryEntryData2 : directoryEntryData) {
|
|
arrayList.add(new DirectoryChannelItem.DirectoryItem(directoryEntryData2));
|
|
}
|
|
widgetDirectoryChannelAdapter.setDirectoryChannelItems(arrayList);
|
|
toggleList(!viewState.getDirectories().isEmpty());
|
|
FloatingActionButton floatingActionButton = getBinding().f;
|
|
m.checkNotNullExpressionValue(floatingActionButton, "binding.search");
|
|
WidgetDirectoriesSearchViewModel viewModel = getViewModel();
|
|
TextInputEditText textInputEditText = getBinding().h;
|
|
m.checkNotNullExpressionValue(textInputEditText, "binding.searchBarText");
|
|
boolean z2 = !viewModel.shouldNotSearch(String.valueOf(textInputEditText.getText()));
|
|
int i = 8;
|
|
floatingActionButton.setVisibility(z2 ? 0 : 8);
|
|
if (viewState.getDirectories().isEmpty() && (!m.areEqual(viewState.getDirectoriesState(), Loading.INSTANCE))) {
|
|
LinkifiedTextView linkifiedTextView = getBinding().b;
|
|
m.checkNotNullExpressionValue(linkifiedTextView, "binding.emptyDescription");
|
|
TextInputEditText textInputEditText2 = getBinding().h;
|
|
m.checkNotNullExpressionValue(textInputEditText2, "binding.searchBarText");
|
|
Editable text = textInputEditText2.getText();
|
|
linkifiedTextView.setText(text == null || t.isBlank(text) ? b.e(this, R.string.guild_discovery_search_protip, new Object[0], new WidgetDirectoriesSearch$configureUI$2(this)) : b.e(this, R.string.directory_search_no_results_subtitle, new Object[0], new WidgetDirectoriesSearch$configureUI$3(this)));
|
|
TextView textView = getBinding().d;
|
|
m.checkNotNullExpressionValue(textView, "binding.emptyTitle");
|
|
TextInputEditText textInputEditText3 = getBinding().h;
|
|
m.checkNotNullExpressionValue(textInputEditText3, "binding.searchBarText");
|
|
Editable text2 = textInputEditText3.getText();
|
|
if (!(text2 == null || t.isBlank(text2))) {
|
|
i = 0;
|
|
}
|
|
textView.setVisibility(i);
|
|
}
|
|
}
|
|
|
|
private final void searchForDirectories() {
|
|
WidgetDirectoriesSearchViewModel viewModel = getViewModel();
|
|
long channelId = getArgs().getChannelId();
|
|
TextInputEditText textInputEditText = getBinding().h;
|
|
m.checkNotNullExpressionValue(textInputEditText, "binding.searchBarText");
|
|
viewModel.searchForDirectories(channelId, String.valueOf(textInputEditText.getText()));
|
|
hideKeyboard(getView());
|
|
}
|
|
|
|
private final void toggleList(boolean z2) {
|
|
RecyclerView recyclerView = getBinding().e;
|
|
m.checkNotNullExpressionValue(recyclerView, "binding.recyclerView");
|
|
int i = 0;
|
|
recyclerView.setVisibility(z2 ? 0 : 8);
|
|
LinearLayout linearLayout = getBinding().f1784c;
|
|
m.checkNotNullExpressionValue(linearLayout, "binding.emptyState");
|
|
if (!(!z2)) {
|
|
i = 8;
|
|
}
|
|
linearLayout.setVisibility(i);
|
|
}
|
|
|
|
public final WidgetDirectoryChannelAdapter getAdapter() {
|
|
return this.adapter;
|
|
}
|
|
|
|
public final DirectoriesSearchArgs getArgs() {
|
|
return (DirectoriesSearchArgs) this.args$delegate.getValue();
|
|
}
|
|
|
|
public final WidgetDirectoriesSearchBinding getBinding() {
|
|
return (WidgetDirectoriesSearchBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
public final WidgetDirectoriesSearchViewModel getViewModel() {
|
|
return (WidgetDirectoriesSearchViewModel) this.viewModel$delegate.getValue();
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
RecyclerView recyclerView = getBinding().e;
|
|
recyclerView.setAdapter(this.adapter);
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
|
|
getBinding().g.setStartIconOnClickListener(new WidgetDirectoriesSearch$onViewBound$2(this, view));
|
|
getBinding().f.setOnClickListener(new WidgetDirectoriesSearch$onViewBound$3(this));
|
|
TextInputLayout textInputLayout = getBinding().g;
|
|
m.checkNotNullExpressionValue(textInputLayout, "binding.searchBar");
|
|
ViewExtensions.setOnImeActionDone$default(textInputLayout, false, new WidgetDirectoriesSearch$onViewBound$4(this), 1, null);
|
|
TextInputEditText textInputEditText = getBinding().h;
|
|
m.checkNotNullExpressionValue(textInputEditText, "binding.searchBarText");
|
|
textInputEditText.addTextChangedListener(new WidgetDirectoriesSearch$onViewBound$$inlined$doOnTextChanged$1(this));
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBoundOrOnResume() {
|
|
super.onViewBoundOrOnResume();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(ObservableExtensionsKt.ui(getViewModel().observeViewState()), this), WidgetDirectoriesSearch.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetDirectoriesSearch$onViewBoundOrOnResume$1(this), 62, (Object) null);
|
|
}
|
|
}
|