148 lines
7.6 KiB
Java
148 lines
7.6 KiB
Java
package com.discord.widgets.chat.input.gifpicker;
|
|
|
|
import android.content.Context;
|
|
import android.view.View;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentViewModelLazyKt;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
|
import c.a.d.h0;
|
|
import c.a.d.j0;
|
|
import c.d.b.a.a;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.app.AppViewFlipper;
|
|
import com.discord.databinding.WidgetGifPickerSearchBinding;
|
|
import com.discord.utilities.dimen.DimenUtils;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.discord.widgets.chat.input.gifpicker.GifAdapter;
|
|
import com.discord.widgets.chat.input.gifpicker.GifSearchViewModel;
|
|
import d0.z.d.a0;
|
|
import d0.z.d.m;
|
|
import kotlin.Lazy;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.reflect.KProperty;
|
|
import rx.Observable;
|
|
/* compiled from: WidgetGifPickerSearch.kt */
|
|
public final class WidgetGifPickerSearch extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.W(WidgetGifPickerSearch.class, "binding", "getBinding()Lcom/discord/databinding/WidgetGifPickerSearchBinding;", 0)};
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetGifPickerSearch$binding$2.INSTANCE, null, 2, null);
|
|
private GifAdapter gifAdapter;
|
|
private final Lazy gifPickerViewModel$delegate;
|
|
private Function0<Unit> onGifSelected;
|
|
|
|
public WidgetGifPickerSearch() {
|
|
super(2131559021);
|
|
WidgetGifPickerSearch$gifPickerViewModel$2 widgetGifPickerSearch$gifPickerViewModel$2 = new WidgetGifPickerSearch$gifPickerViewModel$2(this);
|
|
h0 h0Var = new h0(this);
|
|
this.gifPickerViewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(GifSearchViewModel.class), new WidgetGifPickerSearch$appViewModels$$inlined$viewModels$1(h0Var), new j0(widgetGifPickerSearch$gifPickerViewModel$2));
|
|
}
|
|
|
|
public static final /* synthetic */ GifSearchViewModel access$getGifPickerViewModel$p(WidgetGifPickerSearch widgetGifPickerSearch) {
|
|
return widgetGifPickerSearch.getGifPickerViewModel();
|
|
}
|
|
|
|
public static final /* synthetic */ Function0 access$getOnGifSelected$p(WidgetGifPickerSearch widgetGifPickerSearch) {
|
|
return widgetGifPickerSearch.onGifSelected;
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleViewState(WidgetGifPickerSearch widgetGifPickerSearch, GifSearchViewModel.ViewState viewState) {
|
|
widgetGifPickerSearch.handleViewState(viewState);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$setOnGifSelected$p(WidgetGifPickerSearch widgetGifPickerSearch, Function0 function0) {
|
|
widgetGifPickerSearch.onGifSelected = function0;
|
|
}
|
|
|
|
private final WidgetGifPickerSearchBinding getBinding() {
|
|
return (WidgetGifPickerSearchBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final GifSearchViewModel getGifPickerViewModel() {
|
|
return (GifSearchViewModel) this.gifPickerViewModel$delegate.getValue();
|
|
}
|
|
|
|
private final void handleViewState(GifSearchViewModel.ViewState viewState) {
|
|
if (viewState instanceof GifSearchViewModel.ViewState.Loaded) {
|
|
GifAdapter gifAdapter = this.gifAdapter;
|
|
if (gifAdapter == null) {
|
|
m.throwUninitializedPropertyAccessException("gifAdapter");
|
|
}
|
|
gifAdapter.setItems(((GifSearchViewModel.ViewState.Loaded) viewState).getAdapterItems());
|
|
AppViewFlipper appViewFlipper = getBinding().d;
|
|
m.checkNotNullExpressionValue(appViewFlipper, "binding.gifSearchViewFlipper");
|
|
appViewFlipper.setDisplayedChild(0);
|
|
} else if (m.areEqual(viewState, GifSearchViewModel.ViewState.LoadingSearchResults.INSTANCE)) {
|
|
GifAdapter gifAdapter2 = this.gifAdapter;
|
|
if (gifAdapter2 == null) {
|
|
m.throwUninitializedPropertyAccessException("gifAdapter");
|
|
}
|
|
gifAdapter2.clearItems();
|
|
AppViewFlipper appViewFlipper2 = getBinding().d;
|
|
m.checkNotNullExpressionValue(appViewFlipper2, "binding.gifSearchViewFlipper");
|
|
appViewFlipper2.setDisplayedChild(1);
|
|
}
|
|
}
|
|
|
|
private final void setUpGifRecycler(int i) {
|
|
RecyclerView recyclerView = getBinding().b;
|
|
m.checkNotNullExpressionValue(recyclerView, "binding.gifSearchGifRecycler");
|
|
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(i, 1));
|
|
RecyclerView recyclerView2 = getBinding().b;
|
|
m.checkNotNullExpressionValue(recyclerView2, "binding.gifSearchGifRecycler");
|
|
recyclerView2.setItemAnimator(null);
|
|
int dpToPixels = DimenUtils.dpToPixels(8);
|
|
WidgetGifPickerSearch$setUpGifRecycler$1 widgetGifPickerSearch$setUpGifRecycler$1 = new WidgetGifPickerSearch$setUpGifRecycler$1(this);
|
|
GifAdapter.Companion companion = GifAdapter.Companion;
|
|
RecyclerView recyclerView3 = getBinding().b;
|
|
m.checkNotNullExpressionValue(recyclerView3, "binding.gifSearchGifRecycler");
|
|
this.gifAdapter = new GifAdapter(this, widgetGifPickerSearch$setUpGifRecycler$1, companion.calculateColumnWidth(recyclerView3, i, dpToPixels), new WidgetGifPickerSearch$setUpGifRecycler$2(getBinding().e), null, 16, null);
|
|
RecyclerView recyclerView4 = getBinding().b;
|
|
m.checkNotNullExpressionValue(recyclerView4, "binding.gifSearchGifRecycler");
|
|
GifAdapter gifAdapter = this.gifAdapter;
|
|
if (gifAdapter == null) {
|
|
m.throwUninitializedPropertyAccessException("gifAdapter");
|
|
}
|
|
recyclerView4.setAdapter(gifAdapter);
|
|
getBinding().b.addItemDecoration(new u(dpToPixels, i));
|
|
}
|
|
|
|
private final void setupSearchBar() {
|
|
getBinding().e.a(this, new WidgetGifPickerSearch$setupSearchBar$1(this));
|
|
}
|
|
|
|
public final void clearSearchBar() {
|
|
getGifPickerViewModel().setSearchText("");
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
GifAdapter.Companion companion = GifAdapter.Companion;
|
|
RecyclerView recyclerView = getBinding().b;
|
|
m.checkNotNullExpressionValue(recyclerView, "binding.gifSearchGifRecycler");
|
|
int calculateColumnCount = companion.calculateColumnCount(recyclerView);
|
|
setUpGifRecycler(calculateColumnCount);
|
|
setupSearchBar();
|
|
GifLoadingView.updateView$default(getBinding().f1787c, calculateColumnCount, 0, 2, null);
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBoundOrOnResume() {
|
|
super.onViewBoundOrOnResume();
|
|
getBinding().e.j.f78c.requestFocus();
|
|
Observable<GifSearchViewModel.ViewState> r = getGifPickerViewModel().observeViewState().r();
|
|
m.checkNotNullExpressionValue(r, "gifPickerViewModel\n … .distinctUntilChanged()");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(r, this), WidgetGifPickerSearch.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetGifPickerSearch$onViewBoundOrOnResume$1(this), 62, (Object) null);
|
|
}
|
|
|
|
public final void setOnGifSelected(Function0<Unit> function0) {
|
|
m.checkNotNullParameter(function0, "onSelected");
|
|
this.onGifSelected = function0;
|
|
}
|
|
}
|