Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ItemDecorations #38

Open
BenTilbrook opened this issue Apr 6, 2017 · 7 comments
Open

Support ItemDecorations #38

BenTilbrook opened this issue Apr 6, 2017 · 7 comments
Assignees

Comments

@BenTilbrook
Copy link
Collaborator

Add the ability to specify 0+ ItemDecorations 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.

@BenTilbrook BenTilbrook self-assigned this Apr 6, 2017
@DSteve595
Copy link

DSteve595 commented May 1, 2017

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
Copy link
Collaborator Author

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

@DSteve595
Copy link

Awesome!

Any ideas for working backwards from a position?

@BenTilbrook
Copy link
Collaborator Author

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

@DSteve595
Copy link

DSteve595 commented May 1, 2017

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.

@BenTilbrook
Copy link
Collaborator Author

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants