Search in sources :

Example 6 with FlexibleItemDecoration

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

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

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

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

Example 10 with FlexibleItemDecoration

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

the class BottomSheetDecorationDialog method onCheckedChanged.

/**
 * Called when the checked state of a compound button has changed.
 *
 * @param buttonView The compound button view whose state has changed.
 * @param isChecked  The new checked state of buttonView.
 */
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    FlexibleItemDecoration itemDecoration = mListener.getItemDecoration();
    if (buttonView.getId() == R.id.switch_edge_left) {
        itemDecoration.withLeftEdge(isChecked);
    } else if (buttonView.getId() == R.id.switch_edge_top) {
        itemDecoration.withTopEdge(isChecked);
    } else if (buttonView.getId() == R.id.switch_edge_right) {
        itemDecoration.withRightEdge(isChecked);
    } else if (buttonView.getId() == R.id.switch_edge_bottom) {
        itemDecoration.withBottomEdge(isChecked);
    } else if (buttonView.getId() == R.id.switch_default_divider) {
        itemDecoration.removeDivider();
        if (isChecked)
            itemDecoration.withDefaultDivider();
    } else if (buttonView.getId() == R.id.switch_custom_divider) {
        itemDecoration.removeDivider();
        if (isChecked)
            itemDecoration.withDivider(R.drawable.divider_large);
    } else if (buttonView.getId() == R.id.switch_draw_over) {
        itemDecoration.withDrawOver(isChecked);
    }
    mListener.onDecorationSelected();
}
Also used : FlexibleItemDecoration(eu.davidea.flexibleadapter.common.FlexibleItemDecoration)

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