CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.31k stars 5.16k forks source link

how to implement swipe left or other direction on this library #122

Closed navotera closed 8 years ago

navotera commented 8 years ago

is it possible to add swipe that showed some view on recycler view using this library and how to setdirection on the swipe event... so user can swipe right or left based on the different listener method

thanks

elfman commented 8 years ago

if you just want to showed some text or bitmap on the side when swiping, you can overwrite the onChildDraw method in the ItemDragAndSwipeCallback.java, but will disappear after release.

 @Overwrite
 public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

    // Fade out the view as it is swiped out of the parent's bounds
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        View itemView = viewHolder.itemView;

        Context context = recyclerView.getContext();
        Paint paint = new Paint();

        Bitmap icon;

        if (dX > 0) {

            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.temp);
            // Set color for right swipe
            paint.setColor(Color.YELLOW);

            // Draw Rect with varying right side, equal to displacement dX
            c.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX,
                    (float) itemView.getBottom(), paint);

            // Set the image icon for right swipe
            c.drawBitmap(icon, (float) itemView.getLeft() + 25, (float) itemView.getTop() +
                    ((float) itemView.getBottom() - (float) itemView.getTop() - icon.getHeight()) / 2, paint);
        }
    }
}
navotera commented 8 years ago

i guess it would be great if on the implementation of OnItemSwipeListener interface there are method listener to know which direction is we need...

by the way thanks a lot sir

elfman commented 8 years ago

If you want to set the direction on the swipe event, you can overwrite the getMovementFlags in ItemDragAndSwipeCallback.java, change the swipeFlag like this int swipeFlags = ItemTouchHelper.START; I will add a public method to do this soon.

navotera commented 8 years ago

what if i need both direction ?

elfman commented 8 years ago

int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;

CymChad commented 8 years ago

compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:v1.8.6' Enable change the drag and swipe movement direction and threshold by setters.

CymChad commented 8 years ago

compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:v1.8.7' Enable draw on the edge when swipe moving

navotera commented 8 years ago

pardon me, i cannot test it yet since i got another things to do, please dont close this issue yet

Thanks

CymChad commented 8 years ago

@navotera ok

CymChad commented 8 years ago

Still no test?When you have problems and open the issue

navotera commented 8 years ago

seems like your documentation on this github on how to use this lib need to update.. since when creating new object from class onItemSwipeListener need to implement another method (onItemSwipeMoving method). ....

i notice two feature on this update :

  1. Enable change the drag and swipe movement direction and threshold by setters.
  2. Enable draw on the edge when swipe moving

sorry sir can u give us example on how to implement that two update.. anyway thanks for your kindly reply.....

elfman commented 8 years ago

You can find the usage in the demo ItemDragAndSwipeUseActivity.java

navotera commented 8 years ago

thanks :+1: :+1: :+1: please close this issues (cannot find button comment and close on this issues)

navotera commented 7 years ago

Much Thank u sir

On Thu, Jul 27, 2017, 18:11 arscree notifications@github.com wrote:

What about swiping to the right? @overwrite https://github.com/overwrite public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

// Fade out the view as it is swiped out of the parent's bounds if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { View itemView = viewHolder.itemView;

Context context = recyclerView.getContext();
Paint paint = new Paint();

Bitmap icon;

if (dX > 0) {

    icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.temp);
    // Set color for right swipe
    paint.setColor(Color.YELLOW);

    // Draw Rect with varying right side, equal to displacement dX
    c.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX,
            (float) itemView.getBottom(), paint);

    // Set the image icon for right swipe
    c.drawBitmap(icon, (float) itemView.getLeft() + 25, (float) itemView.getTop() +
            ((float) itemView.getBottom() - (float) itemView.getTop() - icon.getHeight()) / 2, paint);
}

}

}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/122#issuecomment-318319961, or mute the thread https://github.com/notifications/unsubscribe-auth/ABW903tLyrmvD7fcfug_4uwrG5CqiX-3ks5sSGJLgaJpZM4JCvhJ .