SwipeActionAdapter with StickyListHeaders
Asked Answered
B

2

6

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?

Berdichev answered 4/8, 2015 at 23:25 Comment(0)
S
1

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

Singspiel answered 7/8, 2015 at 14:36 Comment(9)
hey thanks for the thoughts.. the problem is the Swipe Adapter only takes in a regular "list view", while the "sticky header list view" is it's own object.. any idea on an alternative option while still using it?Berdichev
Hi @Singspiel - was the WrapperView.java the only file you had to modify? I've made the WrapperView extend SwipeViewGroup which is now throwing more errors across the project. Can you provide your fork?Berdichev
Yes sure Ive added my working example at this location : github.com/he667/StickyListSwipeSingspiel
Hey Gomoku7, so i'm able to run the project however the headers aren't remaining sticky in your example. Are you seeing them remain in place on scroll?Berdichev
Also the first item in the view section is swipeable including the section header which isn't right.. hmmmmmBerdichev
Oh i didnt notice that bug. Sorry. I took a look, just disable the setOnScrollListener in the swipeactionadapter. It is managed by the stickylist so it's useless and the swipe doesnt need listviewscrolling. I updated and made some minor modifications in my example project (i wanted to know if i could mix the adapters).Singspiel
Hi @aherick, does it work for you? I use a CursorAdapter and it doesn't show me the background. Swipe work, but without background. If you use a CursorAdapter can you show me your implementation?Mycosis
@Mycosis unfortunately no the implementation was buggy so I've gone a different direction for now. These two libraries just don't want to play well togetherBerdichev
@gomoku7 thanks for the follow up. I was still seeing issues with the headers being swipeable. I just instead implemented stick headers and provided the functionality that swipe was going to handle via clicking on the row and choosing from a dialog. Not optimal but its not critical path for the app at this timeBerdichev
S
1

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.

Stith answered 11/8, 2015 at 18:12 Comment(1)
Hey thanks for the thoughts. So forked and brought the library locally into my project. I'm just not sure exactly what points need to change after extending SwipeViewGroupBerdichev

© 2022 - 2024 — McMap. All rights reserved.