Sticky header not working with AndroidAnnotations
mathroule opened this issue · comments
I'm using SuperSLiM and AndroidAnnotations in my project. Recycler view with sticky header works correctly with item that extents RecyclerView.ViewHolder
. But if I'm using the AndroidAnnotations way to create view holder (described here: https://github.com/excilys/androidannotations/wiki/Adapters-and-lists#recyclerview-and-viewholder), it doesn't work anymore (the view works correctly, but headers are not sticky).
It's working! Indeed, setting XML attributes to section like this does not work:
app:slm_headerDisplay="inline|sticky"
app:slm_isHeader="true"
Instead setting header attributes in adapter works correctly:
@Override
public void onBindViewHolder(ViewWrapper<View> holder, int position) {
final View itemView = holder.getView();
final GridSLM.LayoutParams layoutParams = GridSLM.LayoutParams.from(itemView.getLayoutParams());
...
// If section type
layoutParams.isHeader = true;
layoutParams.headerDisplay = HEADER_INLINE | HEADER_STICKY;
layoutParams.width = MATCH_PARENT;
...
}
I think XML attributes are not propagated throught itemView.getLayoutParams()
, so indeed this issue is invalid.
The constant private static final int DEFAULT_HEADER_DISPLAY = HEADER_INLINE | HEADER_STICKY;
could be public instead of private? But maybe HEADER_STICKY would not be usefull in next release?
@mathroule Hi there, yes everything is massively different in the new version. Section configuration is no longer buried in layout parameters. It is now explicitly created in the adapter. I don't have any good examples yet, but this is how sections are created and configured (well one way) in the present version5.
Oh yes, as for header and footer configuration. The are now explicit types rather than combining behaviours in a flag. I think it makes things more straightforward as to what you will get.
/* Adapter method which calls into SuperSLiM to register a new section. It returns a
section item which can be added as a child to another section. */
createSection(sectionId,
new LinearSectionConfig(gutterLeft, gutterRight,
SectionConfig.HEADER_STICKY, SectionConfig.FOOTER_STICKY,
paddingLeft, paddingTop, paddingRight, paddingBottom),
headerItem,
footerItem);
The SectionConfig used determines the layout of the section. Configs are immutable, but new ones can be created and assigned to an existing section, triggering the appropriate updates and animations on the display.
For creating the section, only sectionId is required. Appropriate defaults inserted where necessary.
The current adapter does require you to insert items and sections into the adapter. However, I plan to address this in the future and make a simplified adapter with a reduced memory footprint and with which the section graph can be populated without having to insert item placeholders. e.g. You just declare a section with x number of items, and then insert sections into the appropriate child index. However, I see no reason why this initial adapter will go away.
Anyway, I have cleaned up all the old issues not related to the new code base. I've switched to using ZenHub for this project and I wanted a clean slate going forwards. I expect to move version5 over to master over the weekend as the milestone is finished.