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
65
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
24
RxPM vs MVP vs MVVM
dmdevgo
0
220
Other Decks in Programming
See All in Programming
Hypervel - A Coroutine Framework for Laravel Artisans
albertcht
1
110
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
630
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
0
160
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
800
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
130
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
250
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
740
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
560
iOS 26にアップデートすると実機でのHot Reloadができない?
umigishiaoi
0
130
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
440
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
2
150
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
160
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
35
6.7k
GitHub's CSS Performance
jonrohan
1031
460k
Done Done
chrislema
184
16k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Raft: Consensus for Rubyists
vanstee
140
7k
Documentation Writing (for coders)
carmenintech
72
4.9k
Designing for humans not robots
tammielis
253
25k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
We Have a Design System, Now What?
morganepeng
53
7.7k
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]