KBinding


Source link: https://github.com/BennyWang/KBinding

KBinding

???

Android MVVM framework write in kotlin, base on anko, simple but powerful. It depends on my another project AutoAdapter(A library for simplifying adapter creation)

Contents

BindingMode

  • OneWay: Binding from model to view
  • TwoWay: Binding from model to view and view to model
  • OneWayToSource: Binding from view to model
  • OneTime: Binding from model to view, and auto release after first emit

Simple Binding

verticalLayout {

  editText {

bind {
 text("name", mode = TwoWay) 
}

  
}

  button {

bind {
 click("hello") 
}

  
}
 
}
 class SimpleViewModel() : ViewModel() {

  @delegate:Property
  var name: String by Delegates.property("Jason")

 // all the parameter for Command is optional, first parameter pass by event Observable, second parameter is lambda (Boolean) -> Unit
  @Command
  val hello(canExecute: (Boolean) -> Unit) {

toast("Hello, ${
name
}
!")
  
}
 
}

Multiple Binding

//login button enabled only when name and password not empty class ArrayToBooleanConverter : MultipleConverter<Boolean> {

  override fun convert(params: Array<Any>): Boolean {

params.forEach {

 if(it.toString().isEmpty()) return false

}

return true
  
}
 
}
 verticalLayout {

  editText {

bind {
 text("name", mode = TwoWay) 
}

  
}

  editText {

 bind {
 text("password", mode = TwoWay) 
}

}

  button {

bind {
 enabled("name", "password", mode = OneWay, converter = ArrayToBooleanConverter()) 
}

bind {
 click("login") 
}

  
}
 
}
 class LoginViewModel() : ViewModel() {

  @delegate:Property
  var name: String by Delegates.property("[email protected]")

 @delegate:Property
  var password: String by Delegates.property("xxxxxx")

 @Command
  val login() {

//login processing
  
}
 
}

DependencyProperty and ExtractProperty

// @DependencyProperty will generate binding for nameAndSymbol depends on stock, stock changes then nameAndSymbol changes // @ExtractProperty will generate binding for stock properties, for example code below, Property name and price will generated. If hasPrefix = true, then Property stock.name stock.price will generated. class StockViewModel() : ViewModel() {

  @delegate:ExtractProperty(

"name", "price",

hasPrefix = false
  )
  var stock: Stock? by Delegates.property()

 @delegate:DependencyProperty("stock")
  var nameAndSymbol: String by Delegates.property {
 stock?.name + stock?.symbol 
}
 
}

Wait/Until

//wait/until just like OneTime binding, but it need apply action, for example below, it wait for market from model, then decide how to display relativeLayout {

  wait {
 until("market", converter = viewOfMarket) {
 inflate(it, this@verticalLayout) 
}
  
}
 
}

Extend Binding Property

Event

 fun View.click(path: String) : PropertyBinding = commandBinding(path, clicks(), enabled())

Property

 fun View.enabled(vararg paths: String, mode: OneWay = BindingMode.OneWay, converter: OneWayConverter<Boolean> = EmptyOneWayConverter()) : PropertyBinding = oneWayPropertyBinding(paths, enabled(), false, converter)

  //this implements four binding mode for TextView, if just need OneWay mode, remove last three lines, some for other mode
  fun TextView.text(vararg paths: String, mode: OneWay = BindingMode.OneWay, converter: OneWayConverter<out CharSequence> = EmptyOneWayConverter()) : PropertyBinding = oneWayPropertyBinding(paths, text(), false, converter)
  fun TextView.text(vararg paths: String, mode: OneTime, converter: OneWayConverter<out CharSequence> = EmptyOneWayConverter()) : PropertyBinding = oneWayPropertyBinding(paths, text(), true, converter)
  fun TextView.text(path: String, mode: OneWayToSource, converter: OneWayConverter<*> = EmptyOneWayConverter<String>()) : PropertyBinding = oneWayPropertyBinding(path, textChanges2(), converter)
  fun TextView.text(path: String, mode: TwoWay, converter: TwoWayConverter<String, *> = EmptyTwoWayConverter<String, String>()) : PropertyBinding = twoWayPropertyBinding(path, textChanges2(), text(), converter) 

Using with Gradle

dependencies {

  compile 'com.benny.library:kbinding:0.2.3'
  kapt 'com.benny.library:kbinding-compiler:0.2.3'

 // for common bindings, View, TextView, and ...
  compile 'com.benny.library:kbinding-common:0.2.3'
  // for recyclerview bindings
  compile 'com.benny.library:kbinding-adapterview:0.2.3'
  // for support v4 bindings
  compile 'com.benny.library:kbinding-support-v4:0.2.3' 
}

Contribute

Now is just the beginning of KBinding, so everyone interested in this library, just fork it and pull requests to me. Let's make it a little better.

Discussion

QQ Group: 516157585

Resources

Great sound quality, audio cleanliness and very smooth interface. Playing the folder structure, artist or album or create your own playlists with local or online tracks.

  • 10-band equalizer
  • Themes
  • mp3, flac, aac, ogg, oga, m4a, m4b, m4p, wma and other audio formats

Shape Ripple is a library that emulates a ripple like animations with cool tweaks on the go. It runs on API level 11 and upwards.

As addition you can even create your own shape renderer through the canvas to create a custom shape ripple.

An unofficial Unsplash API library.

MapDrawingTools is an android library to Drawing manually polygon, polyline and points in the Google Map and return coordinates from library to your App. this library useful for application that pick multiple point or drawing border of land to get data from users.

Aesthetic is an easy to use, fast, Rx-powered theme engine for Android applications.

Android developers should collect the following utils.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes