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
RxPM-library
Search
Dmitriy Gorbunov
November 23, 2017
Programming
0
68
RxPM-library
Reactive implementation of Presentation Model pattern in Android
Dmitriy Gorbunov
November 23, 2017
Tweet
Share
More Decks by Dmitriy Gorbunov
See All by Dmitriy Gorbunov
Intro to Kotlin/Native and Multi-platform Projects
dmdevgo
1
26
RxPM vs MVP vs MVVM
dmdevgo
0
230
Other Decks in Programming
See All in Programming
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
5.7k
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
5.6k
ゆくKotlin くるRust
exoego
1
210
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
370
AtCoder Conference 2025
shindannin
0
970
AI 駆動開発ライフサイクル(AI-DLC):ソフトウェアエンジニアリングの再構築 / AI-DLC Introduction
kanamasa
11
5.7k
余白を設計しフロントエンド開発を 加速させる
tsukuha
6
1.8k
[AI Engineering Summit Tokyo 2025] LLMは計画業務のゲームチェンジャーか? 最適化業務における活⽤の可能性と限界
terryu16
2
400
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
180
AgentCoreとHuman in the Loop
har1101
5
190
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
1.1k
Architectural Extensions
denyspoltorak
0
200
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.4k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1.1k
4 Signs Your Business is Dying
shpigford
187
22k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
For a Future-Friendly Web
brad_frost
181
10k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
160
Rails Girls Zürich Keynote
gr2m
96
14k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
260
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
230
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]