use of android.support.v7.widget.StaggeredGridLayoutManager in project CloudReader by youlookwhat.
the class XRecyclerView method onScrollStateChanged.
@Override
public void onScrollStateChanged(int state) {
super.onScrollStateChanged(state);
if (state == RecyclerView.SCROLL_STATE_IDLE && mLoadingListener != null && !isLoadingData && loadingMoreEnabled) {
LayoutManager layoutManager = getLayoutManager();
int lastVisibleItemPosition;
if (layoutManager instanceof GridLayoutManager) {
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int[] into = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
((StaggeredGridLayoutManager) layoutManager).findLastVisibleItemPositions(into);
lastVisibleItemPosition = findMax(into);
} else {
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
}
if (layoutManager.getChildCount() > 0 && lastVisibleItemPosition >= layoutManager.getItemCount() - 1 && layoutManager.getItemCount() > layoutManager.getChildCount() && !isnomore && mRefreshHeader.getState() < YunRefreshHeader.STATE_REFRESHING) {
View footView = mFootViews.get(0);
isLoadingData = true;
if (footView instanceof LoadingMoreFooter) {
((LoadingMoreFooter) footView).setState(LoadingMoreFooter.STATE_LOADING);
} else {
footView.setVisibility(View.VISIBLE);
}
if (isNetWorkConnected(getContext())) {
mLoadingListener.onLoadMore();
} else {
postDelayed(new Runnable() {
@Override
public void run() {
mLoadingListener.onLoadMore();
}
}, 1000);
}
}
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project weex-example by KalicyZhou.
the class WXRecyclerViewOnScrollListener method onScrolled.
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
IOnLoadMoreListener l;
if ((l = listener.get()) != null) {
l.onBeforeScroll(dx, dy);
}
// int lastVisibleItemPosition = -1;
if (layoutManagerType == null) {
if (layoutManager instanceof LinearLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
} else if (layoutManager instanceof GridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
} else {
throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
}
switch(layoutManagerType) {
case LINEAR:
lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
listener.get().notifyAppearStateChange(((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition(), lastVisibleItemPosition, dx, dy);
break;
case GRID:
lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case STAGGERED_GRID:
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (lastPositions == null) {
lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
lastVisibleItemPosition = findMax(lastPositions);
break;
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project easy by MehdiBenmesa.
the class Utils method scrollTo.
public static void scrollTo(Object scroll, float yOffset) {
if (scroll instanceof RecyclerView) {
//RecyclerView.scrollTo : UnsupportedOperationException
//Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
//Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
}
} else if (scroll instanceof NestedScrollView) {
((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project wh-app-android by WhiteHouse.
the class FeedItemListFragment method onCreateLayoutManager.
@Override
public RecyclerView.LayoutManager onCreateLayoutManager() {
Resources res = getResources();
int feedGridCols = res.getInteger(R.integer.feed_grid_columns);
int photoGridCols = res.getInteger(R.integer.photo_grid_columns);
switch(mFeedType) {
case TYPE_PHOTOS:
return new StaggeredGridLayoutManager(photoGridCols, VERTICAL);
case TYPE_VIDEOS:
return new GridLayoutManager(getActivity(), feedGridCols);
case TYPE_LIVE:
return new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
case TYPE_ARTICLE:
default:
return new StaggeredGridLayoutManager(feedGridCols, VERTICAL);
}
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project Douya by DreaminginCodeZH.
the class BaseBroadcastListFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
CustomTabsHelperFragment.attachTo(this);
mBroadcastListResource = onAttachBroadcastListResource();
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
onSwipeRefresh();
}
});
mBroadcastList.setHasFixedSize(true);
mBroadcastList.setItemAnimator(new NoChangeAnimationItemAnimator());
// Always use StaggeredGridLayoutManager so that instance state can be saved.
Activity activity = getActivity();
int columnCount = CardUtils.getColumnCount(activity);
mBroadcastList.setLayoutManager(new StaggeredGridLayoutManager(columnCount, StaggeredGridLayoutManager.VERTICAL));
mBroadcastAdapter = new BroadcastAdapter(mBroadcastListResource.get(), this);
mAdapter = new LoadMoreAdapter(R.layout.load_more_card_item, mBroadcastAdapter);
mBroadcastList.setAdapter(mAdapter);
final AppBarHost appBarHost = (AppBarHost) getParentFragment();
mBroadcastList.addOnScrollListener(new OnVerticalScrollWithPagingTouchSlopListener(activity) {
@Override
public void onScrolled(int dy) {
if (!RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
onShow();
}
}
@Override
public void onScrolledUp() {
onShow();
}
private void onShow() {
appBarHost.showAppBar();
mSendFab.show();
}
@Override
public void onScrolledDown() {
if (RecyclerViewUtils.hasFirstChildReachedTop(mBroadcastList)) {
appBarHost.hideAppBar();
mSendFab.hide();
}
}
@Override
public void onScrolledToBottom() {
mBroadcastListResource.load(true);
}
});
updateRefreshing();
CheatSheetUtils.setup(mSendFab);
mSendFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onSendBroadcast();
}
});
}
Aggregations