Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes two cards on double click and swipe. #28

Open
Martinch0 opened this issue Dec 17, 2014 · 1 comment
Open

Removes two cards on double click and swipe. #28

Martinch0 opened this issue Dec 17, 2014 · 1 comment

Comments

@Martinch0
Copy link

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?

@Diolor
Copy link
Owner

Diolor commented Dec 19, 2014

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants