daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

Multiple onStartOpen after onOpen if continue dragging #281

Open XSmile2008 opened 8 years ago

XSmile2008 commented 8 years ago

When I open SwipeLayout and continue drag, the new "cycle" start - SurfaceView moved to the start , called onStartOpen, than when I dragged to the end and onOpen called all repeat again. Video: https://youtu.be/ocXpQQqad6Q

Code: //Commented lined is my temp solution, but this solution contains other bugs

public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
            swipeLayout.addDrag(SwipeLayout.DragEdge.Right, bottomViewReserve);
            if (mode == WishListFragment.GIFT_LIST_MODE) swipeLayout.addDrag(SwipeLayout.DragEdge.Left, bottomViewRemove);
            swipeLayout.addSwipeListener(new SimpleSwipeListener() {
                @Override
                public void onOpen(SwipeLayout layout) {
                    Log.d("swipe", "onOpen");
                    if (layout.getDragEdge() == SwipeLayout.DragEdge.Left) {
                        removeWish(getAdapterPosition());
                    } else {
//                        swipeLayout.setSwipeEnabled(false);
//                        swipeLayout.setOnTouchListener(new View.OnTouchListener() {
//                            @Override
//                            public boolean onTouch(View v, MotionEvent event) {
//                                if (event.getAction() == MotionEvent.ACTION_UP) {
//                                    swipeLayout.setSwipeEnabled(true);
//                                    swipeLayout.setOnTouchListener(null);
//                                    Log.d("swipe", "unlocked");
//                                }
//                                return true;
//                            }
//                        });
                    }
                }

                @Override
                public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
                    //Log.d("swipe", "onUpdate");
                    float alpha = Math.abs((float) leftOffset / (float) bottomViewReserve.getWidth());//TODO:
                    layout.getCurrentBottomView().setAlpha(alpha);
                }

                @Override
                public void onStartOpen(SwipeLayout layout) {
                    Log.e("swipe", "onStartOpen");
                    if (swipedItem != null && !swipeLayout.equals(swipedItem)) swipedItem.close();
                    swipedItem = swipeLayout;
                    if (layout.getDragEdge() == SwipeLayout.DragEdge.Right)
                        textViewReserve.setText(wishes.get(getAdapterPosition()).isReserved() ? R.string.action_unreserve : R.string.action_reserve);
                }

                @Override
                public void onClose(SwipeLayout layout) {
                    Log.d("swipe", "onClose");
                    if (swipeLayout.equals(swipedItem)) swipedItem = null;
                }

            });
        }

wish_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <!-- Bottom View Remove Start-->
    <LinearLayout
        android:id="@+id/bottom_view_remove"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingLeft="@dimen/default_padding_large">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_delete_grey_600_24dp" />

        <TextView
            style="@style/MediumText"
            android:layout_marginRight="@dimen/default_margin_medium"
            android:text="@string/action_remove" />

    </LinearLayout>
    <!-- Bottom View Remove End-->

    <!-- Bottom View Reserve Start-->
    <LinearLayout
        android:id="@+id/bottom_view_reserve"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:paddingRight="@dimen/default_padding_large">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_favorite_red_600_24dp" />

        <TextView
            android:id="@+id/text_view_reserve"
            style="@style/MediumText"
            android:layout_marginLeft="@dimen/default_margin_medium"
            android:text="@string/action_reserve" />

    </LinearLayout>
    <!-- Bottom View Reserve End-->

    <!-- Surface View Start -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/cardview_vertical_margin"
            android:layout_marginLeft="@dimen/cardview_horizontal_margin"
            android:layout_marginRight="@dimen/cardview_horizontal_margin"
            android:layout_marginTop="@dimen/cardview_vertical_margin"
            android:elevation="@dimen/cardview_default_elevation">

            <RelativeLayout
                android:id="@+id/layout_header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="@dimen/cardview_padding">

                <ImageView
                    android:id="@+id/image_view"
                    style="@style/AppTheme.CircleImageView.Large"
                    android:layout_marginRight="@dimen/cardview_horizontal_margin" />

                <TextView
                    android:id="@+id/text_view_title"
                    style="@style/MediumText"
                    android:layout_toRightOf="@+id/image_view" />

                <TextView
                    android:id="@+id/text_view_comment"
                    style="@style/SmallText"
                    android:layout_below="@+id/text_view_title"
                    android:layout_toRightOf="@+id/image_view"
                    android:ellipsize="end" />

                <TextView
                    android:id="@+id/text_view_status"
                    style="@style/SmallText"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:textAllCaps="true" />

            </RelativeLayout>

        </android.support.v7.widget.CardView>

    </FrameLayout>
    <!-- Surface View End -->

</com.daimajia.swipe.SwipeLayout>