Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RxPM-library
Search
Dmitriy Gorbunov
November 23, 2017
Programming
75
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxPM-library
Reactive implementation of Presentation Model pattern in Android
Dmitriy Gorbunov
November 23, 2017
More Decks by Dmitriy Gorbunov
See All by Dmitriy Gorbunov
Intro to Kotlin/Native and Multi-platform Projects
dmdevgo
1
31
RxPM vs MVP vs MVVM
dmdevgo
0
240
Other Decks in Programming
See All in Programming
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.2k
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
Railsバージョンを4倍にした話
optim
0
430
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
210
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
カツオ、ご期待ください
suneo3476
0
190
Featured
See All Featured
My Coaching Mixtape
mlcsv
0
360
Utilizing Notion as your number one productivity tool
mfonobong
4
620
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The agentic SEO stack - context over prompts
schlessera
0
970
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
How to Ace a Technical Interview
jacobian
280
24k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
600
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
59k
Transcript
RxPM — реактивная реализация паттерна Presentation Model Дмитрий Горбунов Senior
Android Developer
Why Use RxPM?
RxPM
val inProgress = State<Boolean>(initialValue = false) // Изменяем значение в
PresentationModel inProgress.consumer.accept(true) // Подписываемся на изменения во View pm.inProgress.observable.bindTo(progressBar.visibility()) RxPM - State 4
val buttonClicks = Action<Unit>() // Слушаем клики в PresentationModel buttonClicks.observable
.subscribe { // handle click } .untilDestroy() // Привязываемся во View button.clicks().bindTo(pm.buttonClicks.consumer) RxPM - Action 5
val errorMessage = Command<String>(bufferSize = 1) // Посылаем сообщение из
PresentationModel errorMessage.consumer.accept(message) // Слушаем команды во View pm.errorMessage.observable.bindTo { // show alert dialog } RxPM - Command 6
RxPM - Command 7
class DataPresentationModel(private val dataModel: DataModel) : PresentationModel() { val data
= State<List<Item>>(emptyList()) val inProgress = State(false) val errorMessage = Command<String>() val refreshAction = Action<Unit>() // ... } RxPM - PresentationModel 8
class DataPresentationModel(private val dataModel: DataModel) : PresentationModel() { val data
= State<List<Item>>(emptyList()) val inProgress = State(false) val errorMessage = Command<String>() val refreshAction = Action<Unit>() override fun onCreate() { super.onCreate() refreshAction.observable .skipWhileInProgress(inProgress.observable) .flatMapSingle { dataModel.loadData() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .bindProgress(inProgress.consumer) .doOnError { errorMessage.consumer.accept("Loading data error") } } .retry() .subscribe(data.consumer) .untilDestroy() // обновляем данные при входе на экран refreshAction.consumer.accept(Unit) } } RxPM - PresentationModel 9
class DataFragment : PmSupportFragment<DataPresentationModel>() { override fun providePresentationModel() = DataPresentationModel(DataModel())
override fun onBindPresentationModel(pm: DataPresentationModel) { pm.inProgress.observable.bindTo(swipeRefreshLayout.refreshing()) pm.data.observable.bindTo { // adapter.setItems(it) } pm.errorMessage.observable.bindTo { // show alert dialog } swipeRefreshLayout.refreshes().bindTo(pm.refreshAction.consumer) } } RxPM - PmView 10
Two-way Data Binding 11
Two-way Data Binding 12
Two-way Data Binding 13
Two-way Data Binding 14
Two-way Data Binding 15
Two-way Data Binding 16
Two-way Data Binding 17
RxPM - Controls 18 // Объявляем в PresentationModel val name
= inputControl( formatter = { it.take(50).toUpperCase() } ) val checked = checkControl(initialChecked = false) // Привязываем виджеты во View pm.name bindTo editText pm.checked bindTo checkBox
Спасибо за внимание! /** * @author Dmitriy Gorbunov (dmdev) *
@author Vasili Chyrvon (Jeevuz) */ Telegram : https://t.me/Rx_PM GitHub : https://github.com/dmdevgo/RxPM Habrahabr : https://habrahabr.ru/company/mobileup/blog/326962/ https://habrahabr.ru/company/mobileup/blog/342850/ Дмитрий Горбунов:
[email protected]