Search in sources :

Example 1 with DividerItemDecoration

use of eu.davidea.flexibleadapter.common.DividerItemDecoration 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()'
    mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
    // Experimenting NEW features (v5.0.0)
    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!
    false).setNotifyChangeOfUnfilteredItems(//We have highlighted text while filtering, so let's enable this feature to be consistent with the active filter
    true).setAnimationOnScrolling(DatabaseConfiguration.animateOnScrolling).setAnimationOnReverseScrolling(true);
    mRecyclerView = (RecyclerView) 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 DividerItemDecoration(getActivity(), R.drawable.divider, //Increase to add gap between sections (Works only with LinearLayout!)
    0));
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller), Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
    // Experimenting NEW features (v5.0.0)
    //Enable long press to drag items
    mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(//Enable handle drag
    true);
    //.setDisplayHeadersAtStartUp(true); //Show Headers at startUp: (not necessary if Headers are also Expandable)
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
    // Add 1 Scrollable Header
    mAdapter.showLayoutInfo(savedInstanceState == null);
}
Also used : ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) DividerItemDecoration(eu.davidea.flexibleadapter.common.DividerItemDecoration) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 2 with DividerItemDecoration

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

the class FragmentAsyncFilter method initializeRecyclerView.

private void initializeRecyclerView() {
    //Settings for FlipView
    FlipView.resetLayoutAnimationDelay(true, 1000L);
    //Experimenting NEW features (v5.0.0)
    mAdapter.setAnimateChangesWithDiffUtil(DatabaseConfiguration.animateWithDiffUtil).setAnimateToLimit(//Size limit = MAX_VALUE will always animate the changes
    DatabaseConfiguration.animateToLimit).setNotifyMoveOfFilteredItems(//When true, filtering on big list is very slow!
    DatabaseConfiguration.notifyMove).setNotifyChangeOfUnfilteredItems(//We have highlighted text while filtering, so let's enable this feature to be consistent with the active filter
    DatabaseConfiguration.notifyChange).setAnimationInitialDelay(100L).setAnimationOnScrolling(true).setAnimationOnReverseScrolling(true).setOnlyEntryAnimation(true);
    if (mRecyclerView == null) {
        mRecyclerView = (RecyclerView) 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 DividerItemDecoration(getActivity(), R.drawable.divider_large).withOffset(true);
    }
    //Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(!configure);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
    if (configure) {
        mFab.setImageResource(R.drawable.ic_check_white_24dp);
        mRecyclerView.addItemDecoration(mDivider);
    } else {
        mFab.setImageResource(R.drawable.ic_settings_white_24dp);
        mRecyclerView.removeItemDecoration(mDivider);
        mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller), Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
    }
    //Settings for FlipView
    FlipView.stopLayoutAnimation();
    showFab(1200L);
}
Also used : DividerItemDecoration(eu.davidea.flexibleadapter.common.DividerItemDecoration) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Example 3 with DividerItemDecoration

use of eu.davidea.flexibleadapter.common.DividerItemDecoration 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()'
    mAdapter = new FlexibleAdapter<>(DatabaseService.getInstance().getDatabaseList(), getActivity(), true);
    mAdapter.addListener(getActivity()).setAnimationOnScrolling(true).setAnimationOnReverseScrolling(true);
    mRecyclerView = (RecyclerView) 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 with 24dpi as empty space between sections
    mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), 0, 24));
    //Show Headers at startUp!
    mAdapter.setDisplayHeadersAtStartUp(true).setStickyHeaders(//Make headers sticky
    true).setEndlessScrollListener(this, new ProgressItem()).setEndlessScrollThreshold(//Default=1
    1);
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.MODE_IDLE);
}
Also used : DividerItemDecoration(eu.davidea.flexibleadapter.common.DividerItemDecoration) ProgressItem(eu.davidea.samples.flexibleadapter.items.ProgressItem) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 4 with DividerItemDecoration

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

the class FragmentSelectionModes method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    //Get copy of 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()'
    mAdapter = new ExampleAdapter(items, getActivity());
    //This will rebind new item when refreshed
    mAdapter.setNotifyChangeOfUnfilteredItems(true).setMode(SelectableAdapter.MODE_SINGLE);
    // Experimenting NEW features (v5.0.0)
    mRecyclerView = (RecyclerView) 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 DividerItemDecoration(getActivity(), R.drawable.divider).withDrawOver(true));
    mRecyclerView.postDelayed(new Runnable() {

        @Override
        public void run() {
            Snackbar.make(getView(), "Selection MODE_SINGLE is enabled", Snackbar.LENGTH_SHORT).show();
        }
    }, 1500L);
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    mAdapter.setFastScroller((FastScroller) getView().findViewById(R.id.fast_scroller), Utils.getColorAccent(getActivity()), (MainActivity) getActivity());
    SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, SelectableAdapter.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)), 1100L, true);
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) DividerItemDecoration(eu.davidea.flexibleadapter.common.DividerItemDecoration) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Aggregations

SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)4 DividerItemDecoration (eu.davidea.flexibleadapter.common.DividerItemDecoration)4 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)2 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 ProgressItem (eu.davidea.samples.flexibleadapter.items.ProgressItem)1 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)1