All Projects → chetdeva → Spinner Bindings

chetdeva / Spinner Bindings

Licence: mit
SpinnerBindings expounds on how we can bind a Spinner with DataBinding or InverseDataBinding.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Spinner Bindings

Pokemongo
神奇宝贝 (PokemonGo) 基于 Jetpack + MVVM + Repository 设计模式 + Data Mapper + Kotlin Flow 的实战项目,如果这个仓库对你有帮助,请仓库右上角帮我 star 一下,非常感谢。
Stars: ✭ 848 (+1704.26%)
Mutual labels:  databinding
Rankmusic
RankMusic音乐排行榜 一个使用kotlin 语言开发的android项目。
Stars: ✭ 30 (-36.17%)
Mutual labels:  databinding
Weaponapp
一个尽量做到极致的集大成App,努力做到最好(开发阶段)——MVVM+Retrofit+RxJava+Small 插件化+单元测试+MD
Stars: ✭ 1,011 (+2051.06%)
Mutual labels:  databinding
Babel Plugin Jsx Two Way Binding
🍺 A two-way data binding solution for React
Stars: ✭ 15 (-68.09%)
Mutual labels:  databinding
Hintspinner
An Android Spinner lilbrary with Hint/Header
Stars: ✭ 28 (-40.43%)
Mutual labels:  spinner
Spinnercpp
Simple header only library to add a spinner / progress indicator to any terminal application.
Stars: ✭ 37 (-21.28%)
Mutual labels:  spinner
Kodein Mvvm
Example app using Kodein for dependency injection with MVVM and Architecture Components
Stars: ✭ 26 (-44.68%)
Mutual labels:  databinding
Exchange Rates Mvvm
Sample Android project which incorporates MVVM, databinding, RxJava2, Dagger2 and Clean Architecture approach.
Stars: ✭ 43 (-8.51%)
Mutual labels:  databinding
Blockchain Tracker
A blockchain market tracking app. Example implementation of reactive clean architecture and testing.
Stars: ✭ 30 (-36.17%)
Mutual labels:  databinding
Noviewholder
No ViewHolder, No Adapter!!! 基于反射实现 DATA 和 VIEW 的绑定,不知 ViewHolder 为何物。
Stars: ✭ 41 (-12.77%)
Mutual labels:  databinding
Karchi
Repository that showcases 3 different Android app architectures, all with Java and Kotlin versions: "Standard Android", MVP and MVVM. The exact same app is built 6 times following the different patterns.
Stars: ✭ 20 (-57.45%)
Mutual labels:  databinding
Aframe Preloader Component
A preloading bar that automatically displays while scene assets load.
Stars: ✭ 27 (-42.55%)
Mutual labels:  spinner
Wanandroid
Jetpack MVVM For Wanandroid 最佳实践 !
Stars: ✭ 1,004 (+2036.17%)
Mutual labels:  databinding
Mvvmhabitcomponent
👕基于MVVMHabit框架,结合阿里ARouter打造的一套Android MVVM组件化开发方案
Stars: ✭ 857 (+1723.4%)
Mutual labels:  databinding
Css Spinner
small, elegant pure css spinner for ajax or loading animation
Stars: ✭ 1,013 (+2055.32%)
Mutual labels:  spinner
Angular Loading Feedback
Angular directive to indicate loads in app
Stars: ✭ 8 (-82.98%)
Mutual labels:  spinner
Spinners
A Sass mixin to generate fully customizable, pure CSS3 loading/busy indicators
Stars: ✭ 33 (-29.79%)
Mutual labels:  spinner
Csspin
CSS Spinners and Loaders - Modular, Customizable and Single HTML Element Code for Pure CSS Loader and Spinner
Stars: ✭ 1,019 (+2068.09%)
Mutual labels:  spinner
Frekans
📻 Frekans is a radio player app. It will be fully developed with Kotlin. It is work-in-progress and under heavy development.
Stars: ✭ 43 (-8.51%)
Mutual labels:  databinding
Fliplog
fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, tracking, presets, & more...
Stars: ✭ 41 (-12.77%)
Mutual labels:  spinner

Spinner Bindings

SpinnerBindings expounds on how we can bind a Spinner with DataBinding or InverseDataBinding.

How to Use

SpinnerExtensions entails extension helper functions for Spinner that can be called from BindingAdapter.

    /**
     * set spinner entries
     */
    fun Spinner.setSpinnerEntries(entries: List<Any>?) {
        // ...
    }

    /**
     * set spinner onItemSelectedListener listener
     */
    fun Spinner.setSpinnerItemSelectedListener(listener: ItemSelectedListener?) {
        // ...
    }

    /**
     * set spinner onItemSelectedListener listener
     */
    fun Spinner.setSpinnerInverseBindingListener(listener: InverseBindingListener?) {
        // ...
    }

    /**
     * set spinner value
     */
    fun Spinner.setSpinnerValue(value: Any?) {
        // ...
    }

    /**
     * get spinner value
     */
    fun Spinner.getSpinnerValue(): Any? {
        // ...
    }

How to Bind

In your Gradle

    dataBinding {
        enabled = true
    }

Using DataBinding

In your BindingAdapter

    @BindingAdapter("entries")
    fun Spinner.setEntries(entries: List<Any>?) {
        setSpinnerEntries(entries)
    }

    @BindingAdapter("onItemSelected")
    fun Spinner.setItemSelectedListener(itemSelectedListener: ItemSelectedListener?) {
        setSpinnerItemSelectedListener(itemSelectedListener)
    }

    @BindingAdapter("newValue")
    fun Spinner.setNewValue(newValue: Any?) {
        setSpinnerValue(newValue)
    }

In your XML file

<Spinner
    android:id="@+id/item_quantity_spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:background="@drawable/ic_spinner_bg"
    android:gravity="center_vertical"
    android:paddingStart="4dp"
    android:textSize="16sp"
    app:entries="@{model.itemQuantityEntries}"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@id/item_image"
    app:newValue="@{model.itemQuantity}"
    app:onItemSelected="@{(newValue) -> presenter.onItemQuantityChange(model.cartItem, Converter.toInt(newValue))}" />

Using InverseDataBinding

In your BindingAdapter

    @BindingAdapter("selectedValue")
    fun Spinner.setSelectedValue(selectedValue: Any?) {
        setSpinnerValue(selectedValue)
    }

    @BindingAdapter("selectedValueAttrChanged")
    fun Spinner.setInverseBindingListener(inverseBindingListener: InverseBindingListener?) {
        setSpinnerInverseBindingListener(inverseBindingListener)
    }

    companion object InverseSpinnerBindings {

        @JvmStatic
        @InverseBindingAdapter(attribute = "selectedValue", event = "selectedValueAttrChanged")
        fun Spinner.getSelectedValue(): Any? {
            return getSpinnerValue()
        }
    }

In your XML file

<Spinner
    android:id="@+id/item_quantity_spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:background="@drawable/ic_spinner_bg"
    android:gravity="center_vertical"
    android:paddingStart="4dp"
    app:layout_constraintBottom_toBottomOf="parent"
    android:textSize="16sp"
    app:entries="@{model.itemQuantityEntries}"
    app:layout_constraintStart_toEndOf="@id/item_image"
    app:selectedValue="@={model.itemQuantity}" />

Library used

Add Android DataBinding Compiler your app gradle file.

    dependencies {
        kapt 'com.android.databinding:compiler:3.0.1'
    }

Make sure to apply kotlin-kapt plugin on top of your app gradle file.

    apply plugin: 'kotlin-kapt'

Also try

Reference

License

Copyright (c) 2018 Chetan Sachdeva

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].