implement android flow layout load more
This commit is contained in:
parent
f9ff72c2ed
commit
c896bfc64c
@ -22,6 +22,7 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||||
|
|
||||||
import com.github.pengfeizhou.jscore.JSArray;
|
import com.github.pengfeizhou.jscore.JSArray;
|
||||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||||
@ -65,15 +66,28 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
|||||||
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
|
holder.flowLayoutItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||||
holder.flowLayoutItemNode.blend(jsObject.getProperty("props").asObject());
|
holder.flowLayoutItemNode.blend(jsObject.getProperty("props").asObject());
|
||||||
}
|
}
|
||||||
|
if (position >= this.itemCount) {
|
||||||
|
this.flowLayoutNode.callJSResponse(this.flowLayoutNode.onLoadMoreFuncId);
|
||||||
|
|
||||||
|
StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
holder.itemView.getLayoutParams().height
|
||||||
|
);
|
||||||
|
layoutParams.setFullSpan(true);
|
||||||
|
holder.itemView.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return itemCount;
|
return this.itemCount + (this.flowLayoutNode.loadMore ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
|
if (position >= itemCount) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
JSValue value = getItemModel(position);
|
JSValue value = getItemModel(position);
|
||||||
if (value.isObject()) {
|
if (value.isObject()) {
|
||||||
if (value.asObject().getProperty("identifier").isString()) {
|
if (value.asObject().getProperty("identifier").isString()) {
|
||||||
@ -84,6 +98,9 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JSValue getItemModel(final int position) {
|
private JSValue getItemModel(final int position) {
|
||||||
|
if (position >= this.itemCount) {
|
||||||
|
return this.flowLayoutNode.getSubModel(this.flowLayoutNode.loadMoreViewId);
|
||||||
|
}
|
||||||
String id = itemValues.get(position);
|
String id = itemValues.get(position);
|
||||||
if (TextUtils.isEmpty(id)) {
|
if (TextUtils.isEmpty(id)) {
|
||||||
AsyncResult<JSDecoder> asyncResult = flowLayoutNode.callJSResponse(
|
AsyncResult<JSDecoder> asyncResult = flowLayoutNode.callJSResponse(
|
||||||
|
@ -70,6 +70,9 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> {
|
|||||||
outRect.set(columnSpace / 2, rowSpace / 2, columnSpace / 2, rowSpace / 2);
|
outRect.set(columnSpace / 2, rowSpace / 2, columnSpace / 2, rowSpace / 2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
String onLoadMoreFuncId;
|
||||||
|
boolean loadMore = false;
|
||||||
|
String loadMoreViewId;
|
||||||
|
|
||||||
public FlowLayoutNode(DoricContext doricContext) {
|
public FlowLayoutNode(DoricContext doricContext) {
|
||||||
super(doricContext);
|
super(doricContext);
|
||||||
@ -115,13 +118,24 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> {
|
|||||||
if (!funcId.equals(this.flowAdapter.renderItemFuncId)) {
|
if (!funcId.equals(this.flowAdapter.renderItemFuncId)) {
|
||||||
this.flowAdapter.renderItemFuncId = funcId;
|
this.flowAdapter.renderItemFuncId = funcId;
|
||||||
// If reset renderItem,should reset native cache.
|
// If reset renderItem,should reset native cache.
|
||||||
|
for (int index = 0; index < this.flowAdapter.itemValues.size(); index++) {
|
||||||
|
removeSubModel(this.flowAdapter.itemValues.valueAt(index));
|
||||||
|
}
|
||||||
this.flowAdapter.itemValues.clear();
|
this.flowAdapter.itemValues.clear();
|
||||||
clearSubModel();
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "batchCount":
|
case "batchCount":
|
||||||
this.flowAdapter.batchCount = prop.asNumber().toInt();
|
this.flowAdapter.batchCount = prop.asNumber().toInt();
|
||||||
break;
|
break;
|
||||||
|
case "onLoadMore":
|
||||||
|
this.onLoadMoreFuncId = prop.asString().value();
|
||||||
|
break;
|
||||||
|
case "loadMoreView":
|
||||||
|
this.loadMoreViewId = prop.asString().value();
|
||||||
|
break;
|
||||||
|
case "loadMore":
|
||||||
|
this.loadMore = prop.asBoolean().value();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
super.blend(view, name, prop);
|
super.blend(view, name, prop);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user