SlideShare a Scribd company logo
1 of 42
Download to read offline
Architecture Components

In Real Life
Season 2
@akexorcist

Lovely Android Developer @ Nextzy
Architecture

Component
• Lifecycles

• LiveData

• ViewModel

• Room
Architecture

Component
• Lifecycles

• LiveData

• ViewModel

• Room

• Navigation

• Paging

• ViewModel SavedState

• Data Binding
Dialog Event Listener
Use case
Activity/Fragment
DialogFragment
Normal
CreateEvent Listener
Activity/Fragment
DialogFragment
Activity destroyed then restored
CreateEvent Listener
Activity/Fragment DialogFragment
Handle dialog event with view model
ViewModel
Activity/Fragment DialogFragment
Handle dialog event with view model
ViewModel
Create
Activity/Fragment DialogFragment
Handle dialog event with view model
ViewModel
Event Listener Event Listener
Activity/Fragment DialogFragment
Handle dialog event with view model
Mapper
Event Listener Event Listener
ViewModel
LiveDataLiveData
DialogManager.showConfirm(
message = message,
key = KEY_DELETE_CONFIRMATION,
fragmentManager = supportFragmentManager
)
dialogViewModel.confirmation.observe(this, object : ConfirmDialogListener {
override fun onConfirmButtonClick(key: String?, data: Bundle?) {
when (key) {
KEY_DELETE_CONFIRMATION -> deleteTask(true)
}
}
override fun onCancelButtonClick(key: String?, data: Bundle?) {
}
})
MVVM + Clean Architecture
With Architecture Components
Reason
• Able to write the testable code 

• Suitable for write the code with others
Activity/Fragment
ViewModel
Repository
Database Network
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
Data Layer
Presentation Layer
Domain Layer
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
LiveDataLiveDataLiveData
LiveData
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
class ValidateUsernameUseCase : UseCase<String?, Boolean>() {
override fun execute(parameters: String?): Boolean {
return parameters?.isNotEmpty() ?: false
}
}
class ValidateUsernameUseCase : UseCase<String?, Boolean>() {
override fun execute(parameters: String?): Boolean {
return parameters?.isNotEmpty() ?: false
}
}
class ValidateUsernameUseCase : UseCase<String?, Boolean>() {
override fun execute(parameters: String?): Boolean {
return parameters?.isNotEmpty() ?: false
}
}
class ValidateUsernameUseCase : UseCase<String?, Boolean>() {
override fun execute(parameters: String?): Boolean {
return parameters?.isNotEmpty() ?: false
}
}
class GetProfileUseCase constructor(
private val repository: ProfileRepository
) : MediatorUseCase<GetProfileRequest, String?>() {
override fun execute(parameters: GetProfileRequest) {
result.addSource(repository.getTermCondition(parameters)) { response ->
result.postValue(response)
}
}
}
class GetProfileUseCase constructor(
private val repository: ProfileRepository
) : MediatorUseCase<GetProfileRequest, String?>() {
override fun execute(parameters: GetProfileRequest) {
result.addSource(repository.getTermCondition(parameters)) { response ->
result.postValue(response)
}
}
}
class GetProfileUseCase constructor(
private val repository: ProfileRepository
) : MediatorUseCase<GetProfileRequest, String?>() {
override fun execute(parameters: GetProfileRequest) {
result.addSource(repository.getTermCondition(parameters)) { response ->
result.postValue(response)
}
}
}
class GetProfileUseCase constructor(
private val repository: ProfileRepository
) : MediatorUseCase<GetProfileRequest, String?>() {
override fun execute(parameters: GetProfileRequest) {
result.addSource(repository.getTermCondition(parameters)) { response ->
result.postValue(response)
}
}
}
class ValidateUsernameUseCase : UseCase<String?, Boolean>() {
override fun execute(parameters: String?): Boolean {
return parameters?.isNotEmpty() ?: false
}
}
class GetProfileUseCase constructor(
private val repository: ProfileRepository
) : MediatorUseCase<GetProfileRequest, String?>() {
override fun execute(parameters: GetProfileRequest) {
result.addSource(repository.getTermCondition(parameters)) { response ->
result.postValue(response)
}
}
}
Synchronous Logic
Asynchronous Logic
LiveDataLiveDataLiveData
LiveData
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
class ValidateUsernameUseCaseTest {
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
}
@Test
fun `Validate the username with normally username - should be true`() {
val useCase = ValidateUsernameUseCase()
val username = "Akexorcist"
val result = useCase.executeNow(username)
Assert.assertTrue(result is Result.Success)
Assert.assertTrue((result as Result.Success).data ?: false)
}
@Test
fun `Validate the username with empty username - should be false`() {
val useCase = ValidateUsernameUseCase()
val username = ""
class ValidateUsernameUseCaseTest {
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
}
@Test
fun `Validate the username with normally username - should be true`() {
val useCase = ValidateUsernameUseCase()
val username = "Akexorcist"
val result = useCase.executeNow(username)
Assert.assertTrue(result is Result.Success)
Assert.assertTrue((result as Result.Success).data ?: false)
}
@Test
fun `Validate the username with empty username - should be false`() {
val useCase = ValidateUsernameUseCase()
val username = ""
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
Data Layer
Presentation Layer
Domain Layer
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
Developer A
Developer B
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
Developer A
Developer B
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
UseCaseUseCase
Developer A
Developer B
Activity/Fragment
ViewModel
UseCase
Database Network
Repository
Data Layer
Presentation Layer
Domain Layer
Navigation

Data Binding

ViewModel SavedState
Coroutine
Activity/Fragment
Paging
Data Layer
Presentation Layer
Domain Layer
Do the 

Proof of Concept 

every time when you learn
something new
Thank you!
@akexorcist

Lovely Android Developer @ Nextzy

More Related Content

What's hot

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
Yekmer Simsek
 

What's hot (20)

TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando CoroutinesTDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
 
What's new in CDI 2.0
What's new in CDI 2.0What's new in CDI 2.0
What's new in CDI 2.0
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
WaveEngine 2D components
WaveEngine 2D componentsWaveEngine 2D components
WaveEngine 2D components
 
Advanced #2 threading
Advanced #2   threadingAdvanced #2   threading
Advanced #2 threading
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Aplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e JetpackAplicações Assíncronas no Android com Coroutines e Jetpack
Aplicações Assíncronas no Android com Coroutines e Jetpack
 
Creating Ext GWT Extensions and Components
Creating Ext GWT Extensions and ComponentsCreating Ext GWT Extensions and Components
Creating Ext GWT Extensions and Components
 
Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard Library
 
外部環境への依存をテストする
外部環境への依存をテストする外部環境への依存をテストする
外部環境への依存をテストする
 
Programação assíncrona utilizando Coroutines
Programação assíncrona utilizando CoroutinesProgramação assíncrona utilizando Coroutines
Programação assíncrona utilizando Coroutines
 
Sequencing Audio Using React and the Web Audio API
Sequencing Audio Using React and the Web Audio APISequencing Audio Using React and the Web Audio API
Sequencing Audio Using React and the Web Audio API
 
WaveEngine 3D components
WaveEngine 3D componentsWaveEngine 3D components
WaveEngine 3D components
 
Matteo Antony Mistretta - Refactoring into React hooks - Codemotion Rome 2019
Matteo Antony Mistretta - Refactoring into React hooks - Codemotion Rome 2019Matteo Antony Mistretta - Refactoring into React hooks - Codemotion Rome 2019
Matteo Antony Mistretta - Refactoring into React hooks - Codemotion Rome 2019
 
Aplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & JetpackAplicações assíncronas no Android com Coroutines & Jetpack
Aplicações assíncronas no Android com Coroutines & Jetpack
 
The Ring programming language version 1.10 book - Part 59 of 212
The Ring programming language version 1.10 book - Part 59 of 212The Ring programming language version 1.10 book - Part 59 of 212
The Ring programming language version 1.10 book - Part 59 of 212
 
Eddystone beacons demo
Eddystone beacons demoEddystone beacons demo
Eddystone beacons demo
 
Aplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & JetpackAplicações assíncronas no Android com
Coroutines & Jetpack
Aplicações assíncronas no Android com
Coroutines & Jetpack
 
Given Groovy Who Needs Java
Given Groovy Who Needs JavaGiven Groovy Who Needs Java
Given Groovy Who Needs Java
 
Deep Dive into Zone.JS
Deep Dive into Zone.JSDeep Dive into Zone.JS
Deep Dive into Zone.JS
 

Similar to Architecture Components In Real Life Season 2

Similar to Architecture Components In Real Life Season 2 (20)

hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
5-Hibernate.ppt
5-Hibernate.ppt5-Hibernate.ppt
5-Hibernate.ppt
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
 
Structuring React.js Components
Structuring React.js ComponentsStructuring React.js Components
Structuring React.js Components
 
4Developers 2018: Structuring React components (Bartłomiej Witczak)
4Developers 2018: Structuring React components (Bartłomiej Witczak)4Developers 2018: Structuring React components (Bartłomiej Witczak)
4Developers 2018: Structuring React components (Bartłomiej Witczak)
 
Gilt Groupe's Selenium 2 Conversion Challenges
Gilt Groupe's Selenium 2 Conversion ChallengesGilt Groupe's Selenium 2 Conversion Challenges
Gilt Groupe's Selenium 2 Conversion Challenges
 
Android architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta IndonesiaAndroid architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta Indonesia
 
Android dev toolbox
Android dev toolboxAndroid dev toolbox
Android dev toolbox
 
[@IndeedEng] Building Indeed Resume Search
[@IndeedEng] Building Indeed Resume Search[@IndeedEng] Building Indeed Resume Search
[@IndeedEng] Building Indeed Resume Search
 
Aspect oriented programming with spring
Aspect oriented programming with springAspect oriented programming with spring
Aspect oriented programming with spring
 
Annotation processing
Annotation processingAnnotation processing
Annotation processing
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with Spring
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and Testing
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
 
APPlause - DemoCamp Munich
APPlause - DemoCamp MunichAPPlause - DemoCamp Munich
APPlause - DemoCamp Munich
 
Annotation processing and code gen
Annotation processing and code genAnnotation processing and code gen
Annotation processing and code gen
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
Binding business data to vaadin components
Binding business data to vaadin componentsBinding business data to vaadin components
Binding business data to vaadin components
 

More from Somkiat Khitwongwattana

More from Somkiat Khitwongwattana (17)

What's new in Android - Google I/O Extended Bangkok 2022
What's new in Android - Google I/O Extended Bangkok 2022What's new in Android - Google I/O Extended Bangkok 2022
What's new in Android - Google I/O Extended Bangkok 2022
 
Canvas API in Android
Canvas API in AndroidCanvas API in Android
Canvas API in Android
 
Get Ready for Target SDK Version 29 and 30
Get Ready for Target SDK Version 29 and 30Get Ready for Target SDK Version 29 and 30
Get Ready for Target SDK Version 29 and 30
 
What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018
 
New things that android developer should not miss in 2019
New things that android developer should not miss in 2019New things that android developer should not miss in 2019
New things that android developer should not miss in 2019
 
Bitmap management like a boss
Bitmap management like a bossBitmap management like a boss
Bitmap management like a boss
 
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
Hello, Android Studio 3.2 & Android App Bundle @ I/O Extended Bangkok 2018
 
Deep Dive Into Repository - Android Architecture Components
Deep Dive Into Repository - Android Architecture ComponentsDeep Dive Into Repository - Android Architecture Components
Deep Dive Into Repository - Android Architecture Components
 
Introduction to Architecture Components @ Google I/O Extended Bangkok 2017
Introduction to Architecture Components @ Google I/O Extended Bangkok 2017Introduction to Architecture Components @ Google I/O Extended Bangkok 2017
Introduction to Architecture Components @ Google I/O Extended Bangkok 2017
 
What's new in Android O @ Google I/O Extended Bangkok 2017
What's new in Android O @ Google I/O Extended Bangkok 2017What's new in Android O @ Google I/O Extended Bangkok 2017
What's new in Android O @ Google I/O Extended Bangkok 2017
 
Pokemon GO 101@Nextzy
Pokemon GO 101@NextzyPokemon GO 101@Nextzy
Pokemon GO 101@Nextzy
 
Advance Android Layout Walkthrough
Advance Android Layout WalkthroughAdvance Android Layout Walkthrough
Advance Android Layout Walkthrough
 
Interface Design for Mobile Application
Interface Design for Mobile ApplicationInterface Design for Mobile Application
Interface Design for Mobile Application
 
Smart Lock for Password @ Game DevFest Bangkok 2015
Smart Lock for Password @ Game DevFest Bangkok 2015Smart Lock for Password @ Game DevFest Bangkok 2015
Smart Lock for Password @ Game DevFest Bangkok 2015
 
Whats new in Android Development Tools @ I/O Rewind Bangkok
Whats new in Android Development Tools @ I/O Rewind BangkokWhats new in Android Development Tools @ I/O Rewind Bangkok
Whats new in Android Development Tools @ I/O Rewind Bangkok
 
What's new in Google Play Services @ I/O Rewind Bangkok
What's new in Google Play Services @ I/O Rewind BangkokWhat's new in Google Play Services @ I/O Rewind Bangkok
What's new in Google Play Services @ I/O Rewind Bangkok
 
ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Architecture Components In Real Life Season 2