Skip to content

Add support for recyclerview-selection#324

Open
you-shimizu wants to merge 3 commits intolisawray:masterfrom
you-shimizu:recyclerview-selection
Open

Add support for recyclerview-selection#324
you-shimizu wants to merge 3 commits intolisawray:masterfrom
you-shimizu:recyclerview-selection

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.

})
}

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

* @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

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.


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