power-adapters
power-adapters copied to clipboard
Support ItemDecorations
Add the ability to specify 0+ ItemDecoration
s on a PowerAdapter
:
- Add item decoration methods to
PowerAdapter
- Apply the existing nesting logic when invoking the decoration methods
This would allow the ability to decorate certain ranges of items.
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.
Exactly.
Currently you can use DividerAdapterBuilder
or the Kotlin extension function addDividers
to achieve this. It's got a couple of issues, though:
- It inserts 1 view per divider, which isn't as efficient as drawing them directly
- It only supports vertical orientations at the moment
Awesome!
Any ideas for working backwards from a position?
Not sure what you mean by that. Can you clarify?
Sure. Let's say I have a big list:
- Header
- PowerAdapter A (currently 10 items)
- Header
- PowerAdapter B (currently 5 items)
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.
Ah, gotcha. My thoughts so far are to use the same logic that PowerAdapter
s already use internally to manage the offsets. So the final ItemDecoration
effectively delegates each draw call to the decoration(s) at each nesting level.
Understood. I think it'd be beneficial if that logic could be exposed through a method.