use of androidx.recyclerview.widget.DefaultItemAnimator 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()'
FlexibleAdapter.useTag("HeadersSectionsAdapter");
mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
mAdapter.setNotifyMoveOfFilteredItems(true).setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling);
mRecyclerView = getView().findViewById(R.id.recycler_view);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
// 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());
mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()).addItemViewType(R.layout.recycler_simple_item, 0, 8, 0, 8).withSectionGapOffset(24).withEdge(true));
// Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity());
mAdapter.setFastScroller(fastScroller);
// New empty views handling, to set after FastScroller
EmptyViewHelper.create(mAdapter, getView().findViewById(R.id.empty_view), getView().findViewById(R.id.filter_view), // Optional!!
(EmptyViewHelper.OnEmptyViewListener) getActivity());
// More settings
mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(true).setSwipeEnabled(true).setStickyHeaderElevation(5).setUnlinkAllItemsOnRemoveHeaders(true).setDisplayHeadersAtStartUp(true).setStickyHeaders(true);
// Simulate developer 2nd call mistake, now it's safe, not executed, no warning log message!
// .setDisplayHeadersAtStartUp(true)
// Simulate developer 3rd call mistake, still safe, not executed, warning log message displayed!
// .showAllHeaders();
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
// Add 2 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.addScrollableFooter();
}
use of androidx.recyclerview.widget.DefaultItemAnimator 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);
}
use of androidx.recyclerview.widget.DefaultItemAnimator in project FlexibleAdapter by davideas.
the class FragmentSelectionModes method initializeRecyclerView.
@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
// Get the Database list
List<AbstractFlexibleItem> items = DatabaseService.getInstance().getDatabaseList();
// Initialize Adapter and RecyclerView
// ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
FlexibleAdapter.useTag("SelectionModesAdapter");
mAdapter = new ExampleAdapter(items, getActivity());
// true is the default! This will rebind new item when refreshed
mAdapter.setNotifyChangeOfUnfilteredItems(true).setMode(Mode.SINGLE);
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());
// Divider item decorator with DrawOver enabled
mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()).withDivider(R.drawable.divider, R.layout.recycler_simple_item).withDrawOver(true));
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
Snackbar.make(getView(), "Selection SINGLE is enabled", Snackbar.LENGTH_SHORT).show();
}
}, 1500L);
// Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
// true is the default value!
fastScroller.setAutoHideEnabled(true);
// 1000ms is the default value!
fastScroller.setAutoHideDelayInMillis(1000L);
// 0 pixel is the default value! When > 0 it mimics the fling gesture
fastScroller.setMinimumScrollThreshold(70);
fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity());
// The color (accentColor) is automatically fetched by the FastScroller constructor, but you can change it at runtime
// fastScroller.setBubbleAndHandleColor(Color.RED);
mAdapter.setFastScroller(fastScroller);
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.SINGLE);
// Add 2 Scrollable Headers
mAdapter.addUserLearnedSelection(savedInstanceState == null);
mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(getString(R.string.selection_modes_use_case_title), getString(R.string.selection_modes_use_case_description)), 1200L, true);
}
use of androidx.recyclerview.widget.DefaultItemAnimator in project FlexibleAdapter by davideas.
the class FragmentViewPager method initializeRecyclerView.
private void initializeRecyclerView() {
// Initialize Adapter and RecyclerView
// Use of stableIds, I strongly suggest to implement 'item.hashCode()'
FlexibleAdapter.useTag("ViewPagerAdapter");
mAdapter = new FlexibleAdapter<>(createList(50, 5), getActivity(), true);
mAdapter.setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling);
RecyclerView mRecyclerView = getView().findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(getActivity()));
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!!!
FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
mAdapter.setFastScroller(fastScroller);
// Sticky Headers
mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(true);
}
use of androidx.recyclerview.widget.DefaultItemAnimator 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()'
FlexibleAdapter.useTag("HolderSectionsAdapter");
mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
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());
// Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
fastScroller.addOnScrollStateChangeListener((MainActivity) getActivity());
mAdapter.setFastScroller(fastScroller);
mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(true).setOnlyEntryAnimation(true);
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, 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)));
}
Aggregations