Search in sources :

Example 1 with PreCachingLayoutManager

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

the class Related method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_search);
    Intent intent = getIntent();
    if (intent.hasExtra(Intent.EXTRA_TEXT) && !intent.getExtras().getString(Intent.EXTRA_TEXT, "").isEmpty()) {
        url = intent.getStringExtra(Intent.EXTRA_TEXT);
    }
    if (intent.hasExtra(EXTRA_URL)) {
        url = intent.getStringExtra(EXTRA_URL);
    }
    if (url == null || url.isEmpty()) {
        new AlertDialogWrapper.Builder(this).setTitle("URL is empty").setMessage("Try again with a different link!").setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        }).show();
    } else {
    }
    setupAppBar(R.id.toolbar, "Related links", true, true);
    // it won't be, trust me
    assert mToolbar != null;
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    final RecyclerView rv = ((RecyclerView) findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(this);
    rv.setLayoutManager(mLayoutManager);
    rv.addOnScrollListener(new ToolbarScrollHideHandler(mToolbar, 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 && (visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                posts.loading = true;
                posts.loadMore(adapter, "", "url:" + url, false);
            }
        }
    });
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("", this));
    // 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 SubredditSearchPosts("", "url:" + url, this);
    adapter = new ContributionAdapter(this, posts, rv);
    rv.setAdapter(adapter);
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, "", "url:" + url, true);
        // TODO catch errors
        }
    });
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorPreferences(me.ccrama.redditslide.ColorPreferences) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) SubredditSearchPosts(me.ccrama.redditslide.Adapters.SubredditSearchPosts) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 2 with PreCachingLayoutManager

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

the class HistoryView 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("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.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);
        }
    });
    posts = new HistoryPosts();
    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 3 with PreCachingLayoutManager

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

the class InboxPage 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(getActivity());
    rv.setLayoutManager(mLayoutManager);
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.activity_main_swipe_refresh_layout);
    v.findViewById(R.id.post_floating_action_button).setVisibility(View.GONE);
    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);
        }
    });
    posts = new InboxMessages(id);
    adapter = new InboxAdapter(getContext(), 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 && !posts.nomore) {
                if ((visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
                    posts.loading = true;
                    posts.loadMore(adapter, id, false);
                }
            }
        }
    });
    return v;
}
Also used : InboxAdapter(me.ccrama.redditslide.Adapters.InboxAdapter) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) InboxMessages(me.ccrama.redditslide.Adapters.InboxMessages) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with PreCachingLayoutManager

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

the class ModLog method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
    RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    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("mod", 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);
        }
    });
    posts = new ModLogPosts();
    adapter = new ModLogAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);
    rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter);
        }
    });
    return v;
}
Also used : ModLogAdapter(me.ccrama.redditslide.Adapters.ModLogAdapter) ModQueue(me.ccrama.redditslide.Activities.ModQueue) ModLogPosts(me.ccrama.redditslide.Adapters.ModLogPosts) RecyclerView(android.support.v7.widget.RecyclerView) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 5 with PreCachingLayoutManager

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

the class ModPage method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_verticalcontent, container, false);
    RecyclerView rv = ((RecyclerView) v.findViewById(R.id.vertical_content));
    final PreCachingLayoutManager mLayoutManager;
    mLayoutManager = new PreCachingLayoutManager(getActivity());
    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(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);
        }
    });
    posts = new ModeratorPosts(id, sub);
    adapter = new ModeratorAdapter(getActivity(), posts, rv);
    rv.setAdapter(adapter);
    rv.setOnScrollListener(new ToolbarScrollHideHandler(((ModQueue) getActivity()).mToolbar, (getActivity()).findViewById(R.id.header)));
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, id, sub);
        }
    });
    return v;
}
Also used : ModQueue(me.ccrama.redditslide.Activities.ModQueue) ModeratorAdapter(me.ccrama.redditslide.Adapters.ModeratorAdapter) ModeratorPosts(me.ccrama.redditslide.Adapters.ModeratorPosts) RecyclerView(android.support.v7.widget.RecyclerView) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)10 PreCachingLayoutManager (me.ccrama.redditslide.Views.PreCachingLayoutManager)10 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)8 View (android.view.View)8 ToolbarScrollHideHandler (me.ccrama.redditslide.handler.ToolbarScrollHideHandler)8 CatchStaggeredGridLayoutManager (me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager)6 ContributionAdapter (me.ccrama.redditslide.Adapters.ContributionAdapter)5 Toolbar (android.support.v7.widget.Toolbar)4 ColorPreferences (me.ccrama.redditslide.ColorPreferences)3 ModQueue (me.ccrama.redditslide.Activities.ModQueue)2 HistoryPosts (me.ccrama.redditslide.Adapters.HistoryPosts)2 SubredditSearchPosts (me.ccrama.redditslide.Adapters.SubredditSearchPosts)2 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1 EditText (android.widget.EditText)1