use of androidx.recyclerview.widget.SimpleItemAnimator in project AntennaPod by AntennaPod.
the class QueueFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.queue_fragment, container, false);
toolbar = root.findViewById(R.id.toolbar);
toolbar.setOnMenuItemClickListener(this);
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
if (savedInstanceState != null) {
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
}
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
toolbar.inflateMenu(R.menu.queue);
refreshToolbarState();
infoBar = root.findViewById(R.id.info_bar);
recyclerView = root.findViewById(R.id.recyclerView);
RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
recyclerView.setRecycledViewPool(((MainActivity) getActivity()).getRecycledViewPool());
registerForContextMenu(recyclerView);
SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh);
swipeRefreshLayout.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance));
swipeRefreshLayout.setOnRefreshListener(() -> {
AutoUpdateManager.runImmediate(requireContext());
new Handler(Looper.getMainLooper()).postDelayed(() -> swipeRefreshLayout.setRefreshing(false), getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms));
});
swipeActions = new QueueSwipeActions();
swipeActions.setFilter(new FeedItemFilter(FeedItemFilter.QUEUED));
swipeActions.attachTo(recyclerView);
emptyView = new EmptyViewHandler(getContext());
emptyView.attachToRecyclerView(recyclerView);
emptyView.setIcon(R.drawable.ic_playlist);
emptyView.setTitle(R.string.no_items_header_label);
emptyView.setMessage(R.string.no_items_label);
progLoading = root.findViewById(R.id.progLoading);
progLoading.setVisibility(View.VISIBLE);
speedDialView = root.findViewById(R.id.fabSD);
speedDialView.setOverlayLayout(root.findViewById(R.id.fabSDOverlay));
speedDialView.inflate(R.menu.episodes_apply_action_speeddial);
speedDialView.removeActionItemById(R.id.mark_read_batch);
speedDialView.removeActionItemById(R.id.mark_unread_batch);
speedDialView.removeActionItemById(R.id.add_to_queue_batch);
speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() {
@Override
public boolean onMainActionSelected() {
return false;
}
@Override
public void onToggleChanged(boolean open) {
if (open && recyclerAdapter.getSelectedCount() == 0) {
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.no_items_selected, Snackbar.LENGTH_SHORT);
speedDialView.close();
}
}
});
speedDialView.setOnActionSelectedListener(actionItem -> {
new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), recyclerAdapter.getSelectedItems()).handleAction(actionItem.getId());
recyclerAdapter.endSelectMode();
return true;
});
return root;
}
use of androidx.recyclerview.widget.SimpleItemAnimator in project SherlockAdapter by EvilBT.
the class ExpandableActivity method initView.
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mRecyclerView = (RecyclerView) findViewById(R.id.list);
mGridLayoutManager = new GridLayoutManager(this, 2);
mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
mAdapter = new MyExpandableAdapter();
// mAdapter.setAlwaysShowFoot(true);
// mAdapter.setAlwaysShowHead(true);
mAdapter.addHeadLayout(R.layout.item_head);
mAdapter.addFootLayout(R.layout.item_foot2);
// 设置DiffUtil效果
mAdapter.setCallback(new DiffUtilCallback<IMultiItem>() {
@Override
public boolean areItemsTheSame(IMultiItem oldItem, IMultiItem newItem) {
if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
return TextUtils.equals(((ImageLabel) oldItem).getData(), ((ImageLabel) newItem).getData());
}
if (oldItem instanceof Card && newItem instanceof Card) {
return ((Card) oldItem).getData().mImageResId == ((Card) newItem).getData().mImageResId;
}
return false;
}
@Override
public boolean areContentsTheSame(IMultiItem oldItem, IMultiItem newItem) {
if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
return true;
}
if (oldItem instanceof Card && newItem instanceof Card) {
return TextUtils.equals(((Card) oldItem).getData().mImageTitle, ((Card) newItem).getData().mImageTitle);
}
return false;
}
});
mRecyclerView.setAdapter(mAdapter);
// 屏障默认的Change动画
((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
// 点击展开/折叠事件
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(@NonNull View view, int adapterPosition) {
if (view.getId() == R.id.label_root) {
IMultiItem item = mAdapter.getData(adapterPosition);
if (item instanceof IExpandable) {
IExpandable expandable = (IExpandable) item;
if (expandable.isExpandable()) {
// 修复issue#2
// 这个支持包的bug: https://issuetracker.google.com/issues/37034096
mStaggeredGridLayoutManager.invalidateSpanAssignments();
mAdapter.collapseAll(adapterPosition);
} else {
mAdapter.expandAll(adapterPosition);
}
}
}
}
});
mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(@NonNull View view, int adapterPosition) {
mAdapter.removeData(adapterPosition);
return true;
}
});
final SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshData();
refresh.setRefreshing(false);
}
});
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
refreshData();
}
});
initData();
}
use of androidx.recyclerview.widget.SimpleItemAnimator in project SherlockAdapter by EvilBT.
the class MultiSelectItemActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_multi_select_item);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getSelectedList();
}
});
findViewById(R.id.selectAll).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 全选
adapter.selectAll();
}
});
findViewById(R.id.unselectAll).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 全不选
adapter.clearSelectAll();
}
});
adapter = new MyMultiSelectAdapter();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
recyclerView.setAdapter(adapter);
// 屏障默认的Change动画,默认的Change动画会闪烁一下
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
adapter.setOnItemCheckedChangeListener(new OnItemCheckedChangeListener() {
@Override
public void onItemCheck(@NonNull View view, boolean isChecked, int adapterPosition) {
final int id = view.getId();
if (id == R.id.checkbox) {
IMultiSelectItem selectorItem = adapter.getData(adapterPosition);
if (selectorItem != null) {
final int selectedSize = adapter.getSelectedItems().size();
if (isChecked && selectedSize > 9) {
Toast.makeText(MultiSelectItemActivity.this, "您最多只能选择9个", Toast.LENGTH_SHORT).show();
selectorItem.setChecked(false);
adapter.notifyItemChanged(adapterPosition);
}
}
}
}
});
List<IMultiSelectItem> data = new ArrayList<>(20);
for (int i = 0; i < 40; i++) {
SelectorCard card = new SelectorCard(i);
data.add(card);
}
// 添加一个不可选中的数据在列表上
NoSelectCard card = new NoSelectCard("我跟他们不一样");
data.add(0, card);
adapter.setData(data);
}
use of androidx.recyclerview.widget.SimpleItemAnimator in project apps-android-commons by commons-app.
the class ContributionsListFragment method initRecyclerView.
private void initRecyclerView() {
final GridLayoutManager layoutManager = new GridLayoutManager(getContext(), getSpanCount(getResources().getConfiguration().orientation));
rvContributionsList.setLayoutManager(layoutManager);
// Setting flicker animation of recycler view to false.
final ItemAnimator animator = rvContributionsList.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
contributionsListPresenter.setup(userName, Objects.equals(sessionManager.getUserName(), userName));
contributionsListPresenter.contributionList.observe(getViewLifecycleOwner(), list -> {
contributionsSize = list.size();
adapter.submitList(list);
if (callback != null) {
callback.notifyDataSetChanged();
}
});
rvContributionsList.setAdapter(adapter);
adapter.registerAdapterDataObserver(new AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
if (itemCount > 0 && positionStart == 0) {
if (adapter.getContributionForPosition(positionStart) != null) {
rvContributionsList.scrollToPosition(// Newly upload items are always added to the top
0);
}
}
}
/**
* Called whenever items in the list have changed
* Calls viewPagerNotifyDataSetChanged() that will notify the viewpager
*/
@Override
public void onItemRangeChanged(final int positionStart, final int itemCount) {
super.onItemRangeChanged(positionStart, itemCount);
if (callback != null) {
callback.viewPagerNotifyDataSetChanged();
}
}
});
// Fab close on touch outside (Scrolling or taping on item triggers this action).
rvContributionsList.addOnItemTouchListener(new OnItemTouchListener() {
/**
* Silently observe and/or take over touch events sent to the RecyclerView before
* they are handled by either the RecyclerView itself or its child views.
*/
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
if (isFabOpen) {
animateFAB(isFabOpen);
}
}
return false;
}
/**
* Process a touch event as part of a gesture that was claimed by returning true
* from a previous call to {@link #onInterceptTouchEvent}.
*
* @param rv
* @param e MotionEvent describing the touch event. All coordinates are in the
* RecyclerView's coordinate system.
*/
@Override
public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
// required abstract method DO NOT DELETE
}
/**
* Called when a child of RecyclerView does not want RecyclerView and its ancestors
* to intercept touch events with {@link ViewGroup#onInterceptTouchEvent(MotionEvent)}.
*
* @param disallowIntercept True if the child does not want the parent to intercept
* touch events.
*/
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
// required abstract method DO NOT DELETE
}
});
}
Aggregations