Coder Social home page Coder Social logo

zacsweers / corbind Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ldralighieri/corbind

0.0 2.0 0.0 28.11 MB

Kotlin Coroutines binding APIs for Android UI widgets from the platform and support libraries

Home Page: https://ldralighieri.github.io/Corbind

License: Apache License 2.0

Kotlin 100.00%

corbind's Introduction

Corbind

Maven Central Codacy Badge GitHub license


Kotlin Coroutines binding APIs for Android UI widgets from the platform and support libraries. Supports Flow, ReceiveChannel and Actor.

Description

This library is for Android applications only. Help you to transform Android UI events into cold Flow, hot ReceiveChannel or just perform an action through an Actor.

Download

Platform bindings:

implementation 'ru.ldralighieri.corbind:corbind:1.0.0'

AndroidX library bindings:

implementation 'ru.ldralighieri.corbind:corbind-core:1.0.0'
implementation 'ru.ldralighieri.corbind:corbind-appcompat:1.0.0'
implementation 'ru.ldralighieri.corbind:corbind-drawerlayout:1.0.0'
implementation 'ru.ldralighieri.corbind:corbind-leanback:1.0.0'
implementation 'ru.ldralighieri.corbind:corbind-recyclerview:1.0.0'
implementation 'ru.ldralighieri.corbind:corbind-slidingpanelayout:1.0.0'
implementation 'ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.0.0'
implementation 'ru.ldralighieri.corbind:corbind-viewpager:1.0.0'

Google 'material' library bindings:

implementation 'ru.ldralighieri.corbind:corbind-material:1.0.0'

How to use it?

If you need to get a text change events of EditText widget, simple use case with cold Flow will look something like this:

findViewById<EditText>(R.id.et_name)
    .textChanges() // Flow<CharSequence>
    .onEach { /* handle text change events */ }
    .launchIn(scope)

If you prefer hot ReceiveChannel and you need to get a ViewPager page selection events, then the use case will transform in something like this:

launch {
    findViewById<ViewPager>(R.id.vp_slides)
        .pageSelections(scope) // ReceiveChannel<Int>
        .consumeEach {
            /* handle ViewPager events */
        }
}

And if you just need to perform an action on button click, the easiest way will be:

launch {
    findViewById<AppCompatButton>(R.id.bt_confirm)
        .clicks {
            /* perform an action on View click events */
        }
}

Just one more traditional example of login button enabling/disabling by email and password field validation:

combine(
    et_email.textChanges()
        .map { Patterns.EMAIL_ADDRESS.matcher(it).matches() },

    et_password.textChanges()
        .map { it.length > 7 },
            
    transform = { email, password -> email && password }
) 
    .onEach { bt_login.isEnabled = it }
    .launchIn(scope)

Missed or forgot something?

If I forgot something or you have any ideas what can be added or corrected, please create an issue or contact me directly.

Special thanks to

Jake Wharton. This project is inspired by RxBinding.

License

Copyright 2019 Vladimir Raupov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

corbind's People

Contributors

ldralighieri avatar

Watchers

 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.