android: list's loadMore change should be synchronized with itemCount

This commit is contained in:
pengfei.zhou 2022-06-23 16:36:09 +08:00 committed by osborn
parent 3594217839
commit a443554cfb
4 changed files with 11 additions and 8 deletions

View File

@ -46,6 +46,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
int batchCount = 15;
SparseArray<String> itemValues = new SparseArray<>();
int loadAnchor = -1;
boolean loadMore = false;
FlowAdapter(FlowLayoutNode flowLayoutNode) {
this.flowLayoutNode = flowLayoutNode;
@ -62,7 +63,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
@Override
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
JSValue jsValue = getItemModel(position);
boolean fullSpan = this.flowLayoutNode.loadMore && position >= this.itemCount;
boolean fullSpan = this.loadMore && position >= this.itemCount;
if (jsValue != null && jsValue.isObject()) {
JSObject jsObject = jsValue.asObject();
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
@ -84,7 +85,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
layoutParams.setFullSpan(true);
holder.itemView.setLayoutParams(layoutParams);
}
if (this.flowLayoutNode.loadMore
if (this.loadMore
&& position >= this.itemCount
&& !TextUtils.isEmpty(this.flowLayoutNode.onLoadMoreFuncId)) {
callLoadMore();
@ -93,7 +94,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
@Override
public int getItemCount() {
return this.itemCount + (this.flowLayoutNode.loadMore ? 1 : 0);
return this.itemCount + (this.loadMore ? 1 : 0);
}
@Override

View File

@ -93,7 +93,7 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> implements IDoricScr
}
};
String onLoadMoreFuncId;
boolean loadMore = false;
private boolean loadMore = false;
String loadMoreViewId;
private final Set<DoricScrollChangeListener> listeners = new HashSet<>();
private String onScrollFuncId;
@ -241,6 +241,7 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> implements IDoricScr
mView.post(new Runnable() {
@Override
public void run() {
flowAdapter.loadMore = loadMore;
flowAdapter.itemCount = itemCount;
flowAdapter.notifyDataSetChanged();
}

View File

@ -48,7 +48,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
int itemCount = 0;
int loadAnchor = -1;
boolean loadMore = false;
@NonNull
@Override
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@ -66,7 +66,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
holder.listItemNode.reset();
holder.listItemNode.blend(jsObject.getProperty("props").asObject());
}
if (this.listNode.loadMore
if (this.loadMore
&& position >= this.itemCount
&& !TextUtils.isEmpty(this.listNode.onLoadMoreFuncId)) {
callLoadMore();
@ -75,7 +75,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
@Override
public int getItemCount() {
return this.itemCount + (this.listNode.loadMore ? 1 : 0);
return this.itemCount + (this.loadMore ? 1 : 0);
}
@Override

View File

@ -64,7 +64,7 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
int itemCount = 0;
int batchCount = 15;
SparseArray<String> itemValues = new SparseArray<>();
boolean loadMore = false;
private boolean loadMore = false;
String loadMoreViewId;
private final Set<DoricScrollChangeListener> listeners = new HashSet<>();
private String onScrollFuncId;
@ -214,6 +214,7 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
@SuppressLint("NotifyDataSetChanged")
@Override
public void run() {
listAdapter.loadMore = loadMore;
listAdapter.itemCount = itemCount;
listAdapter.notifyDataSetChanged();
}