Search in sources :

Example 1 with DefaultItemAnimator

use of androidx.recyclerview.widget.DefaultItemAnimator in project OneSignal-Android-SDK by OneSignal.

the class RecyclerViewBuilder method setupRecyclerView.

public void setupRecyclerView(RecyclerView recyclerView, int viewCache, boolean hasDivider, boolean isVertical) {
    DefaultItemAnimator defaultItemAnimator = new DefaultItemAnimator();
    int orientation = isVertical ? DividerItemDecoration.VERTICAL : DividerItemDecoration.HORIZONTAL;
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(context, orientation);
    int divider = hasDivider ? R.drawable.divider : R.drawable.no_divider;
    dividerItemDecoration.setDrawable(context.getResources().getDrawable(divider));
    recyclerView.setItemAnimator(defaultItemAnimator);
    recyclerView.addItemDecoration(dividerItemDecoration);
    recyclerView.setHasFixedSize(false);
    recyclerView.setItemViewCacheSize(viewCache);
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 2 with DefaultItemAnimator

use of androidx.recyclerview.widget.DefaultItemAnimator in project MVPArms by JessYanCoding.

the class ArmsUtils method configRecycleView.

/**
 * 配置 RecyclerView
 *
 * @param recyclerView
 * @param layoutManager
 * @deprecated Use {@link #configRecyclerView(RecyclerView, RecyclerView.LayoutManager)} instead
 */
@Deprecated
public static void configRecycleView(final RecyclerView recyclerView, RecyclerView.LayoutManager layoutManager) {
    recyclerView.setLayoutManager(layoutManager);
    // 如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
    recyclerView.setHasFixedSize(true);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
}
Also used : DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator)

Example 3 with DefaultItemAnimator

use of androidx.recyclerview.widget.DefaultItemAnimator in project Signal-Android by WhisperSystems.

the class ContactSelectionListFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.contact_selection_list_fragment, container, false);
    emptyText = view.findViewById(android.R.id.empty);
    recyclerView = view.findViewById(R.id.recycler_view);
    swipeRefresh = view.findViewById(R.id.swipe_refresh);
    fastScroller = view.findViewById(R.id.fast_scroller);
    showContactsLayout = view.findViewById(R.id.show_contacts_container);
    showContactsButton = view.findViewById(R.id.show_contacts_button);
    showContactsDescription = view.findViewById(R.id.show_contacts_description);
    showContactsProgress = view.findViewById(R.id.progress);
    chipGroup = view.findViewById(R.id.chipGroup);
    chipGroupScrollContainer = view.findViewById(R.id.chipGroupScrollContainer);
    constraintLayout = view.findViewById(R.id.container);
    shadowView = view.findViewById(R.id.toolbar_shadow);
    toolbarShadowAnimationHelper = new ToolbarShadowAnimationHelper(shadowView);
    recyclerView.addOnScrollListener(toolbarShadowAnimationHelper);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setItemAnimator(new DefaultItemAnimator() {

        @Override
        public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
            return true;
        }
    });
    Intent intent = requireActivity().getIntent();
    Bundle arguments = safeArguments();
    int recyclerViewPadBottom = arguments.getInt(RV_PADDING_BOTTOM, intent.getIntExtra(RV_PADDING_BOTTOM, -1));
    boolean recyclerViewClipping = arguments.getBoolean(RV_CLIP, intent.getBooleanExtra(RV_CLIP, true));
    if (recyclerViewPadBottom != -1) {
        ViewUtil.setPaddingBottom(recyclerView, recyclerViewPadBottom);
    }
    recyclerView.setClipToPadding(recyclerViewClipping);
    boolean isRefreshable = arguments.getBoolean(REFRESHABLE, intent.getBooleanExtra(REFRESHABLE, true));
    swipeRefresh.setNestedScrollingEnabled(isRefreshable);
    swipeRefresh.setEnabled(isRefreshable);
    hideCount = arguments.getBoolean(HIDE_COUNT, intent.getBooleanExtra(HIDE_COUNT, false));
    selectionLimit = arguments.getParcelable(SELECTION_LIMITS);
    if (selectionLimit == null) {
        selectionLimit = intent.getParcelableExtra(SELECTION_LIMITS);
    }
    isMulti = selectionLimit != null;
    canSelectSelf = arguments.getBoolean(CAN_SELECT_SELF, intent.getBooleanExtra(CAN_SELECT_SELF, !isMulti));
    if (!isMulti) {
        selectionLimit = SelectionLimits.NO_LIMITS;
    }
    currentSelection = getCurrentSelection();
    return view;
}
Also used : ToolbarShadowAnimationHelper(org.thoughtcrime.securesms.components.recyclerview.ToolbarShadowAnimationHelper) Bundle(android.os.Bundle) RecyclerView(androidx.recyclerview.widget.RecyclerView) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) SuppressLint(android.annotation.SuppressLint)

Example 4 with DefaultItemAnimator

use of androidx.recyclerview.widget.DefaultItemAnimator 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 5 with DefaultItemAnimator

use of androidx.recyclerview.widget.DefaultItemAnimator 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)

Aggregations

DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)18 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)6 FastScroller (eu.davidea.fastscroller.FastScroller)6 FlexibleItemDecoration (eu.davidea.flexibleadapter.common.FlexibleItemDecoration)6 View (android.view.View)5 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)5 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)5 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)4 SuppressLint (android.annotation.SuppressLint)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 SearchView (androidx.appcompat.widget.SearchView)2 BottomSheetDialog (com.google.android.material.bottomsheet.BottomSheetDialog)2 SortDialogAdapter (org.odk.collect.android.adapters.SortDialogAdapter)2 RecyclerViewClickListener (org.odk.collect.android.listeners.RecyclerViewClickListener)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1