androidx.recyclerview.widget.ItemTouchHelper Java Examples

The following examples show how to use androidx.recyclerview.widget.ItemTouchHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FavoriteActivityTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Config(shadows = {ShadowRecyclerView.class, ShadowItemTouchHelper.class})
@Test
public void testSwipeToDelete() {
    RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0);
    customShadowOf(recyclerView).getItemTouchHelperCallback()
            .onSwiped(holder, ItemTouchHelper.LEFT);
    verify(favoriteManager).remove(any(Context.class), anyCollection());
    when(favoriteManager.getSize()).thenReturn(1);
    observerCaptor.getValue().onChanged();
    assertEquals(1, adapter.getItemCount());
    assertThat((TextView) activity.findViewById(R.id.snackbar_text))
            .isNotNull()
            .containsText(R.string.toast_removed);
    activity.findViewById(R.id.snackbar_action).performClick();
    verify(favoriteManager).add(any(Context.class), any(WebItem.class));
    when(favoriteManager.getSize()).thenReturn(2);
    observerCaptor.getValue().onChanged();
    assertEquals(2, adapter.getItemCount());
}
 
Example #2
Source File: CardDisplayManageActivity.java    From GeometricWeather with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onChildDraw(@NonNull Canvas c,
                        @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
                        float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    switch (actionState) {
        case ItemTouchHelper.ACTION_STATE_SWIPE:
            ((CardDisplayAdapter.ViewHolder) viewHolder)
                    .drawSwipe(dX);
            break;

        case ItemTouchHelper.ACTION_STATE_DRAG:
            ((CardDisplayAdapter.ViewHolder) viewHolder)
                    .drawDrag(CardDisplayManageActivity.this, dY != 0);
            break;

        case ItemTouchHelper.ACTION_STATE_IDLE:
            ((CardDisplayAdapter.ViewHolder) viewHolder)
                    .drawSwipe(0)
                    .drawDrag(CardDisplayManageActivity.this, false);
            break;
    }
}
 
Example #3
Source File: FlexibleViewHolder.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see #toggleActivation()
 * @since 5.0.0-b1
 */
@Override
@CallSuper
public void onClick(View view) {
    int position = getFlexibleAdapterPosition();
    if (!mAdapter.isItemEnabled(position)) {
        return;
    }
    // Experimented that, if LongClick is not consumed, onClick is fired. We skip the
    // call to the listener in this case, which is allowed only in ACTION_STATE_IDLE.
    if (mAdapter.mItemClickListener != null && mActionState == ItemTouchHelper.ACTION_STATE_IDLE) {
        Log.v("onClick on position %s mode=%s", position, LayoutUtils.getModeName(mAdapter.getMode()));
        // Get the permission to activate the View from user
        if (mAdapter.mItemClickListener.onItemClick(view, position)) {
            // Now toggle the activation
            toggleActivation();
        }
    }
}
 
Example #4
Source File: SimpleItemTouchHelperCallback.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    // We only want the active item to change
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        if (viewHolder instanceof ItemTouchHelperViewHolder) {
            // Let the view holder know that this item is being moved or dragged
            ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
            itemViewHolder.onItemSelected();
        }
    }
    super.onSelectedChanged(viewHolder, actionState);

    if (null != mOnSelectChangedListener) {
        mOnSelectChangedListener.onSelectedChanged(viewHolder, actionState);
    }
}
 
Example #5
Source File: DragAndSwipeCallback.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onChildDrawOver(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder,
                            float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        View itemView = viewHolder.itemView;

        c.save();
        if (dX > 0) {
            c.clipRect(itemView.getLeft(), itemView.getTop(),
                    itemView.getLeft() + dX, itemView.getBottom());
            c.translate(itemView.getLeft(), itemView.getTop());
        } else {
            c.clipRect(itemView.getRight() + dX, itemView.getTop(),
                    itemView.getRight(), itemView.getBottom());
            c.translate(itemView.getRight() + dX, itemView.getTop());
        }
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
        }
        c.restore();

    }
}
 
Example #6
Source File: DragAndSwipeCallback.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemDragStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwipeStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.dokit_baseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #7
Source File: DragAndSwipeCallback.java    From BaseRecyclerViewAdapterHelper with MIT License 6 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemDragStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
            && !isViewCreateByAdapter(viewHolder)) {
        if (mDraggableModule != null) {
            mDraggableModule.onItemSwipeStart(viewHolder);
        }
        viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #8
Source File: FiltersSetupActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (viewHolder.getItemViewType() != 2) {
        return makeMovementFlags(0, 0);
    }
    return makeMovementFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0);
}
 
Example #9
Source File: WaypointListAdapter.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
@Override
public int getMovementFlags(final RecyclerView recyclerView, final RecyclerView.ViewHolder viewHolder) {
    final WaypointEntry entry = mWaypointEntries.get(viewHolder.getAdapterPosition());
    final int dragFlags = entry.isDraggable() ?
            ItemTouchHelper.UP | ItemTouchHelper.DOWN :
            ItemTouchHelper.ACTION_STATE_IDLE;
    return makeMovementFlags(dragFlags, ItemTouchHelper.ACTION_STATE_IDLE);
}
 
Example #10
Source File: WXPreviewControllerView.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
private void initPreviewList() {
    mPreviewRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
    previewAdapter = new MultiPreviewAdapter(selectedList, presenter);
    mPreviewRecyclerView.setAdapter(previewAdapter);
    SimpleItemTouchHelperCallback callback = new SimpleItemTouchHelperCallback(previewAdapter);
    ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(mPreviewRecyclerView);
}
 
Example #11
Source File: SimpleItemTouchHelperCallback.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        // Fade out the view as it is swiped out of the parent's bounds
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
        viewHolder.itemView.setAlpha(alpha);
        viewHolder.itemView.setTranslationX(dX);
    } else if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
        if (isCurrentlyActive) {
            viewHolder.itemView.setAlpha(0.5f);
            viewHolder.itemView.setScaleX(moveScaleFactor);
            viewHolder.itemView.setScaleY(moveScaleFactor);
        } else {
            viewHolder.itemView.setAlpha(1f);
            viewHolder.itemView.setScaleX(1f);
            viewHolder.itemView.setScaleY(1f);
        }
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }

    // 从拖动到释放的过程
    if (null != mOnSelectChangedListener && !isCurrentlyActive && lastActive) {
        mOnSelectChangedListener.onSelectedChanged(viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
    lastActive = isCurrentlyActive;
}
 
Example #12
Source File: PollCreateActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        listView.cancelClickRunnables(false);
        viewHolder.itemView.setPressed(true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #13
Source File: ContactActivity.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        final ContactsAdapter.ContactViewHolder holder = (ContactsAdapter.ContactViewHolder) viewHolder;
        final float actionWidth = holder.getActionWidth();
        final float translationX = dX < -actionWidth ? -actionWidth : dX;
        final float menuTranslationX = translationX / 2 + actionWidth / 2;
        holder.getView(R.id.content).setTranslationX(translationX);
        holder.getView(R.id.menu).setTranslationX(menuTranslationX);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example #14
Source File: SimpleItemTouchHelperCallback.java    From andOTP with MIT License 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        // Fade out the view as it is swiped out of the parent's bounds
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
        viewHolder.itemView.setAlpha(alpha);
        viewHolder.itemView.setTranslationX(dX);
    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example #15
Source File: FiltersSetupActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("Filters", R.string.Filters));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));

    listView = new RecyclerListView(context);
    ((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setVerticalScrollBarEnabled(false);
    itemTouchHelper = new ItemTouchHelper(new TouchHelperCallback());
    itemTouchHelper.attachToRecyclerView(listView);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(adapter = new ListAdapter(context));
    listView.setOnItemClickListener((view, position, x, y) -> {
        if (position >= filtersStartRow && position < filtersEndRow) {
            presentFragment(new FilterCreateActivity(getMessagesController().dialogFilters.get(position - filtersStartRow)));
        } else if (position == createFilterRow) {
            presentFragment(new FilterCreateActivity());
        }
    });

    return fragmentView;
}
 
Example #16
Source File: BaseBrickTest.java    From brickkit-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testDismissed() {
    TestBaseBrick brick = new TestBaseBrick(context, brickSize);

    brick.dismissed(ItemTouchHelper.UP);

    // nothing to verify
}
 
Example #17
Source File: RecyclerViewBindingAdapter.java    From deagle with Apache License 2.0 5 votes vote down vote up
@BindingAdapter({"item_touch"})
public static void setItemTouchHelper(final RecyclerView view, final ItemTouchHelper helper) {
	for (int i = 0;; i ++) try {
		final RecyclerView.ItemDecoration decoration = view.getItemDecorationAt(i);
		if (decoration == null) break;								// Null is returned on RecyclerView library 27+
		if (decoration == helper) return;
	} catch (final IndexOutOfBoundsException ignored) { break; }	// IndexOutOfBoundsException is thrown on RecyclerView library prior to 27.
	helper.attachToRecyclerView(view);
}
 
Example #18
Source File: StickersActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_IDLE) {
        sendReorder();
    } else {
        listView.cancelClickRunnables(false);
        viewHolder.itemView.setPressed(true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #19
Source File: QueueItemTouchHelperCallback.java    From CastVideos-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        if (viewHolder instanceof QueueListAdapter.ItemTouchHelperViewHolder) {
            QueueListAdapter.ItemTouchHelperViewHolder itemViewHolder
                    = (QueueListAdapter.ItemTouchHelperViewHolder) viewHolder;
            itemViewHolder.onItemSelected();
        }
    }

    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #20
Source File: StickersActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_IDLE) {
        sendReorder();
    } else {
        listView.cancelClickRunnables(false);
        viewHolder.itemView.setPressed(true);
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #21
Source File: FilterTabsView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        listView.cancelClickRunnables(false);
        viewHolder.itemView.setPressed(true);
        viewHolder.itemView.setBackgroundColor(Theme.getColor(backgroundColorKey));
    }
    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #22
Source File: DownloadFragment.java    From Audinaut with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
    super.onCreateView(inflater, container, bundle);

    ItemTouchHelper touchHelper = new ItemTouchHelper(new DownloadFileItemHelperCallback(this, false));
    touchHelper.attachToRecyclerView(recyclerView);

    return rootView;
}
 
Example #23
Source File: FilterTabsView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (!isEditing || viewHolder.getAdapterPosition() == 0) {
        return makeMovementFlags(0, 0);
    }
    return makeMovementFlags(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, 0);
}
 
Example #24
Source File: BrickDataManager.java    From brickkit-android with Apache License 2.0 5 votes vote down vote up
/**
 * This attaches the touch helper to the recycler view if swipe or drag and drop are enabled.
 */
private void attachTouchHelper() {
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new BrickItemTouchHelperCallback(this));

    if ((dragAndDrop || swipeToDismiss) && brickRecyclerAdapter != null) {
        itemTouchHelper.attachToRecyclerView(brickRecyclerAdapter.getRecyclerView());
    } else {
        itemTouchHelper.attachToRecyclerView(null);
    }
}
 
Example #25
Source File: SimpleItemTouchCallback.java    From YouTube-In-Background with MIT License 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState)
{
    // We only want the active item to change
    if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
        if (viewHolder instanceof ItemTouchViewListener) {
            // Let the view holder know that this item is being moved or dragged
            ItemTouchViewListener itemViewHolder = (ItemTouchViewListener) viewHolder;
            itemViewHolder.onItemSelected();
        }
    }

    super.onSelectedChanged(viewHolder, actionState);
}
 
Example #26
Source File: TxtChapterRuleActivity.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
private void initRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter = new TxtChapterRuleAdapter(this);
    recyclerView.setAdapter(adapter);
    ItemTouchCallback itemTouchCallback = new ItemTouchCallback();
    itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener());
    itemTouchCallback.setDragEnable(true);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example #27
Source File: FlexibleViewHolder.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * Here we handle the event of when the {@code ItemTouchHelper} first registers an item
 * as being moved or swiped.
 * <p>In this implementation, View activation is automatically handled if dragged: The Item
 * will be added to the selection list if not selected yet and mode MULTI is activated.</p>
 *
 * @param position    the position of the item touched
 * @param actionState one of {@link ItemTouchHelper#ACTION_STATE_SWIPE} or
 *                    {@link ItemTouchHelper#ACTION_STATE_DRAG}.
 * @see #shouldActivateViewWhileSwiping()
 * @see #shouldAddSelectionInActionMode()
 * @since 5.0.0-b1
 */
@Override
@CallSuper
public void onActionStateChanged(int position, int actionState) {
    mActionState = actionState;
    alreadySelected = mAdapter.isSelected(position);
    Log.v("onActionStateChanged position=%s mode=%s actionState=%s",
            position, LayoutUtils.getModeName(mAdapter.getMode()),
            (actionState == ItemTouchHelper.ACTION_STATE_SWIPE ? "Swipe(1)" : "Drag(2)"));
    if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
        if (!alreadySelected) {
            // Be sure, if MULTI is active, to add this item to the selection list (call listener!)
            // Also be sure user consumes the long click event if not done in onLongClick.
            // Drag by LongPress or Drag by handleView
            if (mLongClickSkipped || mAdapter.getMode() == Mode.MULTI) {
                // Next check, allows to initiate the ActionMode and to add selection if configured
                if ((shouldAddSelectionInActionMode() || mAdapter.getMode() != Mode.MULTI) &&
                        mAdapter.mItemLongClickListener != null && mAdapter.isSelectable(position)) {
                    Log.v("onLongClick on position %s mode=%s", position, mAdapter.getMode());
                    mAdapter.mItemLongClickListener.onItemLongClick(position);
                    alreadySelected = true; // Keep selection on release!
                }
            }
            // If still not selected, be sure current item appears selected for the Drag transition
            if (!alreadySelected) {
                mAdapter.toggleSelection(position);
            }
        }
        // Now toggle the activation, Activate view and make selection visible only if necessary
        if (!getContentView().isActivated()) {
            toggleActivation();
        }
    } else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE &&
            shouldActivateViewWhileSwiping() && !alreadySelected) {
        mAdapter.toggleSelection(position);
        toggleActivation();
    }
}
 
Example #28
Source File: SwipeAndDragHelper.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onChildDraw(Canvas c,
                        RecyclerView recyclerView,
                        RecyclerView.ViewHolder viewHolder,
                        float dX,
                        float dY,
                        int actionState,
                        boolean isCurrentlyActive) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        float alpha = 1 - (Math.abs(dX) / recyclerView.getWidth());
        viewHolder.itemView.setAlpha(alpha);
    }
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
 
Example #29
Source File: ChatAttachAlertPollLayout.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (viewHolder.getItemViewType() != 5) {
        return makeMovementFlags(0, 0);
    }
    return makeMovementFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0);
}
 
Example #30
Source File: BookSourceActivity.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
private void initRecyclerView() {
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));
    adapter = new BookSourceAdapter(this);
    recyclerView.setAdapter(adapter);
    itemTouchCallback = new ItemTouchCallback();
    itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener());
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    setDragEnable(getSort());
}