Java Code Examples for androidx.recyclerview.widget.ItemTouchHelper#RIGHT

The following examples show how to use androidx.recyclerview.widget.ItemTouchHelper#RIGHT . 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: MessagesActivity.java    From android with MIT License 6 votes vote down vote up
public SwipeToDeleteCallback(ListMessageAdapter adapter) {
    super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
    this.adapter = adapter;

    int backgroundColorId =
            ContextCompat.getColor(MessagesActivity.this, R.color.swipeBackground);
    int iconColorId = ContextCompat.getColor(MessagesActivity.this, R.color.swipeIcon);

    Drawable drawable =
            ContextCompat.getDrawable(MessagesActivity.this, R.drawable.ic_delete);
    icon = null;
    if (drawable != null) {
        icon = DrawableCompat.wrap(drawable.mutate());
        DrawableCompat.setTint(icon, iconColorId);
    }

    background = new ColorDrawable(backgroundColorId);
}
 
Example 2
Source File: ItemMoveCallback.java    From RecyclerViewHelper with Apache License 2.0 6 votes vote down vote up
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView,
                            @NonNull RecyclerView.ViewHolder viewHolder) {
    // Set movement flags based on the layout manager.
    int swipeFlags = 0;
    int dragFlags;
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN
                | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    } else {
        if (mIsFreedom) {
            dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN
                    | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
        } else {
            dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        }
    }
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 3
Source File: QueryItemTouchHelper.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
@Override
public int getSwipeDirs(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
    if (viewHolder instanceof ThreadOverviewAdapter.ThreadOverviewViewHolder) {
        final ThreadOverviewAdapter.ThreadOverviewViewHolder threadOverviewViewHolder = (ThreadOverviewAdapter.ThreadOverviewViewHolder) viewHolder;
        if (onQueryItemSwipe != null) {
            final Swipable swipable = onQueryItemSwipe.onQueryItemSwipe(viewHolder.getAdapterPosition());
            if (swipable == Swipable.NO) {
                return 0;
            }
            @DrawableRes final int resource;
            switch (swipable) {
                case ARCHIVE:
                    resource = R.drawable.ic_archive_white_24dp;
                    break;
                case REMOVE_FLAGGED:
                    resource = R.drawable.ic_star_border_white_24dp;
                    break;
                default:
                    resource = R.drawable.ic_label_off_white_24dp;
                    break;

            }
            threadOverviewViewHolder.binding.endSwipeActionIndicator.setImageResource(resource);
            threadOverviewViewHolder.binding.startSwipeActionIndicator.setImageResource(resource);
            return ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT;
        }
    }
    return 0;
}
 
Example 4
Source File: ItemSwipeCallback.java    From RecyclerViewHelper with Apache License 2.0 5 votes vote down vote up
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView,
                            @NonNull RecyclerView.ViewHolder viewHolder) {
    // Set movement flags.
    int dragFlags = 0;
    int swipeFlags;
    if (mOrientation == LinearLayout.HORIZONTAL) {
        swipeFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
    } else {
        swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    }
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 5
Source File: ItemTouchHelperCallback.java    From FastLib with Apache License 2.0 5 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    //上下拖拽
    int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
    //向右侧滑
    int swipeFlags = ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT;
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 6
Source File: PeekabooTouchHelperCallback.java    From materialistic with Apache License 2.0 5 votes vote down vote up
PeekabooTouchHelperCallback(Context context) {
    super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
    mDefaultTextColor = ContextCompat.getColor(context,
            AppUtils.getThemedResId(context, android.R.attr.textColorPrimary));
    mPaint.setTextSize(context.getResources().getDimensionPixelSize(R.dimen.text_size_small));
    mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
    mPadding = context.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
}
 
Example 7
Source File: ItemTouchHelperCallback.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int dragFlags;
    int swipeFlags;
    // Set movement flags based on the Layout Manager and Orientation
    if (layoutManager instanceof GridLayoutManager || layoutManager instanceof StaggeredGridLayoutManager) {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
        swipeFlags = 0;
    } else if (LayoutUtils.getOrientation(recyclerView) == LinearLayoutManager.HORIZONTAL) {
        dragFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
        swipeFlags = mSwipeFlags > 0 ? mSwipeFlags : ItemTouchHelper.UP | ItemTouchHelper.DOWN;
    } else {
        dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        swipeFlags = mSwipeFlags > 0 ? mSwipeFlags : ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    }
    // Disallow item swiping or dragging
    if (viewHolder instanceof ViewHolderCallback) {
        ViewHolderCallback viewHolderCallback = (ViewHolderCallback) viewHolder;
        if (!viewHolderCallback.isDraggable()) {
            dragFlags = 0;
        }
        if (!viewHolderCallback.isSwipeable()) {
            swipeFlags = 0;
        }
    }
    return makeMovementFlags(dragFlags, swipeFlags);
}
 
Example 8
Source File: ItemTouchHelperCallback.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@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 &&
            viewHolder instanceof ViewHolderCallback) {

        // Update visibility for RearViews - Convert to custom VH
        ViewHolderCallback viewHolderCallback = (ViewHolderCallback) viewHolder;
        View frontView = viewHolderCallback.getFrontView();

        // Orientation independent
        float dragAmount = dX;
        if (dY != 0) {
            dragAmount = dY;
        }

        // Manage opening - Is Left or Right View?
        int swipingDirection = 0;//0 is to reset the frontView
        if (dragAmount > 0) {
            swipingDirection = ItemTouchHelper.RIGHT;//DOWN
        } else if (dragAmount < 0) {
            swipingDirection = ItemTouchHelper.LEFT;//TOP
        }

        setLayoutVisibility(viewHolderCallback, swipingDirection);
        // Translate the FrontView
        getDefaultUIUtil().onDraw(c, recyclerView, frontView, dX, dY, actionState, isCurrentlyActive);

    } else {
        super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    }
}
 
Example 9
Source File: ConversationListFragment.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
ArchiveListenerCallback() {
  super(0, ItemTouchHelper.RIGHT);
}
 
Example 10
Source File: QueryItemTouchHelper.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
public QueryItemTouchHelper() {
    super(0, ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT);
}
 
Example 11
Source File: DownloadFileItemHelperCallback.java    From Audinaut with GNU General Public License v3.0 4 votes vote down vote up
public DownloadFileItemHelperCallback(SubsonicFragment fragment, boolean mainList) {
    super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
    this.fragment = fragment;
    this.mainList = mainList;
}
 
Example 12
Source File: RecyclerViewExampleActivity.java    From realm-android-adapters with Apache License 2.0 4 votes vote down vote up
TouchHelperCallback() {
    super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
}
 
Example 13
Source File: SimpleItemTouchHelperCallback.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
	int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
	return makeMovementFlags(dragFlags, 0);
}
 
Example 14
Source File: AccessLogActivity.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * コンストラクタ.
 * @param context コンテキスト
 */
SwipeToDeleteCallback(Context context) {
    super(0, (ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT));
    mDeleteIcon = ContextCompat.getDrawable(context, android.R.drawable.ic_menu_delete);
    mBackground = new ColorDrawable(Color.rgb(235, 55, 35));
}
 
Example 15
Source File: MainActivity.java    From FlexibleAdapter with Apache License 2.0 4 votes vote down vote up
@Override
public void onItemSwipe(final int position, int direction) {
    Log.i("onItemSwipe position=%s direction=%s", position, (direction == ItemTouchHelper.LEFT ? "LEFT" : "RIGHT"));

    // FULL_SWIPE: Direct action no Undo Action.
    // Do something based on direction when item has been swiped:
    //   1) optional: update item, set "read" if an email, etc..
    //   2) remove the item from the adapter

    // Create list for single position (only in onItemSwipe)
    List<Integer> positions = Collections.singletonList(position); // This is an immutable list and cannot be sort!
    // Build the message
    IFlexible abstractItem = mAdapter.getItem(position);
    StringBuilder message = new StringBuilder();
    message.append(extractTitleFrom(abstractItem)).append(" ");
    // Experimenting NEW feature
    if (abstractItem.isSelectable())
        mAdapter.setRestoreSelectionOnUndo(false);

    // Perform different actions
    // Here, option 1) is implemented
    if (direction == ItemTouchHelper.LEFT) {
        message.append(getString(R.string.action_archived));

        // Example of UNDO color
        int actionTextColor;
        if (Utils.hasMarshmallow()) {
            actionTextColor = getColor(R.color.material_color_orange_500);
        } else {
            //noinspection deprecation
            actionTextColor = getResources().getColor(R.color.material_color_orange_500);
        }

        mAdapter.setPermanentDelete(false);
        new UndoHelper(mAdapter, this)
                .withPayload(Payload.CHANGE)          // You can provide any custom object
                .withConsecutive(false)               // Keep all previous archived items until time out
                .withAction(UndoHelper.Action.UPDATE) // Specify the action
                .withActionTextColor(actionTextColor) // Change color of the action text
                .start(positions, findViewById(R.id.main_view), R.string.action_archived,
                        R.string.undo, UndoHelper.UNDO_TIMEOUT);

        // Here, option 2) is implemented
    } else if (direction == ItemTouchHelper.RIGHT) {
        // Prepare for next deletion
        message.append(getString(R.string.action_deleted));
        mRefreshHandler.sendEmptyMessage(REFRESH_START);
        mAdapter.setPermanentDelete(false);

        new UndoHelper(mAdapter, this)
                .withPayload(null)     // You can provide any custom object
                .withConsecutive(true) // Commit the previous action
                .start(positions, findViewById(R.id.main_view), message,
                        getString(R.string.undo), UndoHelper.UNDO_TIMEOUT);

        // Handle ActionMode title
        if (mAdapter.getSelectedItemCount() == 0) {
            mActionModeHelper.destroyActionModeIfCan();
        } else {
            mActionModeHelper.updateContextTitle(mAdapter.getSelectedItemCount());
        }
    }
}