MBLTDev15: Cesar Valiente, Wunderlist

26
Engineering Wunderlist for Android César Valiente

Transcript of MBLTDev15: Cesar Valiente, Wunderlist

Page 1: MBLTDev15: Cesar Valiente, Wunderlist

Engineering Wunderlist for Android

César Valiente

Page 2: MBLTDev15: Cesar Valiente, Wunderlist

Who is this guy?

Image Placeholder

César ValienteAndroid Engineer @Wunderlist (@Microsoft)

FLOSS & Android Google Developer Expert (GDE)

+CesarValiente @CesarValiente

Page 3: MBLTDev15: Cesar Valiente, Wunderlist

- A very nice and good app.

- Monolithic structure.- Highly coupled.- Sync in batch.- Difficult to test .

Wunderlist 2

Page 4: MBLTDev15: Cesar Valiente, Wunderlist

Wunderlist 3- Completely redesigned.- Divided into modules (layers).- Highly decoupled.- Real time sync.- Easier to maintain, test and adapt.- Easy to understand.

Page 5: MBLTDev15: Cesar Valiente, Wunderlist

PARENTAL ADVISORY

The following architecture is shared between all Wunderlist platforms!

yes, iOS, Android, Mac OSX, Web and Windows.

Page 6: MBLTDev15: Cesar Valiente, Wunderlist

Layers

AndroidLayer

SyncLayer

SDKLayer

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

Page 7: MBLTDev15: Cesar Valiente, Wunderlist

Dependency rule

The outer model knows the inner, not viceversa.

Presentation

Sync

Sdk

Interfaces are the key

Layered architecture

Page 8: MBLTDev15: Cesar Valiente, Wunderlist

package com.wunderlist.sdk;

Page 9: MBLTDev15: Cesar Valiente, Wunderlist

• Websocket (real time).

• REST.

• Services

Network

• API data models.

• Serializers/deserializers.

• Interfaces/callbacks.

• Sync and async tests.

API model

SDK

Page 10: MBLTDev15: Cesar Valiente, Wunderlist

Real time (websocket)

Request to setup a web socket connection

Response to accept the request

Payload

Payload

Close payload

Initial handshake

Bidirectional flowof packets

Closingthe connection

Page 12: MBLTDev15: Cesar Valiente, Wunderlist

package com.wunderlist.sync;

Page 13: MBLTDev15: Cesar Valiente, Wunderlist

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

Page 14: MBLTDev15: Cesar Valiente, Wunderlist

Cache

• Caches for different models (Tasks, Lists, Memberships, etc.)

• Data interface which our database model (in presentation layer) and Cache implement to work on the same way.

Dat

a in

terfa

ce

StoreManager

DDBB

Cache

Page 15: MBLTDev15: Cesar Valiente, Wunderlist

Servicespublic class WLTaskService extends WLService<WLTask, TaskService> { 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 responseuiCallbacks.onSuccess(tasks);

} @Override public void onFailure(Response response) { //Manage your response uiCallbacks.onFailure(response); } };

Used to communicate the Android layer with the SDK.

Page 16: MBLTDev15: Cesar Valiente, Wunderlist

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).

Page 17: MBLTDev15: Cesar Valiente, Wunderlist

package com.wunderlist.wunderlistandroid;

Page 18: MBLTDev15: Cesar Valiente, Wunderlist

Presentation layer• UI + Android libs and code.

• Maximized decoupling among UI and business logic.

• Database, sadly, is located here (native SQLite ddbb).

Page 19: MBLTDev15: Cesar Valiente, Wunderlist

Communication

Activity/FragmentA

FragmentB

(do something that theActivity/Fragment A

uses to update its UI)

BUS

Subscription Data Data

Code which managesa mutation

(this data has to be usedby the Activity/Fragment A)

Data

Page 20: MBLTDev15: Cesar Valiente, Wunderlist

Retrieving local data

Loader

(Gets the data anddoes something with it)

Activity/Fragment

BUS

Subscription Data

Event or data is fired

Data

Page 21: MBLTDev15: Cesar Valiente, Wunderlist

What’s next (WIP)?

Page 22: MBLTDev15: Cesar Valiente, Wunderlist

Presenter(Supervising controller)

Passive view

User events

Updates model

Updates view

State-changes event

Model

Model View Presenter (MVP)

Page 23: MBLTDev15: Cesar Valiente, Wunderlist

Java project

Sync (domain)MVP

Presentation

Interactors (use cases)

Repository

Cache

Web socket

DDBB

REST

Data

Repositoryinterface

Clean Architecture

Page 24: MBLTDev15: Cesar Valiente, Wunderlist

?+CesarValiente @CesarValiente

Page 25: MBLTDev15: Cesar Valiente, Wunderlist

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/

Page 26: MBLTDev15: Cesar Valiente, Wunderlist

Image licenses• Wunderlist 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