👇 Easy Google Photos style multi-selection for RecyclerViews, powered by Kotlin and AndroidX.

Overview

Drag Select Recycler View

Maven Central Android CI License

This library allows you to implement Google Photos style multi-selection in your apps! You start by long pressing an item in your list, then you drag your finger without letting go to select more.

Range Mode GIF

Sample

You can download a sample APK.


Gradle Dependency

The Gradle dependency is available via jCenter. jCenter is the default Maven repository used by Android Studio.

Dependency

Add the following to your module's build.gradle file:

dependencies {

  implementation 'com.afollestad:drag-select-recyclerview:2.4.0'
}

Introduction

DragSelectTouchListener is the main class of this library.

This library will handle drag interception and auto scroll logic - if you drag to the top of the RecyclerView, the list will scroll up, and vice versa.


DragSelectTouchListener

Basics

DragSelectTouchListener attaches to your RecyclerViews. It intercepts touch events when it's active, and reports to a receiver which handles updating UI

val receiver: DragSelectReceiver = // ...
val touchListener = DragSelectTouchListener.create(context, receiver)

Configuration

There are a few things that you can configure, mainly around auto scroll.

DragSelectTouchListener.create(context, adapter) {
  // Configure the auto-scroll hotspot
  hotspotHeight = resources.getDimensionPixelSize(R.dimen.default_56dp)
  hotspotOffsetTop = 0 // default
  hotspotOffsetBottom = 0 // default
  
  // Listen for auto scroll start/end
  autoScrollListener = { isScrolling -> } 

  // Or instead of the above...
  disableAutoScroll()
  
  // The drag selection mode, RANGE is the default
  mode = RANGE
}

The auto-scroll hotspot is a invisible section at the top and bottom of your RecyclerView, when your finger is in one of those sections, auto scroll is triggered and the list will move up or down until you lift your finger.

If you use PATH as the mode instead of RANGE, the behavior is a bit different:

Path Mode GIF

Compare it to the GIF at the top.


Interaction

A receiver looks like this:

class MyReceiver : DragSelectReceiver {

  override fun setSelected(index: Int, selected: Boolean) {
    // do something to mark this index as selected/unselected
    if(selected && !selectedIndices.contains(index)) {
      selectedIndices.add(index)
    } else if(!selected) {
      selectedIndices.remove(index)
    }
  }
  
  override fun isSelected(index: Int): Boolean {
    // return true if this index is currently selected
    return selectedItems.contains(index)
  }
  
  override fun isIndexSelectable(index: Int): Boolean {
    // if you return false, this index can't be used with setIsActive()
    return true
  }

  override fun getItemCount(): Int {
    // return size of your data set
    return 0
  }
}

In the sample project, our adapter is also our receiver.

To start drag selection, you use setIsActive, which should be triggered from user input such as a long press on a list item.

val recyclerView: RecyclerView = // ...
val receiver: DragSelectReceiver = // ...

val touchListener = DragSelectTouchListener.create(context, receiver)
recyclerView.addOnItemTouchListener(touchListener) // important!!

// true for active = true, 0 is the initial selected index
touchListener.setIsActive(true, 0)
Comments
  • Fix for an unexpected behavior when selecting

    Fix for an unexpected behavior when selecting

    The method RecyclerView#getAdapterPosition()returns NO_POSITION until the next layout pass when RecyclerView.Adapter#notifyDataSetChanged() has been called.

    The code on //Drag selection logic was assuming that the value of itemPosition woud be -2 or the index of the pressed item, but if notifyDataSetChanged() had been called, it was passing the conditional with the value NO_POSITION for itemPosition, and therefore selecting the whole range from -1 to the pressed item.

    This was causing the next behavior in some situations.

    selection-error

    The code to replicate the error can be found on 36e2910ca9e3152e37c1e0be363ad75f34b1a76f.

    opened by Carlosph 2
  • Stop drag selection after ACTION_UP on edge case

    Stop drag selection after ACTION_UP on edge case

    As commented on the issue thread #34, the drag selection was not terminated when the user started it with a long press but didn't move the finger before the ACTION_UP event.

    The proposed solution is to terminate the drag selection when an ACTION_UP event is detected in either the onTouchEvent or onInterceptTouchEvent.

    opened by Carlosph 0
  • add selectAll() method

    add selectAll() method

    when adapter data is large, selecting all by using selectRange() method calls too much SelectionListener and makes the UI not response. So I add selectAll() method for less calling the listener callback, firing the listener only once.

    opened by ccl1115 0
  • Using helper classes and interfaces to provide drag selection functio…

    Using helper classes and interfaces to provide drag selection functio…

    …nality instead of using inheritance that is not that flexible when user of library multiple wants to implement multiple recycler view features at once.

    opened by MartinRajniak 0
  • Improved items selectability check, and stop scrolling when an item is not selectable

    Improved items selectability check, and stop scrolling when an item is not selectable

    Main changes:

    • removed getItemCount (was not used at all)
    • renamed isIndexSelectable to isSelectable for consistency
    • check items selectable also during selection, not only at first selection
    • stop drag to select when an item cannot be selected
    • added a DragToSelectListener in order to monitor activation/deactivation of drag to select
    opened by ccodega 0
Releases(2.4.0)
Owner
Aidan Follestad
25 years old. Senior Android Engineer @square. Apple fan. Full stack (Android, iOS, web, backend). Triumph Street Triple RS, Tesla Model 3. Gamer (PS5). Metal.
Aidan Follestad
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
*** WARNING: This library is no longer maintained *** An easy way to add a simple 'swipe-and-do-something' behavior to your `RecyclerView` items. Just like in Gmail or Inbox apps.

SwipeToAction An easy way to add a simple 'swipe-and-do-something' behavior to your RecyclerView items. Just like in Gmail or Inbox apps. Integration

Victor Calvello 223 Nov 16, 2022
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
Kotlin way of building RecyclerView Adapter 🧩. You do not have to write RecyclerView Adapters again and again and suffer from handling of different view types. Kiel will help you.

Kiel Kiel is a RecyclerView.Adapter with a minimalistic and convenient Kotlin DSL which provides utility on top of Android's normal RecyclerView.Adapt

ibrahim yilmaz 370 Jan 2, 2023
A modified version of Android's experimental StaggeredGridView. Includes own OnItemClickListener and OnItemLongClickListener, selector, and fixed position restore.

StaggeredGridView Introduction This is a modified version of Android's experimental StaggeredGridView. The StaggeredGridView allows the user to create

Maurycy Wojtowicz 1.7k Nov 28, 2022
Android library to display a ListView whose cells are not rigid but flabby and react to ListView scroll.

FlabbyListView This library is not maintained anymore and there will be no further releases Android library to display a ListView which cells are not

JPARDOGO 762 Nov 23, 2022
An Android custom ListView and ScrollView with pull to zoom-in.

PullZoomView An Android custom ListView and ScrollView with pull to zoom-in. Features Set ZoomView enable Add HeaderView Custom ZoomView Parallax or N

Frank-Zhu 2.3k Dec 26, 2022
Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span

AsymmetricGridView An Android custom ListView that implements multiple columns and variable sized elements. Please note that this is currently in a pr

Felipe Lima 1.8k Jan 7, 2023
Drag and drop GridView for Android

DynamicGrid Drag and drop GridView for Android. Depricated It's much better to use solutions based on recycler view. For example https://github.com/h6

Alex Askerov 920 Dec 2, 2022
A GridView which can addHeaderView and addFooterView

Please follow me on GitHub, I need your support Github: https://github.com/liaohuqiu twitter: https://twitter.com/liaohuqiu 中文版文档 GridView with Header

Huqiu Liao 1.3k Nov 30, 2022
A drag-and-drop scrolling grid view for Android

DraggableGridView¶ ↑ a drag-and-drop scrolling grid view for Android Including in your project¶ ↑ To start using DraggableGridView: Place libs/Draggab

Tom Quinn 565 Dec 27, 2022
It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

Shutter-Android It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android. What is Shutter? Shutter is an Androi

Levi Bostian 56 Oct 3, 2022
It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android.

Shutter-Android It's finally easy to take photos/videos via camera or get photos/videos from gallery on Android. What is Shutter? Shutter is an Androi

Levi Bostian 56 Oct 3, 2022
Android Spinner Dialog Library supported on both Java and Kotlin, Use for single or multi selection of choice

SpinnerDialog Android Spinner Dialog Library, Use for single or multi selection of choice Android UI Download To include SpinnerDialog in your project

Hamza Khan 55 Sep 15, 2022
Dividers is a simple Android library to create easy separators for your RecyclerViews

Dividers Dividers is an Android library to easily create separators for your RecyclerViews. It supports a wide range of dividers from simple ones, tha

Karumi 490 Dec 28, 2022
Dividers is a simple Android library to create easy separators for your RecyclerViews

Dividers Dividers is an Android library to easily create separators for your RecyclerViews. It supports a wide range of dividers from simple ones, tha

Karumi 490 Dec 28, 2022
Fontize is an Android library that enables multi-font selection functionality to diversify your app.

Fontize Android Library Built with ❤︎ by Gourav Khunger Fontize is an Android library, written in kotlin, that enables your android app have multiple

Gourav Khunger 8 Nov 28, 2022
LSPosed module to add Google Pixel features on Google Photos for any device.

Pixelify-Google-Photos LSPosed module to add Google Pixel features on Google Photos for any device. LSPosed module repo Development repo Steps to use:

null 502 Jan 9, 2023
📒Note taking app, MVVM with Google Architectural components Room, LiveData and ViewModel written in Kotlin, androidx libraries

?? MyNotes Note taking Android App using androidx libraries, MVVM with Google Architectural components Room, LiveData and ViewModel. Written in Kotlin

Akshat Bhuhagal 60 Dec 5, 2022