Swipecards icon indicating copy to clipboard operation
Swipecards copied to clipboard

Removes two cards on double click and swipe.

Open Martinch0 opened this issue 11 years ago • 1 comments

I have just tried out the library and it looks really cool. However, there is something that I don't like and would like to fix it. I followed the example from https://github.com/Diolor/Swipecards/blob/master/example/src/main/java/com/lorentzos/swipecards/MyActivity.java

When I double click on a card and swipe (even sometimes one click and swipe), I get a null pointer exception in the onScroll method. Tried removing it and now when I do a double click and swipe, two cards disappear at once. The error I got was:

12-17 20:55:20.702    2283-2283/com.testproject  E/InputEventReceiver﹕ Exception dispatching input event.
12-17 20:55:20.702    2283-2283/com.testproject  E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
12-17 20:55:20.702    2283-2283/com.testproject  E/MessageQueue-JNI﹕ java.lang.NullPointerException

And when I tried just to print what was happening. I got:

12-17 21:00:15.218    2370-2370/com.testproject D/LIST﹕ Scroll: 0.27310812
12-17 21:00:15.234    2370-2370/com.testproject D/LIST﹕ Scroll: 0.5979347
12-17 21:00:15.250    2370-2370/com.testproject D/LIST﹕ Scroll: 1.0
12-17 21:00:15.266    2370-2370/com.testproject D/LIST﹕ Scroll: 1.0
12-17 21:00:15.266    2370-2370/com.testproject D/LIST﹕ removed object!
12-17 21:00:15.266    2370-2370/com.testproject D/LIST﹕ Right!
12-17 21:00:15.266    2370-2370/com.testproject D/LIST﹕ Scroll: 1.0
12-17 21:00:15.386    2370-2370/com.testproject D/LIST﹕ removed object!
12-17 21:00:15.386    2370-2370/com.testproject D/LIST﹕ Right!

It seems like a really simple bug, but it is annoying and I would like some help on how I can fix it. Looks like the removeFirstObjectInAdapter function get called twice. A really simple fix would be to change it to something like:

            public void removeFirstObjectInAdapter() {
                // this is the simplest way to delete an object from the Adapter (/AdapterView)
                long time = System.currentTimeMillis();
                if (time - last_delete > 200) {
                    Log.d("LIST", "removed object!");
                    al.remove(0);
                    last_delete = time;
                }
                arrayAdapter.notifyDataSetChanged();
            }

However, it doesn't look very reliable. Please help me fix this?

Martinch0 avatar Dec 17 '14 21:12 Martinch0

Hey @Martinch0 and thanks for reporting this. onScroll was implemented via pull request and I didn't have the time since then to optimize and test as much I would liked to do so.

I would highly refrain you from using these kind of solutions unless you really want to throttle the behavior for 200ms :)

FlingCardListener has all the logic of the animations. A simple solution with the current architecture would have been to "block" the clicks, in reality instead of blocking the clicks just "to do nothing" until the next card is fully available (probably just catching the nulls).

Diolor avatar Dec 19 '14 20:12 Diolor