Codewaves / Sticky-Header-Grid

Sticky header grid layout manager for RecycleView
MIT License
116 stars 33 forks source link

Updating data using notifySectionDataSetChanged while multithreading #23

Closed Aaboub closed 5 years ago

Aaboub commented 5 years ago

In calculateSections method, the getSectionCount is called twice: the first time to populate mSections list and the second time to calculate mSectionIndices. This is working fine in case the whole work is done in one thread.

In my case, I had a big number of data to work on and I used several threads to do so and after finishing working on a section, I call the if the notifySectionDataSetChanged to be executed on the UI thread.

In some cases, if the work on the other threads is being processed faster than the UI thread, the values returned by getSectionCount between the first call and the second one, are different:

I/Sticky: section count before : 4 I/Sticky: section : StickyHeaderGridAdapter$Section@25ef8b0d I/Sticky: section : StickyHeaderGridAdapter$Section@3c6a5ac2 I/Sticky: section : StickyHeaderGridAdapter$Section@14fbf0d3 I/Sticky: section : StickyHeaderGridAdapter$Section@8d80410 E/Sticky: section count after : 5

I fixed this by calling the getSectionCount only once.

Codewaves commented 5 years ago

I've added changes to 0.9.7. But layout was not created as thread safe. So be careful.