Search in sources :

Example 1 with ListBaseViewHolder

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;
}
Also used : OnWXScrollListener(com.taobao.weex.common.OnWXScrollListener) ImageView(android.widget.ImageView) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Point(android.graphics.Point) ListBaseViewHolder(com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder) RecyclerViewBaseAdapter(com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) ArrayList(java.util.ArrayList) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi)

Example 2 with ListBaseViewHolder

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);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXBaseRefresh(com.taobao.weex.ui.component.WXBaseRefresh) Point(android.graphics.Point) ListBaseViewHolder(com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder)

Example 3 with ListBaseViewHolder

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);
}
Also used : FrameLayout(android.widget.FrameLayout) ListBaseViewHolder(com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder) NonNull(android.support.annotation.NonNull)

Example 4 with ListBaseViewHolder

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);
}
Also used : FrameLayout(android.widget.FrameLayout) ListBaseViewHolder(com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder)

Aggregations

ListBaseViewHolder (com.taobao.weex.ui.view.listview.adapter.ListBaseViewHolder)4 Point (android.graphics.Point)2 FrameLayout (android.widget.FrameLayout)2 TargetApi (android.annotation.TargetApi)1 NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 ImageView (android.widget.ImageView)1 OnWXScrollListener (com.taobao.weex.common.OnWXScrollListener)1 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)1 RecyclerViewBaseAdapter (com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1