Giter Club home page Giter Club logo

covert's Introduction

Covert

Covert

Download

Covert is an Android Library for easily implementing Material Swipe Actions in a RecyclerView. The design of the animations was based heavily around the Swipe Action Gestures demonstrated in the Material Interaction guidelines.

Download

implementation 'nz.co.trademe.covert:covert:1.0.0'

Usage

A setup of Covert matching the demo takes three steps

  1. Set up your configuration - this is what tells Covert what to draw
val covertConfig = Covert.Config(
        iconRes = R.drawable.ic_star_border_black_24dp, // The icon to show
        iconDefaultColorRes = R.color.black,            // The color of the icon
        actionColorRes = R.color.colorPrimary           // The color of the background
)
  1. Build Covert by defining your listeners and attaching to your RecyclerView
val covert = Covert.with(covertConfig)
                .setIsActiveCallback {
                    // This is a callback to check if the item is active, i.e checked
                    repository.isActive(it.adapterPosition)
                }
                .doOnSwipe { viewHolder, _ ->
                    // This callback is fired when a ViewHolder is swiped
                    repository.toggleActiveState(viewHolder.adapterPosition)
                }
                .attachTo(recyclerView)
  1. Pass Covert to your adapter to apply your corner flags
override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, index: Int) {
    covert.drawCornerFlag(viewHolder)
    ...
}

Optimisations

Covert notifies the RecyclerView that the current ViewHolder has changed for each frame it draws. If the layout your using is complicated, this can sometimes drop frames and cause weird behaviour. To work around this, Covert triggers invalidations using a payload, which you can look for to skip a full rebind of your ViewHolder:

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: List<Any>) {
    // The following is an optimisation for Covert, allowing us to skip re-binding of ViewHolders if only drawing the child
    if (payloads.size == 1 && payloads.contains(Covert.SKIP_FULL_BIND_PAYLOAD)) return
    ...
}

Advanced Setup

Covert tries to make set up as easy as possible. It does however support more advanced setup:

Covert.Config(
        // Define the icon to show in an active state, with start and end colors 
        activeIcon = Icon(
            iconRes = R.drawable.ic_active,
            startColorRes = R.color.start,
            endColorRes = R.color.end),

        // Define the icon to show in an inactive state, with start and end colors 
        inactiveIcon = Icon(
            iconRes = R.drawable.ic_inactive,
            startColorRes = R.color.end,
            endColorRes = R.color.start),
        
        // Define the backdrop color of the active background
        activeBackdropColorRes = R.color.green,

        // Define the backdrop color of the inactive background
        inactiveBackdropColorRes = R.color.red,

        // Toggle on and off haptic feedback (available in simple constructor)
        isHapticFeedbackEnabled = (true | false),

        // Choose your cornerflag (available in simple constructor)
        cornerFlag: CornerFlag = (CornerFlag.Round | CornerFlag.Triangular | CornerFlag.Custom(R.dimen.size, R.drawable.flag) | CornerFlag.Disabled)
)

Contributing

We love contributions, but make sure to checkout CONTRIBUTING.MD first!

covert's People

Watchers

James Cloos avatar  avatar

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.