Search in sources :

Example 6 with FastScroller

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);
}
Also used : FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) FastScroller(eu.davidea.fastscroller.FastScroller) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 7 with FastScroller

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();
    }
}
Also used : FastScroller(eu.davidea.fastscroller.FastScroller) TextView(android.widget.TextView) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) HeaderView(eu.davidea.samples.flexibleadapter.views.HeaderView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 8 with FastScroller

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();
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) EmptyViewHelper(eu.davidea.flexibleadapter.helpers.EmptyViewHelper) FastScroller(eu.davidea.fastscroller.FastScroller) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 9 with FastScroller

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);
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) FastScroller(eu.davidea.fastscroller.FastScroller) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 10 with FastScroller

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);
}
Also used : FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) EmptyViewHelper(eu.davidea.flexibleadapter.helpers.EmptyViewHelper) FastScroller(eu.davidea.fastscroller.FastScroller) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout)

Aggregations

FastScroller (eu.davidea.fastscroller.FastScroller)12 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)8 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)6 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)6 FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)5 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)4 EmptyViewHelper (eu.davidea.flexibleadapter.helpers.EmptyViewHelper)2 NavigationView (android.support.design.widget.NavigationView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 View (android.view.View)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 SmoothScrollLinearLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager)1 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 FadeInDownItemAnimator (eu.davidea.samples.flexibleadapter.animators.FadeInDownItemAnimator)1 GarageDoorItemAnimator (eu.davidea.samples.flexibleadapter.animators.GarageDoorItemAnimator)1 ScrollableLayoutItem (eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem)1 HeaderView (eu.davidea.samples.flexibleadapter.views.HeaderView)1