Search in sources :

Example 11 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class NewsView method resetScroll.

public void resetScroll() {
    if (toolbarScroll == null) {
        toolbarScroll = new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, header) {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (!posts.loading && !posts.nomore && !posts.offline && !adapter.isError) {
                    visibleItemCount = rv.getLayoutManager().getChildCount();
                    totalItemCount = rv.getLayoutManager().getItemCount();
                    int[] firstVisibleItems;
                    firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(null);
                    if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                        for (int firstVisibleItem : firstVisibleItems) {
                            pastVisiblesItems = firstVisibleItem;
                            if (SettingValues.scrollSeen && pastVisiblesItems > 0 && SettingValues.storeHistory) {
                                HasSeen.addSeenScrolling(posts.posts.get(pastVisiblesItems - 1).getFullName());
                            }
                        }
                    }
                    if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                        posts.loading = true;
                        posts.loadMore(mSwipeRefreshLayout.getContext(), NewsView.this, false, posts.subreddit);
                    }
                }
                if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
                    diff += dy;
                } else {
                    diff = 0;
                }
                if (fab != null) {
                    if (dy <= 0 && fab.getId() != 0 && SettingValues.fab) {
                        if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_DRAGGING || diff < -fab.getHeight() * 2) {
                            fab.show();
                        }
                    } else {
                        fab.hide();
                    }
                }
            }

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                // switch (newState) {
                // case RecyclerView.SCROLL_STATE_IDLE:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_DRAGGING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_SETTLING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().pause();
                // break;
                // }
                super.onScrollStateChanged(recyclerView, newState);
                // If the toolbar search is open, and the user scrolls in the Main view--close the search UI
                if (getActivity() instanceof MainActivity && (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
                    ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).performClick();
                }
            }
        };
        rv.addOnScrollListener(toolbarScroll);
    } else {
        toolbarScroll.reset = true;
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 12 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class ReadLaterView method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
    final RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getContext());
    rv.setLayoutManager(mLayoutManager);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("default", getActivity()));
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new HistoryPosts("readLater");
    adapter = new ContributionAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, true);
        // TODO catch errors
        }
    });
    rv.addOnScrollListener(new ToolbarScrollHideHandler((Toolbar) getActivity().findViewById(R.id.toolbar), getActivity().findViewById(R.id.header)) {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }
            if (!posts.loading) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                    posts.loading = true;
                    posts.loadMore(adapter, false);
                }
            }
        }
    });
    return v;
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(android.support.v7.widget.RecyclerView) HistoryPosts(me.ccrama.redditslide.Adapters.HistoryPosts) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Toolbar(android.support.v7.widget.Toolbar)

Example 13 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class SubmissionsView method resetScroll.

public void resetScroll() {
    if (toolbarScroll == null) {
        toolbarScroll = new ToolbarScrollHideHandler(((BaseActivity) getActivity()).mToolbar, header) {

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (!posts.loading && !posts.nomore && !posts.offline && !adapter.isError) {
                    visibleItemCount = rv.getLayoutManager().getChildCount();
                    totalItemCount = rv.getLayoutManager().getItemCount();
                    int[] firstVisibleItems;
                    firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(null);
                    if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                        for (int firstVisibleItem : firstVisibleItems) {
                            pastVisiblesItems = firstVisibleItem;
                            if (SettingValues.scrollSeen && pastVisiblesItems > 0 && SettingValues.storeHistory) {
                                HasSeen.addSeenScrolling(posts.posts.get(pastVisiblesItems - 1).getFullName());
                            }
                        }
                    }
                    if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                        posts.loading = true;
                        posts.loadMore(mSwipeRefreshLayout.getContext(), SubmissionsView.this, false, posts.subreddit);
                    }
                }
                if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
                    diff += dy;
                } else {
                    diff = 0;
                }
                if (fab != null) {
                    if (dy <= 0 && fab.getId() != 0 && SettingValues.fab) {
                        if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_DRAGGING || diff < -fab.getHeight() * 2) {
                            fab.show();
                        }
                    } else {
                        fab.hide();
                    }
                }
            }

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                // switch (newState) {
                // case RecyclerView.SCROLL_STATE_IDLE:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_DRAGGING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().resume();
                // break;
                // case RecyclerView.SCROLL_STATE_SETTLING:
                // ((Reddit)getActivity().getApplicationContext()).getImageLoader().pause();
                // break;
                // }
                super.onScrollStateChanged(recyclerView, newState);
                // If the toolbar search is open, and the user scrolls in the Main view--close the search UI
                if (getActivity() instanceof MainActivity && (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) && ((MainActivity) getContext()).findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
                    ((MainActivity) getContext()).findViewById(R.id.close_search_toolbar).performClick();
                }
            }
        };
        rv.addOnScrollListener(toolbarScroll);
    } else {
        toolbarScroll.reset = true;
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) BaseActivity(me.ccrama.redditslide.Activities.BaseActivity) RecyclerView(android.support.v7.widget.RecyclerView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 14 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class MainActivity method getCurrentPage.

public int getCurrentPage() {
    int position = 0;
    int currentOrientation = getResources().getConfiguration().orientation;
    if (adapter.getCurrentFragment() == null) {
        return 0;
    }
    if (((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof LinearLayoutManager && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        position = ((LinearLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
    } else if (((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
        int[] firstVisibleItems = null;
        firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPositions(firstVisibleItems);
        if (firstVisibleItems != null && firstVisibleItems.length > 0) {
            position = firstVisibleItems[0] - 1;
        }
    } else {
        position = ((PreCachingLayoutManager) ((SubmissionsView) adapter.getCurrentFragment()).rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition() - 1;
    }
    return position;
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Point(android.graphics.Point)

Example 15 with CatchStaggeredGridLayoutManager

use of me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager in project Slide by ccrama.

the class MultiredditOverview method setDataSet.

private void setDataSet(List<MultiReddit> data) {
    try {
        usedArray = data;
        if (usedArray.isEmpty()) {
            buildDialog();
        } else {
            if (adapter == null) {
                adapter = new OverviewPagerAdapter(getSupportFragmentManager());
            } else {
                adapter.notifyDataSetChanged();
            }
            pager.setAdapter(adapter);
            pager.setOffscreenPageLimit(1);
            tabs.setupWithViewPager(pager);
            tabs.setSelectedTabIndicatorColor(new ColorPreferences(MultiredditOverview.this).getColor(usedArray.get(0).getDisplayName()));
            doDrawerSubs(0);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = this.getWindow();
                window.setStatusBarColor(Palette.getDarkerColor(usedArray.get(0).getDisplayName()));
            }
            final View header = findViewById(R.id.header);
            tabs.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(pager) {

                @Override
                public void onTabReselected(TabLayout.Tab tab) {
                    super.onTabReselected(tab);
                    int[] firstVisibleItems;
                    int pastVisiblesItems = 0;
                    firstVisibleItems = ((CatchStaggeredGridLayoutManager) (((MultiredditView) adapter.getCurrentFragment()).rv.getLayoutManager())).findFirstVisibleItemPositions(null);
                    if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                        for (int firstVisibleItem : firstVisibleItems) {
                            pastVisiblesItems = firstVisibleItem;
                        }
                    }
                    if (pastVisiblesItems > 8) {
                        ((MultiredditView) adapter.getCurrentFragment()).rv.scrollToPosition(0);
                        if (header != null) {
                            header.animate().translationY(header.getHeight()).setInterpolator(new LinearInterpolator()).setDuration(0);
                        }
                    } else {
                        ((MultiredditView) adapter.getCurrentFragment()).rv.smoothScrollToPosition(0);
                    }
                }
            });
            findViewById(R.id.header).setBackgroundColor(Palette.getColor(usedArray.get(0).getDisplayName()));
        }
    } catch (NullPointerException e) {
        buildDialog(true);
        Log.e(LogUtil.getTag(), "Cannot load multis:\n" + e);
    }
}
Also used : Window(android.view.Window) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorPreferences(me.ccrama.redditslide.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) TabLayout(android.support.design.widget.TabLayout) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView) View(android.view.View) TextView(android.widget.TextView) MultiredditView(me.ccrama.redditslide.Fragments.MultiredditView)

Aggregations

CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)24 RecyclerView (android.support.v7.widget.RecyclerView)15 View (android.view.View)13 ToolbarScrollHideHandler (me.ccrama.redditslide.handler.ToolbarScrollHideHandler)9 Intent (android.content.Intent)7 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)7 TextView (android.widget.TextView)7 PreCachingLayoutManager (me.ccrama.redditslide.Views.PreCachingLayoutManager)6 DialogInterface (android.content.DialogInterface)5 Snackbar (android.support.design.widget.Snackbar)5 Toolbar (android.support.v7.widget.Toolbar)5 LinearLayout (android.widget.LinearLayout)5 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)5 ContributionAdapter (me.ccrama.redditslide.Adapters.ContributionAdapter)5 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)5 Submission (net.dean.jraw.models.Submission)5 Handler (android.os.Handler)4 MainActivity (me.ccrama.redditslide.Activities.MainActivity)4 SubredditView (me.ccrama.redditslide.Activities.SubredditView)4 ColorPreferences (me.ccrama.redditslide.ColorPreferences)4