use of com.mikepenz.fastadapter.swipe_drag.SimpleSwipeDrawerDragCallback in project Hentoid by avluis.
the class QueueFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_queue, container, false);
mEmptyText = requireViewById(rootView, R.id.queue_empty_txt);
btnStart = requireViewById(rootView, R.id.btnStart);
btnPause = requireViewById(rootView, R.id.btnPause);
queueStatus = requireViewById(rootView, R.id.queueStatus);
queueInfo = requireViewById(rootView, R.id.queueInfo);
dlPreparationProgressBar = requireViewById(rootView, R.id.queueDownloadPreparationProgressBar);
// Both queue control buttons actually just need to send a signal that will be processed accordingly by whom it may concern
btnStart.setOnClickListener(v -> EventBus.getDefault().post(new DownloadEvent(DownloadEvent.Type.EV_UNPAUSE)));
btnPause.setOnClickListener(v -> EventBus.getDefault().post(new DownloadEvent(DownloadEvent.Type.EV_PAUSE)));
// Book list
recyclerView = requireViewById(rootView, R.id.queue_list);
ContentItem item = new ContentItem(ContentItem.ViewType.QUEUE);
fastAdapter.registerItemFactory(item.getType(), item);
// 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<ContentItem> helper = new FastAdapterPreClickSelectHelper<>(selectExtension);
fastAdapter.setOnPreClickListener(helper::onPreClickListener);
fastAdapter.setOnPreLongClickListener(helper::onPreLongClickListener);
}
recyclerView.setAdapter(fastAdapter);
recyclerView.setHasFixedSize(true);
llm = (LinearLayoutManager) recyclerView.getLayoutManager();
// Fast scroller
new FastScrollerBuilder(recyclerView).build();
// Drag, drop & swiping
SimpleSwipeDrawerDragCallback dragSwipeCallback = new SimpleSwipeDrawerDragCallback(this, ItemTouchHelper.LEFT, this).withSwipeLeft(Helper.dimensAsDp(requireContext(), R.dimen.delete_drawer_width_list)).withSensitivity(1.5f).withSurfaceThreshold(0.3f).withNotifyAllDrops(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));
initToolbar();
initSelectionToolbar();
attachButtons(fastAdapter);
// Network usage display refresh
compositeDisposable.add(Observable.timer(1, TimeUnit.SECONDS).subscribeOn(Schedulers.computation()).repeat().observeOn(Schedulers.computation()).map(v -> NetworkHelper.getIncomingNetworkUsage(requireContext())).observeOn(AndroidSchedulers.mainThread()).subscribe(this::updateNetworkUsage));
addCustomBackControl();
return rootView;
}
use of com.mikepenz.fastadapter.swipe_drag.SimpleSwipeDrawerDragCallback in project Hentoid by avluis.
the class LibraryContentFragment method setPagingMethod.
/**
* Initialize the paging method of the screen
*
* @param isEndless True if endless mode has to be set; false if paged mode has to be set
*/
private void setPagingMethod(boolean isEndless, boolean isEditMode) {
// Editing will always be done in Endless mode
viewModel.setPagingMethod(isEndless || isEditMode);
// RecyclerView horizontal centering
ViewGroup.LayoutParams layoutParams = recyclerView.getLayoutParams();
recyclerView.setLayoutParams(layoutParams);
// Pager appearance
if (!isEndless && !isEditMode) {
pager.setCurrentPage(1);
pager.show();
} else
pager.hide();
// Adapter initialization
if (isEndless && !isEditMode) {
@ContentItem.ViewType int viewType;
if (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay())
viewType = ContentItem.ViewType.LIBRARY;
else
viewType = ContentItem.ViewType.LIBRARY_GRID;
pagedItemAdapter = new PagedModelAdapter<>(asyncDifferConfig, i -> new ContentItem(viewType), c -> new ContentItem(c, touchHelper, viewType, this::onDeleteSwipedBook));
fastAdapter = FastAdapter.with(pagedItemAdapter);
ContentItem item = new ContentItem(viewType);
fastAdapter.registerItemFactory(item.getType(), item);
itemAdapter = null;
} else {
// Paged mode or edit mode
itemAdapter = new ItemAdapter<>();
fastAdapter = FastAdapter.with(itemAdapter);
pagedItemAdapter = null;
}
if (!fastAdapter.hasObservers())
fastAdapter.setHasStableIds(true);
// Item click listener
fastAdapter.setOnClickListener((v, a, i, p) -> onItemClick(p, i));
// Favourite button click listener
fastAdapter.addEventHook(new ClickEventHook<ContentItem>() {
@Override
public void onClick(@NotNull View view, int i, @NotNull FastAdapter<ContentItem> fastAdapter, @NotNull ContentItem item) {
if (item.getContent() != null)
onBookFavouriteClick(item.getContent());
}
@org.jetbrains.annotations.Nullable
@Override
public View onBind(RecyclerView.@NotNull ViewHolder viewHolder) {
if (viewHolder instanceof ContentItem.ContentViewHolder) {
return ((ContentItem.ContentViewHolder) viewHolder).getFavouriteButton();
}
return super.onBind(viewHolder);
}
});
// Site button click listener
fastAdapter.addEventHook(new ClickEventHook<ContentItem>() {
@Override
public void onClick(@NotNull View view, int i, @NotNull FastAdapter<ContentItem> fastAdapter, @NotNull ContentItem item) {
if (item.getContent() != null)
onBookSourceClick(item.getContent());
}
@org.jetbrains.annotations.Nullable
@Override
public View onBind(RecyclerView.@NotNull ViewHolder viewHolder) {
if (viewHolder instanceof ContentItem.ContentViewHolder) {
return ((ContentItem.ContentViewHolder) viewHolder).getSiteButton();
}
return super.onBind(viewHolder);
}
});
// "To top" button click listener (groups view only)
fastAdapter.addEventHook(new ClickEventHook<ContentItem>() {
@Override
public void onClick(@NotNull View view, int position, @NotNull FastAdapter<ContentItem> fastAdapter, @NotNull ContentItem item) {
itemTouchOnMove(position, 0);
}
@org.jetbrains.annotations.Nullable
@Override
public View onBind(RecyclerView.@NotNull ViewHolder viewHolder) {
if (viewHolder instanceof ContentItem.ContentViewHolder) {
return ((ContentItem.ContentViewHolder) viewHolder).getTopButton();
}
return super.onBind(viewHolder);
}
});
// "To bottom" button click listener (groups view only)
fastAdapter.addEventHook(new ClickEventHook<ContentItem>() {
@Override
public void onClick(@NotNull View view, int position, @NotNull FastAdapter<ContentItem> fastAdapter, @NotNull ContentItem item) {
itemTouchOnMove(position, fastAdapter.getItemCount() - 1);
}
@org.jetbrains.annotations.Nullable
@Override
public View onBind(RecyclerView.@NotNull ViewHolder viewHolder) {
if (viewHolder instanceof ContentItem.ContentViewHolder) {
return ((ContentItem.ContentViewHolder) viewHolder).getBottomButton();
}
return super.onBind(viewHolder);
}
});
// 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((item, b) -> this.onSelectionChanged());
FastAdapterPreClickSelectHelper<ContentItem> helper = new FastAdapterPreClickSelectHelper<>(selectExtension);
fastAdapter.setOnPreClickListener(helper::onPreClickListener);
fastAdapter.setOnPreLongClickListener(helper::onPreLongClickListener);
}
// Drag, drop & swiping
@DimenRes int dimen = (Preferences.Constant.LIBRARY_DISPLAY_LIST == Preferences.getLibraryDisplay()) ? R.dimen.delete_drawer_width_list : R.dimen.delete_drawer_width_grid;
SimpleSwipeDrawerDragCallback dragSwipeCallback = new SimpleSwipeDrawerDragCallback(this, ItemTouchHelper.LEFT, this).withSwipeLeft(Helper.dimensAsDp(requireContext(), dimen)).withSensitivity(1.5f).withSurfaceThreshold(0.3f).withNotifyAllDrops(true);
// Despite its name, that's actually to disable drag on long tap
dragSwipeCallback.setIsDragEnabled(false);
touchHelper = new ItemTouchHelper(dragSwipeCallback);
touchHelper.attachToRecyclerView(recyclerView);
recyclerView.setAdapter(fastAdapter);
recyclerView.setHasFixedSize(true);
}
Aggregations