luizgrp / SectionedRecyclerViewAdapter

An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
MIT License
1.68k stars 372 forks source link

Can we have a getSectionCount() function, and getSection(int index) function in SectionedRecyclerViewAdapter #152

Closed yccheok closed 5 years ago

yccheok commented 5 years ago

Is your feature request related to a problem? Please describe. Sometimes, number of Sections can changed dynamically, and we need to get Nth Section, to turn on and turn off header. Instead of keeping separate List of Section within the app, it is better if we can get such information directly from SectionedRecyclerViewAdapter

Describe the solution you'd like Provide a getSectionCount() function, and getSection(int index) function in SectionedRecyclerViewAdapter

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Currently, Map<String, Section> sections is being used in SectionedRecyclerViewAdapter. Not sure we need an additional List<Section> sectionList to serve the above purpose.

luizgrp commented 5 years ago

Hi @yccheok, the current alternative to getSectionCount() is getCopyOfSectionsMap().size() but yes, let's add a getSectionCount() with an implementation of sections.size().

Regarding getSection(index), it's a little more complex as sections is currently a LinkedHashMap and it does not track index position. I would look for alternatives from Guava or Apache Commons.

luizgrp commented 5 years ago

Also there is this solution in #28 that I never had time to have a proper look at. Not sure it would be good to have the index in the Section class as proposed there, it would get out of sync if the Section index gets changed and the adapter is not notified.