use of com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter 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.RecyclerViewBaseAdapter in project incubator-weex by apache.
the class WXRecyclerTemplateList method initComponentHostView.
@Override
protected BounceRecyclerView initComponentHostView(@NonNull Context context) {
final BounceRecyclerView bounceRecyclerView = new BounceRecyclerView(context, mLayoutType, mColumnCount, mColumnGap, getOrientation());
WXAttr attrs = getDomObject().getAttrs();
String transforms = (String) attrs.get(Constants.Name.TRANSFORM);
if (transforms != null) {
bounceRecyclerView.getInnerView().addItemDecoration(RecyclerTransform.parseTransforms(getOrientation(), transforms));
}
mItemAnimator = bounceRecyclerView.getInnerView().getItemAnimator();
if (attrs.get(NAME_TEMPLATE_CACHE_SIZE) != null) {
templateCacheSize = WXUtils.getInteger(attrs.get(NAME_TEMPLATE_CACHE_SIZE), templateCacheSize);
}
boolean hasFixedSize = false;
int itemViewCacheSize = 2;
if (attrs.get(NAME_ITEM_VIEW_CACHE_SIZE) != null) {
itemViewCacheSize = WXUtils.getNumberInt(getDomObject().getAttrs().get(NAME_ITEM_VIEW_CACHE_SIZE), itemViewCacheSize);
}
if (attrs.get(NAME_HAS_FIXED_SIZE) != null) {
hasFixedSize = WXUtils.getBoolean(attrs.get(NAME_HAS_FIXED_SIZE), hasFixedSize);
}
RecyclerViewBaseAdapter recyclerViewBaseAdapter = new RecyclerViewBaseAdapter<>(this);
recyclerViewBaseAdapter.setHasStableIds(true);
bounceRecyclerView.getInnerView().setItemAnimator(null);
if (itemViewCacheSize != 2) {
bounceRecyclerView.getInnerView().setItemViewCacheSize(itemViewCacheSize);
}
if (bounceRecyclerView.getSwipeLayout() != null) {
if (WXUtils.getBoolean(getDomObject().getAttrs().get("nestedScrollingEnabled"), false)) {
bounceRecyclerView.getSwipeLayout().setNestedScrollingEnabled(true);
}
}
bounceRecyclerView.getInnerView().setHasFixedSize(hasFixedSize);
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);
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) {
try {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
if (listener instanceof ICheckBindingScroller) {
if (((ICheckBindingScroller) listener).isNeedScroller(getRef(), null)) {
listener.onScrolled(recyclerView, dx, dy);
}
} else {
listener.onScrolled(recyclerView, dx, dy);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
bounceRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
BounceRecyclerView 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);
}
}
});
listUpdateRunnable = new Runnable() {
@Override
public void run() {
/**
* compute sticky position
*/
if (mStickyHelper != null) {
if (mStickyHelper.getStickyTypes().size() > 0) {
mStickyHelper.getStickyPositions().clear();
if (cellDataManager.listData != null) {
for (int i = 0; i < cellDataManager.listData.size(); i++) {
WXCell cell = getSourceTemplate(i);
if (cell == null) {
continue;
}
if (cell.isSticky()) {
mStickyHelper.getStickyPositions().add(i);
}
}
}
}
}
if (getHostView() != null && getHostView().getRecyclerViewBaseAdapter() != null) {
getHostView().getRecyclerViewBaseAdapter().notifyDataSetChanged();
}
if (WXEnvironment.isOpenDebugLog() && ENABLE_TRACE_LOG) {
WXLogUtils.d(TAG, "WXTemplateList notifyDataSetChanged");
}
}
};
return bounceRecyclerView;
}
use of com.taobao.weex.ui.view.listview.adapter.RecyclerViewBaseAdapter in project incubator-weex by apache.
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(RecyclerTransform.parseTransforms(getOrientation(), transforms));
}
if (getDomObject().getAttrs().get(Constants.Name.KEEP_POSITION_LAYOUT_DELAY) != null) {
keepPositionLayoutDelay = WXUtils.getNumberInt(getDomObject().getAttrs().get(Constants.Name.KEEP_POSITION_LAYOUT_DELAY), (int) keepPositionLayoutDelay);
}
if (getDomObject().getAttrs().get("appearActionDelay") != null) {
mAppearDelay = WXUtils.getNumberInt(getDomObject().getAttrs().get("appearActionDelay"), (int) mAppearDelay);
}
mItemAnimator = bounceRecyclerView.getInnerView().getItemAnimator();
RecyclerViewBaseAdapter recyclerViewBaseAdapter = new RecyclerViewBaseAdapter<>(this);
recyclerViewBaseAdapter.setHasStableIds(true);
bounceRecyclerView.setRecyclerViewBaseAdapter(recyclerViewBaseAdapter);
bounceRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
bounceRecyclerView.getInnerView().clearOnScrollListeners();
bounceRecyclerView.getInnerView().addOnScrollListener(mViewOnScrollListener);
if (getDomObject().getAttrs().get(Constants.Name.HAS_FIXED_SIZE) != null) {
boolean hasFixedSize = WXUtils.getBoolean(getDomObject().getAttrs().get(Constants.Name.HAS_FIXED_SIZE), false);
bounceRecyclerView.getInnerView().setHasFixedSize(hasFixedSize);
}
bounceRecyclerView.getInnerView().addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
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) {
try {
for (OnWXScrollListener listener : listeners) {
if (listener != null) {
if (listener instanceof ICheckBindingScroller) {
if (((ICheckBindingScroller) listener).isNeedScroller(getRef(), null)) {
listener.onScrolled(recyclerView, dx, dy);
}
} else {
listener.onScrolled(recyclerView, dx, dy);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
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;
}
Aggregations