use of eu.davidea.fastscroller.FastScroller 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.fastscroller.FastScroller in project FlexibleAdapter by davideas.
the class MainActivity method onUpdateEmptyView.
/**
* Handling RecyclerView when empty.
* <p><b>Note:</b> The order, how the 3 Views (RecyclerView, EmptyView, FastScroller)
* are placed in the Layout, is important!</p>
*/
@Override
public void onUpdateEmptyView(int size) {
Log.d(TAG, "onUpdateEmptyView size=" + size);
FastScroller fastScroller = (FastScroller) findViewById(R.id.fast_scroller);
View emptyView = findViewById(R.id.empty_view);
TextView emptyText = (TextView) findViewById(R.id.empty_text);
if (emptyText != null)
emptyText.setText(getString(R.string.no_items));
if (size > 0) {
fastScroller.setVisibility(View.VISIBLE);
mRefreshHandler.removeMessages(2);
emptyView.setAlpha(0);
} else {
emptyView.setAlpha(0);
mRefreshHandler.sendEmptyMessage(2);
fastScroller.setVisibility(View.GONE);
}
if (mAdapter != null) {
String message = (mAdapter.hasSearchText() ? "Filtered " : "Refreshed ");
message += size + " items in " + mAdapter.getTime() + "ms";
Snackbar.make(findViewById(R.id.main_view), message, Snackbar.LENGTH_SHORT).show();
}
}
use of eu.davidea.fastscroller.FastScroller 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 eu.davidea.fastscroller.FastScroller 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 eu.davidea.fastscroller.FastScroller in project FlexibleAdapter by davideas.
the class FragmentAsyncFilter method initializeRecyclerView.
private void initializeRecyclerView() {
// Settings for FlipView
FlipView.resetLayoutAnimationDelay(true, 1000L);
// Size limit = MAX_VALUE will always animate the changes
mAdapter.setAnimateChangesWithDiffUtil(DatabaseConfiguration.animateWithDiffUtil).setAnimateToLimit(DatabaseConfiguration.animateToLimit).setNotifyMoveOfFilteredItems(DatabaseConfiguration.notifyMove).setNotifyChangeOfUnfilteredItems(DatabaseConfiguration.notifyChange).setAnimationInitialDelay(100L).setAnimationOnForwardScrolling(true).setAnimationOnReverseScrolling(true).setOnlyEntryAnimation(true);
if (mRecyclerView == null) {
mRecyclerView = getView().findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
// Adapter changes won't affect the size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
}
// ViewHolders are different so we do NOT swap Adapters
mRecyclerView.setAdapter(mAdapter);
// Custom divider item decorator with Offset
if (mDivider == null) {
mDivider = new FlexibleItemDecoration(getActivity()).withDivider(R.drawable.divider_large);
}
// Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!
SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setEnabled(!configure);
mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
if (configure) {
mFab.setImageResource(R.drawable.ic_check_white_24dp);
mRecyclerView.addItemDecoration(mDivider);
FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
fastScroller.setEnabled(false);
} else {
mFab.setImageResource(R.drawable.ic_settings_white_24dp);
mRecyclerView.removeItemDecoration(mDivider);
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());
// Settings for FlipView
FlipView.stopLayoutAnimation();
showFab(1200L);
}
Aggregations