Simple to use swipe gestures for an Android RecyclerView

Overview

Android-RecyclerView-Swipe-Gestures

Codacy Badge GitHub last commit Issues
PR's Welcome

Contribution

Contributions / PRs are welcome.

1. Introduction

An easy to use and highly customizable implementation of swipe gestures for an android RecyclerView.

  • Support for left and right swipes for any RecyclerView
  • Set Colours as background for each swipe direction
  • Set Icons for each swipe direction
  • Set texts in addition to icons

2. Planned

  • The Actions will be executed only when clicking on the coloured button, which will be schown when swiped, not directly after swiping.
  • More then one Action for each swipe direction (several buttons will be displayed)

3. Setup

3.1. Add JitPack to your Project

Gradle

  • Add it in your root build.gradle at the end of repositories:
    (!!! Note: check the JitPack link for newer version, the following ones may not be up to date !!!)
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
  • Add the dependencie
dependencies {
	implementation 'com.github.WilliBoelke:simple-recycler-view-swipe-gestures:1.3'
}

Maven

  • Add the JitPack Repository to your pom.xml
<repositories>
	<repository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</repository>
</repositories>
  • Add the dependency to your pom.xml
<dependency>
    <groupId>com.github.WilliBoelke</groupId>
    <artifactId>simple-recycler-view-swipe-gestures</artifactId>
    <version>1.3</version>
</dependency>

Or find other versions here

JitPack-SompleSwipeGestures

3.2 Import GestureManager

In your Activity add

import swipe.gestures.GestureManager;

4. Usage

4.1 Implement the SwipeCallbackLeft and/or SwipeCallbackLeft

In your activity implement the interfaces.
Here you put the code which will be executed when the recycler item was swiped.

  private GestureManager.SwipeCallbackLeft leftCallback leftCallback = new SwipeCallbackLeft()
    {
        @Override
        public void onLeftSwipe(int position)
        {
            // your code here 
        }
    }; 

4.2 Initialize 'GestureManager'in your activity

 GestureManager recyclerAdapterSwipeGestures = new GestureManager(rightCallback, leftCallback);

If you just need one swipe gesture the just implement one of the interfaces and pass it:

GestureManager recyclerAdapterSwipeGestures = new GestureManager(rightCallback);

4.3 Set a colour

Use the setter to set a colour:

recyclerAdapterSwipeGestures.setBackgroundColorLeft(new ColorDrawable(Color.RED));

You can set a different colour for the two directions. The standard colours are RED and GREEN.

Colours

Blue Yellow
BLUE YELLOW

4.4 Set Icons

Optionally you can use icons for the swipe acions which will be displayed when the swpie is performed.

recyclerAdapterSwipeGestures.setIconRight(ContextCompat.getDrawable(this, R.drawable.your_icon));

That again works for both actions. you also can change the size of the icons by using

recyclerAdapterSwipeGestures.setIconSizeMultiplier(2);
Icon Icon
RIGHT LEFT
Small Small
SMALLLEFT SMAllRIGHT
Big Big
BIGLEFT BIGRIGHT

4.5 Text

You can set a text (insead or with and icon), the text can be customized by using the setters.

recyclerAdapterSwipeGestures.setTextLeft("LEFT");
recyclerAdapterSwipeGestures.setTextRight("RIGHT");

Customize the text :

//Set text size
recyclerAdapterSwipeGestures.setTextSize(60);

//Set text colour
recyclerAdapterSwipeGestures.setTextColor(Color.BLACK);

Texts can also be customized seperatly by using the setters as follows:

//Set text size
recyclerAdapterSwipeGestures.setTextSize(60, 100

//Set text colour
recyclerAdapterSwipeGestures.setTextColor(Color.BLACK, Color.YELLOW);
Text Text
Right Text Small
RIGHTTEXT TEXTWITHICON
Text and icon color Only Text
COLOURTEXT ONLYTEXT

4.6 Attach to the RecylerViewAdapter

You need to attach the swipe gestures to the RecyyclerView Adapter using a ItemTouchHelper

ItemTouchHelper itemTouchHelper = new ItemTouchHelper(recyclerAdapterSwipeGestures);
itemTouchHelper.attachToRecyclerView(recyclerView);

And thats it for now. You can find an example implementation in the MainActivity

You might also like...
Shot is an Android project you can use to write screenshot for your apps in a simple and friendly way
Shot is an Android project you can use to write screenshot for your apps in a simple and friendly way

Shot is an Android project you can use to write screenshot for your apps in a simple and friendly way. What is this? Shot is a Gradle plugin and

A simple xposed module that helps you use your AdGuard subscription in multiple devices

DualGuard A simple xposed module that helps you use your AdGuard subscription in multiple (3) devices. Monstor ahead! / 警告 This is NOT a module that

Simple-todo-app - Simple Memo App using SQLite

Judul Aplikasi Aplikasi Memo Sederhana menggunakan SQLite. Fitur Aplikasi Memo y

FoldingNavigationDrawer-Android This is a sample project present how to use Folding-Android to add Folding Efect to Navigation Drawer.

FoldingNavigationDrawer-Android Sample (Play Store Demo) This is a sample project present how to use Folding-Android to add Folding Efect to Navigatio

 🍲Foodium is a sample food blog Android application 📱 built to demonstrate the use of Modern Android development tools - (Kotlin, Coroutines, Flow, Dagger 2/Hilt, Architecture Components, MVVM, Room, Retrofit, Moshi, Material Components).
A collection of custom Android/Kotlin lint checks we use in our Android and Kotlin code bases at Slack.

slack-lints This repository contains a collection of custom Android/Kotlin lint checks we use in our Android and Kotlin code bases at Slack. This repo

Android port of Simon Tatham's Puzzles. *git replace in use* - you might want to {{ git fetch origin 'refs/replace/*:refs/replace/*' }}

This is the README accompanying the source code to Simon Tatham's puzzle collection. The collection's web site is at https://www.chiark.greenend.org.

📱 Android Library to implement Rich, Beautiful, Stylish 😍 Material Navigation View for your project with Material Design Guidelines. Easy to use.
📱 Android Library to implement Rich, Beautiful, Stylish 😍 Material Navigation View for your project with Material Design Guidelines. Easy to use.

Material NavigationView for Android 📱 📱 Android Library to implement Rich, Beautiful Material Navigation View for your project with Material Design

📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT 🖊️ NotyKT is the complete Kotlin-stack note taking 🖊️ application 📱 built to demonstrate a use of Kotlin programming language in server-side

Comments
  • Swipe needs additional click to performe the action

    Swipe needs additional click to performe the action

    That works like the current version. But instead of executing the Callback method right away, the swiped Item will stay like it is. The Background /Icon/text will be shown and serve as a button which needs to be clicked.

    This can serve also as a kind of safety mechanism for example for delete actions. (Instead of having an alert dialog or something similar in the callback)

    enhancement 
    opened by WilliBoelke 0
  • Several actions for each swipe direction

    Several actions for each swipe direction

    Each swipe direction can have up to 3 (?) actions assigned to it. Like in the current version they will show up behind the Recycler Item, but here they require and additional click on them.

    Example:

    enhancement 
    opened by WilliBoelke 0
Releases(1.3.1)
Owner
Willi Bölke
Willi Bölke
A beautiful app showing the use of a single recyclerview to display multiple views with motion layout and clean architecture

This app shows how to use a single recyclerview to build a beautiful multiple view layout (See image below) using clean architectural pattern

Ibrajix 62 Dec 26, 2022
A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar

#Android-LollipopShowcase This is a simple showcase to show off Android's all new Material Design and some other cool new stuff which is (new) in Andr

Mike Penz 1.8k Nov 10, 2022
The App Loads list of popular movies from a mock API and shows in a recyclerView

popular-movies-app About The App Loads list of popular movies from a mock API and shows in a recyclerView. Any item can be clicked to open the Movie D

Mayank Agarwal 0 Oct 30, 2021
Static recyclerview dan kalkulator sederhana, dibuat dengan menggunakan kotlin

Static Recyclerview Using Kotlin Static recyclerview dan kalkulator sederhana, dibuat dengan menggunakan kotlin. Screenshot License Copyright (C) 2021

AR Hakim 2 Dec 14, 2021
😳 This app shows a recyclerView grid list with images from Picsum Photos API 🖥️

GalleryImagesWithRecyclerView ?? This app shows a recyclerView grid list with images from Picsum Photos API ??️ ?? ✏️ Architeture Components MVVM View

Rodrigo Loss Taborda 0 Dec 29, 2021
App made using Kotlin to retrieve data from an API and show in a recyclerview with Login and SignUp features

App made using Kotlin to retrieve data from an API and show in a recyclerview with Login and SignUp features.

Altair Wallace 1 Feb 17, 2022
A simple Android app to demonstrate the use of Hover SDK for M-PESA Send Money while offline. This SDK does not require an internet connection, it automates USSD sessions in the background of an android application.

HoverSDKDemo Hover SDK is an Android SDK that lets mobile developers to add money features to the applications. This SDK does not require an internet

Joel Kanyi 9 Dec 21, 2022
A Simple Expense Tracker App 📱 built to demonstrate the use of modern android architecture component with MVVM Architecture

Expenso ?? A Simple Expense Tracker App ?? built to demonstrate the use of modern android architecture component with MVVM Architecture ?? . Made with

Michel Horacio 1 Dec 28, 2022
simple-flank is a Gradle plugin to use Flank in Android projects with no configuration needed

simple-flank simple-flank is a new gradle plugin with a clear focus: make the setup as simple as possible. Applied to any application or library modul

Flank 8 May 10, 2022
A simple and easy to use stopwatch and timer library for android

TimeIt Now with Timer support! A simple and easy to use stopwatch and timer library for android Introduction A stopwatch can be a very important widge

Yashovardhan Dhanania 35 Dec 10, 2022