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
690
Gang of Four Patterns in Kotlin
lmller
2
140
Convert your legacy (Android) app to Kotlin!
lmller
0
91
Kotlin ist auch eine Insel
lmller
0
410
Other Decks in Programming
See All in Programming
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.4k
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Jakarta EE meets AI
ivargrimstad
0
260
useSyncExternalStoreを使いまくる
ssssota
6
1.2k
良いユニットテストを書こう
mototakatsu
8
3k
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
170
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
Go の GC の不得意な部分を克服したい
taiyow
3
800
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
1
100
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Making Projects Easy
brettharned
116
6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.6k
The Cult of Friendly URLs
andyhume
78
6.1k
Building Applications with DynamoDB
mza
91
6.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
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