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
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
790
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
ジョジョの世界をXRで再現する
mofurune
0
160
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
590
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
The Rails Doctrine Decade
koic
2
590
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Navigating Weather and Climate Data
rabernat
0
560
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
550
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Being A Developer After 40
akosma
92
590k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
So, you think you're a good person
axbom
PRO
2
2.2k
Scaling GitHub
holman
464
140k
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]