use of eu.davidea.samples.flexibleadapter.ExampleAdapter in project FlexibleAdapter by davideas.
the class FragmentAnimators method initializeRecyclerView.
@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
FlexibleAdapter.useTag("AnimatorsAdapter");
mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
mAdapter.expandItemsAtStartUp().setAutoCollapseOnExpand(false).setAutoScrollOnExpand(true).setOnlyEntryAnimation(false).setAnimationEntryStep(// In Overall, watch the effect at initial loading when Grid Layout is set
true).setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling).setAnimationOnReverseScrolling(true).setAnimationInterpolator(new DecelerateInterpolator()).setAnimationDuration(300L);
mRecyclerView = getView().findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
mRecyclerView.setAdapter(mAdapter);
// mRecyclerView.setHasFixedSize(true); //Size of RV will not change
// NOTE: Custom item animators inherit 'canReuseUpdatedViewHolder()' from Default Item
// Animator. It will return true if a Payload is provided. FlexibleAdapter is actually
// sending Payloads onItemChange notifications.
mRecyclerView.setItemAnimator(new FlexibleItemAnimator());
initializeSpinnerItemAnimators();
initializeSpinnerScrollAnimators();
mAdapter.setSwipeEnabled(true).getItemTouchHelperCallback().setSwipeFlags(// Enable swipe
ItemTouchHelper.RIGHT);
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(false);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
// Add 1 Scrollable Header
mAdapter.addScrollableHeader(new ScrollableUseCaseItem(getString(R.string.animator_use_case_title), getString(R.string.animator_use_case_description)));
}
use of eu.davidea.samples.flexibleadapter.ExampleAdapter in project FlexibleAdapter by davideas.
the class FragmentExpandableMultiLevel 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("ExpandableMultiLevelAdapter");
mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
mAdapter.expandItemsAtStartUp().setNotifyMoveOfFilteredItems(true).setAutoCollapseOnExpand(false).setMinCollapsibleLevel(// Auto-collapse only items with level >= 1 (avoid to collapse also sections!)
1).setAutoScrollOnExpand(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());
// 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));
// Enable long press to drag items
mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(// Enable handle drag
true).setSwipeEnabled(// Enable swipe items
true);
// .setDisplayHeadersAtStartUp(true); //Show Headers at startUp: not necessary if Headers are also Expandable!
mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()).withSectionGapOffset(24));
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
// Add 1 Scrollable Header
mAdapter.addUserLearnedSelection(savedInstanceState == null);
}
use of eu.davidea.samples.flexibleadapter.ExampleAdapter in project FlexibleAdapter by davideas.
the class FragmentEndlessScrolling method initializeRecyclerView.
private void initializeRecyclerView(Bundle savedInstanceState) {
// Initialize Adapter and RecyclerView
// ExampleAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
FlexibleAdapter.useTag("EndlessScrollingAdapter");
if (savedInstanceState != null) {
mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
} else {
mAdapter = new ExampleAdapter(null, getActivity());
}
mAdapter.setAutoScrollOnExpand(true).setNotifyMoveOfFilteredItems(// When true, filtering on big list is very slow, not in this case!
true).setNotifyChangeOfUnfilteredItems(// true by default
true).setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling).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 the custom FadeInDownAnimator for ALL notifications for ALL items,
// but ScrollableFooterItem implements AnimatedViewHolder with a unique animation: SlideInUp!
mRecyclerView.setItemAnimator(new FadeInDownItemAnimator());
// 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));
// Enable long press to drag items
mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(// Enable drag using handle view
true).setSwipeEnabled(// Enable swipe items
true);
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
// EndlessScrollListener - OnLoadMore (v5.0.0)
// To call only if the list is empty
mAdapter.setLoadingMoreAtStartUp(savedInstanceState == null).setEndlessScrollThreshold(// Default=1
20).setEndlessScrollListener(this, mProgressItem).setTopEndless(false);
// Add 1 Header item
ScrollableLayoutItem scrollHeader = new ScrollableLayoutItem("SLI");
scrollHeader.setTitle("Endless Scrolling");
scrollHeader.setSubtitle("...with ScrollableHeaderItem");
mAdapter.addScrollableHeader(scrollHeader);
}
use of eu.davidea.samples.flexibleadapter.ExampleAdapter in project FlexibleAdapter by davideas.
the class FragmentExpandableSections 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("ExpandableSectionAdapter");
mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
// OnItemAdd and OnItemRemove listeners
mAdapter.addListener(this);
mAdapter.expandItemsAtStartUp().setAutoCollapseOnExpand(false).setAutoScrollOnExpand(true).setAnimateToLimit(// Size limit = MAX_VALUE will always animate the changes
Integer.MAX_VALUE).setNotifyMoveOfFilteredItems(// When true, filtering on big list is very slow!
true).setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling).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());
// Custom divider item decorator
mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()).addItemViewType(R.layout.recycler_expandable_header_item).withOffset(4));
// 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));
// Enable long press to drag items
mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(// Enable handle drag
true).setStickyHeaders(true);
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(true);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
}
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()'
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();
}
Aggregations