use of com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder in project weex-example by KalicyZhou.
the class BasicListComponent method initComponentHostView.
@Override
protected T initComponentHostView(@NonNull Context context) {
T bounceRecyclerView = generateListView(context, getOrientation());
String transforms = (String) getDomObject().getAttrs().get(TRANSFORM);
if (transforms != null) {
bounceRecyclerView.getInnerView().addItemDecoration(parseTransforms(transforms));
}
RecyclerViewBaseAdapter recyclerViewBaseAdapter = new RecyclerViewBaseAdapter<>(this);
recyclerViewBaseAdapter.setHasStableIds(true);
bounceRecyclerView.setRecyclerViewBaseAdapter(recyclerViewBaseAdapter);
bounceRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
bounceRecyclerView.getInnerView().clearOnScrollListeners();
bounceRecyclerView.getInnerView().addOnScrollListener(mViewOnScrollListener);
bounceRecyclerView.getInnerView().addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
for (ListBaseViewHolder holder : recycleViewList) {
if (holder != null && holder.getComponent() != null && !holder.getComponent().isUsing()) {
recycleImage(holder.getView());
}
}
recycleViewList.clear();
}
List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
if (listeners != null && listeners.size() > 0) {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
View topView = recyclerView.getChildAt(0);
if (topView != null) {
int y = topView.getTop();
listener.onScrollStateChanged(recyclerView, 0, y, newState);
}
}
}
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
List<OnWXScrollListener> listeners = getInstance().getWXScrollListeners();
if (listeners != null && listeners.size() > 0) {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
listener.onScrolled(recyclerView, dx, dy);
}
}
}
}
});
bounceRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
T view;
if ((view = getHostView()) == null)
return;
mViewOnScrollListener.onScrolled(view.getInnerView(), 0, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
return bounceRecyclerView;
}
use of com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder in project weex-example by KalicyZhou.
the class BasicListComponent method onCreateViewHolder.
/**
* Create an instance of {@link ListBaseViewHolder} for the given viewType (not for the given
* index). This method will look up for the first component that fits the viewType requirement and
* doesn't be used. Then create the certain type of view, detach the view f[rom the component.
*
* @param parent the ViewGroup into which the new view will be inserted
* @param viewType the type of the new view
* @return the created view holder.
*/
@Override
public ListBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (mChildren != null) {
if (mViewTypes == null)
return createVHForFakeComponent(viewType);
ArrayList<WXComponent> mTypes = mViewTypes.get(viewType);
checkRecycledViewPool(viewType);
if (mTypes == null)
return createVHForFakeComponent(viewType);
for (int i = 0; i < mTypes.size(); i++) {
WXComponent component = mTypes.get(i);
if (component == null || component.isUsing()) {
continue;
}
if (component.getDomObject() != null && component.getDomObject().isFixed()) {
return createVHForFakeComponent(viewType);
} else {
if (component instanceof WXCell) {
if (component.getRealView() != null) {
return new ListBaseViewHolder(component, viewType);
} else {
((WXCell) component).lazy(false);
component.createView();
component.applyLayoutAndEvent(component);
return new ListBaseViewHolder(component, viewType);
}
} else if (component instanceof WXBaseRefresh) {
return createVHForRefreshComponent(viewType);
} else {
WXLogUtils.e(TAG, "List cannot include element except cell、header、fixed、refresh and loading");
return createVHForFakeComponent(viewType);
}
}
}
}
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.e(TAG, "Cannot find request viewType: " + viewType);
}
return createVHForFakeComponent(viewType);
}
use of com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder in project weex-example by KalicyZhou.
the class BasicListComponent method createVHForFakeComponent.
@NonNull
private ListBaseViewHolder createVHForFakeComponent(int viewType) {
FrameLayout view = new FrameLayout(getContext());
view.setBackgroundColor(Color.WHITE);
view.setLayoutParams(new FrameLayout.LayoutParams(0, 0));
return new ListBaseViewHolder(view, viewType);
}
use of com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder in project weex-example by KalicyZhou.
the class BasicListComponent method createVHForRefreshComponent.
private ListBaseViewHolder createVHForRefreshComponent(int viewType) {
FrameLayout view = new FrameLayout(getContext());
view.setBackgroundColor(Color.WHITE);
view.setLayoutParams(new FrameLayout.LayoutParams(1, 1));
view.setVisibility(View.GONE);
return new ListBaseViewHolder(view, viewType);
}
Aggregations