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

Add support for recyclerview-selection #324

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

you-shimizu
Copy link

    implementation "androidx.recyclerview:recyclerview:1.1.0"
    implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01"

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.

Copy link
Collaborator

@ValCanBuild ValCanBuild left a 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>(
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Copy link
Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add javadocs

Copy link
Author

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() {
Copy link
Collaborator

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.

Copy link
Author

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.

@@ -35,6 +35,7 @@ android {

dependencies {
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01"
Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the code

@you-shimizu
Copy link
Author

Thanks for the review! Please take a look at the changes I made in response to your comments.

@you-shimizu you-shimizu requested a review from ValCanBuild March 31, 2020 05:10
@Zhuinden
Copy link
Collaborator

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. 🤔

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

Successfully merging this pull request may close these issues.

3 participants