-
Notifications
You must be signed in to change notification settings - Fork 293
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
Add support for recyclerview-selection #324
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -102,6 +92,16 @@ class MainActivity : AppCompatActivity() { | |||
}) | |||
} | |||
|
|||
tracker = SelectionTracker.Builder<Long>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the code
@@ -40,16 +41,18 @@ public VH createViewHolder(@NonNull View itemView) { | |||
* @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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add javadocs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the code
@@ -94,4 +95,19 @@ public Item getItem() { | |||
public View getRoot() { | |||
return itemView; | |||
} | |||
|
|||
public ItemDetailsLookup.ItemDetails<Long> getItemDetails() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the type of the custom selection key I would like to suggest Long.
library/build.gradle
Outdated
@@ -35,6 +35,7 @@ android { | |||
|
|||
dependencies { | |||
implementation "androidx.recyclerview:recyclerview:1.1.0" | |||
implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a compileOnly
dependency as we don't want to force it on people.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the code
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.