Merge branch 'master' of code.aliyun.com:Doric/doric-Android

This commit is contained in:
pengfei.zhou 2019-12-13 14:39:18 +08:00
commit 75547d1117
2 changed files with 33 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import com.github.pengfeizhou.jscore.JSArray;
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.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
public int getItemCount() {
return itemCount;
return this.itemCount + (this.flowLayoutNode.loadMore ? 1 : 0);
}
@Override
public int getItemViewType(int position) {
if (position >= itemCount) {
return Integer.MAX_VALUE;
}
JSValue value = getItemModel(position);
if (value.isObject()) {
if (value.asObject().getProperty("identifier").isString()) {
@ -84,6 +98,9 @@ class FlowAdapter extends RecyclerView.Adapter<FlowAdapter.DoricViewHolder> {
}
private JSValue getItemModel(final int position) {
if (position >= this.itemCount) {
return this.flowLayoutNode.getSubModel(this.flowLayoutNode.loadMoreViewId);
}
String id = itemValues.get(position);
if (TextUtils.isEmpty(id)) {
AsyncResult<JSDecoder> asyncResult = flowLayoutNode.callJSResponse(

View File

@ -70,6 +70,9 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> {
outRect.set(columnSpace / 2, rowSpace / 2, columnSpace / 2, rowSpace / 2);
}
};
String onLoadMoreFuncId;
boolean loadMore = false;
String loadMoreViewId;
public FlowLayoutNode(DoricContext doricContext) {
super(doricContext);
@ -115,13 +118,24 @@ public class FlowLayoutNode extends SuperNode<RecyclerView> {
if (!funcId.equals(this.flowAdapter.renderItemFuncId)) {
this.flowAdapter.renderItemFuncId = funcId;
// 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();
clearSubModel();
}
break;
case "batchCount":
this.flowAdapter.batchCount = prop.asNumber().toInt();
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:
super.blend(view, name, prop);
break;