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
C++でシェーダを書く
fadis
6
4.1k
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
360
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
250
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
150
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
630
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.8k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1k
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Side Projects
sachag
452
42k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
BBQ
matthewcrist
85
9.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Facilitating Awesome Meetings
lara
50
6.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Ruby is Unlike a Banana
tanoku
97
11k
Why Our Code Smells
bkeepers
PRO
334
57k
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