Implementing MVVM
in Android
Wajahat Karim
GDE in Android
wajahatkarim.com
GDG Live Pakistan
Slide 2
Slide 2 text
- Google Developer Expert in Android
- Over 8 years experience in Android
- Open Source Contributor
- Technical Blogs & Books Writer
- Love to share my knowledge with others
Follow me on Twitter @WajahatKarim |
wajahatkarim.com
This is Wajahat Karim
Slide 3
Slide 3 text
MV* - The Confusion Begins!
Model
Controller
Presenter
ViewModel
Intent
View
Slide 4
Slide 4 text
Model-View-ViewModel (MVVM)
Model ViewModel View
This is a architecture not the architecture
Exposes Data
Requests Data
Observes
User Actions & Events
Slide 5
Slide 5 text
MVVM on Android
Jetpack for the Rescue
Slide 6
Slide 6 text
LiveData
1. An Observable with LifeCycle
ability
2. Instantly notifies the changes in
the data to the UI
Observes for updates
LiveData value updates
Notifies the observer
Update the UI
STARTED
Or
RESUMED?
Slide 7
Slide 7 text
ViewModel
1. Middle man for View & Model
2. Decouples data from the view to
survive the configuration
changes
3. Never put the references to
“Context” or “View” inside the
ViewModel
Slide 8
Slide 8 text
Finally, the Architecture
All the UI related stuff
Holds data required by UI and survives
configuration changes
Responsible for providing data to ViewModel
Data sources (or model) such as database or
from the server
Slide 9
Slide 9 text
Testing
Who got time for it? My code is perfect.
Slide 10
Slide 10 text
Focus of this session
https://github.com/wajahatkarim3/MVVM-GDG-Live
1. ViewModel, LiveData
2. Kotlin, Extension Methods
3. Dependency Injection with Koin
4. Retrofit for Networking
5. Coil for image downloading
Slide 11
Slide 11 text
Coding Time
https://github.com/wajahatkarim3/MVVM-GDG-Live
Slide 12
Slide 12 text
Thank you for listening...
Give us feedback: http://bit.ly/gdgpkfeedback
@WajahatKarim
wajahatkarim.com youtube.com/c/wajahatkarim3