Search in sources :

Example 1 with FlexibleItemDecoration

use of eu.davidea.flexibleadapter.common.FlexibleItemDecoration 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 2 with FlexibleItemDecoration

use of eu.davidea.flexibleadapter.common.FlexibleItemDecoration in project FlexibleAdapter by davideas.

the class FragmentOverall method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    // OverallAdapter makes use of stableIds, I strongly suggest to implement 'item.hashCode()'
    FlexibleAdapter.useTag("OverallAdapter");
    mAdapter = new OverallAdapter(getActivity());
    mAdapter.setOnlyEntryAnimation(true).setAnimationInterpolator(new DecelerateInterpolator()).setAnimationInitialDelay(INITIAL_DELAY_300);
    // Prepare the RecyclerView and attach the Adapter to it
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    // Setting ViewCache to 0 (default=2) will animate items better while scrolling down+up with LinearLayout
    mRecyclerView.setItemViewCacheSize(0);
    mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    // Size of RV will not change
    mRecyclerView.setHasFixedSize(true);
    mItemDecoration = new FlexibleItemDecoration(getActivity()).addItemViewType(R.layout.recycler_overall_item).withOffset(// This helps when top items are removed!!
    8).withEdge(true);
    mRecyclerView.addItemDecoration(mItemDecoration);
    // After Adapter is attached to RecyclerView
    mAdapter.setLongPressDragEnabled(true);
    mRecyclerView.postDelayed(new Runnable() {

        @Override
        public void run() {
            if (getView() != null) {
                // Fix NPE when closing app before the execution of Runnable
                Snackbar.make(getView(), "Long press drag is enabled", Snackbar.LENGTH_SHORT).show();
            }
        }
    }, 4000L);
    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
    // Add 1 Scrollable Header
    scrollableUseCaseItem = new ScrollableUseCaseItem(getString(R.string.overall_use_case_title), getString(R.string.overall_use_case_description));
    // Delayed! So entry animation will perform together
    mAdapter.addScrollableHeaderWithDelay(scrollableUseCaseItem, INITIAL_DELAY_300, true);
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) OverallAdapter(eu.davidea.samples.flexibleadapter.OverallAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout)

Example 3 with FlexibleItemDecoration

use of eu.davidea.flexibleadapter.common.FlexibleItemDecoration in project FlexibleAdapter by davideas.

the class FragmentStaggeredLayout 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("StaggeredLayoutAdapter");
    mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity());
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    // Customize the speed of the smooth scroll.
    // NOTE: Every time you change this value you MUST recreate the LayoutManager instance
    // and to assign it again to the RecyclerView!
    // Make faster the smooth scroll
    TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 33f;
    mRecyclerView.setLayoutManager(createNewStaggeredGridLayoutManager());
    // This value is restored to 100f (default) right here, because it is used in the
    // constructor by Android. If we don't change it now, others LayoutManager will be
    // impacted too by the above modification!
    TopSnappedSmoothScroller.MILLISECONDS_PER_INCH = 100f;
    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());
    mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()).addItemViewType(R.layout.recycler_staggered_item, 8).withEdge(true));
    // Show Headers at startUp!
    mAdapter.setDisplayHeadersAtStartUp(true).setNotifyMoveOfFilteredItems(true).setPermanentDelete(// Default=true
    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.staggered_use_case_title), getString(R.string.staggered_use_case_description)));
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 4 with FlexibleItemDecoration

use of eu.davidea.flexibleadapter.common.FlexibleItemDecoration 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);
}
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 5 with FlexibleItemDecoration

use of eu.davidea.flexibleadapter.common.FlexibleItemDecoration in project Neuronizer by djuelg.

the class FlexibleRecyclerView method configure.

public void configure(View emptyView, RecyclerView.Adapter adapter, View view) {
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
    FlexibleItemDecoration decoration = new FlexibleItemDecoration(getContext());
    decoration.withDefaultDivider();
    decoration.withDrawOver(true);
    setHasFixedSize(false);
    setLayoutManager(layoutManager);
    setEmptyView(emptyView);
    setAdapter(adapter);
    addItemDecoration(decoration);
    addOnScrollListener(new RecyclerViewScrollListener(view));
}
Also used : FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration) RecyclerViewScrollListener(de.djuelg.neuronizer.presentation.ui.custom.RecyclerViewScrollListener) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)10 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)8 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)6 FastScroller (eu.davidea.fastscroller.FastScroller)5 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)4 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)4 EmptyViewHelper (eu.davidea.flexibleadapter.helpers.EmptyViewHelper)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 RecyclerViewScrollListener (de.djuelg.neuronizer.presentation.ui.custom.RecyclerViewScrollListener)1 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 OverallAdapter (eu.davidea.samples.flexibleadapter.OverallAdapter)1 ProgressItem (eu.davidea.samples.flexibleadapter.items.ProgressItem)1