Code Monkey home page Code Monkey logo

itemdecorator's Introduction

ItemDecorator

A utility class that enables you to customize your RecyclerView's ItemTouchHelper.SimpleCallback.onChildDraw behavior, when ItemTouchHelper.ACTION_STATE_SWIPE is triggered.

Left swipe Right swipe Gif demonstration
Demonstration 1 Demonstration 2 Demonstration 2

How to get this library in your android app

Step 1. Add the jitpack repository to the repositories { } function, inside your project build.gradle or your settings.gradle like so:

repositories {
    google()
    mavenCentral()
    // Place the jitpack repository inside this, like so:
    maven { url 'https://jitpack.io' }
}

Step 2. Add the dependency in your module build.gradle file, like so:

dependencies {
    implementation "com.github.kevingermainbusiness:ItemDecorator:1.0.16"
}

That's it!

Usage

Basic usage is shown below, there's a more elaborate example in the sample app. In this case, if you want to set a default background color,text,text color,text size,typeface,icon,icon tint color, as you swipe on each sides:

val colorAlert = ContextCompat.getColor(this@MainActivity, R.color.colorAlert)
val teal200 = ContextCompat.getColor(this@MainActivity, R.color.teal_200)
val defaultWhiteColor = ContextCompat.getColor(this@MainActivity, R.color.white)

ItemDecorator.Builder(c, recyclerView, viewHolder, dX, actionState).set(
    backgroundColorFromStartToEnd = colorAlert,
    backgroundColorFromEndToStart = teal200,
    textFromStartToEnd = getString(R.string.action_delete),
    textFromEndToStart = getString(R.string.action_add_to_fav),
    textColorFromStartToEnd = defaultWhiteColor,
    textColorFromEndToStart = defaultWhiteColor,
    iconTintColorFromStartToEnd = defaultWhiteColor,
    iconTintColorFromEndToStart = defaultWhiteColor,
    textSizeFromStartToEnd = 16f,
    textSizeFromEndToStart = 16f,
    typeFaceFromStartToEnd = Typeface.DEFAULT_BOLD,
    typeFaceFromEndToStart = Typeface.SANS_SERIF,
    iconResIdFromStartToEnd = R.drawable.ic_baseline_delete_24,
    iconResIdFromEndToStart = R.drawable.ic_baseline_done_24
)

Note

You can change the default icon horizontal margin of 16dp of the ItemDecorator by passing your desired margin for the icons like so:

val desiredValue = 18f
ItemDecorator.Builder(c, recyclerView, viewHolder, dX, actionState).set(
    iconHorizontalMargin = desiredValue,
    backgroundColorFromStartToEnd = colorAlert,
    backgroundColorFromEndToStart = teal200,
    textFromStartToEnd = getString(R.string.action_delete),
    textFromEndToStart = getString(R.string.action_add_to_fav),
    textColorFromStartToEnd = defaultWhiteColor,
    textColorFromEndToStart = defaultWhiteColor,
    iconTintColorFromStartToEnd = defaultWhiteColor,
    iconTintColorFromEndToStart = defaultWhiteColor,
    textSizeFromStartToEnd = 16f,
    textSizeFromEndToStart = 16f,
    iconResIdFromStartToEnd = R.drawable.ic_baseline_delete_24,
    iconResIdFromEndToStart = R.drawable.ic_baseline_done_24
)

License

Licenced under the MIT Licence

Copyright (c) 2022 Kevin Germain

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

itemdecorator's People

Contributors

kevingermainbusiness avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

itemdecorator's Issues

please update version

please update the version in the Readme to 15 or draft a new release.. I was searching for the bug for hours

should not expect the user to remove the item in any case

Would be great if there were a way to restore the old recycler view item canvas after the onSwipeListener is called.
Maybe add a bool 'restoreCanvasLeftToRight' and 'restoreCanvasRightToLeft' to the builder.
In my case for example I display an alert popup on deletion. If the user says he does not want to delete, I am stuck with a red delete symbol instead of the restored item.
To circumvent that one has to remove the old item in any case and restore the item if the user does not want to delete.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.