Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwipeActionAdapter with StickyListHeaders

I'm trying to combine these two awesome Android libraries:

https://github.com/emilsjolander/StickyListHeaders

https://github.com/wdullaer/SwipeActionAdapter

I've worked with the SwipeActionAdapter's owner who says it's possible (https://github.com/wdullaer/SwipeActionAdapter/issues/29) but I'm still receiving errors:

08-02 11:33:07.364    1655-1655/com.slaptap.tappedin E/InputEventReceiver﹕ Exception dispatching input event.
08-02 11:33:07.364    1655-1655/com.slaptap.tappedin E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
08-02 11:33:07.380    1655-1655/com.slaptap.tappedin E/MessageQueue-JNI﹕ java.lang.NullPointerException
            at com.wdullaer.swipeactionadapter.SwipeActionTouchListener.onTouch(SwipeActionTouchListener.java:419)
            at android.view.View.dispatchTouchEvent(View.java:7701)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)

I have my Base Adapter wrapped by the Swipe Adapter. I then Have another adapter (ListStickyAdapter) which extends Decorator Adapter and implements Sticky Adapater.

 mAdapter = new ListAdapter(getActivity(), data);
 swipeAdapter = new SwipeActionAdapter(mAdapter);
 ListStickyAdapter vbsa = new ListStickyAdapter(swipeAdapter);
 listView.setAdapter(vbsa);

 // is it because of this line? (having to pass the sticky header child list)
 swipeAdapter.setListView(listView.getWrappedList())

What am I doing wrong here?

like image 756
aherrick Avatar asked Aug 04 '15 23:08

aherrick


2 Answers

It looks like StickyListHeaders is using a very similar approach to SwipeActionAdapter in that it wraps the underlying views and probably overwrites some touchlisteners to do it's job.

Gomoku7 is correct in that you will need to create a fork of StickyListHeaders to make it work. Their wrapper must be the last one due to how the library is done and hence it needs to be aware of the SwipeViewGroup underneath (by extending from that class), just like it needs to be aware of the fact that the underlying View could implement Checkable.

like image 124
wdullaer Avatar answered Sep 28 '22 07:09

wdullaer


Your guess seems correct, it's probably that line :

swipeAdapter.setListView(listView.getWrappedList())

You have an error at line 419 in SwipeActionTouchListener because there is no (down) view group found :

L419 mDownViewGroup.showBackground...

mDownViewGroup is a child view initialized on action down :

 ...
 child = mListView.getChildAt(i);
 child.getHitRect(rect);
 if (rect.contains(x, y)) {
     try {
         mDownViewGroup = (SwipeViewGroup) child;
         ...

I dont know the structure behind the listview.getWrappedList() you provide but my guess is that swipeaction doesn't like it. If it doesn't like it, it's probably because the wrapping remove the children structure (int childCount = mListView.getChildCount(); <- you get childcount = 0, mDownViewGroup is not initialized). Try understanding why the wrapped list remove the child structure and you'll probably get what is happening.

Edit : Searched a little bit more, it seems it's not the fact that it doesnt get the childs but because what it gets are not swipeviewgroup :

java.lang.ClassCastException: se.emilsjolander.stickylistheaders.WrapperView cannot be cast to com.wdullaer.swipeactionadapter.SwipeViewGroup

I managed to make it work by forking and making WrapperView extends SwipeViewGroup (instead of ViewGroup). Also had to protect some touchlistener npe but no big deal here. But that's all it requires.

Working example available here : https://github.com/he667/StickyListSwipe

like image 43
Gomoku7 Avatar answered Sep 28 '22 06:09

Gomoku7