Search in sources :

Example 1 with SelectExtension

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();
}
Also used : LibraryGroupsFragment(me.devsaki.hentoid.fragments.library.LibraryGroupsFragment) Content(me.devsaki.hentoid.database.domains.Content) LibraryViewModel(me.devsaki.hentoid.viewmodels.LibraryViewModel) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) Attribute(me.devsaki.hentoid.database.domains.Attribute) RC_DRAWER(me.devsaki.hentoid.events.CommunicationEvent.RC_DRAWER) ContentHelper(me.devsaki.hentoid.util.ContentHelper) BuildConfig(me.devsaki.hentoid.BuildConfig) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Handler(android.os.Handler) Looper(android.os.Looper) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) EV_SEARCH(me.devsaki.hentoid.events.CommunicationEvent.EV_SEARCH) EV_UPDATE_SORT(me.devsaki.hentoid.events.CommunicationEvent.EV_UPDATE_SORT) ArchiveProgressNotification(me.devsaki.hentoid.notification.archive.ArchiveProgressNotification) RC_CONTENTS(me.devsaki.hentoid.events.CommunicationEvent.RC_CONTENTS) EV_DISABLE(me.devsaki.hentoid.events.CommunicationEvent.EV_DISABLE) SearchView(androidx.appcompat.widget.SearchView) ThreadMode(org.greenrobot.eventbus.ThreadMode) UpdateSuccessDialogFragment(me.devsaki.hentoid.fragments.library.UpdateSuccessDialogFragment) CommunicationEvent(me.devsaki.hentoid.events.CommunicationEvent) Timber(timber.log.Timber) ViewModelFactory(me.devsaki.hentoid.viewmodels.ViewModelFactory) IdRes(androidx.annotation.IdRes) List(java.util.List) EV_CLOSED(me.devsaki.hentoid.events.CommunicationEvent.EV_CLOSED) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Grouping(me.devsaki.hentoid.enums.Grouping) ProcessEvent(me.devsaki.hentoid.events.ProcessEvent) DocumentFile(androidx.documentfile.provider.DocumentFile) Toolbar(androidx.appcompat.widget.Toolbar) ArchiveCompleteNotification(me.devsaki.hentoid.notification.archive.ArchiveCompleteNotification) CollectionDAO(me.devsaki.hentoid.database.CollectionDAO) Snackbar(com.google.android.material.snackbar.Snackbar) ViewDragHelper(androidx.customview.widget.ViewDragHelper) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) Debouncer(me.devsaki.hentoid.util.Debouncer) Preferences(me.devsaki.hentoid.util.Preferences) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) HashMap(java.util.HashMap) BaseTransientBottomBar(com.google.android.material.snackbar.BaseTransientBottomBar) AppUpdatedEvent(me.devsaki.hentoid.events.AppUpdatedEvent) NotificationManager(me.devsaki.hentoid.util.notification.NotificationManager) MenuItem(android.view.MenuItem) FragmentActivity(androidx.fragment.app.FragmentActivity) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) RC_GROUPS(me.devsaki.hentoid.events.CommunicationEvent.RC_GROUPS) SuppressLint(android.annotation.SuppressLint) TooltipHelper(me.devsaki.hentoid.util.TooltipHelper) EV_ENABLE(me.devsaki.hentoid.events.CommunicationEvent.EV_ENABLE) Helper(me.devsaki.hentoid.util.Helper) SelectExtension(com.mikepenz.fastadapter.select.SelectExtension) EventBus(org.greenrobot.eventbus.EventBus) LibraryContentFragment(me.devsaki.hentoid.fragments.library.LibraryContentFragment) PermissionHelper(me.devsaki.hentoid.util.PermissionHelper) ArchiveNotificationChannel(me.devsaki.hentoid.notification.archive.ArchiveNotificationChannel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) GravityCompat(androidx.core.view.GravityCompat) Field(java.lang.reflect.Field) FileHelper(me.devsaki.hentoid.util.FileHelper) ObjectBoxDAO(me.devsaki.hentoid.database.ObjectBoxDAO) PopupMenu(androidx.appcompat.widget.PopupMenu) ArchiveStartNotification(me.devsaki.hentoid.notification.archive.ArchiveStartNotification) ArrowOrientation(com.skydoves.balloon.ArrowOrientation) R(me.devsaki.hentoid.R) Subscribe(org.greenrobot.eventbus.Subscribe) SharedPreferences(android.content.SharedPreferences) LENGTH_LONG(com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_LONG) EV_ADVANCED_SEARCH(me.devsaki.hentoid.events.CommunicationEvent.EV_ADVANCED_SEARCH) Collections(java.util.Collections) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) SuppressLint(android.annotation.SuppressLint)

Example 2 with SelectExtension

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();
}
Also used : LibraryGroupsFragment(me.devsaki.hentoid.fragments.library.LibraryGroupsFragment) Content(me.devsaki.hentoid.database.domains.Content) LibraryViewModel(me.devsaki.hentoid.viewmodels.LibraryViewModel) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) Attribute(me.devsaki.hentoid.database.domains.Attribute) RC_DRAWER(me.devsaki.hentoid.events.CommunicationEvent.RC_DRAWER) ContentHelper(me.devsaki.hentoid.util.ContentHelper) BuildConfig(me.devsaki.hentoid.BuildConfig) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Handler(android.os.Handler) Looper(android.os.Looper) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) EV_SEARCH(me.devsaki.hentoid.events.CommunicationEvent.EV_SEARCH) EV_UPDATE_SORT(me.devsaki.hentoid.events.CommunicationEvent.EV_UPDATE_SORT) ArchiveProgressNotification(me.devsaki.hentoid.notification.archive.ArchiveProgressNotification) RC_CONTENTS(me.devsaki.hentoid.events.CommunicationEvent.RC_CONTENTS) EV_DISABLE(me.devsaki.hentoid.events.CommunicationEvent.EV_DISABLE) SearchView(androidx.appcompat.widget.SearchView) ThreadMode(org.greenrobot.eventbus.ThreadMode) UpdateSuccessDialogFragment(me.devsaki.hentoid.fragments.library.UpdateSuccessDialogFragment) CommunicationEvent(me.devsaki.hentoid.events.CommunicationEvent) Timber(timber.log.Timber) ViewModelFactory(me.devsaki.hentoid.viewmodels.ViewModelFactory) IdRes(androidx.annotation.IdRes) List(java.util.List) EV_CLOSED(me.devsaki.hentoid.events.CommunicationEvent.EV_CLOSED) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Grouping(me.devsaki.hentoid.enums.Grouping) ProcessEvent(me.devsaki.hentoid.events.ProcessEvent) DocumentFile(androidx.documentfile.provider.DocumentFile) Toolbar(androidx.appcompat.widget.Toolbar) ArchiveCompleteNotification(me.devsaki.hentoid.notification.archive.ArchiveCompleteNotification) CollectionDAO(me.devsaki.hentoid.database.CollectionDAO) Snackbar(com.google.android.material.snackbar.Snackbar) ViewDragHelper(androidx.customview.widget.ViewDragHelper) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) Debouncer(me.devsaki.hentoid.util.Debouncer) Preferences(me.devsaki.hentoid.util.Preferences) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) HashMap(java.util.HashMap) BaseTransientBottomBar(com.google.android.material.snackbar.BaseTransientBottomBar) AppUpdatedEvent(me.devsaki.hentoid.events.AppUpdatedEvent) NotificationManager(me.devsaki.hentoid.util.notification.NotificationManager) MenuItem(android.view.MenuItem) FragmentActivity(androidx.fragment.app.FragmentActivity) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) RC_GROUPS(me.devsaki.hentoid.events.CommunicationEvent.RC_GROUPS) SuppressLint(android.annotation.SuppressLint) TooltipHelper(me.devsaki.hentoid.util.TooltipHelper) EV_ENABLE(me.devsaki.hentoid.events.CommunicationEvent.EV_ENABLE) Helper(me.devsaki.hentoid.util.Helper) SelectExtension(com.mikepenz.fastadapter.select.SelectExtension) EventBus(org.greenrobot.eventbus.EventBus) LibraryContentFragment(me.devsaki.hentoid.fragments.library.LibraryContentFragment) PermissionHelper(me.devsaki.hentoid.util.PermissionHelper) ArchiveNotificationChannel(me.devsaki.hentoid.notification.archive.ArchiveNotificationChannel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) GravityCompat(androidx.core.view.GravityCompat) Field(java.lang.reflect.Field) FileHelper(me.devsaki.hentoid.util.FileHelper) ObjectBoxDAO(me.devsaki.hentoid.database.ObjectBoxDAO) PopupMenu(androidx.appcompat.widget.PopupMenu) ArchiveStartNotification(me.devsaki.hentoid.notification.archive.ArchiveStartNotification) ArrowOrientation(com.skydoves.balloon.ArrowOrientation) R(me.devsaki.hentoid.R) Subscribe(org.greenrobot.eventbus.Subscribe) SharedPreferences(android.content.SharedPreferences) LENGTH_LONG(com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_LONG) EV_ADVANCED_SEARCH(me.devsaki.hentoid.events.CommunicationEvent.EV_ADVANCED_SEARCH) Collections(java.util.Collections) NotificationManager(me.devsaki.hentoid.util.notification.NotificationManager) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ArchiveStartNotification(me.devsaki.hentoid.notification.archive.ArchiveStartNotification)

Example 3 with SelectExtension

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);
    }
}
Also used : Content(me.devsaki.hentoid.database.domains.Content) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) FastAdapterDiffUtil(com.mikepenz.fastadapter.diff.FastAdapterDiffUtil) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Chapter(me.devsaki.hentoid.database.domains.Chapter) Optional(com.annimon.stream.Optional) ItemAdapter(com.mikepenz.fastadapter.adapters.ItemAdapter) Handler(android.os.Handler) Looper(android.os.Looper) ImageFile(me.devsaki.hentoid.database.domains.ImageFile) Fragment(androidx.fragment.app.Fragment) ImageViewerActivity(me.devsaki.hentoid.activities.ImageViewerActivity) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ItemTouchCallback(com.mikepenz.fastadapter.drag.ItemTouchCallback) PowerSpinnerView(com.skydoves.powerspinner.PowerSpinnerView) ExpandableExtension(com.mikepenz.fastadapter.expandable.ExpandableExtension) DragSelectTouchListener(me.devsaki.hentoid.widget.DragSelectTouchListener) Set(java.util.Set) ToastHelper(me.devsaki.hentoid.util.ToastHelper) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) ViewModelFactory(me.devsaki.hentoid.viewmodels.ViewModelFactory) Nullable(org.jetbrains.annotations.Nullable) ViewCompat.requireViewById(androidx.core.view.ViewCompat.requireViewById) List(java.util.List) ImageItemBundle(me.devsaki.hentoid.activities.bundles.ImageItemBundle) ContentNotProcessedException(me.devsaki.hentoid.util.exception.ContentNotProcessedException) ImageFileItem(me.devsaki.hentoid.viewholders.ImageFileItem) SubExpandableItem(me.devsaki.hentoid.viewholders.SubExpandableItem) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(androidx.appcompat.widget.Toolbar) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Snackbar(com.google.android.material.snackbar.Snackbar) IntStream(com.annimon.stream.IntStream) Context(android.content.Context) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Preferences(me.devsaki.hentoid.util.Preferences) Stream(com.annimon.stream.Stream) DiffCallback(com.mikepenz.fastadapter.diff.DiffCallback) SimpleDragCallback(com.mikepenz.fastadapter.drag.SimpleDragCallback) BaseTransientBottomBar(com.google.android.material.snackbar.BaseTransientBottomBar) IntDef(androidx.annotation.IntDef) MenuItem(android.view.MenuItem) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) FastAdapterPreClickSelectHelper(me.devsaki.hentoid.widget.FastAdapterPreClickSelectHelper) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) SelectExtension(com.mikepenz.fastadapter.select.SelectExtension) WeakReference(java.lang.ref.WeakReference) ImageViewerViewModel(me.devsaki.hentoid.viewmodels.ImageViewerViewModel) FragmentManager(androidx.fragment.app.FragmentManager) ViewerKeyListener(me.devsaki.hentoid.widget.ViewerKeyListener) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) INestedItem(me.devsaki.hentoid.viewholders.INestedItem) DragDropUtil(com.mikepenz.fastadapter.utils.DragDropUtil) FastScrollerBuilder(me.zhanghai.android.fastscroll.FastScrollerBuilder) R(me.devsaki.hentoid.R) ProgressDialogFragment(me.devsaki.hentoid.fragments.ProgressDialogFragment) RetentionPolicy(java.lang.annotation.RetentionPolicy) SimpleDragCallback(com.mikepenz.fastadapter.drag.SimpleDragCallback) SelectExtension(com.mikepenz.fastadapter.select.SelectExtension) SubExpandableItem(me.devsaki.hentoid.viewholders.SubExpandableItem) SuppressLint(android.annotation.SuppressLint) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ImageFileItem(me.devsaki.hentoid.viewholders.ImageFileItem) FastAdapterPreClickSelectHelper(me.devsaki.hentoid.widget.FastAdapterPreClickSelectHelper) INestedItem(me.devsaki.hentoid.viewholders.INestedItem) DragSelectTouchListener(me.devsaki.hentoid.widget.DragSelectTouchListener)

Example 4 with SelectExtension

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;
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) ImageButton(android.widget.ImageButton) Content(me.devsaki.hentoid.database.domains.Content) Bundle(android.os.Bundle) QueueActivity(me.devsaki.hentoid.activities.QueueActivity) NonNull(androidx.annotation.NonNull) FastAdapterDiffUtil(com.mikepenz.fastadapter.diff.FastAdapterDiffUtil) NetworkHelper(me.devsaki.hentoid.util.network.NetworkHelper) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ISwipeableViewHolder(me.devsaki.hentoid.viewholders.ISwipeableViewHolder) ClickEventHook(com.mikepenz.fastadapter.listeners.ClickEventHook) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ContentHelper(me.devsaki.hentoid.util.ContentHelper) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) ItemAdapter(com.mikepenz.fastadapter.adapters.ItemAdapter) StringHelper(me.devsaki.hentoid.util.StringHelper) Handler(android.os.Handler) Looper(android.os.Looper) Consumer(com.annimon.stream.function.Consumer) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) RecyclerView(androidx.recyclerview.widget.RecyclerView) ItemTouchCallback(com.mikepenz.fastadapter.drag.ItemTouchCallback) BlinkAnimation(me.devsaki.hentoid.ui.BlinkAnimation) DownloadEvent(me.devsaki.hentoid.events.DownloadEvent) SimpleSwipeDrawerDragCallback(com.mikepenz.fastadapter.swipe_drag.SimpleSwipeDrawerDragCallback) Set(java.util.Set) ToastHelper(me.devsaki.hentoid.util.ToastHelper) SearchView(androidx.appcompat.widget.SearchView) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) ViewModelFactory(me.devsaki.hentoid.viewmodels.ViewModelFactory) ViewCompat.requireViewById(androidx.core.view.ViewCompat.requireViewById) StringRes(androidx.annotation.StringRes) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ProcessEvent(me.devsaki.hentoid.events.ProcessEvent) ThemeHelper(me.devsaki.hentoid.util.ThemeHelper) QueueViewModel(me.devsaki.hentoid.viewmodels.QueueViewModel) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(androidx.appcompat.widget.Toolbar) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NotNull(org.jetbrains.annotations.NotNull) Snackbar(com.google.android.material.snackbar.Snackbar) CircularProgressView(me.devsaki.hentoid.views.CircularProgressView) Context(android.content.Context) Debouncer(me.devsaki.hentoid.util.Debouncer) ContentItem(me.devsaki.hentoid.viewholders.ContentItem) Preferences(me.devsaki.hentoid.util.Preferences) Stream(com.annimon.stream.Stream) PrefsBundle(me.devsaki.hentoid.activities.bundles.PrefsBundle) IDraggableViewHolder(me.devsaki.hentoid.viewholders.IDraggableViewHolder) Intent(android.content.Intent) BaseTransientBottomBar(com.google.android.material.snackbar.BaseTransientBottomBar) PrefsActivity(me.devsaki.hentoid.activities.PrefsActivity) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) TooltipHelper(me.devsaki.hentoid.util.TooltipHelper) FastAdapterPreClickSelectHelper(me.devsaki.hentoid.widget.FastAdapterPreClickSelectHelper) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) DownloadPreparationEvent(me.devsaki.hentoid.events.DownloadPreparationEvent) Helper(me.devsaki.hentoid.util.Helper) SelectExtension(com.mikepenz.fastadapter.select.SelectExtension) EventBus(org.greenrobot.eventbus.EventBus) Observable(io.reactivex.Observable) PermissionHelper(me.devsaki.hentoid.util.PermissionHelper) WeakReference(java.lang.ref.WeakReference) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ServiceDestroyedEvent(me.devsaki.hentoid.events.ServiceDestroyedEvent) LayoutInflater(android.view.LayoutInflater) ContentQueueManager(me.devsaki.hentoid.util.download.ContentQueueManager) FileHelper(me.devsaki.hentoid.util.FileHelper) DragDropUtil(com.mikepenz.fastadapter.utils.DragDropUtil) FastScrollerBuilder(me.zhanghai.android.fastscroll.FastScrollerBuilder) ObjectBoxDAO(me.devsaki.hentoid.database.ObjectBoxDAO) TimeUnit(java.util.concurrent.TimeUnit) ArrowOrientation(com.skydoves.balloon.ArrowOrientation) R(me.devsaki.hentoid.R) SimpleSwipeDrawerCallback(com.mikepenz.fastadapter.swipe.SimpleSwipeDrawerCallback) Subscribe(org.greenrobot.eventbus.Subscribe) ProgressDialogFragment(me.devsaki.hentoid.fragments.ProgressDialogFragment) DownloadSpeedCalculator(me.devsaki.hentoid.util.network.DownloadSpeedCalculator) QueueRecord(me.devsaki.hentoid.database.domains.QueueRecord) FastScrollerBuilder(me.zhanghai.android.fastscroll.FastScrollerBuilder) DownloadEvent(me.devsaki.hentoid.events.DownloadEvent) SimpleSwipeDrawerDragCallback(com.mikepenz.fastadapter.swipe_drag.SimpleSwipeDrawerDragCallback) SelectExtension(com.mikepenz.fastadapter.select.SelectExtension) FastAdapterPreClickSelectHelper(me.devsaki.hentoid.widget.FastAdapterPreClickSelectHelper) ContentItem(me.devsaki.hentoid.viewholders.ContentItem)

Example 5 with SelectExtension

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;
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) FastScrollerBuilder(me.zhanghai.android.fastscroll.FastScrollerBuilder) SimpleSwipeDrawerCallback(com.mikepenz.fastadapter.swipe.SimpleSwipeDrawerCallback) SelectExtension(com.mikepenz.fastadapter.select.SelectExtension) FastAdapterPreClickSelectHelper(me.devsaki.hentoid.widget.FastAdapterPreClickSelectHelper) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ContentItem(me.devsaki.hentoid.viewholders.ContentItem)

Aggregations

View (android.view.View)8 SelectExtension (com.mikepenz.fastadapter.select.SelectExtension)8 SuppressLint (android.annotation.SuppressLint)7 Bundle (android.os.Bundle)6 Handler (android.os.Handler)6 Looper (android.os.Looper)6 MenuItem (android.view.MenuItem)6 TextView (android.widget.TextView)6 NonNull (androidx.annotation.NonNull)6 ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)6 RecyclerView (androidx.recyclerview.widget.RecyclerView)6 List (java.util.List)6 R (me.devsaki.hentoid.R)6 FastAdapterPreClickSelectHelper (me.devsaki.hentoid.widget.FastAdapterPreClickSelectHelper)6 Nullable (androidx.annotation.Nullable)5 Helper (me.devsaki.hentoid.util.Helper)5 Intent (android.content.Intent)4 Toolbar (androidx.appcompat.widget.Toolbar)4 Fragment (androidx.fragment.app.Fragment)4 ViewModelProvider (androidx.lifecycle.ViewModelProvider)4