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

[5.0.0-b6] Duplicate SubItems when starting with expanded Headers #95

Closed
bornest opened this issue Jun 2, 2016 · 3 comments
Closed

Comments

@bornest
Copy link

bornest commented Jun 2, 2016

I've encountered an interesting bug:

if Header is set to be Expanded in constructor or at any time before it's passed to Adapter,
its SubItems are duplicated (and sometimes tripled) when displayed.
[I've checked the list that I pass to updateDataSet() - it has no duplicates]
If you collapse this header and expand it again, duplicates disappear.
But if it is the last header in the list, the app crashes when you try to collapse it
with following exception
FATAL EXCEPTION: main Process: , PID: 12372 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{1630a510 position=44 id=-1, oldPos=45, pLpos:45 scrap [attachedScrap] tmpDetached no parent} at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4505) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4636) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574) at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2979) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2904) at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1482) at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:147) at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:294) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:549) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5294) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)

And if you set the Header to be Collapsed in constructor or at any time before it's passed to Adapter,
there are no duplicate SubItems and everything is OK.

(I wonder why example app doesn't have this issue)

@davideas davideas mentioned this issue Jun 3, 2016
@davideas
Copy link
Owner

davideas commented Jun 3, 2016

@bornest, can you enable debug log, and post here it?
The initial expand is made in initializeItems() then as you said, in the demo app there's no duplication, some difference in your code exists.

Also in the demo app the collapsed header last item works fine.
I just changed to false in the constructor of my ExpandableHeaderItem the expanded attribute with setExpanded();

@bornest
Copy link
Author

bornest commented Jun 3, 2016

I call setExpanded(true); in my ExpandableHeaderItem constructor.
After that I don't expand/collapse headers anywhere in code, I just click on screen.

Here's the log of my Fragment creation and initialization (from click on navigation drawer item till everything is loaded):

- 06-03 19:34:58.849 29772-29772/com.apps.myapp V/ScheduleListFragment: constructor
- 06-03 19:34:58.859 29772-29772/com.apps.myapp V/ScheduleListFragment: onCreate null
- 06-03 19:34:58.879 29772-29772/com.apps.myapp V/NewsListFragment: onPause
- 06-03 19:34:58.879 29772-29772/com.apps.myapp V/NewsListFragment: onStop
- 06-03 19:34:58.879 29772-29772/com.apps.myapp V/NewsListPresenter: onDropView
- 06-03 19:34:58.879 29772-29772/com.apps.myapp V/NewsListFragment: onDestroyView
- 06-03 19:34:58.889 29772-29772/com.apps.myapp V/NewsListPresenter: onDestroy
- 06-03 19:34:58.889 29772-29772/com.apps.myapp V/NewsListFragment: onDestroy
- 06-03 19:34:58.899 29772-29772/com.apps.myapp V/ScheduleListFragment: onViewCreated
- 06-03 19:34:58.899 29772-29772/com.apps.myapp V/ScheduleListPresenter: constructor
- 06-03 19:34:58.909 29772-29772/com.apps.myapp V/ScheduleListPresenter: onCreate
- 06-03 19:34:58.909 29772-29772/com.apps.myapp V/ScheduleListFragment: onActivityCreated
- 06-03 19:34:58.929 29772-29772/com.apps.myapp V/ScheduleListFragment: onStart
- 06-03 19:34:58.939 29772-29772/com.apps.myapp V/ScheduleListPresenter: onTakeView
- 06-03 19:34:58.939 29772-29772/com.apps.myapp V/ScheduleListFragment: onResume
- 06-03 19:34:58.939 29772-29772/com.apps.myapp V/NewsListPresenter: constructor
- 06-03 19:34:58.939 29772-29772/com.apps.myapp V/NewsListPresenter: onCreate
- 06-03 19:34:58.939 29772-29772/com.apps.myapp V/NewsListPresenter: onDestroy
- 06-03 19:34:59.009 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals total out=0 in=0
- 06-03 19:34:59.009 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions total out=0 in=0
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals total out=0 in=3
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions  add position=0 item=EventFlexibleHeaderItem[Mon 08/02/2016//SubItems[EventFlexibleItem{id='5c42ca85-5f97-4345-9c53-a5a300d55b46'_title='Лабораторная работа №1'}]]
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions  add position=1 item=EventFlexibleHeaderItem[Mon 04/04/2016//SubItems[EventFlexibleItem{id='dfa4290d-cde8-4dc5-9eb9-a5de01155c13'_title='filterTest комп зр'}]]
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions  add position=2 item=EventFlexibleHeaderItem[Sun 24/04/2016//SubItems[EventFlexibleItem{id='a4889130-dedc-456f-a375-a5f400fd1844'_title='ept3'}]]
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions total out=0 in=3
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 0
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=1 itemCount=1
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 2
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=3 itemCount=1
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 4
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=5 itemCount=1
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 0
- 06-03 19:34:59.019 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=1 itemCount=1
- 06-03 19:34:59.029 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 3
- 06-03 19:34:59.029 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=4 itemCount=1
- 06-03 19:34:59.029 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 6
- 06-03 19:34:59.029 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=7 itemCount=1
- 06-03 19:34:59.039 29772-29772/com.apps.myapp I/FlexibleAdapter: Mapped viewType 2130968690 from EventFlexibleHeaderItem
- 06-03 19:34:59.049 29772-29772/com.apps.myapp I/FlexibleAdapter: Mapped viewType 2130968651 from EventFlexibleItem
- 06-03 19:34:59.079 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=8 item=EventFlexibleItem{id='a4889130-dedc-456f-a375-a5f400fd1844'_title='ept3'}
- 06-03 19:34:59.079 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=7 item=EventFlexibleItem{id='a4889130-dedc-456f-a375-a5f400fd1844'_title='ept3'}
- 06-03 19:34:59.079 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=6 item=EventFlexibleHeaderItem[Sun 24/04/2016//SubItems[EventFlexibleItem{id='a4889130-dedc-456f-a375-a5f400fd1844'_title='ept3'}]]
- 06-03 19:34:59.079 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=5 item=EventFlexibleItem{id='dfa4290d-cde8-4dc5-9eb9-a5de01155c13'_title='filterTest комп зр'}
- 06-03 19:34:59.079 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=4 item=EventFlexibleItem{id='dfa4290d-cde8-4dc5-9eb9-a5de01155c13'_title='filterTest комп зр'}
- 06-03 19:34:59.079 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=3 item=EventFlexibleHeaderItem[Mon 04/04/2016//SubItems[EventFlexibleItem{id='dfa4290d-cde8-4dc5-9eb9-a5de01155c13'_title='filterTest комп зр'}]]
- 06-03 19:34:59.089 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=2 item=EventFlexibleItem{id='5c42ca85-5f97-4345-9c53-a5a300d55b46'_title='Лабораторная работа №1'}
- 06-03 19:34:59.089 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=1 item=EventFlexibleItem{id='5c42ca85-5f97-4345-9c53-a5a300d55b46'_title='Лабораторная работа №1'}
- 06-03 19:34:59.089 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals remove position=0 item=EventFlexibleHeaderItem[Mon 08/02/2016//SubItems[EventFlexibleItem{id='5c42ca85-5f97-4345-9c53-a5a300d55b46'_title='Лабораторная работа №1'}]]
- 06-03 19:34:59.089 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals total out=9 in=0
- 06-03 19:34:59.089 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions total out=0 in=0
- 06-03 19:34:59.109 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals total out=0 in=0
- 06-03 19:34:59.109 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions total out=0 in=0
- 06-03 19:34:59.109 29772-29772/com.apps.myapp V/FlexibleAdapter: animateRemovals total out=0 in=3
- 06-03 19:34:59.109 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions  add position=0 item=EventFlexibleHeaderItem[Mon 08/02/2016//SubItems[EventFlexibleItem{id='5c42ca85-5f97-4345-9c53-a5a300d55b46'_title='Лабораторная работа №1'}]]
- 06-03 19:34:59.109 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions  add position=1 item=EventFlexibleHeaderItem[Mon 04/04/2016//SubItems[EventFlexibleItem{id='dfa4290d-cde8-4dc5-9eb9-a5de01155c13'_title='filterTest комп зр'}]]
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions  add position=2 item=EventFlexibleHeaderItem[Sun 24/04/2016//SubItems[EventFlexibleItem{id='a4889130-dedc-456f-a375-a5f400fd1844'_title='ept3'}]]
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: animateAdditions total out=0 in=3
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 0
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=1 itemCount=1
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 2
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=3 itemCount=1
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 4
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=5 itemCount=1
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 0
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=1 itemCount=1
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 3
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=4 itemCount=1
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 6
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=7 itemCount=1
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 0
- 06-03 19:34:59.119 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=1 itemCount=1
- 06-03 19:34:59.129 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 4
- 06-03 19:34:59.129 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=5 itemCount=1
- 06-03 19:34:59.129 29772-29772/com.apps.myapp V/FlexibleAdapter: Initially expand item on position 8
- 06-03 19:34:59.129 29772-29772/com.apps.myapp V/FlexibleAdapter: addItems on position=9 itemCount=1

And here's the log of what happens when I try to collapse the last header:

- 06-03 19:36:15.639 29772-29772/com.apps.myapp V/FlexibleAdapter: Request to Collapse on position 8 ExpandedItems=[0, 4, 8]
- 06-03 19:36:15.639 29772-29772/com.apps.myapp V/FlexibleAdapter: Collapsed 1 subItems on position=8 ExpandedItems=[0, 4]
- 06-03 19:36:15.639 29772-29772/com.apps.myapp V/FlexibleViewHolder: onClick on position 8 mode=0
- 06-03 19:36:15.649 29772-29772/com.apps.myapp D/AndroidRuntime: Shutting down VM

06-03 19:36:15.649 29772-29772/com.apps.myapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.apps.myapp, PID: 29772 java.lang.IndexOutOfBoundsException:
Inconsistency detected. Invalid view holder adapter positionViewHolder{2fb434ac position=9 id=-1, oldPos=10, pLpos:10 scrap [attachedScrap] tmpDetached no parent}
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4505)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4636)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at
android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2979)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2904)
at ...

@davideas
Copy link
Owner

davideas commented Jun 4, 2016

@bornest, could you also give the part of the code with all the calls of the Adapter when you start the Activity?

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

No branches or pull requests

2 participants