use of com.mikepenz.fastadapter.select.SelectExtension in project Hentoid by avluis.
the class LibraryActivity method askDeleteItems.
/**
* Display the yes/no dialog to make sure the user really wants to delete selected items
*
* @param contents Items to be deleted if the answer is yes
*/
public void askDeleteItems(@NonNull final List<Content> contents, @NonNull final List<me.devsaki.hentoid.database.domains.Group> groups, @Nullable final Runnable onSuccess, @NonNull final SelectExtension<?> selectExtension) {
// TODO display the number of books and groups that will be deleted
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
int count = !groups.isEmpty() ? groups.size() : contents.size();
String title = getResources().getQuantityString(R.plurals.ask_delete_multiple, count, count);
builder.setMessage(title).setPositiveButton(R.string.yes, (dialog, which) -> {
selectExtension.deselect(selectExtension.getSelections());
viewModel.deleteItems(contents, groups, false, onSuccess);
}).setNegativeButton(R.string.no, (dialog, which) -> selectExtension.deselect(selectExtension.getSelections())).setOnCancelListener(dialog -> selectExtension.deselect(selectExtension.getSelections())).create().show();
}
use of com.mikepenz.fastadapter.select.SelectExtension in project Hentoid by avluis.
the class LibraryActivity method askArchiveItems.
/**
* Display the yes/no dialog to make sure the user really wants to archive selected items
*
* @param items Items to be archived if the answer is yes
*/
public void askArchiveItems(@NonNull final List<Content> items, @NonNull final SelectExtension<?> selectExtension) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
String title = getResources().getQuantityString(R.plurals.ask_archive_multiple, items.size(), items.size());
builder.setMessage(title).setPositiveButton(R.string.yes, (dialog, which) -> {
selectExtension.deselect(selectExtension.getSelections());
ArchiveNotificationChannel.init(this);
archiveNotificationManager = new NotificationManager(this, R.id.archive_processing);
archiveNotificationManager.cancel();
archiveProgress = 0;
archiveMax = items.size();
archiveNotificationManager.notify(new ArchiveStartNotification());
viewModel.archiveContents(items, this::onContentArchiveProgress, this::onContentArchiveSuccess, this::onContentArchiveError);
}).setNegativeButton(R.string.no, (dialog, which) -> selectExtension.deselect(selectExtension.getSelections())).create().show();
}
use of com.mikepenz.fastadapter.select.SelectExtension in project Hentoid by avluis.
the class ViewerGalleryFragment method updateListAdapter.
private void updateListAdapter(boolean isChapterEditMode) {
if (isChapterEditMode) {
if (!fastAdapter2.hasObservers())
fastAdapter2.setHasStableIds(true);
itemAdapter2.clear();
ExpandableExtension<INestedItem<SubExpandableItem.ViewHolder>> expandableExtension = fastAdapter2.getOrCreateExtension(ExpandableExtension.class);
GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager();
if (glm != null) {
int spanCount = Preferences.getViewerGalleryColumns();
glm.setSpanCount(spanCount);
// Use the correct size to display chapter separators, if any
GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (fastAdapter2.getItemViewType(position) == R.id.expandable_item) {
return spanCount;
}
return 1;
}
};
glm.setSpanSizeLookup(spanSizeLookup);
}
// Activate drag & drop
SimpleDragCallback dragCallback = new SimpleDragCallback(this);
dragCallback.setNotifyAllDrops(true);
touchHelper = new ItemTouchHelper(dragCallback);
touchHelper.attachToRecyclerView(recyclerView);
recyclerView.setAdapter(fastAdapter2);
fastAdapter2.addEventHook(new SubExpandableItem.DragHandlerTouchEvent(position -> {
RecyclerView.ViewHolder vh = recyclerView.findViewHolderForAdapterPosition(position);
if (vh != null)
touchHelper.startDrag(vh);
return null;
}));
// Item click listener
fastAdapter2.setOnClickListener((v, a, i, p) -> onNestedItemClick(i));
// Select on swipe
if (mDragSelectTouchListener != null) {
recyclerView.removeOnItemTouchListener(mDragSelectTouchListener);
mDragSelectTouchListener = null;
}
} else {
if (!fastAdapter.hasObservers())
fastAdapter.setHasStableIds(true);
itemAdapter.clear();
// 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<ImageFileItem> helper = new FastAdapterPreClickSelectHelper<>(selectExtension);
fastAdapter.setOnPreClickListener(helper::onPreClickListener);
fastAdapter.setOnPreLongClickListener((v, a, i, p) -> {
// Warning : specific code for drag selection
mDragSelectTouchListener.startDragSelection(p);
return helper.onPreLongClickListener(v, a, i, p);
});
}
// Item click listener
fastAdapter.setOnClickListener((v, a, i, p) -> onItemClick(i));
GridLayoutManager glm = (GridLayoutManager) recyclerView.getLayoutManager();
if (glm != null) {
int spanCount = Preferences.getViewerGalleryColumns();
glm.setSpanCount(spanCount);
// Use the correct size to display chapter separators, if any
GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (fastAdapter.getItemViewType(position) == R.id.expandable_item) {
return spanCount;
}
return 1;
}
};
glm.setSpanSizeLookup(spanSizeLookup);
}
if (touchHelper != null)
touchHelper.attachToRecyclerView(null);
recyclerView.setAdapter(fastAdapter);
// Select on swipe
DragSelectTouchListener.OnDragSelectListener onDragSelectionListener = (start, end, isSelected) -> selectExtension.select(IntStream.rangeClosed(start, end).boxed().toList());
mDragSelectTouchListener = new DragSelectTouchListener().withSelectListener(onDragSelectionListener);
if (mDragSelectTouchListener2 != null) {
recyclerView.removeOnItemTouchListener(mDragSelectTouchListener2);
mDragSelectTouchListener2 = null;
}
recyclerView.addOnItemTouchListener(mDragSelectTouchListener);
}
}
use of com.mikepenz.fastadapter.select.SelectExtension 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.select.SelectExtension in project Hentoid by avluis.
the class ErrorsFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// UI ELEMENTS
View rootView = inflater.inflate(R.layout.fragment_queue_errors, container, false);
mEmptyText = requireViewById(rootView, R.id.errors_empty_txt);
// Book list container
recyclerView = requireViewById(rootView, R.id.queue_list);
fastAdapter = FastAdapter.with(itemAdapter);
ContentItem item = new ContentItem(ContentItem.ViewType.ERRORS);
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();
// Swiping
SimpleSwipeDrawerCallback swipeCallback = new SimpleSwipeDrawerCallback(ItemTouchHelper.LEFT, this).withSwipeLeft(Helper.dimensAsDp(requireContext(), R.dimen.delete_drawer_width_list)).withSensitivity(1.5f).withSurfaceThreshold(0.3f);
touchHelper = new ItemTouchHelper(swipeCallback);
touchHelper.attachToRecyclerView(recyclerView);
// Item click listener
fastAdapter.setOnClickListener((v, a, i, p) -> onItemClick(i));
// Fast scroller
new FastScrollerBuilder(recyclerView).build();
initToolbar();
initSelectionToolbar();
attachButtons(fastAdapter);
addCustomBackControl();
return rootView;
}
Aggregations