548 lines
18 KiB
Java
548 lines
18 KiB
Java
package com.recyclelib;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.util.Log;
|
|
import android.view.MotionEvent;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
|
import com.thoughtworks.xstream.XStream;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class URecyclerView extends RecyclerView {
|
|
private String K0;
|
|
private LoadingListener L0;
|
|
private boolean M0;
|
|
private boolean N0;
|
|
private boolean O0;
|
|
private float P0;
|
|
private boolean Q0;
|
|
private WrapAdapter R0;
|
|
private RefreshHeaderViewCompact S0;
|
|
private View T0;
|
|
private View U0;
|
|
private final RecyclerView.AdapterDataObserver V0;
|
|
private AppBarLayoutStateChangeListener$State W0;
|
|
private List<HeaderView> X0;
|
|
private boolean Y0;
|
|
private boolean Z0;
|
|
|
|
class HeaderView {
|
|
int a;
|
|
String b;
|
|
View c;
|
|
|
|
HeaderView(URecyclerView uRecyclerView) {
|
|
}
|
|
}
|
|
|
|
public interface LoadingListener {
|
|
void onLoadingMore();
|
|
|
|
void onRefreshing();
|
|
}
|
|
|
|
public class WrapAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
private RecyclerView.Adapter a;
|
|
|
|
private class SimpleViewHolder extends RecyclerView.ViewHolder {
|
|
public SimpleViewHolder(WrapAdapter wrapAdapter, View view) {
|
|
super(view);
|
|
}
|
|
}
|
|
|
|
public WrapAdapter(RecyclerView.Adapter adapter) {
|
|
this.a = adapter;
|
|
}
|
|
|
|
public int a() {
|
|
return URecyclerView.this.X0.size();
|
|
}
|
|
|
|
public boolean b(int i) {
|
|
return URecyclerView.this.O0 && i == getItemCount() - 1;
|
|
}
|
|
|
|
public boolean c(int i) {
|
|
return i >= 1 && i < URecyclerView.this.X0.size() + 1;
|
|
}
|
|
|
|
public boolean d(int i) {
|
|
return i == 0;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public int getItemCount() {
|
|
return URecyclerView.this.O0 ? this.a != null ? a() + this.a.getItemCount() + 2 : a() + 2 : this.a != null ? a() + this.a.getItemCount() + 1 : a() + 1;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public long getItemId(int i) {
|
|
int a;
|
|
if (this.a == null || i < a() + 1 || (a = i - (a() + 1)) >= this.a.getItemCount()) {
|
|
return -1L;
|
|
}
|
|
return this.a.getItemId(a);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public int getItemViewType(int i) {
|
|
int a = i - (a() + 1);
|
|
if (d(i)) {
|
|
return XStream.PRIORITY_VERY_HIGH;
|
|
}
|
|
if (c(i)) {
|
|
return ((HeaderView) URecyclerView.this.X0.get(i - 1)).a;
|
|
}
|
|
if (b(i)) {
|
|
return 10001;
|
|
}
|
|
RecyclerView.Adapter adapter = this.a;
|
|
if (adapter == null || a >= adapter.getItemCount()) {
|
|
return 0;
|
|
}
|
|
return this.a.getItemViewType(a);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
|
super.onAttachedToRecyclerView(recyclerView);
|
|
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
|
|
if (layoutManager instanceof GridLayoutManager) {
|
|
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
|
|
gridLayoutManager.a(new GridLayoutManager.SpanSizeLookup() { // from class: com.recyclelib.URecyclerView.WrapAdapter.1
|
|
@Override // androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup
|
|
public int getSpanSize(int i) {
|
|
if (WrapAdapter.this.c(i) || WrapAdapter.this.b(i) || WrapAdapter.this.d(i)) {
|
|
return gridLayoutManager.N();
|
|
}
|
|
return 1;
|
|
}
|
|
});
|
|
}
|
|
this.a.onAttachedToRecyclerView(recyclerView);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
|
|
if (c(i) || d(i)) {
|
|
return;
|
|
}
|
|
int a = i - (a() + 1);
|
|
RecyclerView.Adapter adapter = this.a;
|
|
if (adapter == null || a >= adapter.getItemCount()) {
|
|
return;
|
|
}
|
|
this.a.onBindViewHolder(viewHolder, a);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
return i == 10000 ? new SimpleViewHolder(this, URecyclerView.this.S0) : URecyclerView.this.m(i) ? new SimpleViewHolder(this, URecyclerView.this.l(i)) : i == 10001 ? new SimpleViewHolder(this, URecyclerView.this.T0) : this.a.onCreateViewHolder(viewGroup, i);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
|
|
this.a.onDetachedFromRecyclerView(recyclerView);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public boolean onFailedToRecycleView(RecyclerView.ViewHolder viewHolder) {
|
|
return this.a.onFailedToRecycleView(viewHolder);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onViewAttachedToWindow(RecyclerView.ViewHolder viewHolder) {
|
|
super.onViewAttachedToWindow(viewHolder);
|
|
ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
|
|
if (layoutParams != null && (layoutParams instanceof StaggeredGridLayoutManager.LayoutParams) && (c(viewHolder.getLayoutPosition()) || d(viewHolder.getLayoutPosition()) || b(viewHolder.getLayoutPosition()))) {
|
|
((StaggeredGridLayoutManager.LayoutParams) layoutParams).a(true);
|
|
}
|
|
this.a.onViewAttachedToWindow(viewHolder);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onViewDetachedFromWindow(RecyclerView.ViewHolder viewHolder) {
|
|
this.a.onViewDetachedFromWindow(viewHolder);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void onViewRecycled(RecyclerView.ViewHolder viewHolder) {
|
|
this.a.onViewRecycled(viewHolder);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void registerAdapterDataObserver(RecyclerView.AdapterDataObserver adapterDataObserver) {
|
|
this.a.registerAdapterDataObserver(adapterDataObserver);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.Adapter
|
|
public void unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver adapterDataObserver) {
|
|
this.a.unregisterAdapterDataObserver(adapterDataObserver);
|
|
}
|
|
}
|
|
|
|
public URecyclerView(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
private boolean B() {
|
|
return this.S0.getParent() != null;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public View l(int i) {
|
|
if (!m(i)) {
|
|
return null;
|
|
}
|
|
for (HeaderView headerView : this.X0) {
|
|
if (headerView.a == i) {
|
|
return headerView.c;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public boolean m(int i) {
|
|
boolean z;
|
|
Iterator<HeaderView> it = this.X0.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
z = false;
|
|
break;
|
|
}
|
|
if (it.next().a == i) {
|
|
z = true;
|
|
break;
|
|
}
|
|
}
|
|
return this.X0.size() > 0 && z;
|
|
}
|
|
|
|
public void A() {
|
|
this.Z0 = false;
|
|
this.S0.b();
|
|
}
|
|
|
|
public int getHeaderAndRefreshingViewCount() {
|
|
return this.X0.size() + 1;
|
|
}
|
|
|
|
public int getHeaderViewCount() {
|
|
return this.X0.size();
|
|
}
|
|
|
|
public RefreshHeaderViewCompact getRefreshHeader() {
|
|
return this.S0;
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView
|
|
public void i(int i) {
|
|
int J;
|
|
super.i(i);
|
|
Log.d(this.K0, "onScrollStateChanged");
|
|
if (i != 0 || this.L0 == null || this.M0 || !this.O0) {
|
|
return;
|
|
}
|
|
RecyclerView.LayoutManager layoutManager = getLayoutManager();
|
|
if (layoutManager instanceof GridLayoutManager) {
|
|
J = ((GridLayoutManager) layoutManager).J();
|
|
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
|
|
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
|
|
int[] iArr = new int[staggeredGridLayoutManager.K()];
|
|
staggeredGridLayoutManager.b(iArr);
|
|
J = a(iArr);
|
|
} else {
|
|
J = ((LinearLayoutManager) layoutManager).J();
|
|
}
|
|
if (layoutManager.e() <= 0 || J < layoutManager.j() - 1 || layoutManager.j() <= layoutManager.e() || this.Q0 || this.S0.getState() >= 2) {
|
|
Log.d("test", "不转");
|
|
return;
|
|
}
|
|
this.M0 = true;
|
|
this.T0.setVisibility(0);
|
|
View view = this.T0;
|
|
if (view instanceof LoadingMoreFootView) {
|
|
((LoadingMoreFootView) view).a();
|
|
}
|
|
this.L0.onLoadingMore();
|
|
}
|
|
|
|
public void n(View view) {
|
|
if (view == null) {
|
|
return;
|
|
}
|
|
String str = (String) view.getTag();
|
|
HeaderView headerView = new HeaderView(this);
|
|
if (!TextUtils.isEmpty(str)) {
|
|
headerView.b = str;
|
|
}
|
|
headerView.a = this.X0.size() + 10002;
|
|
headerView.c = view;
|
|
this.X0.add(headerView);
|
|
WrapAdapter wrapAdapter = this.R0;
|
|
if (wrapAdapter != null) {
|
|
wrapAdapter.notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onScrollChanged(int i, int i2, int i3, int i4) {
|
|
super.onScrollChanged(i, i2, i3, i4);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView, android.view.View
|
|
public boolean onTouchEvent(MotionEvent motionEvent) {
|
|
if (this.P0 == -1.0f) {
|
|
this.P0 = motionEvent.getRawY();
|
|
}
|
|
if (!this.Y0) {
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
}
|
|
int action = motionEvent.getAction();
|
|
if (action == 0) {
|
|
this.P0 = motionEvent.getRawY();
|
|
Log.d(this.K0, "ACTION_DOWN");
|
|
} else if (action == 1) {
|
|
motionEvent.getRawY();
|
|
Log.d(this.K0, "ACTION_UP");
|
|
this.P0 = -1.0f;
|
|
if (B() && this.N0 && this.W0 == AppBarLayoutStateChangeListener$State.EXPANDED) {
|
|
if (this.S0.c()) {
|
|
this.Z0 = true;
|
|
LoadingListener loadingListener = this.L0;
|
|
if (loadingListener != null) {
|
|
loadingListener.onRefreshing();
|
|
}
|
|
}
|
|
} else if (this.Z0) {
|
|
this.Z0 = false;
|
|
this.S0.d();
|
|
}
|
|
} else if (action == 2) {
|
|
float rawY = motionEvent.getRawY() - this.P0;
|
|
this.P0 = motionEvent.getRawY();
|
|
if (B() && this.N0 && this.W0 == AppBarLayoutStateChangeListener$State.EXPANDED) {
|
|
Log.d(this.K0, "top");
|
|
if (this.S0.a()) {
|
|
this.S0.a(rawY);
|
|
}
|
|
this.S0.b(rawY / 3.0f);
|
|
if (this.S0.getVisibleHeight() > 0 && this.S0.getState() < 2) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView
|
|
public void setAdapter(RecyclerView.Adapter adapter) {
|
|
this.R0 = new WrapAdapter(adapter);
|
|
super.setAdapter(this.R0);
|
|
adapter.registerAdapterDataObserver(this.V0);
|
|
this.V0.a();
|
|
}
|
|
|
|
public void setEmptyView(View view) {
|
|
this.U0 = view;
|
|
this.V0.a();
|
|
}
|
|
|
|
public void setFootView(View view) {
|
|
this.T0 = view;
|
|
}
|
|
|
|
public void setLoadingListener(LoadingListener loadingListener) {
|
|
this.L0 = loadingListener;
|
|
}
|
|
|
|
public void setLoadingMoreEnabled(boolean z) {
|
|
this.O0 = z;
|
|
}
|
|
|
|
public void setNoMore(boolean z) {
|
|
this.M0 = false;
|
|
this.Q0 = z;
|
|
if (z) {
|
|
this.T0.setVisibility(0);
|
|
((LoadingMoreFootView) this.T0).setNoMore(z);
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public void setNoMoreWithoutFooter(boolean z) {
|
|
this.M0 = false;
|
|
this.Q0 = z;
|
|
View view = this.T0;
|
|
if (view == null || !this.O0) {
|
|
return;
|
|
}
|
|
view.setVisibility(8);
|
|
}
|
|
|
|
public void setPullRefreshEnabled(boolean z) {
|
|
this.N0 = z;
|
|
}
|
|
|
|
public void setRefreshingViewBackground(int i) {
|
|
}
|
|
|
|
public void y() {
|
|
this.S0.b();
|
|
z();
|
|
}
|
|
|
|
public void z() {
|
|
this.M0 = false;
|
|
View view = this.T0;
|
|
if (view == null || this.Q0) {
|
|
return;
|
|
}
|
|
view.setVisibility(8);
|
|
}
|
|
|
|
public URecyclerView(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public void c(String str) {
|
|
HeaderView headerView;
|
|
Iterator<HeaderView> it = this.X0.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
headerView = null;
|
|
break;
|
|
} else {
|
|
headerView = it.next();
|
|
if (headerView.b.equals(str)) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (headerView != null) {
|
|
this.X0.remove(headerView);
|
|
}
|
|
WrapAdapter wrapAdapter = this.R0;
|
|
if (wrapAdapter != null) {
|
|
wrapAdapter.notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
public void d(boolean z) {
|
|
this.Y0 = z;
|
|
}
|
|
|
|
public void e(boolean z) {
|
|
this.S0.setVisibility(z ? 0 : 8);
|
|
}
|
|
|
|
public URecyclerView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.K0 = "URecyclerView";
|
|
this.M0 = false;
|
|
this.N0 = true;
|
|
this.O0 = true;
|
|
this.P0 = -1.0f;
|
|
this.Q0 = false;
|
|
this.V0 = new DataObserver();
|
|
this.W0 = AppBarLayoutStateChangeListener$State.EXPANDED;
|
|
this.X0 = new ArrayList();
|
|
this.Y0 = true;
|
|
this.Z0 = false;
|
|
a(context);
|
|
}
|
|
|
|
private void a(Context context) {
|
|
if (this.N0) {
|
|
this.S0 = new RefreshHeaderViewCompact(context);
|
|
this.S0.a(true);
|
|
}
|
|
if (this.O0) {
|
|
this.T0 = new LoadingMoreFootView(context);
|
|
this.T0.setVisibility(8);
|
|
}
|
|
}
|
|
|
|
public boolean b(String str) {
|
|
Iterator<HeaderView> it = this.X0.iterator();
|
|
boolean z = false;
|
|
while (it.hasNext()) {
|
|
if (str.equals(it.next().b)) {
|
|
z = true;
|
|
}
|
|
}
|
|
return z;
|
|
}
|
|
|
|
private int a(int[] iArr) {
|
|
int i = iArr[0];
|
|
for (int i2 : iArr) {
|
|
if (i2 > i) {
|
|
i = i2;
|
|
}
|
|
}
|
|
return i;
|
|
}
|
|
|
|
private class DataObserver extends RecyclerView.AdapterDataObserver {
|
|
private DataObserver() {
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
|
public void a() {
|
|
RecyclerView.Adapter adapter = URecyclerView.this.getAdapter();
|
|
if (adapter != null && URecyclerView.this.U0 != null) {
|
|
int i = URecyclerView.this.N0 ? 1 : 0;
|
|
if (URecyclerView.this.O0) {
|
|
i++;
|
|
}
|
|
if (adapter.getItemCount() == i) {
|
|
URecyclerView.this.U0.setVisibility(0);
|
|
URecyclerView.this.setVisibility(8);
|
|
} else {
|
|
URecyclerView.this.U0.setVisibility(8);
|
|
URecyclerView.this.setVisibility(0);
|
|
}
|
|
}
|
|
if (URecyclerView.this.R0 != null) {
|
|
URecyclerView.this.R0.notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
|
public void b(int i, int i2) {
|
|
URecyclerView.this.R0.notifyItemRangeInserted(i, i2);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
|
public void c(int i, int i2) {
|
|
URecyclerView.this.R0.notifyItemRangeRemoved(i, i2);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
|
public void a(int i, int i2) {
|
|
URecyclerView.this.R0.notifyItemRangeChanged(i, i2);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
|
public void a(int i, int i2, Object obj) {
|
|
URecyclerView.this.R0.notifyItemRangeChanged(i, i2, obj);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
|
public void a(int i, int i2, int i3) {
|
|
URecyclerView.this.R0.notifyItemMoved(i, i2);
|
|
}
|
|
}
|
|
}
|