lisawray / groupie

Groupie helps you display and manage complex RecyclerView layouts.
MIT License
3.67k stars 293 forks source link

Add support for recyclerview-selection #323

Open MihashiHans opened 4 years ago

MihashiHans commented 4 years ago

Thanks a lot for this great library! Enabling selection/multiple selections is kind of tedious and it would be very nice if Groupie took care of the setup to some extent as an option. If this is a feature you would consider, I'd be happy to give it a try.

you-shimizu commented 4 years ago
    public void setSelectionTracker(@Nullable SelectionTracker<Long> selectionTracker) {
        this.selectionTracker = selectionTracker;
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position, @NonNull List<Object> payloads) {
        Item contentItem = getItem(position);
        if (selectionTracker != null) {
            contentItem.bind(holder, position, payloads, onItemClickListener, onItemLongClickListener, selectionTracker.isSelected(contentItem.getId()));
        }else {
            contentItem.bind(holder, position, payloads, onItemClickListener, onItemLongClickListener, false);
        }
    }

@ValCanBuild Implementing this would require adding the above to GroupAdapter.java, GroupieLookup.java, GroupieViewHolder.java, Item.java. If needed I would be more than happy to come up with a PR.

ValCanBuild commented 4 years ago

Implementing this directly in the library means we'd need to depend on the recyclerview-selection library. Would it be more prudent to add support for this via another library? A SelectableItem subclass maybe?

Haven't played with the selection library so am not sure what the best approach for it would be - I welcome PRs, though.