317 lines
14 KiB
Java
317 lines
14 KiB
Java
package com.discord.widgets.chat.input.expression;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Resources;
|
|
import android.util.DisplayMetrics;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.core.view.MarginLayoutParamsCompat;
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import c.d.b.a.a;
|
|
import com.discord.app.AppLog;
|
|
import com.discord.utilities.dimen.DimenUtils;
|
|
import com.discord.utilities.logging.Logger;
|
|
import com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple;
|
|
import com.discord.utilities.mg_recycler.MGRecyclerDataPayload;
|
|
import com.discord.utilities.rx.LeadingEdgeThrottle;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.views.StickyHeaderItemDecoration;
|
|
import com.discord.widgets.chat.input.ExpressionPickerItemDecoration;
|
|
import d0.t.m0;
|
|
import d0.t.n;
|
|
import d0.z.d.m;
|
|
import j0.l.a.r;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.ListIterator;
|
|
import java.util.Set;
|
|
import java.util.concurrent.TimeUnit;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import rx.Emitter;
|
|
import rx.Observable;
|
|
/* compiled from: WidgetExpressionPickerAdapter.kt */
|
|
public abstract class WidgetExpressionPickerAdapter extends MGRecyclerAdapterSimple<MGRecyclerDataPayload> implements StickyHeaderItemDecoration.StickyHeaderAdapter {
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final int ITEM_TYPE_HEADER = 0;
|
|
public List<Integer> headerIndices;
|
|
private final Set<Integer> headerTypes;
|
|
private ExpressionPickerItemDecoration itemDecoration;
|
|
private RecyclerView.OnScrollListener onScrollListener;
|
|
private Function1<? super Integer, Unit> onScrollPositionListener;
|
|
public StickyHeadersManager stickyHeaderManager;
|
|
|
|
/* compiled from: WidgetExpressionPickerAdapter.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
|
|
public final int calculateNumOfColumns(int i, float f, int i2, Resources resources) {
|
|
m.checkNotNullParameter(resources, "resources");
|
|
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
|
|
int i3 = (int) (((float) (displayMetrics.widthPixels - i)) / f);
|
|
if (i3 != 0) {
|
|
return i3;
|
|
}
|
|
AppLog appLog = AppLog.g;
|
|
StringBuilder L = a.L("\n invalid dimensions while calculating numColumns\n displayMetrics.widthPixels: ");
|
|
L.append(displayMetrics.widthPixels);
|
|
L.append("\n total margin marginStart: ");
|
|
L.append(i);
|
|
L.append("\n itemSize: ");
|
|
L.append(f);
|
|
L.append("\n ");
|
|
Logger.e$default(appLog, d0.g0.m.trimIndent(L.toString()), null, null, 6, null);
|
|
return i2;
|
|
}
|
|
|
|
public final int calculateNumOfColumns(RecyclerView recyclerView, float f, int i) {
|
|
m.checkNotNullParameter(recyclerView, "recyclerView");
|
|
ViewGroup.LayoutParams layoutParams = recyclerView.getLayoutParams();
|
|
int i2 = 0;
|
|
int marginStart = layoutParams instanceof ViewGroup.MarginLayoutParams ? MarginLayoutParamsCompat.getMarginStart((ViewGroup.MarginLayoutParams) layoutParams) : 0;
|
|
ViewGroup.LayoutParams layoutParams2 = recyclerView.getLayoutParams();
|
|
if (layoutParams2 instanceof ViewGroup.MarginLayoutParams) {
|
|
i2 = MarginLayoutParamsCompat.getMarginEnd((ViewGroup.MarginLayoutParams) layoutParams2);
|
|
}
|
|
Resources resources = recyclerView.getResources();
|
|
m.checkNotNullExpressionValue(resources, "recyclerView.resources");
|
|
return calculateNumOfColumns(marginStart + i2, f, i, resources);
|
|
}
|
|
}
|
|
|
|
/* compiled from: WidgetExpressionPickerAdapter.kt */
|
|
public interface StickyHeaderViewHolder {
|
|
void bind(int i, MGRecyclerDataPayload mGRecyclerDataPayload);
|
|
|
|
View getItemView();
|
|
}
|
|
|
|
/* compiled from: WidgetExpressionPickerAdapter.kt */
|
|
public static final class StickyHeadersManager {
|
|
private final View currentStickyHeaderView;
|
|
private final StickyHeaderViewHolder stickyHeaderHolder;
|
|
|
|
public StickyHeadersManager(WidgetExpressionPickerAdapter widgetExpressionPickerAdapter) {
|
|
m.checkNotNullParameter(widgetExpressionPickerAdapter, "adapter");
|
|
StickyHeaderViewHolder createStickyHeaderViewHolder = widgetExpressionPickerAdapter.createStickyHeaderViewHolder(widgetExpressionPickerAdapter);
|
|
this.stickyHeaderHolder = createStickyHeaderViewHolder;
|
|
this.currentStickyHeaderView = createStickyHeaderViewHolder.getItemView();
|
|
}
|
|
|
|
public final View getCurrentStickyHeaderView() {
|
|
return this.currentStickyHeaderView;
|
|
}
|
|
|
|
public final StickyHeaderViewHolder getStickyHeaderHolder() {
|
|
return this.stickyHeaderHolder;
|
|
}
|
|
|
|
public final void layoutViews(RecyclerView recyclerView) {
|
|
m.checkNotNullParameter(recyclerView, "recyclerView");
|
|
View view = this.currentStickyHeaderView;
|
|
if (view != null) {
|
|
StickyHeaderItemDecoration.LayoutManager.layoutHeaderView(recyclerView, view);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
|
|
public WidgetExpressionPickerAdapter(RecyclerView recyclerView, Set<Integer> set) {
|
|
super(recyclerView, false, 2, null);
|
|
m.checkNotNullParameter(recyclerView, "recycler");
|
|
m.checkNotNullParameter(set, "headerTypes");
|
|
this.headerTypes = set;
|
|
this.onScrollPositionListener = WidgetExpressionPickerAdapter$onScrollPositionListener$1.INSTANCE;
|
|
setupScrollObservables();
|
|
}
|
|
|
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
|
public /* synthetic */ WidgetExpressionPickerAdapter(RecyclerView recyclerView, Set set, int i, DefaultConstructorMarker defaultConstructorMarker) {
|
|
this(recyclerView, (i & 2) != 0 ? m0.setOf(0) : set);
|
|
}
|
|
|
|
private final void setupScrollObservables() {
|
|
Observable n = Observable.n(new WidgetExpressionPickerAdapter$setupScrollObservables$1(this), Emitter.BackpressureMode.LATEST);
|
|
Observable h02 = Observable.h0(new r(n.i, new LeadingEdgeThrottle(250, TimeUnit.MILLISECONDS)));
|
|
m.checkNotNullExpressionValue(h02, "Observable\n .crea…, TimeUnit.MILLISECONDS))");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui(h02), getClass(), (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetExpressionPickerAdapter$setupScrollObservables$2(this), 62, (Object) null);
|
|
RecyclerView.OnScrollListener onScrollListener = this.onScrollListener;
|
|
if (onScrollListener != null) {
|
|
getRecycler().addOnScrollListener(onScrollListener);
|
|
}
|
|
}
|
|
|
|
public abstract StickyHeaderViewHolder createStickyHeaderViewHolder(WidgetExpressionPickerAdapter widgetExpressionPickerAdapter);
|
|
|
|
@Override // com.discord.utilities.views.StickyHeaderItemDecoration.StickyHeaderAdapter
|
|
public View getAndBindHeaderView(int i) {
|
|
MGRecyclerDataPayload mGRecyclerDataPayload = getInternalData().get(i);
|
|
StickyHeadersManager stickyHeadersManager = this.stickyHeaderManager;
|
|
if (stickyHeadersManager == null) {
|
|
m.throwUninitializedPropertyAccessException("stickyHeaderManager");
|
|
}
|
|
stickyHeadersManager.getStickyHeaderHolder().bind(i, mGRecyclerDataPayload);
|
|
StickyHeadersManager stickyHeadersManager2 = this.stickyHeaderManager;
|
|
if (stickyHeadersManager2 == null) {
|
|
m.throwUninitializedPropertyAccessException("stickyHeaderManager");
|
|
}
|
|
return stickyHeadersManager2.getCurrentStickyHeaderView();
|
|
}
|
|
|
|
public final List<Integer> getHeaderIndices() {
|
|
List<Integer> list = this.headerIndices;
|
|
if (list == null) {
|
|
m.throwUninitializedPropertyAccessException("headerIndices");
|
|
}
|
|
return list;
|
|
}
|
|
|
|
@Override // com.discord.utilities.views.StickyHeaderItemDecoration.StickyHeaderAdapter
|
|
public Integer getHeaderPositionForItem(int i) {
|
|
Integer num;
|
|
boolean z2;
|
|
List<Integer> list = this.headerIndices;
|
|
if (list == null) {
|
|
m.throwUninitializedPropertyAccessException("headerIndices");
|
|
}
|
|
ListIterator<Integer> listIterator = list.listIterator(list.size());
|
|
while (true) {
|
|
if (!listIterator.hasPrevious()) {
|
|
num = null;
|
|
break;
|
|
}
|
|
num = listIterator.previous();
|
|
if (i >= num.intValue()) {
|
|
z2 = true;
|
|
continue;
|
|
} else {
|
|
z2 = false;
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
break;
|
|
}
|
|
}
|
|
Integer num2 = num;
|
|
if (num2 == null) {
|
|
AppLog appLog = AppLog.g;
|
|
StringBuilder L = a.L("failed to find header position for item in ");
|
|
L.append(getClass().getName());
|
|
Logger.e$default(appLog, L.toString(), null, null, 6, null);
|
|
}
|
|
return num2;
|
|
}
|
|
|
|
public final Set<Integer> getHeaderTypes() {
|
|
return this.headerTypes;
|
|
}
|
|
|
|
public final ExpressionPickerItemDecoration getItemDecoration() {
|
|
return this.itemDecoration;
|
|
}
|
|
|
|
public abstract GridLayoutManager getLayoutManager();
|
|
|
|
public abstract int getNumColumns();
|
|
|
|
public final RecyclerView.OnScrollListener getOnScrollListener() {
|
|
return this.onScrollListener;
|
|
}
|
|
|
|
/* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: kotlin.jvm.functions.Function1<? super java.lang.Integer, kotlin.Unit>, kotlin.jvm.functions.Function1<java.lang.Integer, kotlin.Unit> */
|
|
public final Function1<Integer, Unit> getOnScrollPositionListener() {
|
|
return this.onScrollPositionListener;
|
|
}
|
|
|
|
public final StickyHeadersManager getStickyHeaderManager() {
|
|
StickyHeadersManager stickyHeadersManager = this.stickyHeaderManager;
|
|
if (stickyHeadersManager == null) {
|
|
m.throwUninitializedPropertyAccessException("stickyHeaderManager");
|
|
}
|
|
return stickyHeadersManager;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
|
m.checkNotNullParameter(recyclerView, "recyclerView");
|
|
super.onAttachedToRecyclerView(recyclerView);
|
|
this.stickyHeaderManager = new StickyHeadersManager(this);
|
|
recyclerView.addOnLayoutChangeListener(new WidgetExpressionPickerAdapter$onAttachedToRecyclerView$1(this, recyclerView));
|
|
}
|
|
|
|
public final void scrollToPosition(int i) {
|
|
RecyclerView.OnScrollListener onScrollListener = this.onScrollListener;
|
|
if (onScrollListener != null) {
|
|
getRecycler().removeOnScrollListener(onScrollListener);
|
|
}
|
|
getLayoutManager().scrollToPositionWithOffset(i, 0);
|
|
RecyclerView.OnScrollListener onScrollListener2 = this.onScrollListener;
|
|
if (onScrollListener2 != null) {
|
|
getRecycler().addOnScrollListener(onScrollListener2);
|
|
}
|
|
}
|
|
|
|
@Override // com.discord.utilities.mg_recycler.MGRecyclerAdapterSimple
|
|
public void setData(List<? extends MGRecyclerDataPayload> list) {
|
|
m.checkNotNullParameter(list, "data");
|
|
super.setData(list);
|
|
ArrayList arrayList = new ArrayList();
|
|
int i = 0;
|
|
for (Object obj : list) {
|
|
int i2 = i + 1;
|
|
if (i < 0) {
|
|
n.throwIndexOverflow();
|
|
}
|
|
Integer valueOf = this.headerTypes.contains(Integer.valueOf(((MGRecyclerDataPayload) obj).getType())) ? Integer.valueOf(i) : null;
|
|
if (valueOf != null) {
|
|
arrayList.add(valueOf);
|
|
}
|
|
i = i2;
|
|
}
|
|
this.headerIndices = arrayList;
|
|
ExpressionPickerItemDecoration expressionPickerItemDecoration = this.itemDecoration;
|
|
if (expressionPickerItemDecoration != null) {
|
|
getRecycler().removeItemDecoration(expressionPickerItemDecoration);
|
|
}
|
|
int numColumns = getNumColumns();
|
|
List<Integer> list2 = this.headerIndices;
|
|
if (list2 == null) {
|
|
m.throwUninitializedPropertyAccessException("headerIndices");
|
|
}
|
|
ExpressionPickerItemDecoration expressionPickerItemDecoration2 = new ExpressionPickerItemDecoration(numColumns, list2, DimenUtils.dpToPixels(8));
|
|
getRecycler().addItemDecoration(expressionPickerItemDecoration2);
|
|
this.itemDecoration = expressionPickerItemDecoration2;
|
|
}
|
|
|
|
public final void setHeaderIndices(List<Integer> list) {
|
|
m.checkNotNullParameter(list, "<set-?>");
|
|
this.headerIndices = list;
|
|
}
|
|
|
|
public final void setItemDecoration(ExpressionPickerItemDecoration expressionPickerItemDecoration) {
|
|
this.itemDecoration = expressionPickerItemDecoration;
|
|
}
|
|
|
|
public final void setOnScrollListener(RecyclerView.OnScrollListener onScrollListener) {
|
|
this.onScrollListener = onScrollListener;
|
|
}
|
|
|
|
public final void setOnScrollPositionListener(Function1<? super Integer, Unit> function1) {
|
|
m.checkNotNullParameter(function1, "<set-?>");
|
|
this.onScrollPositionListener = function1;
|
|
}
|
|
|
|
public final void setStickyHeaderManager(StickyHeadersManager stickyHeadersManager) {
|
|
m.checkNotNullParameter(stickyHeadersManager, "<set-?>");
|
|
this.stickyHeaderManager = stickyHeadersManager;
|
|
}
|
|
}
|