Search in sources :

Example 1 with ScrollableUseCaseItem

use of eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem 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 2 with ScrollableUseCaseItem

use of eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem 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 3 with ScrollableUseCaseItem

use of eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem in project FlexibleAdapter by davideas.

the class FragmentAnimators method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    FlexibleAdapter.useTag("AnimatorsAdapter");
    mAdapter = new ExampleAdapter(DatabaseService.getInstance().getDatabaseList(), getActivity());
    mAdapter.expandItemsAtStartUp().setAutoCollapseOnExpand(false).setAutoScrollOnExpand(true).setOnlyEntryAnimation(false).setAnimationEntryStep(// In Overall, watch the effect at initial loading when Grid Layout is set
    true).setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling).setAnimationOnReverseScrolling(true).setAnimationInterpolator(new DecelerateInterpolator()).setAnimationDuration(300L);
    mRecyclerView = getView().findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(createNewLinearLayoutManager());
    mRecyclerView.setAdapter(mAdapter);
    // mRecyclerView.setHasFixedSize(true); //Size of RV will not change
    // NOTE: Custom item animators inherit 'canReuseUpdatedViewHolder()' from Default Item
    // Animator. It will return true if a Payload is provided. FlexibleAdapter is actually
    // sending Payloads onItemChange notifications.
    mRecyclerView.setItemAnimator(new FlexibleItemAnimator());
    initializeSpinnerItemAnimators();
    initializeSpinnerScrollAnimators();
    mAdapter.setSwipeEnabled(true).getItemTouchHelperCallback().setSwipeFlags(// Enable swipe
    ItemTouchHelper.RIGHT);
    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(false);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
    // Add 1 Scrollable Header
    mAdapter.addScrollableHeader(new ScrollableUseCaseItem(getString(R.string.animator_use_case_title), getString(R.string.animator_use_case_description)));
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FlexibleItemAnimator(eu.davidea.flexibleadapter.common.FlexibleItemAnimator) ExampleAdapter(eu.davidea.samples.flexibleadapter.ExampleAdapter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout)

Example 4 with ScrollableUseCaseItem

use of eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem in project FlexibleAdapter by davideas.

the class FragmentDataBinding method initializeRecyclerView.

@SuppressWarnings({ "ConstantConditions", "NullableProblems" })
private void initializeRecyclerView(Bundle savedInstanceState) {
    // Initialize Adapter and RecyclerView
    FlexibleAdapter.useTag("DataBindingAdapter");
    mAdapter = new BindingFlexibleAdapter<>(getActivity(), true);
    mAdapter.setAnimationOnForwardScrolling(DatabaseConfiguration.animateOnForwardScrolling);
    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 GarageDoorItemAnimator());
    // Add FastScroll to the RecyclerView, after the Adapter has been attached the RecyclerView!!!
    FastScroller fastScroller = getView().findViewById(R.id.fast_scroller);
    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));
    mAdapter.setLongPressDragEnabled(true).setHandleDragEnabled(true).setSwipeEnabled(true).setDisplayHeadersAtStartUp(true).setStickyHeaders(true);
    SwipeRefreshLayout swipeRefreshLayout = getView().findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setEnabled(true);
    mListener.onFragmentChange(swipeRefreshLayout, mRecyclerView, Mode.IDLE);
    mAdapter.addScrollableHeaderWithDelay(new ScrollableUseCaseItem(getString(R.string.databinding_use_case_title), getString(R.string.databinding_use_case_description)), 500L, false);
}
Also used : ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) FastScroller(eu.davidea.fastscroller.FastScroller) GarageDoorItemAnimator(eu.davidea.samples.flexibleadapter.animators.GarageDoorItemAnimator) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout)

Example 5 with ScrollableUseCaseItem

use of eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem in project FlexibleAdapter by davideas.

the class OverallAdapter method onBindViewHolder.

/**
	 * METHOD A - NEW! Via Model objects. In this case you don't need to implement this method!
	 * METHOD B - You override and implement this method as you prefer (don't call super).
	 *
	 * Using Method B, some methods need to be called by the user, see bottom of this method!
	 */
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payload) {
    int viewType = getItemViewType(position);
    Context context = holder.itemView.getContext();
    if (viewType == R.layout.recycler_scrollable_usecase_item) {
        ScrollableUseCaseItem item = (ScrollableUseCaseItem) getItem(position);
        ScrollableUseCaseItem.UCViewHolder vHolder = (ScrollableUseCaseItem.UCViewHolder) holder;
        assert item != null;
        DrawableUtils.setBackgroundCompat(holder.itemView, DrawableUtils.getRippleDrawable(DrawableUtils.getColorDrawable(context.getResources().getColor(R.color.material_color_blue_grey_50)), DrawableUtils.getColorControlHighlight(context)));
        vHolder.mTitle.setText(Utils.fromHtmlCompat(item.getTitle()));
        vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getSubtitle()));
        //Support for StaggeredGridLayoutManager
        if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
            ((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
            Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
        }
    } else if (viewType == R.layout.recycler_scrollable_layout_item) {
        ScrollableLayoutItem item = (ScrollableLayoutItem) getItem(position);
        ScrollableLayoutItem.LayoutViewHolder vHolder = (ScrollableLayoutItem.LayoutViewHolder) holder;
        assert item != null;
        //For marquee
        vHolder.mTitle.setSelected(true);
        vHolder.mTitle.setText(item.getTitle());
        vHolder.mSubtitle.setText(item.getSubtitle());
        //Support for StaggeredGridLayoutManager
        if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
            ((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
            Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
        }
    } else if (viewType == R.layout.recycler_overall_item) {
        OverallItem item = (OverallItem) getItem(position);
        OverallItem.LabelViewHolder vHolder = (OverallItem.LabelViewHolder) holder;
        assert item != null;
        if (item.getTitle() != null) {
            vHolder.mTitle.setText(item.getTitle());
            vHolder.mTitle.setEnabled(isEnabled(position));
        }
        if (item.getDescription() != null) {
            vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getDescription()));
            vHolder.mSubtitle.setEnabled(isEnabled(position));
        }
        if (item.getIcon() != null) {
            vHolder.mIcon.setImageDrawable(item.getIcon());
        }
    }
    // IMPORTANT!!!
    // With method B, animateView() needs to be called by the user!
    // With method A, the call is handled by the Adapter
    animateView(holder, position);
// Same concept for EndlessScrolling and View activation:
// - onLoadMore(position);
// - holder.itemView.setActivated(isSelected(position));
}
Also used : Context(android.content.Context) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) OverallItem(eu.davidea.samples.flexibleadapter.items.OverallItem) ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) ScrollableLayoutItem(eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem)

Aggregations

ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)8 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)7 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)4 FastScroller (eu.davidea.fastscroller.FastScroller)4 FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)4 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)4 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)2 Context (android.content.Context)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 FlexibleItemAnimator (eu.davidea.flexibleadapter.common.FlexibleItemAnimator)1 EmptyViewHelper (eu.davidea.flexibleadapter.helpers.EmptyViewHelper)1 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 OverallAdapter (eu.davidea.samples.flexibleadapter.OverallAdapter)1 GarageDoorItemAnimator (eu.davidea.samples.flexibleadapter.animators.GarageDoorItemAnimator)1 OverallItem (eu.davidea.samples.flexibleadapter.items.OverallItem)1 ScrollableLayoutItem (eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem)1