Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kotlin + RxBinding = ❤️
Search
Lovis
October 14, 2016
Programming
1
830
Kotlin + RxBinding = ❤️
Lightning talk from GDG Devfest Hamburg 2016
Lovis
October 14, 2016
Tweet
Share
More Decks by Lovis
See All by Lovis
Microservices with Kotlin and Ktor
lmller
0
680
Gang of Four Patterns in Kotlin
lmller
2
140
Convert your legacy (Android) app to Kotlin!
lmller
0
88
Kotlin ist auch eine Insel
lmller
0
410
Other Decks in Programming
See All in Programming
Realtime API 入門
riofujimon
0
150
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
3
1.2k
最新TCAキャッチアップ
0si43
0
200
Ethereum_.pdf
nekomatu
0
470
Outline View in SwiftUI
1024jp
1
340
イベント駆動で成長して委員会
happymana
1
340
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
120
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1k
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
For a Future-Friendly Web
brad_frost
175
9.4k
Unsuck your backbone
ammeep
668
57k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Why Our Code Smells
bkeepers
PRO
334
57k
4 Signs Your Business is Dying
shpigford
180
21k
What's new in Ruby 2.0
geeforr
343
31k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Transcript
Kotlin + RxBinding = Lovis Möller @lovisbrot #devfestHH
RxBinding • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island
RxBinding • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island • Make your Android Views reactive
RxBinding • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island • Make your Android Views reactive RxView.clicks(myView) .filter(…) .flatMap(…) .subscribe(…)
RxBinding • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island • Make your Android Views reactive RxView.clicks(myView) .filter(…) .flatMap(…) .subscribe(…) • JakeWharton
RxBinding • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island • Make your Android Views reactive RxView.clicks(myView) .filter(…) .flatMap(…) .subscribe(…) • JakeWharton ✔
Kotlin • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island
Kotlin • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island
Kotlin • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island
Kotlin • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island
Kotlin • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island
Kotlin • JVM language • developed by JetBrains • Null
safety, immutability • Extension functions • It’s an Island
Kotlin - Extension Functions fun String?.orEmpty(): String { if(this ==
null) return "" return this }
Kotlin - Extension Functions fun String?.orEmpty(): String { } if(this
== null) return "" return this }
Kotlin - Extension Functions fun String?.orEmpty(): String { if(this ==
null) return "" return this }
Kotlin - Extension Functions fun String?.orEmpty(): String { if(this ==
null) return "" return this } val name: String? = null val option = name.orEmpty()
Kotlin - Extension Functions fun String?.orEmpty(): String { return this
?: "" } val name: String? = null val option = name.orEmpty()
Kotlin - Extension Functions fun String?.orEmpty() = this ?: ""
return this ?: "" } val name: String? = null val option = name.orEmpty()
Get that View! <EditText android:id="@+id/editName" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Get that View! <EditText android:id="@+id/editName" android:layout_width="wrap_content" android:layout_height="wrap_content" /> EditText name
= (EditText) findViewById(R.id.editName);
Get that View! <EditText android:id="@+id/editName" android:layout_width="wrap_content" android:layout_height="wrap_content" /> @BindView(R.id.editName) EditText
name;
Get that View! <EditText android:id="@+id/editName" android:layout_width="wrap_content" android:layout_height="wrap_content" /> val name:
TextView by bindView(R.id.first_name)
Get that View! <EditText android:id="@+id/editName" android:layout_width="wrap_content" android:layout_height="wrap_content" /> import kotlinx.android.synthetic.main.activity_main.*
Get that View! <EditText android:id="@+id/editName" android:layout_width="wrap_content" android:layout_height="wrap_content" /> import kotlinx.android.synthetic.main.activity_main.*
... editName.text = "Lovis"
Get that View! <EditText android:id="@+id/editName" android:layout_width="wrap_content" android:layout_height="wrap_content" /> import kotlinx.android.synthetic.main.activity_main.*
... editName.text = "Lovis" //no findViewById necessary!
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" }
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" }
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" }
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" }
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" }
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" }
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" }
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" } static method looks ugly
Java + RxBinding EditText name = ... RxTextView.textChanges(name) .debounce(400, TimeUnit.MILLISECONDS)
.flatMap(text -> api.sendToServer(text)) .observeOn(AndroidSchedulers.mainThread()) .subscribe( this::handleResponse, this::handleError ); return this ?: "" } NOT RxEditText! static method looks ugly
Java + RxBinding • RxAbsListView • RxAdapter • RxAdapterView •
RxAutoCompleteTextView • RxCheckedTextView • RxCompoundButton • RxProgressBar • RxRadioGroup • RxRecyclerView • RxSeekBar • RxView • RxViewGroup • RxSnackbar • RxAppBarLayout • RxDrawerLayout • RxNestedScrollView • RxSwipeRefreshLayout • RxSearchView • RxToolbar • …
Java + RxBinding • RxButton → clicks() ❓ • RxEditText
RxTextView → textChanges()
Java + RxBinding • RxButton RxView → clicks() • RxEditText
RxTextView → textChanges()
Java + RxBinding • RxButton RxView → clicks() • RxEditText
RxTextView → textChanges()
Java + RxBinding • RxButton RxView → clicks() • RxEditText
RxTextView → textChanges()
Kotlin + RxBinding val name: EditText = ... name.textChanges() .debounce(400,
TimeUnit.MILLISECONDS) .flatMap { text -> api.sendToServer(text) } .observeOn(AndroidSchedulers.mainThread()) .subscribe( { handleResponse(it) }, { handleError(it) } ); return this ?: "" }
Kotlin + RxBinding val name: EditText = ... name.textChanges() .debounce(400,
TimeUnit.MILLISECONDS) .flatMap { text -> api.sendToServer(text) } .observeOn(AndroidSchedulers.mainThread()) .subscribe( { handleResponse(it) }, { handleError(it) } ); return this ?: "" } extension method
Kotlin + RxBinding val name: EditText = ... name.textChanges() .debounce(400,
TimeUnit.MILLISECONDS) .flatMap { text -> api.sendToServer(text) } .observeOn(AndroidSchedulers.mainThread()) .subscribe( { handleResponse(it) }, { handleError(it) } ); return this ?: "" } extension method No need to know!
Kotlin + RxBinding val button: Button = ... val buttonClicks
= button.clicks().share() buttonClicks.subscribe { //do something useful } buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
Kotlin + RxBinding val button: Button = ... // in
Java: Observable<Void> buttonClicks = ... val buttonClicks = button.clicks().share() buttonClicks.subscribe { //do something useful } buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
Kotlin + RxBinding val button: Button = ... val buttonClicks
= button.clicks().share() buttonClicks.subscribe { //do something useful } buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
Kotlin + RxBinding val button: Button = ... val buttonClicks
= button.clicks().share() buttonClicks.subscribe { //do something useful } buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
Kotlin + RxBinding val button: Button = ... val buttonClicks
= button.clicks().share() buttonClicks.subscribe { //do something useful } buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
Kotlin + RxBinding val button: Button = ... val buttonClicks
= button.clicks().share() val sub1 = buttonClicks.subscribe { //do something useful } val sub2 = buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
Kotlin + RxBinding val button: Button = ... val compositeSub
= CompositeSubscription() val buttonClicks = button.clicks().share() val sub1 = buttonClicks.subscribe { //do something useful } val sub2 = buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
Kotlin + RxBinding val button: Button = ... val compositeSub
= CompositeSubscription() val buttonClicks = button.clicks().share() compositeSub += buttonClicks.subscribe { //do something useful } compositeSub += buttonClicks.subscribe { //two listeners on one button! } return this ?: "" }
• kotlinlang.org • try.kotlinlang.org • leanpub.com/kotlin-for-android-developers • https://github.com/JakeWharton/RxBinding Lovis Möller
@lovisbrot #devfestHH
println("Thanks a lot!") Lovis Möller @lovisbrot #devfestHH