Skip to content

ozanlimited/slidable-counter-button

Repository files navigation

contributions welcome ktlint

Slidable Counter Button

GIF

Installation

Step 1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
	implementation 'com.github.ozanlimited:slidable-counter-button:1.3.1'
}

Basic Usage

counterButton.setup(
            SlidableCounterButtonViewState("My Awesome Product", 499.99, "$", 5),
            SlidableCounterButtonState.STATE_COLLAPSED
        )

XML Attributes

XML Attribute Format Description
app:animOnStart boolean Apply [R.anim.anim_bounce_left_to_right] on start. Just works with [STATE_COLLAPSED]
app:makeRollAnimation boolean Make roll animation on count changed.
app:minusActiveDrawable reference Set minus active drawable.
app:minusInactiveDrawable reference Set minus inactive drawable.
app:plusActiveDrawable reference Set plus active drawable.
app:plusInactiveDrawable reference Set plus inactive drawable.
app:defaultTextColor color Set default text color.
app:accentTextColor color Set accent text color.
app:cardViewTopBackgroundColor color Set top card's background color.
app:cardViewBottomBackgroundColor color Set bottom card's background color.
app:cornerRadius dimension Set card corner radius. Default is 8dp
app:topCardDrawable reference Set top card's background drawable. Default is null
app:bottomCardDrawable reference Set bottom card's background drawable. Default is null

For formatting your price label you can use PriceFormatter

counterButton.setPriceFormatter(object : PriceFormatter() {
            override fun getFormattedValue(price: Double, pieceValueSign: String?): CharSequence =
                // TODO - Format price
        })

You can use ValueChangedListener for observing value changes.

counterButton.setValueChangedListener(object : SlidableCounterButton.ValueChangedListener {

            override fun onValueIncreased(count: Int, currentState: SlidableCounterButtonState) {
                // TODO - Value increased.
            }

            override fun onValueDecreased(count: Int, currentState: SlidableCounterButtonState) {
                // TODO - Value decreased.
            }

        })

Also, you can use OutOfStockListener for handling out of stock situation.

counterButton.setOutOfStockListener(object : SlidableCounterButton.OutOfStockListener {
            override fun outOfStock() {
                // TODO - Out of stock.
            }
        })

License


MIT License

Copyright (c) 2020 Ozan

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.