discord-jadx/app/src/main/java/com/discord/widgets/chat/input/gifpicker/WidgetGifCategory.java

203 lines
9.8 KiB
Java

package com.discord.widgets.chat.input.gifpicker;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentViewModelLazyKt;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import c.a.d.g0;
import c.a.d.h0;
import c.a.d.j0;
import c.d.b.a.a;
import com.discord.app.AppFragment;
import com.discord.databinding.WidgetGifCategoryBinding;
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.expression.ExpressionTrayViewModel;
import com.discord.widgets.chat.input.gifpicker.GifAdapter;
import com.discord.widgets.chat.input.gifpicker.GifAdapterItem;
import com.discord.widgets.chat.input.gifpicker.GifCategoryItem;
import com.discord.widgets.chat.input.gifpicker.GifCategoryViewModel;
import d0.z.d.a0;
import d0.z.d.m;
import java.io.Serializable;
import java.util.Objects;
import kotlin.Lazy;
import kotlin.NoWhenBranchMatchedException;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.reflect.KProperty;
/* compiled from: WidgetGifCategory.kt */
public final class WidgetGifCategory extends AppFragment {
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.V(WidgetGifCategory.class, "binding", "getBinding()Lcom/discord/databinding/WidgetGifCategoryBinding;", 0)};
public static final String ARG_GIF_CATEGORY_ITEM = "GIF_CATEGORY_ITEM";
public static final Companion Companion = new Companion(null);
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetGifCategory$binding$2.INSTANCE, null, 2, null);
private final Lazy expressionTrayViewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(ExpressionTrayViewModel.class), new WidgetGifCategory$appActivityViewModels$$inlined$activityViewModels$1(this), new g0(WidgetGifCategory$expressionTrayViewModel$2.INSTANCE));
private GifAdapter gifAdapter;
private final Lazy gifCategoryViewModel$delegate;
private Function0<Unit> onGifSelected;
/* compiled from: WidgetGifCategory.kt */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
}
public WidgetGifCategory() {
super(2131559036);
WidgetGifCategory$gifCategoryViewModel$2 widgetGifCategory$gifCategoryViewModel$2 = new WidgetGifCategory$gifCategoryViewModel$2(this);
h0 h0Var = new h0(this);
this.gifCategoryViewModel$delegate = FragmentViewModelLazyKt.createViewModelLazy(this, a0.getOrCreateKotlinClass(GifCategoryViewModel.class), new WidgetGifCategory$appViewModels$$inlined$viewModels$1(h0Var), new j0(widgetGifCategory$gifCategoryViewModel$2));
}
public static final /* synthetic */ WidgetGifCategoryBinding access$getBinding$p(WidgetGifCategory widgetGifCategory) {
return widgetGifCategory.getBinding();
}
public static final /* synthetic */ GifCategoryItem access$getGifCategory(WidgetGifCategory widgetGifCategory) {
return widgetGifCategory.getGifCategory();
}
public static final /* synthetic */ void access$handleBack(WidgetGifCategory widgetGifCategory) {
widgetGifCategory.handleBack();
}
public static final /* synthetic */ void access$handleViewState(WidgetGifCategory widgetGifCategory, GifCategoryViewModel.ViewState viewState) {
widgetGifCategory.handleViewState(viewState);
}
public static final /* synthetic */ void access$selectGif(WidgetGifCategory widgetGifCategory, GifAdapterItem.GifItem gifItem) {
widgetGifCategory.selectGif(gifItem);
}
private final WidgetGifCategoryBinding getBinding() {
return (WidgetGifCategoryBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
}
private final ExpressionTrayViewModel getExpressionTrayViewModel() {
return (ExpressionTrayViewModel) this.expressionTrayViewModel$delegate.getValue();
}
private final GifCategoryItem getGifCategory() {
Serializable serializable = requireArguments().getSerializable("GIF_CATEGORY_ITEM");
Objects.requireNonNull(serializable, "null cannot be cast to non-null type com.discord.widgets.chat.input.gifpicker.GifCategoryItem");
return (GifCategoryItem) serializable;
}
private final GifCategoryViewModel getGifCategoryViewModel() {
return (GifCategoryViewModel) this.gifCategoryViewModel$delegate.getValue();
}
private final void handleBack() {
getExpressionTrayViewModel().clickBack();
}
private final void handleViewState(GifCategoryViewModel.ViewState viewState) {
RecyclerView recyclerView = getBinding().f1799c;
m.checkNotNullExpressionValue(recyclerView, "binding.gifCategoryGifRecycler");
recyclerView.setVisibility(0);
GifLoadingView gifLoadingView = getBinding().d;
m.checkNotNullExpressionValue(gifLoadingView, "binding.gifCategoryLoadingView");
gifLoadingView.setVisibility(8);
GifAdapter gifAdapter = this.gifAdapter;
if (gifAdapter == null) {
m.throwUninitializedPropertyAccessException("gifAdapter");
}
gifAdapter.setItems(viewState.getGifItems());
}
private final void selectGif(GifAdapterItem.GifItem gifItem) {
getGifCategoryViewModel().selectGif(gifItem);
Function0<Unit> function0 = this.onGifSelected;
if (function0 != null) {
function0.mo1invoke();
}
}
private final void setUpBackBehavior() {
setOnBackPressed(new WidgetGifCategory$setUpBackBehavior$1(this), 0);
getBinding().e.setOnClickListener(new WidgetGifCategory$setUpBackBehavior$2(this));
}
private final void setUpGifRecycler(int i) {
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(i, 1);
RecyclerView recyclerView = getBinding().f1799c;
m.checkNotNullExpressionValue(recyclerView, "binding.gifCategoryGifRecycler");
recyclerView.setLayoutManager(staggeredGridLayoutManager);
RecyclerView recyclerView2 = getBinding().f1799c;
m.checkNotNullExpressionValue(recyclerView2, "binding.gifCategoryGifRecycler");
recyclerView2.setItemAnimator(null);
int dpToPixels = DimenUtils.dpToPixels(8);
GifAdapter.Companion companion = GifAdapter.Companion;
RecyclerView recyclerView3 = getBinding().f1799c;
m.checkNotNullExpressionValue(recyclerView3, "binding.gifCategoryGifRecycler");
this.gifAdapter = new GifAdapter(this, new WidgetGifCategory$setUpGifRecycler$1(this), companion.calculateColumnWidth(recyclerView3, i, dpToPixels), null, null, 24, null);
RecyclerView recyclerView4 = getBinding().f1799c;
m.checkNotNullExpressionValue(recyclerView4, "binding.gifCategoryGifRecycler");
GifAdapter gifAdapter = this.gifAdapter;
if (gifAdapter == null) {
m.throwUninitializedPropertyAccessException("gifAdapter");
}
recyclerView4.setAdapter(gifAdapter);
getBinding().f1799c.addItemDecoration(new u(dpToPixels, i));
}
private final void setUpTitle() {
String str;
GifCategoryItem gifCategory = getGifCategory();
TextView textView = getBinding().e;
m.checkNotNullExpressionValue(textView, "binding.gifCategoryTitle");
if (gifCategory instanceof GifCategoryItem.Standard) {
str = ((GifCategoryItem.Standard) gifCategory).getGifCategory().getCategoryName();
} else if (gifCategory instanceof GifCategoryItem.Trending) {
str = getResources().getString(2131888982);
} else {
throw new NoWhenBranchMatchedException();
}
textView.setText(str);
}
private final void setWindowInsetsListeners() {
ViewCompat.setOnApplyWindowInsetsListener(getBinding().f1799c, WidgetGifCategory$setWindowInsetsListeners$1.INSTANCE);
ViewCompat.setOnApplyWindowInsetsListener(getBinding().b, new WidgetGifCategory$setWindowInsetsListeners$2(this));
}
@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().f1799c;
m.checkNotNullExpressionValue(recyclerView, "binding.gifCategoryGifRecycler");
int calculateColumnCount = companion.calculateColumnCount(recyclerView);
setUpTitle();
setUpBackBehavior();
setUpGifRecycler(calculateColumnCount);
GifLoadingView.updateView$default(getBinding().d, calculateColumnCount, 0, 2, null);
setWindowInsetsListeners();
}
@Override // com.discord.app.AppFragment
public void onViewBoundOrOnResume() {
super.onViewBoundOrOnResume();
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.bindToComponentLifecycle(getGifCategoryViewModel().observeViewState(), this), WidgetGifCategory.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetGifCategory$onViewBoundOrOnResume$1(this), 62, (Object) null);
}
public final void setOnGifSelected(Function0<Unit> function0) {
m.checkNotNullParameter(function0, "onSelected");
this.onGifSelected = function0;
}
}