android: list's loadMore change should be synchronized with itemCount
This commit is contained in:
parent
3594217839
commit
a443554cfb
@ -46,6 +46,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
|||||||
int batchCount = 15;
|
int batchCount = 15;
|
||||||
SparseArray<String> itemValues = new SparseArray<>();
|
SparseArray<String> itemValues = new SparseArray<>();
|
||||||
int loadAnchor = -1;
|
int loadAnchor = -1;
|
||||||
|
boolean loadMore = false;
|
||||||
|
|
||||||
FlowAdapter(FlowLayoutNode flowLayoutNode) {
|
FlowAdapter(FlowLayoutNode flowLayoutNode) {
|
||||||
this.flowLayoutNode = flowLayoutNode;
|
this.flowLayoutNode = flowLayoutNode;
|
||||||
@ -62,7 +63,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||||
JSValue jsValue = getItemModel(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()) {
|
if (jsValue != null && jsValue.isObject()) {
|
||||||
JSObject jsObject = jsValue.asObject();
|
JSObject jsObject = jsValue.asObject();
|
||||||
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
|
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||||
@ -84,7 +85,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
|||||||
layoutParams.setFullSpan(true);
|
layoutParams.setFullSpan(true);
|
||||||
holder.itemView.setLayoutParams(layoutParams);
|
holder.itemView.setLayoutParams(layoutParams);
|
||||||
}
|
}
|
||||||
if (this.flowLayoutNode.loadMore
|
if (this.loadMore
|
||||||
&& position >= this.itemCount
|
&& position >= this.itemCount
|
||||||
&& !TextUtils.isEmpty(this.flowLayoutNode.onLoadMoreFuncId)) {
|
&& !TextUtils.isEmpty(this.flowLayoutNode.onLoadMoreFuncId)) {
|
||||||
callLoadMore();
|
callLoadMore();
|
||||||
@ -93,7 +94,7 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return this.itemCount + (this.flowLayoutNode.loadMore ? 1 : 0);
|
return this.itemCount + (this.loadMore ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,7 +93,7 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> implements IDoricScr
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
String onLoadMoreFuncId;
|
String onLoadMoreFuncId;
|
||||||
boolean loadMore = false;
|
private boolean loadMore = false;
|
||||||
String loadMoreViewId;
|
String loadMoreViewId;
|
||||||
private final Set<DoricScrollChangeListener> listeners = new HashSet<>();
|
private final Set<DoricScrollChangeListener> listeners = new HashSet<>();
|
||||||
private String onScrollFuncId;
|
private String onScrollFuncId;
|
||||||
@ -241,6 +241,7 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> implements IDoricScr
|
|||||||
mView.post(new Runnable() {
|
mView.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
flowAdapter.loadMore = loadMore;
|
||||||
flowAdapter.itemCount = itemCount;
|
flowAdapter.itemCount = itemCount;
|
||||||
flowAdapter.notifyDataSetChanged();
|
flowAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
|||||||
|
|
||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
int loadAnchor = -1;
|
int loadAnchor = -1;
|
||||||
|
boolean loadMore = false;
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public DoricViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
@ -66,7 +66,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
|||||||
holder.listItemNode.reset();
|
holder.listItemNode.reset();
|
||||||
holder.listItemNode.blend(jsObject.getProperty("props").asObject());
|
holder.listItemNode.blend(jsObject.getProperty("props").asObject());
|
||||||
}
|
}
|
||||||
if (this.listNode.loadMore
|
if (this.loadMore
|
||||||
&& position >= this.itemCount
|
&& position >= this.itemCount
|
||||||
&& !TextUtils.isEmpty(this.listNode.onLoadMoreFuncId)) {
|
&& !TextUtils.isEmpty(this.listNode.onLoadMoreFuncId)) {
|
||||||
callLoadMore();
|
callLoadMore();
|
||||||
@ -75,7 +75,7 @@ class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return this.itemCount + (this.listNode.loadMore ? 1 : 0);
|
return this.itemCount + (this.loadMore ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +64,7 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
int batchCount = 15;
|
int batchCount = 15;
|
||||||
SparseArray<String> itemValues = new SparseArray<>();
|
SparseArray<String> itemValues = new SparseArray<>();
|
||||||
boolean loadMore = false;
|
private boolean loadMore = false;
|
||||||
String loadMoreViewId;
|
String loadMoreViewId;
|
||||||
private final Set<DoricScrollChangeListener> listeners = new HashSet<>();
|
private final Set<DoricScrollChangeListener> listeners = new HashSet<>();
|
||||||
private String onScrollFuncId;
|
private String onScrollFuncId;
|
||||||
@ -214,6 +214,7 @@ public class ListNode extends SuperNode<RecyclerView> implements IDoricScrollabl
|
|||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
listAdapter.loadMore = loadMore;
|
||||||
listAdapter.itemCount = itemCount;
|
listAdapter.itemCount = itemCount;
|
||||||
listAdapter.notifyDataSetChanged();
|
listAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user