Search in sources :

Example 6 with Profile

use of me.ccrama.redditslide.Activities.Profile in project Slide by ccrama.

the class ContributionsView 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);
    rv.setItemViewCacheSize(2);
    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(id, 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.TAB_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.TAB_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    if (where.equals("saved") && getActivity() instanceof Profile)
        posts = new ContributionPostsSaved(id, where, ((Profile) getActivity()).category);
    else
        posts = new ContributionPosts(id, where);
    // noinspection StringEquality
    if (where == "hidden")
        adapter = new ContributionAdapter(getActivity(), posts, rv, true);
    else
        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, id, 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, id, 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) Profile(me.ccrama.redditslide.Activities.Profile) ContributionPosts(me.ccrama.redditslide.Adapters.ContributionPosts) ContributionPostsSaved(me.ccrama.redditslide.Adapters.ContributionPostsSaved) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Profile (me.ccrama.redditslide.Activities.Profile)6 Intent (android.content.Intent)5 DialogInterface (android.content.DialogInterface)3 TypedArray (android.content.res.TypedArray)3 Drawable (android.graphics.drawable.Drawable)3 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 BottomSheet (com.cocosw.bottomsheet.BottomSheet)3 Activity (android.app.Activity)2 Snackbar (android.support.design.widget.Snackbar)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MainActivity (me.ccrama.redditslide.Activities.MainActivity)2 MediaView (me.ccrama.redditslide.Activities.MediaView)2 MultiredditOverview (me.ccrama.redditslide.Activities.MultiredditOverview)2 Search (me.ccrama.redditslide.Activities.Search)2 SubredditView (me.ccrama.redditslide.Activities.SubredditView)2 PeekViewActivity (me.ccrama.redditslide.ForceTouch.PeekViewActivity)2 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)2 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)2