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
NSC AD 340 5210 - Week 8
Search
Nate Ebel
June 02, 2020
Programming
500
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
NSC AD 340 5210 - Week 8
Nate Ebel
June 02, 2020
More Decks by Nate Ebel
See All by Nate Ebel
Adopting Kotlin Multiplatform in Brownfield Applications - DCIT22
n8ebel
2
270
Adopting Kotlin Multiplatform in Brownfield Applications - DCNYC22
n8ebel
1
810
Demystify and Optimize Your Android Gradle Builds - Mobiconf 2021
n8ebel
2
510
Building an Android CI Pipeline with GitHub Actions - Chicago Roboto 2020
n8ebel
1
1.1k
Kotlin First - Taking Advantage of Kotlin for Android Development // 360AnDev 2020
n8ebel
0
510
NSC AD 340 5210 - Week 7
n8ebel
1
430
NSC AD 340 5210 - Week 6
n8ebel
1
360
NSC AD 340 5210 - Week 5
n8ebel
1
440
NSC AD 340 5210 - Week 4
n8ebel
2
530
Other Decks in Programming
See All in Programming
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
4
1.3k
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
290
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
200
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
1
190
プロポーザルを書いてもらう
pvcresin
0
150
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
170
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
460
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
210
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
140
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.8k
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
660
Featured
See All Featured
Chasing Engaging Ingredients in Design
codingconduct
0
260
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
890
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
400
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
270
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
The Limits of Empathy - UXLibs8
cassininazir
1
590
Balancing Empowerment & Direction
lara
6
1.2k
Transcript
Week 8 Lecture ViewBinding, ViewModel and MVVM
What are we building this week? Replacing findViewById() using ViewBinding
02 Project Demo ViewBinding 01 Saving data across configuration changes ViewModel Scoping 04 Android ViewModel Implementing MVVM using Android ViewModel 03
Project Demo What are we building this week?
Week 8 Project Updates • Refactoring ForecastDetailsFragment • Using ViewBinding
to replace calls to findViewById() • Using ViewModel to implement MVVM • Saving data across configuration changes using ViewModel scoping
ViewBinding Replacing calls to findViewById()
Generate statically typed view references Removes any need for findViewById()
Access Generated View Properties // inflate layout and get ViewBinding
reference val binding = FragmentForecastDetailsBinding.inflate(inflater, parent, false) // access null-safe properties to reference you views binding.descriptionText.text = viewState.description binding.dateText.text = viewState.date binding.forecastIcon.load(viewState.iconUrl)
Enable ViewBinding // app/build.gradle android { … viewBinding { enabled
= true } }
ViewModel Separating business logic from UI presentation
“The ViewModel class is designed to store and manage UI-related
data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations”
• Manage data sources • Format data • Save data
across configuration change • Expose data to be displayed in the UI Using ViewModel
MVVM Separation of business logic and UI presentation
MVVM VIEW VIEW MODEL MODEL
MVVM FRAGMENT VIEW MODEL REPOSITORIES
ViewModel Scoping Save data across configuration changes
• Avoid creating a new ViewModel in response to configuration
changes • Reuse existing ViewModels (and data) within different scopes ◦ Fragment ◦ Activity ◦ Navigation Graph ViewModel Scoping
• More responsive apps • Fewer network and database requests
• Better user experience ViewModel Scoping
Demo