NextFaze / power-adapters

Composable adapters for Android RecyclerViews and ListViews
Apache License 2.0
108 stars 13 forks source link

Support ItemDecorations #38

Open BenTilbrook opened 7 years ago

BenTilbrook commented 7 years ago

Add the ability to specify 0+ ItemDecorations on a PowerAdapter:

This would allow the ability to decorate certain ranges of items.

DSteve595 commented 7 years ago

I'm assuming this is to make it easy and logical to add decorations to only certain parts of the whole list. For example, if the list is comprised of adapter A followed by adapter B, calling A.addItemDecoration(divider) will cause A's items to have a divider, but not B's.

Is that the case? If so, it'd be a great thing to have.

I'd also like to have this sort of logic abstracted out so the "source" of a position can be determined for any reason. In my particular case, I've got a header view followed by a list, and I'm implementing drag-and-drop. I'd like to, with only the list positions old and new, be able to map those to positions in my Data. I don't think this is currently possible (without hardcoding position + headerCount), but I'm still new to the library.

BenTilbrook commented 7 years ago

Exactly.

Currently you can use DividerAdapterBuilder or the Kotlin extension function addDividers to achieve this. It's got a couple of issues, though:

DSteve595 commented 7 years ago

Awesome!

Any ideas for working backwards from a position?

BenTilbrook commented 7 years ago

Not sure what you mean by that. Can you clarify?

DSteve595 commented 7 years ago

Sure. Let's say I have a big list:

Let's say I have some callback that gives me the RecyclerView.Adapter position of an item. If, for example, I get position 15, logically I can determine that the corresponding item belongs to PowerAdapter B and is at position 3. To get that, I had to subtract every item before it (one for the first header, then A's item count, then one for the second header), but that logic would have to be hardcoded for each particular list and would probably get pretty complicated.

This is somewhat related to the issue since that's essentially what ItemDecoration gives you: a view, which intrinsically has a position. Since ItemDecorations can only be added to the whole RecyclerView (as far as I know), the logic above would be needed to determine whether to show the decoration for each position. To do that, I think you'd need to know which adapter each position is a part of.

BenTilbrook commented 7 years ago

Ah, gotcha. My thoughts so far are to use the same logic that PowerAdapters already use internally to manage the offsets. So the final ItemDecoration effectively delegates each draw call to the decoration(s) at each nesting level.

DSteve595 commented 7 years ago

Understood. I think it'd be beneficial if that logic could be exposed through a method.