Eduardo Medina
@eduardomedina | emedinaa@gmail.com | github/emedinaa
Android SME Belatrix / Globant
Mapsalud�Instructor en Academia Móviles
Android Dev Perú
Kotlin User Group Perú
IOS Dev Perú�GDG Lima
MVVM Pattern
Model View ViewModel
MVC Model View Controller
MVP Model View Presenter
Clean Architecture
MVVM Model View ViewModel
Architecture Patterns & Architectures
https://github.com/emedinaa/kotlin-mvvm
https://github.com/emedinaa/kotlin-mvvm/tree/koin
https://github.com/emedinaa/kotlin-mvvm/tree/coroutines
Kotlin mvvm samples
https://github.com/emedinaa/kotlin-mvvm/tree/hilt
https://github.com/emedinaa/kotlin-mvvm/tree/clean
Kotlin mvvm samples
https://github.com/emedinaa/kotlin-mvvm
UI
Retrofit
VIEW - DATA
channel
DataSource
DataSource
View - DataSource
UI
View - Repository - DataSource
Callback
Callback
Repository
UI
View - ?? - Repository - DataSource
Callback
Callback
MVVM - Model View ViewModel
Callbacks
Property changed events
UI events
MVVM - Model View ViewModel
Callbacks
Property changed events
UI events
View
Observers
UI events
LiveData
Property changed events
LiveData & Lifecycle
LiveData & Lifecycle
UI
ViewModel
ViewModel provides data for UI components and survive configuration changes.
View actions | ViewModel |
showLoading() | isViewLoading�<Boolean> |
hideLoading() | isViewLoading <Boolean> |
errorMessage() | onErrorMessage�<Any> |
emptyData() | isEmptyList <Boolean> |
renderMuseums() | museums List<Museum>> |
View - ViewModel - Model (Repository | DataSource)
Callback
Callback
Callbacks
Callbacks
LiveData
ViewModel
ViewModel
UI
Architecture
https://developer.android.com/jetpack/docs/guide
Unit Tests
Unit tests
JUnit + Mockito
Test
Test
Test
Test
Test
Test
Layer
communication
MVVM - Model View ViewModel
Callbacks
Property changed events
UI events
Sealed
classes
Operation Result
Success
Error
https://kotlinlang.org/docs/reference/sealed-classes.html
Sealed classes
OperationResult
Success
Error
Coroutines
https://kotlinlang.org/docs/reference/coroutines-overview.html
Coroutines
fun fetchCoupons() {
viewModelScope.launch {
val result = withContext(Dispatchers.IO) {
repository.retrieveCoupons()
}
}
...
}
fetchCoupons()
onDraw()
onDraw()
renderCoupons()
onDraw()
Other
thread
DataSource
ViewModel
UI
Unit Tests
Test
Test
Test
Test
Test
Test
Checklist
You should use some architecture pattern...
MVVM - Model View ViewModel
Property changed events
UI events
Sealed class
Model
LiveData
request data
Sealed class
Repository
Data source
Entity
Use Case
ViewModel
Property changed events
UI events
Request data
Sealed class
Observers
LiveData
MVVM
LiveData
MVVM - Clean
Sealed class
Sealed class
DTO
Entity
Clean Architecture
DI
DI
https://github.com/emedinaa/kotlin-mvvm
Eduardo Medina
Thank you
@eduardomedina | emedinaa@gmail.com | github/emedinaa
Android
Dev�Perú
https://www.meetup.com/es-ES/Android-Dev-Peru/