Search in sources :

Example 1 with ProgressItem

use of eu.davidea.samples.flexibleadapter.items.ProgressItem in project FlexibleAdapter by davideas.

the class FragmentInstagramHeaders method initializeRecyclerView.

@SuppressWarnings({ "unchecked", "ConstantConditions" })
private void initializeRecyclerView() {
    // Initialize Adapter and RecyclerView
    // true = it makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    FlexibleAdapter.useTag("InstagramHeadersAdapter");
    mAdapter = new FlexibleAdapter<>(null, getActivity(), true);
    mAdapter.addListener(getActivity()).setAnimationOnForwardScrolling(true).setAnimationOnReverseScrolling(true);
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    // Size of RV will not change
    mRecyclerView.setHasFixedSize(true);
    // NOTE: Use default item animator 'canReuseUpdatedViewHolder()' will return true if
    // a Payload is provided. FlexibleAdapter is actually sending Payloads onItemChange.
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // 24dpi as empty space between sections (each post)
    mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()).withSectionGapOffset(24));
    // New empty views handling
    EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view));
    // Show Headers at startUp!
    mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(// Make headers sticky
    true).setLoadingMoreAtStartUp(true).setEndlessScrollListener(this, new ProgressItem()).setEndlessScrollThreshold(// Default=1
    1);
    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
}
Also used : FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) ProgressItem(eu.davidea.samples.flexibleadapter.items.ProgressItem) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Aggregations

DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)1 ProgressItem (eu.davidea.samples.flexibleadapter.items.ProgressItem)1