152 lines
6.6 KiB
Java
152 lines
6.6 KiB
Java
|
package com.discord.utilities.views;
|
||
|
|
||
|
import android.graphics.Canvas;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import androidx.recyclerview.widget.RecyclerView;
|
||
|
import d0.z.d.m;
|
||
|
/* compiled from: StickyHeaderItemDecoration.kt */
|
||
|
public final class StickyHeaderItemDecoration extends RecyclerView.ItemDecoration {
|
||
|
private Float actionDownRawX;
|
||
|
private Float actionDownRawY;
|
||
|
private final StickyHeaderAdapter adapter;
|
||
|
private float stickyHeaderBottom;
|
||
|
|
||
|
/* compiled from: StickyHeaderItemDecoration.kt */
|
||
|
public static final class LayoutManager {
|
||
|
public static final LayoutManager INSTANCE = new LayoutManager();
|
||
|
|
||
|
private LayoutManager() {
|
||
|
}
|
||
|
|
||
|
public static final void layoutHeaderView(ViewGroup viewGroup, View view) {
|
||
|
m.checkNotNullParameter(viewGroup, "parent");
|
||
|
m.checkNotNullParameter(view, "view");
|
||
|
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(viewGroup.getWidth(), 1073741824);
|
||
|
int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(viewGroup.getHeight(), 0);
|
||
|
view.measure(ViewGroup.getChildMeasureSpec(makeMeasureSpec, viewGroup.getPaddingRight() + viewGroup.getPaddingLeft(), view.getLayoutParams().width), ViewGroup.getChildMeasureSpec(makeMeasureSpec2, viewGroup.getPaddingBottom() + viewGroup.getPaddingTop(), view.getLayoutParams().height));
|
||
|
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* compiled from: StickyHeaderItemDecoration.kt */
|
||
|
public interface StickyHeaderAdapter {
|
||
|
View getAndBindHeaderView(int i);
|
||
|
|
||
|
Integer getHeaderPositionForItem(int i);
|
||
|
|
||
|
boolean isHeader(int i);
|
||
|
}
|
||
|
|
||
|
public StickyHeaderItemDecoration(StickyHeaderAdapter stickyHeaderAdapter) {
|
||
|
m.checkNotNullParameter(stickyHeaderAdapter, "adapter");
|
||
|
this.adapter = stickyHeaderAdapter;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ Float access$getActionDownRawX$p(StickyHeaderItemDecoration stickyHeaderItemDecoration) {
|
||
|
return stickyHeaderItemDecoration.actionDownRawX;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ Float access$getActionDownRawY$p(StickyHeaderItemDecoration stickyHeaderItemDecoration) {
|
||
|
return stickyHeaderItemDecoration.actionDownRawY;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ float access$getStickyHeaderBottom$p(StickyHeaderItemDecoration stickyHeaderItemDecoration) {
|
||
|
return stickyHeaderItemDecoration.stickyHeaderBottom;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$resetActionDownCoordinates(StickyHeaderItemDecoration stickyHeaderItemDecoration) {
|
||
|
stickyHeaderItemDecoration.resetActionDownCoordinates();
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$setActionDownRawX$p(StickyHeaderItemDecoration stickyHeaderItemDecoration, Float f) {
|
||
|
stickyHeaderItemDecoration.actionDownRawX = f;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$setActionDownRawY$p(StickyHeaderItemDecoration stickyHeaderItemDecoration, Float f) {
|
||
|
stickyHeaderItemDecoration.actionDownRawY = f;
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ void access$setStickyHeaderBottom$p(StickyHeaderItemDecoration stickyHeaderItemDecoration, float f) {
|
||
|
stickyHeaderItemDecoration.stickyHeaderBottom = f;
|
||
|
}
|
||
|
|
||
|
private final void drawHeader(Canvas canvas, View view, float f) {
|
||
|
canvas.save();
|
||
|
if (f != 0.0f) {
|
||
|
canvas.translate(0.0f, f);
|
||
|
}
|
||
|
this.stickyHeaderBottom = ((float) view.getBottom()) - f;
|
||
|
view.draw(canvas);
|
||
|
canvas.restore();
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void drawHeader$default(StickyHeaderItemDecoration stickyHeaderItemDecoration, Canvas canvas, View view, float f, int i, Object obj) {
|
||
|
if ((i & 4) != 0) {
|
||
|
f = 0.0f;
|
||
|
}
|
||
|
stickyHeaderItemDecoration.drawHeader(canvas, view, f);
|
||
|
}
|
||
|
|
||
|
private final View getAndBindHeaderViewForItem(int i) {
|
||
|
Integer headerPositionForItem = this.adapter.getHeaderPositionForItem(i);
|
||
|
if (headerPositionForItem == null) {
|
||
|
return null;
|
||
|
}
|
||
|
return this.adapter.getAndBindHeaderView(headerPositionForItem.intValue());
|
||
|
}
|
||
|
|
||
|
private final View getOverlappingView(RecyclerView recyclerView, int i) {
|
||
|
int childCount = recyclerView.getChildCount();
|
||
|
for (int i2 = 0; i2 < childCount; i2++) {
|
||
|
View childAt = recyclerView.getChildAt(i2);
|
||
|
m.checkNotNullExpressionValue(childAt, "child");
|
||
|
int top = childAt.getTop();
|
||
|
int bottom = childAt.getBottom();
|
||
|
if (top <= i && bottom > i) {
|
||
|
return childAt;
|
||
|
}
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
private final void resetActionDownCoordinates() {
|
||
|
this.actionDownRawX = null;
|
||
|
this.actionDownRawY = null;
|
||
|
}
|
||
|
|
||
|
public final void blockClicks(RecyclerView recyclerView) {
|
||
|
m.checkNotNullParameter(recyclerView, "parent");
|
||
|
recyclerView.addOnItemTouchListener(new StickyHeaderItemDecoration$blockClicks$1(this));
|
||
|
}
|
||
|
|
||
|
@Override // androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
||
|
public void onDrawOver(Canvas canvas, RecyclerView recyclerView, RecyclerView.State state) {
|
||
|
int childAdapterPosition;
|
||
|
int childAdapterPosition2;
|
||
|
m.checkNotNullParameter(canvas, "canvas");
|
||
|
m.checkNotNullParameter(recyclerView, "parent");
|
||
|
m.checkNotNullParameter(state, "state");
|
||
|
super.onDrawOver(canvas, recyclerView, state);
|
||
|
View childAt = recyclerView.getChildAt(0);
|
||
|
if (childAt != null && (childAdapterPosition = recyclerView.getChildAdapterPosition(childAt)) != -1) {
|
||
|
View andBindHeaderViewForItem = getAndBindHeaderViewForItem(childAdapterPosition);
|
||
|
float f = 0.0f;
|
||
|
if (andBindHeaderViewForItem == null) {
|
||
|
this.stickyHeaderBottom = 0.0f;
|
||
|
return;
|
||
|
}
|
||
|
int top = recyclerView.getTop();
|
||
|
int bottom = recyclerView.getBottom();
|
||
|
int bottom2 = andBindHeaderViewForItem.getBottom();
|
||
|
if (top <= bottom2 && bottom > bottom2) {
|
||
|
View overlappingView = getOverlappingView(recyclerView, andBindHeaderViewForItem.getBottom());
|
||
|
if (!(overlappingView == null || (childAdapterPosition2 = recyclerView.getChildAdapterPosition(overlappingView)) == -1 || !this.adapter.isHeader(childAdapterPosition2))) {
|
||
|
f = (float) (overlappingView.getTop() - andBindHeaderViewForItem.getHeight());
|
||
|
}
|
||
|
drawHeader(canvas, andBindHeaderViewForItem, f);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|