Add support for recyclerview-selection#324
Add support for recyclerview-selection#324you-shimizu wants to merge 3 commits intolisawray:masterfrom
Conversation
ValCanBuild
left a comment
There was a problem hiding this comment.
It's looking promising, I've left a few comments.
One thing I would mention is that we should have an isSelectable property on Item to indicate whether or not it can be selected. This should default to false. Then, we should check for this when selections start happening so that we don't end up selecting such items.
| }) | ||
| } | ||
|
|
||
| tracker = SelectionTracker.Builder<Long>( |
There was a problem hiding this comment.
Adding this tracker to the whole recyclerview in the example breaks it. You should only add selection on the items that can actually be selected. From the looks of it, we should probably change GroupieLookup to only returns items if they can be selected
| } | ||
|
|
||
| public abstract void bind(@NonNull VH viewHolder, int position); | ||
| public abstract void bind(@NonNull VH viewHolder, int position, boolean isSelected); |
There was a problem hiding this comment.
adding isSelected to the main bind function would require everyone who updates to change their code. Instead, create a separate bind function that takes isSelected and pass it false from this one.
| * @param payloads Any payloads (this list may be empty) | ||
| * @param onItemClickListener An optional adapter-level click listener | ||
| * @param onItemLongClickListener An optional adapter-level long click listener | ||
| * @param isSelected |
| return itemView; | ||
| } | ||
|
|
||
| public ItemDetailsLookup.ItemDetails<Long> getItemDetails() { |
There was a problem hiding this comment.
Not sure whether this is the best place for this. Should this instead be on the item so that users can overwrite it? I can imagine us wanting to provide users with a custom selection key.
There was a problem hiding this comment.
Regarding the type of the custom selection key I would like to suggest Long.
library/build.gradle
Outdated
|
|
||
| dependencies { | ||
| implementation "androidx.recyclerview:recyclerview:1.1.0" | ||
| implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01" |
There was a problem hiding this comment.
this should be a compileOnly dependency as we don't want to force it on people.
|
Thanks for the review! Please take a look at the changes I made in response to your comments. |
|
The idea is sound, but RecyclerView-Selection is so intrusive that it should honestly be a separate module, and requires further investigation. Just the other day I tried RecyclerView-Selection and it's a bit of a nightmare to work with, but it does provide drag select multi-selection with touch events. 🤔 |
At this point I am not aware of other libraries specifically addressing selection in recyclerviews, so with the dependencies above the feature should be on the safe side.