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
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
250
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
350
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
170
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
qmuntal/stateless のススメ
sgash708
0
120
C#/.NETのこれまでのふりかえり
tomokusaba
1
160
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4.1k
Go言語でターミナルフレンドリーなAIコマンド、afaを作った/fukuokago20_afa
monochromegane
2
140
go.mod、DockerfileやCI設定に分散しがちなGoのバージョンをまとめて管理する / Go Connect #3
arthur1
10
2.4k
Java ジェネリクス入門 2024
nagise
0
610
CSC509 Lecture 08
javiergs
PRO
0
110
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Teambox: Starting and Learning
jrom
132
8.7k
How to Think Like a Performance Engineer
csswizardry
19
1.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
4 Signs Your Business is Dying
shpigford
180
21k
How GitHub (no longer) Works
holman
311
140k
The Cost Of JavaScript in 2023
addyosmani
45
6.6k
Producing Creativity
orderedlist
PRO
341
39k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
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