ebarrenechea / header-decor

A couple of sticky header decorations for android's recycler view.
Apache License 2.0
878 stars 159 forks source link

Added ability to have optional headers #32

Closed ghost closed 8 years ago

ghost commented 8 years ago

Greetings!

I added the ability to have optional headers for each item. I had the need to have the first few items be without headers.

I've tested this with 1 item with no header and all other items being in one section with a header.

Cheers! Justin

ebarrenechea commented 8 years ago

Hi Justin, thanks for the contribution! I think StickyHeaderDecoration.java is in the wrong location as it seems to have re-added the entire file. You'll need to move it back to its original location so that the diff works and I can properly check what the code does.

Thanks! :)

ghost commented 8 years ago

Hi, yes sorry about that. For some reason the file ended up in the top level of the repo. Fixed ;)

ghost commented 8 years ago

In Reply To: We determine is we need a header by checking if the header id of the current item is different from the previous item. If we simply check if the id is not -1 then we would end up adding headers to all items, including items that should share a header.

Yes, I found that logic to be problematic. Here are the issues I found with that approach: 1) If forces you to have a header for the first item. This was specifically something I needed to avoid. 2) It stopped working correctly if you had many list items in one section and the section header was "offscreen". In other words, if section 1 had 20 items, only item 1:1 would say "yes I have a header", and if you were displaying 1:10 - 1:20 on screen, then no header would display at all.

The way I implemented it, the adapter has the ability to tell the decorator if the header belongs to any particular section item.

ebarrenechea commented 8 years ago

@justinATfanhero LGTM and I deleted the comment about the header id because I saw how it was being handled in the onDraw method which ends up having the same effect.