Search in sources :

Example 1 with SimpleSwipeDrawerCallback

use of com.mikepenz.fastadapter.swipe.SimpleSwipeDrawerCallback 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)1 TextView (android.widget.TextView)1 ItemTouchHelper (androidx.recyclerview.widget.ItemTouchHelper)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 SelectExtension (com.mikepenz.fastadapter.select.SelectExtension)1 SimpleSwipeDrawerCallback (com.mikepenz.fastadapter.swipe.SimpleSwipeDrawerCallback)1 ContentItem (me.devsaki.hentoid.viewholders.ContentItem)1 FastAdapterPreClickSelectHelper (me.devsaki.hentoid.widget.FastAdapterPreClickSelectHelper)1 FastScrollerBuilder (me.zhanghai.android.fastscroll.FastScrollerBuilder)1