SlideShare a Scribd company logo
1 of 48
Download to read offline
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Effective Android UI
Pedro Vicente Gómez Sánchez
Android Expert
pedro@karumi.com
@pedro_g_s
github.com/pedrovgs
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Irene Herranz
Managing Director
Alberto Gragera
Technical Director
Jorge Barroso
Android Expert
Davide Mendolia
Full Stack Engineer
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
This talk is the continuation of Software Design Patterns on Android
http://www.slideshare.net/PedroVicenteGmezSnch/software-design-patterns-on-android
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Is the UI code less important?
Are we using Android SDK properly?
How can I improve the UI code?
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
● Introduction.
● Resources and qualifiers.
● Custom Views.
● Model View Presenter.
● Model View ViewModel.
● MVP vs MVVM.
● Some advices.
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
https://github.com/pedrovgs/EffectiveAndroidUI
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
● MVP and MVVM samples.
● How to work with Fragments.
● Communication between Fragments and Activities.
● How to use Dagger as Dependency Injector.
● How to use resources to support different screen
densities, device orientation and different Android
versions.
● How to use styles and themes.
● How to use Navigator or ActionCommand to
implement activities navigation.
● How to use custom qualifiers with resources.
● How to use different layouts: RelativeLayout,
LinearLayout, FrameLayout, etc.
● Usage of merge, include and view stub.
● How to implement a ListView using Renderers.
● Simple Interactors implementation described in
“Software Design Patterns on Android” talk.
● How to use Dagger with different scopes, Application
scope and Activity scope.
Introduction
https://github.com/pedrovgs/EffectiveAndroidUI
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Introduction: S4 - Android 4.4.2
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Introduction: DraggablePanel
https://github.com/pedrovgs/DraggablePanel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Introduction: MDPI device
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Introduction: Nexus 7 and Nexus 10 - Android 4.4.4
Portrait Landscape
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
How can we change the UI depending
on the device?
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Android resources are one of the Android SDK powerful tools
to work with the UI layer. Some common resources are:
● Color: Colors available for your application. In colors.xml you can declare
your color palette.
● Drawable: Shapes and statics assets ready to be used in Image
components as src or background.
● Layout: XML files to describe the application UI and to be inflated by the
system.
● Menu: Android menus can be described in xml files and used directly
from our activities.
● Integer: Integer values ready to be used in xml files or java code.
● XML: XML configuration files that can be used to indicate different
configuration parameters. Not really common.
Resources and qualifiers
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
For complex projects where we have to support tons of different devices with different screen
densities and sizes and different Android API versions we need to use our resources and qualifiers
properly to get the max development performance.
Qualifiers are really important to work with different Android configurations. We can prepare
different resources for different Android configurations and these resources are going to be
provided automatically. Configuration based on qualifiers:
● Screen density: ldpi, mdpi, hdpi, xhdpi, etc.
● Language: es, en, fr, en-rUS, etc.
● Min width: sw600dp, sw720dip.
● Available width or height: w720dp, h1024dp.
● Screen orientation: landscape, portrait.
● Android API level: v7, v8, v9, etc.
Resources and qualifiers
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
How have we used resources and qualifiers in Effective Android UI project?
● Layouts:
○ layout-v10: Android 2.X is using one layout with just one fragment.
○ layout-v11: Android 3.X y 4.X (except tablets in landscape).
○ layout-sw600dp-land: Layout with two fragments in landscape.
● Values:
○ values-mdpi: Mdpi and ldpi devices are using one column for the GridView and different
ImageView height.
○ values-hdpi: Hdpi, xhdpi and xxhdpi devices with screen width lower than 820 dip are
using two columns for the GridView and another ImageView height.
○ values-w820: Devices with more than 820 dip width are going to use 3 columns for the
GridView configuration.
Resources and qualifiers
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Resources and qualifiers
http://developer.android.com/guide/topics/resources/providing-resources.html
How it’s working if we haven’
t declared every possible
configuration?
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Custom Views
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Main motivations to use custom views are:
● Create a non implemented Android SDK widget.
● Group presentation logic for different views. Really useful with
MVVM.
● Add semantic to UI layer components.
● Avoid code duplicity.
Custom Views
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
There are 5 approaches to implement your custom views:
● Extend an already written widget like TextView, ImageView.
● Extend View and override onDraw method using the Canvas API.
● Extend one Layout/ViewGroup and inflate your own layout file.
● Extend one Layout/ViewGroup and wait for views added by other
developers using this custom view.
● Inflate different layouts provided by the custom view client
Custom Views
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Custom Views
http://github.com/pedrovgs/Nox
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Are you ready to talk about MVP and
MVVM?
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Model View Presenter
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Model View Presenter is a software
design pattern that comes from MVC and is
used to build user interfaces. In this pattern,
the “presenter” has the responsibility to
implement all the presentation logic and data
transformation in order to send information to
the view. Works as an abstraction between the
UI layer and the business logic layer.
The “view” in MVP is going to be
abstracted using an interface implemented by
Android components.
Model View Presenter
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
The main problem that MVP solves is related
to testing, to avoid coupling and to avoid code
duplicity.
The usage of MVP improves the testability of
your code because we can test all our UI code
without executing framework code, just with unit
tests. To do this, all the presentation logic is moved
to the presenter.
The view implementation is going to be really
lightweight.
Model View Presenter
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
One of the key points related to
MVP is to leave your presenters free of
Android dependencies. By removing all
your Android code from your
presenters you’ll be able to test it
easily.
Model View Presenter
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Using MVP, Activity Fragments and
Custom Views are going to implement a
presenter “view” interface and are going to
be configured as presenter views.
Views are going to contain code to
implement your view details - described in
the View interface - and to connect user
actions with presenters.
Model View Presenter
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Even if we are using MVP, we need to connect our component lifecycle to our
presenter in order to notify whether the view is ready to work or not.
Some methods like “onSavedInstanceState” will update our presenter state if
needed.
Model View Presenter
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Model View Presenter
To implement user events - like a button clicked - our
view implementation will delegate to the presenter to take
some decisions.
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
If you want to extract navigation
implementation out of Activities or
Fragments you can use a “Navigator”.
Using one Navigator you can avoid
some cycles in the collaboration diagram
between view implementations and presenter
when a user action has to open another
activity or modify the navigation stack.
To do this, you need to be able to inject
Activity context using a dependency injector.
Model View Presenter
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Model View ViewModel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Model View ViewModel is a software
design pattern derived from Presentation
Model (by Martin Fowler). It’s commonly used
to build user interfaces and used by Microsoft
to implement Windows applications.
The power of this pattern is in the usage
of a binding engine, but we can use it without
one.
The binding engine is going to avoid all
the boilerplate code we have to write to
connect our view model with the view to keep
it updated.
Model View ViewModel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
ViewModel implementations will contain
all the logic state of the view. “Visibility”, “is
focused?”, “is clickable?”, “has been clicked?”
and keeps references to all the data related to
the view.
If you want to implement a reactive UI
you have to connect your ViewModels with
your events mechanism to be able to change
the view state changing the ViewModel
information.
Android UI components lifecycle will be
connected with the ViewModel as we were
already doing with MVP.
Model View ViewModel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
In MVVM ViewModel implementation
will not contain a view instance, it is going to
use an events mechanism - data binding
engine - to communicate state changes to the
view implementation.
In this pattern, the “View” is not an
interface, is just an implementation using the
ViewModel. Activities, Fragments and Custom
Views will keep an instance of the View Model
and will register different listeners to know
when the View Model has changed.
Model View ViewModel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
In the view implementation we are using - Activities, Fragments or Custom Views - we will
execute Action Commands offered by the ViewModel.
Model View ViewModel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
If the user clicks a widget, the view
implementation will get an Action Command
from the View Model to execute it.
This implementation will be really
interesting when Action Commands are going
to represent UI actions that could be really
repetitive like open Activities or show Toasts.
Model View ViewModel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
View Models represent big views like
Activities and return little ViewModels for
Custom Views or ListView rows. This
implementation is really easy to adopt if you
use Renderers.
Model View ViewModel
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
To implement MVVM is really convenient to connect our ViewModels
and view implementations using a binding engine. This is going to reduce
all the boilerplate needed to connect these elements manually and is
going to get a reactive view.
Model View ViewModel
RoboBinding AndroidBinding
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
¿ MVP vs MVVM ?
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
● MVVM data binding engines are really powerful, but not every library
supports obfuscation.
● MVP used to be easier to understand and implement.
● If you use little presenters your MVP implementation will look like
MVVM, be careful with the presenter size!
● MVP could be easier to test, depending on the binding engine you are
using.
● MVVM is going to be faster to implement, if you use binding, because
you have to write less code.
● Both patterns are going to improve code quality and testability.
MVP vs MVVM
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
The motivations of this patterns are the same. These
patterns try to solve the same problems.
Both patterns are going to abstract our model
implementation and view implementation. This is useful
to change any UI boundary layer implementation as you
wish.
MVP vs MVVM
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
To me, MVP is not better than MVVM and
vice versa.
Think about these patterns and use the one
you understand better.
MVP vs MVVM
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
● Avoid expensive tasks executed over the UI thread.
● Avoid code duplicity.
● Measure your UI performance using performance tools.
● Use themes, styles, dimensions and colors properly.
● Think in the UI layer like an isolated domain.
● Write testable code and test it.
● Return all the information needed to paint your UI.
● Implement your ListView and Adapters recycling your views.
● Write code for your buddies, not for the machine.
Some advices
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
Questions?
pedro@karumi.com
@pedro_g_s
github.com/pedrovgs
Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs

More Related Content

What's hot

Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGeoff Hoffman
 
위대한 게임개발팀의 공통점
위대한 게임개발팀의 공통점위대한 게임개발팀의 공통점
위대한 게임개발팀의 공통점Ryan Park
 
Linguagem C 03 Estruturas De Decisao
Linguagem C 03 Estruturas De DecisaoLinguagem C 03 Estruturas De Decisao
Linguagem C 03 Estruturas De DecisaoRegis Magalhães
 
C++ introducao
C++ introducaoC++ introducao
C++ introducaoSedu
 
Criando jogos com python e pygame 1 aula
Criando jogos com python e pygame 1 aulaCriando jogos com python e pygame 1 aula
Criando jogos com python e pygame 1 aulaDiego Lopes
 
Codigo limpo: Nomes Significativos Cap 2
Codigo limpo:  Nomes Significativos Cap 2Codigo limpo:  Nomes Significativos Cap 2
Codigo limpo: Nomes Significativos Cap 2Inael Rodrigues
 
UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1Hong-Gi Joe
 
게임 시스템 디자인 시작하기
게임 시스템 디자인 시작하기게임 시스템 디자인 시작하기
게임 시스템 디자인 시작하기ByungChun2
 

What's hot (10)

Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
위대한 게임개발팀의 공통점
위대한 게임개발팀의 공통점위대한 게임개발팀의 공통점
위대한 게임개발팀의 공통점
 
Halloween para pintar
Halloween para pintarHalloween para pintar
Halloween para pintar
 
Linguagem C 03 Estruturas De Decisao
Linguagem C 03 Estruturas De DecisaoLinguagem C 03 Estruturas De Decisao
Linguagem C 03 Estruturas De Decisao
 
C++ introducao
C++ introducaoC++ introducao
C++ introducao
 
Criando jogos com python e pygame 1 aula
Criando jogos com python e pygame 1 aulaCriando jogos com python e pygame 1 aula
Criando jogos com python e pygame 1 aula
 
Codigo limpo: Nomes Significativos Cap 2
Codigo limpo:  Nomes Significativos Cap 2Codigo limpo:  Nomes Significativos Cap 2
Codigo limpo: Nomes Significativos Cap 2
 
[PandoraCube] 게임 기초 인공지능
[PandoraCube] 게임 기초 인공지능[PandoraCube] 게임 기초 인공지능
[PandoraCube] 게임 기초 인공지능
 
UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1UI아트 작업자를 위한 언리얼엔진4 UMG #1
UI아트 작업자를 위한 언리얼엔진4 UMG #1
 
게임 시스템 디자인 시작하기
게임 시스템 디자인 시작하기게임 시스템 디자인 시작하기
게임 시스템 디자인 시작하기
 

Viewers also liked

Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Ken William
 
Android cleanarchitecture
Android cleanarchitectureAndroid cleanarchitecture
Android cleanarchitectureTomoaki Imai
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in androidJay Kumarr
 
Android Clean Architecture for Dummies
Android Clean Architecture for DummiesAndroid Clean Architecture for Dummies
Android Clean Architecture for DummiesKengo Suzuki
 
Android Design Principles and Popular Patterns
Android Design Principles and Popular PatternsAndroid Design Principles and Popular Patterns
Android Design Principles and Popular PatternsFaiz Malkani
 
World-Class Testing Development Pipeline for Android
 World-Class Testing Development Pipeline for Android World-Class Testing Development Pipeline for Android
World-Class Testing Development Pipeline for AndroidPedro Vicente Gómez Sánchez
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Androidintive
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidOutware Mobile
 
Clean architecture
Clean architectureClean architecture
Clean architectureandbed
 
Lightning Talk - Clean Architecture and Design
Lightning Talk - Clean Architecture and DesignLightning Talk - Clean Architecture and Design
Lightning Talk - Clean Architecture and DesignDeivison Sporteman
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 

Viewers also liked (20)

Software Design patterns on Android English
Software Design patterns on Android EnglishSoftware Design patterns on Android English
Software Design patterns on Android English
 
Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~Is Activity God? ~ The MVP Architecture ~
Is Activity God? ~ The MVP Architecture ~
 
Android cleanarchitecture
Android cleanarchitectureAndroid cleanarchitecture
Android cleanarchitecture
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
 
Karumi Dojo: Kata Maxibon
Karumi Dojo: Kata MaxibonKarumi Dojo: Kata Maxibon
Karumi Dojo: Kata Maxibon
 
Dependency injection on Android
Dependency injection on AndroidDependency injection on Android
Dependency injection on Android
 
Android Clean Architecture for Dummies
Android Clean Architecture for DummiesAndroid Clean Architecture for Dummies
Android Clean Architecture for Dummies
 
Android Design Principles and Popular Patterns
Android Design Principles and Popular PatternsAndroid Design Principles and Popular Patterns
Android Design Principles and Popular Patterns
 
World-Class Testing Development Pipeline for Android
 World-Class Testing Development Pipeline for Android World-Class Testing Development Pipeline for Android
World-Class Testing Development Pipeline for Android
 
Clean architecture: Android
Clean architecture: AndroidClean architecture: Android
Clean architecture: Android
 
Karumi Dojo - String Calculator Kata
Karumi Dojo - String Calculator KataKarumi Dojo - String Calculator Kata
Karumi Dojo - String Calculator Kata
 
The Good Developer - Spanish
The Good Developer - SpanishThe Good Developer - Spanish
The Good Developer - Spanish
 
Kata Contacts
Kata ContactsKata Contacts
Kata Contacts
 
A Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on AndroidA Separation of Concerns: Clean Architecture on Android
A Separation of Concerns: Clean Architecture on Android
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Effective Android UI - spanish
Effective Android UI - spanishEffective Android UI - spanish
Effective Android UI - spanish
 
Android MVVM
Android MVVMAndroid MVVM
Android MVVM
 
Working with Android TV - English
Working with Android TV - EnglishWorking with Android TV - English
Working with Android TV - English
 
Lightning Talk - Clean Architecture and Design
Lightning Talk - Clean Architecture and DesignLightning Talk - Clean Architecture and Design
Lightning Talk - Clean Architecture and Design
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 

Similar to Effective Android UI - English

Frontend Development vs Backend Development | Detailed Comparison
Frontend Development vs Backend Development | Detailed ComparisonFrontend Development vs Backend Development | Detailed Comparison
Frontend Development vs Backend Development | Detailed ComparisonMariya James
 
UpdatedMuhammadBilalResume.docx (1)
UpdatedMuhammadBilalResume.docx (1)UpdatedMuhammadBilalResume.docx (1)
UpdatedMuhammadBilalResume.docx (1)Muhammad Bilal Ahmed
 
VS Code and Modern Development Environment Preview
VS Code and Modern Development Environment PreviewVS Code and Modern Development Environment Preview
VS Code and Modern Development Environment PreviewRoberto Stefanetti
 
Interim Report.docx - vsiogap3d.googlecode.com
Interim Report.docx - vsiogap3d.googlecode.comInterim Report.docx - vsiogap3d.googlecode.com
Interim Report.docx - vsiogap3d.googlecode.combutest
 
Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...
Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...
Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...Dana Gardner
 
Arquitectura MVVM para la construcción de aplicaciones Windows Store
Arquitectura MVVM para la construcción de aplicaciones Windows StoreArquitectura MVVM para la construcción de aplicaciones Windows Store
Arquitectura MVVM para la construcción de aplicaciones Windows StoreDamian Schenkelman
 
Business management application
Business management applicationBusiness management application
Business management applicationPritam Tirpude
 
How to Become a Front-End Developer? Step-by-Step Guide by Careervira
How to Become a Front-End Developer? Step-by-Step Guide by CareerviraHow to Become a Front-End Developer? Step-by-Step Guide by Careervira
How to Become a Front-End Developer? Step-by-Step Guide by CareerviraCareervira
 
Android training-in-gurgaon
Android training-in-gurgaonAndroid training-in-gurgaon
Android training-in-gurgaonAP EDUSOFT
 
Anup_Resume_Update_9_1_16
Anup_Resume_Update_9_1_16Anup_Resume_Update_9_1_16
Anup_Resume_Update_9_1_16Anup Tyagi
 

Similar to Effective Android UI - English (20)

Frontend Development vs Backend Development | Detailed Comparison
Frontend Development vs Backend Development | Detailed ComparisonFrontend Development vs Backend Development | Detailed Comparison
Frontend Development vs Backend Development | Detailed Comparison
 
UpdatedMuhammadBilalResume.docx (1)
UpdatedMuhammadBilalResume.docx (1)UpdatedMuhammadBilalResume.docx (1)
UpdatedMuhammadBilalResume.docx (1)
 
DotVVM Fundamentals
DotVVM FundamentalsDotVVM Fundamentals
DotVVM Fundamentals
 
VS Code and Modern Development Environment Preview
VS Code and Modern Development Environment PreviewVS Code and Modern Development Environment Preview
VS Code and Modern Development Environment Preview
 
Interim Report.docx - vsiogap3d.googlecode.com
Interim Report.docx - vsiogap3d.googlecode.comInterim Report.docx - vsiogap3d.googlecode.com
Interim Report.docx - vsiogap3d.googlecode.com
 
Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...
Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...
Kony Visualizer Puts Mobile Apps Features Control in Hands of Those Closest t...
 
Arquitectura MVVM para la construcción de aplicaciones Windows Store
Arquitectura MVVM para la construcción de aplicaciones Windows StoreArquitectura MVVM para la construcción de aplicaciones Windows Store
Arquitectura MVVM para la construcción de aplicaciones Windows Store
 
Business management application
Business management applicationBusiness management application
Business management application
 
Vrushali_Resume
Vrushali_ResumeVrushali_Resume
Vrushali_Resume
 
How to Become a Front-End Developer? Step-by-Step Guide by Careervira
How to Become a Front-End Developer? Step-by-Step Guide by CareerviraHow to Become a Front-End Developer? Step-by-Step Guide by Careervira
How to Become a Front-End Developer? Step-by-Step Guide by Careervira
 
Android training-in-gurgaon
Android training-in-gurgaonAndroid training-in-gurgaon
Android training-in-gurgaon
 
CV
CVCV
CV
 
GE Predix - The IIoT Platform
GE Predix - The IIoT PlatformGE Predix - The IIoT Platform
GE Predix - The IIoT Platform
 
3D Web Visualization 1
3D Web Visualization 13D Web Visualization 1
3D Web Visualization 1
 
3D Web Visualization
3D Web Visualization 3D Web Visualization
3D Web Visualization
 
Devraj_Nataraj_CV_PDF
Devraj_Nataraj_CV_PDFDevraj_Nataraj_CV_PDF
Devraj_Nataraj_CV_PDF
 
GAURAV_MAKKAR
GAURAV_MAKKARGAURAV_MAKKAR
GAURAV_MAKKAR
 
who we are
who we arewho we are
who we are
 
Anup_Resume_Update_9_1_16
Anup_Resume_Update_9_1_16Anup_Resume_Update_9_1_16
Anup_Resume_Update_9_1_16
 
Wecreate
WecreateWecreate
Wecreate
 

Recently uploaded

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

Effective Android UI - English

  • 1. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Effective Android UI Pedro Vicente Gómez Sánchez Android Expert pedro@karumi.com @pedro_g_s github.com/pedrovgs
  • 2. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
  • 3. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Irene Herranz Managing Director Alberto Gragera Technical Director Jorge Barroso Android Expert Davide Mendolia Full Stack Engineer
  • 4. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs This talk is the continuation of Software Design Patterns on Android http://www.slideshare.net/PedroVicenteGmezSnch/software-design-patterns-on-android
  • 5. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Is the UI code less important? Are we using Android SDK properly? How can I improve the UI code?
  • 6. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs ● Introduction. ● Resources and qualifiers. ● Custom Views. ● Model View Presenter. ● Model View ViewModel. ● MVP vs MVVM. ● Some advices.
  • 7. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs https://github.com/pedrovgs/EffectiveAndroidUI
  • 8. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs ● MVP and MVVM samples. ● How to work with Fragments. ● Communication between Fragments and Activities. ● How to use Dagger as Dependency Injector. ● How to use resources to support different screen densities, device orientation and different Android versions. ● How to use styles and themes. ● How to use Navigator or ActionCommand to implement activities navigation. ● How to use custom qualifiers with resources. ● How to use different layouts: RelativeLayout, LinearLayout, FrameLayout, etc. ● Usage of merge, include and view stub. ● How to implement a ListView using Renderers. ● Simple Interactors implementation described in “Software Design Patterns on Android” talk. ● How to use Dagger with different scopes, Application scope and Activity scope. Introduction https://github.com/pedrovgs/EffectiveAndroidUI
  • 9. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Introduction: S4 - Android 4.4.2
  • 10. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Introduction: DraggablePanel https://github.com/pedrovgs/DraggablePanel
  • 11. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Introduction: MDPI device
  • 12. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Introduction: Nexus 7 and Nexus 10 - Android 4.4.4 Portrait Landscape
  • 13. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs How can we change the UI depending on the device?
  • 14. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Android resources are one of the Android SDK powerful tools to work with the UI layer. Some common resources are: ● Color: Colors available for your application. In colors.xml you can declare your color palette. ● Drawable: Shapes and statics assets ready to be used in Image components as src or background. ● Layout: XML files to describe the application UI and to be inflated by the system. ● Menu: Android menus can be described in xml files and used directly from our activities. ● Integer: Integer values ready to be used in xml files or java code. ● XML: XML configuration files that can be used to indicate different configuration parameters. Not really common. Resources and qualifiers
  • 15. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs For complex projects where we have to support tons of different devices with different screen densities and sizes and different Android API versions we need to use our resources and qualifiers properly to get the max development performance. Qualifiers are really important to work with different Android configurations. We can prepare different resources for different Android configurations and these resources are going to be provided automatically. Configuration based on qualifiers: ● Screen density: ldpi, mdpi, hdpi, xhdpi, etc. ● Language: es, en, fr, en-rUS, etc. ● Min width: sw600dp, sw720dip. ● Available width or height: w720dp, h1024dp. ● Screen orientation: landscape, portrait. ● Android API level: v7, v8, v9, etc. Resources and qualifiers
  • 16. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs How have we used resources and qualifiers in Effective Android UI project? ● Layouts: ○ layout-v10: Android 2.X is using one layout with just one fragment. ○ layout-v11: Android 3.X y 4.X (except tablets in landscape). ○ layout-sw600dp-land: Layout with two fragments in landscape. ● Values: ○ values-mdpi: Mdpi and ldpi devices are using one column for the GridView and different ImageView height. ○ values-hdpi: Hdpi, xhdpi and xxhdpi devices with screen width lower than 820 dip are using two columns for the GridView and another ImageView height. ○ values-w820: Devices with more than 820 dip width are going to use 3 columns for the GridView configuration. Resources and qualifiers
  • 17. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Resources and qualifiers http://developer.android.com/guide/topics/resources/providing-resources.html How it’s working if we haven’ t declared every possible configuration?
  • 18. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Custom Views
  • 19. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Main motivations to use custom views are: ● Create a non implemented Android SDK widget. ● Group presentation logic for different views. Really useful with MVVM. ● Add semantic to UI layer components. ● Avoid code duplicity. Custom Views
  • 20. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs There are 5 approaches to implement your custom views: ● Extend an already written widget like TextView, ImageView. ● Extend View and override onDraw method using the Canvas API. ● Extend one Layout/ViewGroup and inflate your own layout file. ● Extend one Layout/ViewGroup and wait for views added by other developers using this custom view. ● Inflate different layouts provided by the custom view client Custom Views
  • 21. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Custom Views http://github.com/pedrovgs/Nox
  • 22. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Are you ready to talk about MVP and MVVM?
  • 23. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Model View Presenter
  • 24. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Model View Presenter is a software design pattern that comes from MVC and is used to build user interfaces. In this pattern, the “presenter” has the responsibility to implement all the presentation logic and data transformation in order to send information to the view. Works as an abstraction between the UI layer and the business logic layer. The “view” in MVP is going to be abstracted using an interface implemented by Android components. Model View Presenter
  • 25. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs The main problem that MVP solves is related to testing, to avoid coupling and to avoid code duplicity. The usage of MVP improves the testability of your code because we can test all our UI code without executing framework code, just with unit tests. To do this, all the presentation logic is moved to the presenter. The view implementation is going to be really lightweight. Model View Presenter
  • 26. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs One of the key points related to MVP is to leave your presenters free of Android dependencies. By removing all your Android code from your presenters you’ll be able to test it easily. Model View Presenter
  • 27. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Using MVP, Activity Fragments and Custom Views are going to implement a presenter “view” interface and are going to be configured as presenter views. Views are going to contain code to implement your view details - described in the View interface - and to connect user actions with presenters. Model View Presenter
  • 28. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
  • 29. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Even if we are using MVP, we need to connect our component lifecycle to our presenter in order to notify whether the view is ready to work or not. Some methods like “onSavedInstanceState” will update our presenter state if needed. Model View Presenter
  • 30. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Model View Presenter To implement user events - like a button clicked - our view implementation will delegate to the presenter to take some decisions.
  • 31. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs If you want to extract navigation implementation out of Activities or Fragments you can use a “Navigator”. Using one Navigator you can avoid some cycles in the collaboration diagram between view implementations and presenter when a user action has to open another activity or modify the navigation stack. To do this, you need to be able to inject Activity context using a dependency injector. Model View Presenter
  • 32. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Model View ViewModel
  • 33. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Model View ViewModel is a software design pattern derived from Presentation Model (by Martin Fowler). It’s commonly used to build user interfaces and used by Microsoft to implement Windows applications. The power of this pattern is in the usage of a binding engine, but we can use it without one. The binding engine is going to avoid all the boilerplate code we have to write to connect our view model with the view to keep it updated. Model View ViewModel
  • 34. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs ViewModel implementations will contain all the logic state of the view. “Visibility”, “is focused?”, “is clickable?”, “has been clicked?” and keeps references to all the data related to the view. If you want to implement a reactive UI you have to connect your ViewModels with your events mechanism to be able to change the view state changing the ViewModel information. Android UI components lifecycle will be connected with the ViewModel as we were already doing with MVP. Model View ViewModel
  • 35. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs In MVVM ViewModel implementation will not contain a view instance, it is going to use an events mechanism - data binding engine - to communicate state changes to the view implementation. In this pattern, the “View” is not an interface, is just an implementation using the ViewModel. Activities, Fragments and Custom Views will keep an instance of the View Model and will register different listeners to know when the View Model has changed. Model View ViewModel
  • 36. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs In the view implementation we are using - Activities, Fragments or Custom Views - we will execute Action Commands offered by the ViewModel. Model View ViewModel
  • 37. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
  • 38. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs If the user clicks a widget, the view implementation will get an Action Command from the View Model to execute it. This implementation will be really interesting when Action Commands are going to represent UI actions that could be really repetitive like open Activities or show Toasts. Model View ViewModel
  • 39. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs View Models represent big views like Activities and return little ViewModels for Custom Views or ListView rows. This implementation is really easy to adopt if you use Renderers. Model View ViewModel
  • 40. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs To implement MVVM is really convenient to connect our ViewModels and view implementations using a binding engine. This is going to reduce all the boilerplate needed to connect these elements manually and is going to get a reactive view. Model View ViewModel RoboBinding AndroidBinding
  • 41. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs ¿ MVP vs MVVM ?
  • 42. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs
  • 43. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs ● MVVM data binding engines are really powerful, but not every library supports obfuscation. ● MVP used to be easier to understand and implement. ● If you use little presenters your MVP implementation will look like MVVM, be careful with the presenter size! ● MVP could be easier to test, depending on the binding engine you are using. ● MVVM is going to be faster to implement, if you use binding, because you have to write less code. ● Both patterns are going to improve code quality and testability. MVP vs MVVM
  • 44. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs The motivations of this patterns are the same. These patterns try to solve the same problems. Both patterns are going to abstract our model implementation and view implementation. This is useful to change any UI boundary layer implementation as you wish. MVP vs MVVM
  • 45. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs To me, MVP is not better than MVVM and vice versa. Think about these patterns and use the one you understand better. MVP vs MVVM
  • 46. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs ● Avoid expensive tasks executed over the UI thread. ● Avoid code duplicity. ● Measure your UI performance using performance tools. ● Use themes, styles, dimensions and colors properly. ● Think in the UI layer like an isolated domain. ● Write testable code and test it. ● Return all the information needed to paint your UI. ● Implement your ListView and Adapters recycling your views. ● Write code for your buddies, not for the machine. Some advices
  • 47. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs Questions? pedro@karumi.com @pedro_g_s github.com/pedrovgs
  • 48. Pedro V. Gómez Sánchez - pedro@karumi.com - @pedro_g_s - github.com/pedrovgs