Search in sources :

Example 1 with NewsView

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;
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) NewsView(me.ccrama.redditslide.Fragments.NewsView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Point(android.graphics.Point)

Example 2 with NewsView

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();
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) NewsView(me.ccrama.redditslide.Fragments.NewsView) Point(android.graphics.Point)

Aggregations

Point (android.graphics.Point)2 NewsView (me.ccrama.redditslide.Fragments.NewsView)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)1