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
820
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
85
Kotlin ist auch eine Insel
lmller
0
410
Other Decks in Programming
See All in Programming
Piniaの現状と今後
waka292
5
1.5k
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
160
Vue.js学習の振り返り
hiro_xre
2
130
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
370
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
300
offers_20241022_imakiire.pdf
imakurusu
2
360
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
現場で役立つモデリング 超入門
masuda220
PRO
13
2.9k
qmuntal/stateless のススメ
sgash708
0
120
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
Featured
See All Featured
A Tale of Four Properties
chriscoyier
156
23k
RailsConf 2023
tenderlove
29
880
Building Your Own Lightsaber
phodgson
102
6.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Fireside Chat
paigeccino
32
3k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
How to Think Like a Performance Engineer
csswizardry
19
1.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
Optimizing for Happiness
mojombo
376
69k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
What's new in Ruby 2.0
geeforr
342
31k
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