Who is this guy?
Image Placeholder
César Valiente
Android Engineer @Wunderlist (@Microsoft)
FLOSS & Android Google Developer Expert (GDE)
+CesarValiente @CesarValiente
Slide 3
Slide 3 text
- A very nice and good app.
- Monolithic structure.
- Highly coupled.
- Sync in batch.
- Difficult to test .
Wunderlist 2
Slide 4
Slide 4 text
Wunderlist 3
- Completely redesigned.
- Divided into modules (layers).
- Highly decoupled.
- Real time sync.
- Easier to maintain, test and adapt.
- Easy to understand.
Slide 5
Slide 5 text
PARENTAL ADVISORY
The following architecture is shared between all
Wunderlist platforms!
yes,
iOS, Android, Mac OSX, Web and Windows.
Slide 6
Slide 6 text
Layers
Android
Layer
Sync
Layer
SDK
Layer
Presentation layer
(UI and Android stuff)
Model layer
(Business logic)
Data layer
(Accessing to the API data)
Android project Java project Java project
Sync boundaries SDK boundaries
Slide 7
Slide 7 text
Dependency rule
The outer model knows
the inner, not viceversa.
Presentation
Sync
Sdk
Interfaces are the key
Layered architecture
Slide 8
Slide 8 text
package com.wunderlist.sdk;
Slide 9
Slide 9 text
• Websocket (real time).
• REST.
• Services
Network
• API data models.
• Serializers/deserializers.
• Interfaces/callbacks.
• Sync and async tests.
API model
SDK
Slide 10
Slide 10 text
Real time (websocket)
Request to setup a web socket connection
Response to accept the request
Payload
Payload
Close payload
Initial
handshake
Bidirectional flow
of packets
Closing
the connection
Slide 11
Slide 11 text
Real time (2)
Slide 12
Slide 12 text
package com.wunderlist.sync;
Slide 13
Slide 13 text
Sync
• Data models.
• Deserializers from the
basic model.
• Cache.
• Services that manage data.
Data
• Matryoshka (aka Russian doll).
• Conflict resolver (included in
Matryoshka).
Sync logic
Slide 14
Slide 14 text
Cache
• Caches for different models (Tasks, Lists, Memberships, etc.)
• DataStore interface which our database model (in presentation layer) and
Cache implement to work on the same way.
Data interface
Store
Manager
DDBB
Cache
Slide 15
Slide 15 text
Services
public class WLTaskService extends WLService {
public WLTaskService(Client client) {
super(new TaskService(client));
}
public void getCompletedTasks(final WLList list, final SyncCallback uiCallbacks) {
ResponseCallback responseCallback = new ResponseCallback() {
service.getCompletedTasksForList(list.getId(), responseCallback);
}
@Override
public void onSuccess(Response response) {
//Manage your response
uiCallbacks.onSuccess(tasks);
}
@Override
public void onFailure(Response response) {
//Manage your response
uiCallbacks.onFailure(response);
}
};
Slide 16
Slide 16 text
Matryoshka
(Russian Doll)
Mechanism to properly
sync entire model.
Revision based.
When a child is updated the revision changes the whole tree up
(eg.: when a Task is created the List's revision is incremented, as
well the root).
Slide 17
Slide 17 text
root = Download()
CompareRevision(old, root)
Outdated?
foreach(childType)
compareChildren()
UpdateChildrenRevisionRoot(root)
Publish(root)
yes
no
CompareRevision(old, children)
foreach(childType)
compareChildren()
Outdated?
Publish(children)
yes
children = Download()
no
UpdateChildrenRevisionRoot(children)
……….
……….
……….
Slide 18
Slide 18 text
root = Download()
CompareRevision(old, root)
foreach(childType)
compareChildren()
Outdated?
Publish(root)
UpdateChildrenRevisionRoot(root)
yes
no
Matryoshka is a recursive
algorithm!
Slide 19
Slide 19 text
package com.wunderlist.wunderlistandroid;
Slide 20
Slide 20 text
Presentation layer
• UI + Android libs and code.
• Maximized decoupling among UI and business logic.
• Database, sadly, is located here (native SQLite ddbb).
Slide 21
Slide 21 text
Communication
Activity/Fragment
A
Fragment
B
(do something that the
Activity/Fragment A
uses to update its UI)
BUS
Subscription Data Data
Code which manages
a mutation
(this data has to be used
by the Activity/Fragment A)
Data
Slide 22
Slide 22 text
Retrieving local data
Loader
(Gets the data and
does something with it)
Activity/Fragment
BUS
Subscription Data
Event or data
is fired
Data
Slide 23
Slide 23 text
What’s next (WIP)?
Slide 24
Slide 24 text
Presenter
(Supervising controller)
Passive view
User events
Updates model
Updates view
State-changes event
Model
Model View Presenter (MVP)
Slide 25
Slide 25 text
Java project
Sync
(domain)
MVP
Presentation
Interactors
(use cases)
Repository
Cache
Web
socket
DDBB
REST
Data
Repository
interface
Clean Architecture
Slide 26
Slide 26 text
?
+CesarValiente @CesarValiente
Slide 27
Slide 27 text
+CesarValiente @CesarValiente
Thanks!
Slide 28
Slide 28 text
License
(cc) 2015 César Valiente. Some rights reserved. This document is distributed under
the Creative Commons Attribution-ShareAlike 3.0 license, available in http://
creativecommons.org/licenses/by-sa/3.0/
Slide 29
Slide 29 text
Image licenses
• Wunderlist and Microsoft images: permission granted.
• Computer (CC0): http://goo.gl/ChBXuX
• Server (CC0): https://goo.gl/WRTm4y
• Matryoshka (CC0): http://goo.gl/HWgVa6
• ReactiveX logo (CC-BY 3.0, ReactiveX): http://goo.gl/hK076f