Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Customizable Android library that helps you to implement swipe-to-delete logic for your RecyclerView's adapters in an easy way!

License

Notifications You must be signed in to change notification settings

agilie/SwipeToDelete

 
 

Repository files navigation

SwipeToDelete

Download

What is SwipeToDelete?

SwipeToDelete is a library you can use to simplify implementation of well-known (I believe for every Android developer :) ) swipe-to-delete behavior for your data lists. The main idea is that user has some time to undo unwanted delete operation. Swipe twice to remove the row immediately! Also, this library is fully customizable, feel free to use your own UI for undo layer, add extra buttons etc.

Features

  • Based on interface implementation;
  • Supports pending deletion with bottom layout;
  • Full customization of upper layout and bottom layout;
  • Easy way to handle deletion. All you need is to call removeItem(key: K) which should be overriden in your adapter and to invoke swipeToDeleteDelegate.removeItem(key: K) at the end of method's definition.

Usage

Gradle

Add dependency in your build.gradle file:

compile 'com.agilie:swipe2delete:1.0'

Maven

Add rependency in your .pom file:

<dependency>
  <groupId>com.agilie</groupId>
  <artifactId>swipe2delete</artifactId>
  <version>1.0</version>
  <type>pom</type>
</dependency>

How does it work?

  • Implement ISwipeToDeleteAdapter in your own adapter or another class.
  • Make instance of SwipeToDeleteDelegate in your own adapter
SwipeToDeleteDelegate(context = context, items = mutableList, swipeToDeleteDelegate = this)
  • Call corresponding methods in your overrided methods
 override fun onBindViewHolder(holder: Holder, position: Int) {
        swipeToDeleteDelegate.onBindViewHolder(holder, mutableList[position].name, position)
    }
    
 override fun removeItem(key: String) {
        swipeToDeleteDelegate.removeItem(key)
    }
  • Implement ISwipeToDeleteHolder in your holder. You need to have container with your regular item layout and if you need bottom container too.
  • In your holder you need to have var pendingDelete as false by default and you need to override val topContainer
override val topContainer: View
            get() =
            if (pendingDelete) undoContainer
            else itemContainer

override var pendingDelete: Boolean = false
  • Also you need to make default key in holder by yourself
override var key: Int = -1
  • If you need bottom container appearence while waiting, simply override onBindPendingItem(holder: Holder, key: Int, item: User) method:
override fun onBindPendingItem(holder: Holder, key: Int, item: User) {
...
}
  • Also you can implement IAnimationUpdateListener and IAnimatorListener to override methods to achieve animation along the axis x with duration which equally deleting duration
UserAdapter(...) : ... , IAnimationUpdateListener {
...
  fun onAnimationUpdated(animation: android.animation.ValueAnimator?, options: ModelOptions<*>) {}
  
  fun onAnimationEnd(animation: Animator?, options: ModelOptions<*>) {}
  
  fun onAnimationCancel(animation: Animator?, options: ModelOptions<*>) {}

  fun onAnimationStart(animation: Animator?, options: ModelOptions<*>) {}
  
  fun onAnimationRepeat(animation: Animator, options: ModelOptions<*>) {}
}

To get more information refer our usage example. Just clone the project and run this module. Examples are provided in Java and Kotlin as well!

Troubleshooting

Problems? Check the Issues block to find the solution or create an new issue that we will fix asap. Feel free to contribute.

Author

This library is open-sourced by Agilie Team info@agilie.com

Contributors

Contact us

If you have any questions, suggestions or just need a help with web or mobile development, please email us at
android@agilie.com
You can ask us anything from basic to complex questions.
We will continue publishing new open-source projects. Stay with us, more updates will follow!

License

The MIT License (MIT) Copyright © 2017 Agilie Team

About

Customizable Android library that helps you to implement swipe-to-delete logic for your RecyclerView's adapters in an easy way!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 76.1%
  • Java 23.9%