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);
}
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());
}
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;
}
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);
}
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)));
}
Aggregations