• Stars
    star
    365
  • Rank 113,170 (Top 3 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Covert is an Android library for Material Swipe Actions within a RecyclerView

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:2.0.1'

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)
    ...
}

Swipe Refresh Layouts

In some cases, swipe refresh layouts may consume touch events that Covert uses, leading to janky animations. To address this, you can add the following line to the builder.

Covert.with(covertConfig)
                .setIsActiveCallback { ...}
                .doOnSwipe { viewHolder, _ -> ...}
                .disablePullToRefreshOnSwipe(swipeRefreshLayout)
                .attachTo(recyclerView)

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!

More Repositories

1

MapMe

The Android maps adapter
Kotlin
845
star
2

bootup.js

Cache and load static files from local storage.
JavaScript
821
star
3

ReviewMe

Google Play and App Store reviews posted to Slack
JavaScript
175
star
4

ng-defer-load

TypeScript
128
star
5

PlayMe

JavaScript
51
star
6

konfigure

An Application Configuration Library based on Kotlin Property Delegation
Kotlin
32
star
7

tractor

A UI around Protractor to help write E2E tests for Angular applications without needing to know JavaScript
JavaScript
26
star
8

IncludeMe

A Gradle plugin that simplifies working with composite builds
Kotlin
24
star
9

angular-master-class-exercises

18
star
10

Plunge

An Android Library for building and testing Deep Link handling
Kotlin
10
star
11

iOSWrapper

Official Trade Me API for iOS
Objective-C
9
star
12

tm-feature-toggle

Feature toggle module for Angular. AoT friendly, lazy-loaded component and route based feature toggling.
TypeScript
6
star
13

ngAddToCalendar

TypeScript
5
star
14

trade-me-api-wrapper

# This project is depricated # This is a .NET library to authenticate via OAuth, and access data from Trade Me's Developer API.
C#
4
star
15

KeyboardDodger

An iOS cocoapod that uses a constraint to move a view out of the way of the on-screen keyboard.
Swift
4
star
16

ensure

Utility decorators for Trade Me
TypeScript
4
star
17

TradeMe-IconFont

Trade Me Classic iconfont
HTML
3
star
18

OAuthExample

Example of how to use OAuth with the Trade Me API
C#
2
star
19

add2Calendar

A small lib to provide integration with online and desktop calendars
TypeScript
1
star
20

ngrx

TypeScript
1
star
21

KotlinBeyondCompare

A Kotlin syntax plugin for Beyond Compare
Kotlin
1
star