Search in sources :

Example 16 with DefaultItemAnimator

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();
}
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 17 with DefaultItemAnimator

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

Example 18 with DefaultItemAnimator

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);
}
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 19 with DefaultItemAnimator

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);
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) FastScroller(eu.davidea.fastscroller.FastScroller) SmoothScrollLinearLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 20 with DefaultItemAnimator

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

Aggregations

DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)27 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)14 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 View (android.view.View)9 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)9 TextView (android.widget.TextView)6 FastScroller (eu.davidea.fastscroller.FastScroller)6 FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)6 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)5 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)3 Context (android.content.Context)2 Resources (android.content.res.Resources)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 SearchView (androidx.appcompat.widget.SearchView)2 BottomSheetDialog (com.google.android.material.bottomsheet.BottomSheetDialog)2