use of com.mikepenz.fastadapter.swipe_drag.SimpleSwipeDragCallback in project Hentoid by avluis.
the class LibraryGroupsFragment method setPagingMethod.
/**
* Initialize the paging method of the screen
*/
private void setPagingMethod() /*boolean isEditMode*/
{
viewModel.setPagingMethod(true);
itemAdapter = new ItemAdapter<>();
fastAdapter = FastAdapter.with(itemAdapter);
if (!fastAdapter.hasObservers())
fastAdapter.setHasStableIds(true);
// Gets (or creates and attaches if not yet existing) the extension from the given `FastAdapter`
selectExtension = fastAdapter.getOrCreateExtension(SelectExtension.class);
if (selectExtension != null) {
selectExtension.setSelectable(true);
selectExtension.setMultiSelect(true);
selectExtension.setSelectOnLongClick(true);
selectExtension.setSelectWithItemUpdate(true);
selectExtension.setSelectionListener((i, b) -> this.onSelectionChanged());
FastAdapterPreClickSelectHelper<GroupDisplayItem> helper = new FastAdapterPreClickSelectHelper<>(selectExtension);
fastAdapter.setOnPreClickListener(helper::onPreClickListener);
fastAdapter.setOnPreLongClickListener(helper::onPreLongClickListener);
}
// Drag, drop & swiping
if (activity.get().isEditMode()) {
SimpleDragCallback dragSwipeCallback = new SimpleSwipeDragCallback(this, this, ContextCompat.getDrawable(requireContext(), R.drawable.ic_action_delete_forever)).withSensitivity(10f).withSurfaceThreshold(0.75f);
dragSwipeCallback.setNotifyAllDrops(true);
// Despite its name, that's actually to disable drag on long tap
dragSwipeCallback.setIsDragEnabled(false);
touchHelper = new ItemTouchHelper(dragSwipeCallback);
touchHelper.attachToRecyclerView(recyclerView);
}
// Item click listener
fastAdapter.setOnClickListener((v, a, i, p) -> onItemClick(i));
// Favourite button click listener
fastAdapter.addEventHook(new ClickEventHook<GroupDisplayItem>() {
@Override
public void onClick(@NotNull View view, int i, @NotNull FastAdapter<GroupDisplayItem> fastAdapter, @NotNull GroupDisplayItem item) {
if (item.getGroup() != null)
onGroupFavouriteClick(item.getGroup());
}
@org.jetbrains.annotations.Nullable
@Override
public View onBind(RecyclerView.@NotNull ViewHolder viewHolder) {
if (viewHolder instanceof GroupDisplayItem.GroupViewHolder) {
return ((GroupDisplayItem.GroupViewHolder) viewHolder).getFavouriteButton();
}
return super.onBind(viewHolder);
}
});
fastAdapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY);
recyclerView.setAdapter(fastAdapter);
recyclerView.setHasFixedSize(true);
}
Aggregations