use of me.ccrama.redditslide.Fragments.NewsView in project Slide by ccrama.
the class NewsActivity method getCurrentPage.
public int getCurrentPage() {
int position = 0;
int currentOrientation = getResources().getConfiguration().orientation;
if (adapter.getCurrentFragment() == null) {
return 0;
}
if (((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
position = ((LinearLayoutManager) ((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
} else if (((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
int[] firstVisibleItems = null;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
position = firstVisibleItems[0] - 1;
}
} else {
position = ((PreCachingLayoutManager) ((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
}
return position;
}
use of me.ccrama.redditslide.Fragments.NewsView in project Slide by ccrama.
the class NewsActivity method scrollToTop.
public void scrollToTop() {
int[] firstVisibleItems;
int pastVisiblesItems = 0;
if (((adapter.getCurrentFragment()) == null))
return;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) (((NewsView) adapter.getCurrentFragment()).rv.getLayoutManager())).findFirstVisibleItemPositions(null);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
for (int firstVisibleItem : firstVisibleItems) {
pastVisiblesItems = firstVisibleItem;
}
}
if (pastVisiblesItems > 8) {
((NewsView) adapter.getCurrentFragment()).rv.scrollToPosition(0);
header.animate().translationY(header.getHeight()).setInterpolator(new LinearInterpolator()).setDuration(0);
} else {
((NewsView) adapter.getCurrentFragment()).rv.smoothScrollToPosition(0);
}
((NewsView) adapter.getCurrentFragment()).resetScroll();
}
Aggregations