Search in sources :

Example 6 with ExampleAdapter

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

the class FragmentHeadersSections method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
    // Experimenting NEW features (v5.0.0)
    //We have highlighted text while filtering, so let's enable this feature to be consistent with the active filter
    mAdapter.setNotifyChangeOfUnfilteredItems(true).setAnimationOnScrolling(DatabaseConfiguration.animateOnScrolling);
    mRecyclerView = (RecyclerView) 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());
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller), Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
    mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(true).setSwipeEnabled(true).setUnlinkAllItemsOnRemoveHeaders(true).setDisplayHeadersAtStartUp(true).setStickyHeaders(true).setDisplayHeadersAtStartUp(true).showAllHeaders();
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
    // Add 3 Scrollable Headers and 1 Footer
    mAdapter.addUserLearnedSelection(savedInstanceState == null);
    mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(getString(R.string.headers_sections_use_case_title), getString(R.string.headers_sections_use_case_description)), 900L, false);
    mAdapter.showLayoutInfo(savedInstanceState == null);
    mAdapter.addScrollableFooter();
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 7 with ExampleAdapter

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

the class FragmentHolderSections method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    // ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
    mRecyclerView = (RecyclerView) 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());
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller), Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
    mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(true).setOnlyEntryAnimation(true);
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
    // Add 1 Scrollable Header
    mAdapter.addScrollableHeader(new ScrollableUseCaseItem(getString(R.string.model_holders_use_case_title), getString(R.string.model_holders_use_case_description)));
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)7 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)7 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)5 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)4 DividerItemDecoration (eu.davidea.flexibleadapter.common.DividerItemDecoration)2 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 FlexibleItemAnimator (eu.davidea.flexibleadapter.common.FlexibleItemAnimator)1 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 FadeInDownAnimator (eu.davidea.samples.flexibleadapter.animators.FadeInDownAnimator)1