Upload
futurice
View
103
Download
3
Embed Size (px)
Citation preview
reark.ioPowered by Futurice Spice Program
reark.ioPowered by Futurice Spice Program
Now it has library
components as well.
Why native, and not
React Native?
Who am I?
@tehmou• Reactive
programmer
History of reark.io
SAMSUNG KICKPowered by Futurice
Samsung KICK had an average score of 4.1 out of 5 on Google Play store, it was downloaded over 3 million times.
It was rebranded into Goal+ summer 2016.
Statistics
Total Lines of Code155384
(546410 added, 391026 removed)
Total Commits10103
Authors31
Commit HistoryMWC Demo Tablet release
(1089 commits in May)
Ramp up
Phone release
A lot of challenges keeping the code together.
Android 4.1.x has a bug that crashes it for view hierarchies deeper than ~30.
On a complex tablet application with nested fragments under 30 is a dream world.
- Big codebase- Large velocity- Long- “Satellite” apps
What does the app look
like?
Main App
First there was an app.
Main App
Store
View
“Database” to hold the data and publish updates.
What is shown on the screen by the platform.
Main App
Store
View Model
View
Push updates to the data.
Process the raw data.
Display data.
This is the MVVM architecture, you can see an example in the reark.io sample.
Main App
Main App
Process
A process has its own “stack”, which means that other processes
do not see variables in it.
Main App
Process
Product owner wants to make a cool new widget. It has to run in
its own “remote process”.
Process
Main App
KICK Livewidget
ProcessProcess
Now we have two processes that both have their own memory
space.
Main App
KICK Livewidget
ProcessProcess
StoreBut the Store is stuck in
one process.
Main App
KICK Livewidget
ProcessProcess
StoreBut the Store is stuck in
one process.
Main App
KICK Livewidget
ProcessProcess
Store Move store into a shared container.
Main App
KICK Livewidget
ProcessProcess
Provide data and changes to
all attached processes.
Store
StoreWhat about
other devices connected to the phone?
Store
Gear
SmartTV
StoreUse Samsung web socket bridge to publish updates.
One Store for different uses:• Inside of one process• Between processes• Between physical devices
What’s in the Store then?
On Android the Store is traditionally an database.SQLite
Also known as ContentProvider.
SQLite- Can be shared across processes - Allows to observe changes - Asynchronous read / write
SQLite
- It’s been there since the beginning
- Can be shared across processes - Allows to observe changes - Asynchronous read / write
What’s the problem?
SQLite
- … - A pain to implement!
SQLite
- Nobody got time for that!
What if there was a way to start with a simple Store that
could be later changed into an SQLite?
Introduce an MVP Store that can use SQLite internally.
… or not use is it until it is needed.
Generic App v0.1Super simple proof of concept.
Flickr: infinity7664
Generic App v0.01Super simple proof of concept.
Flickr: infinity7664
PO
Generic App v0.01Super simple proof of concept.
Flickr: infinity7664
This is just a demo, it will
never go into production!
PO
Generic App v0.01Super simple proof of concept.
Flickr: infinity7664
This is just a demo, it will
never go into production!
PO
Generic App v0.01Super simple proof of concept.
Flickr: infinity7664
This is just a demo, it will
never go into production!
PO
Generic App v0.01Super simple proof of concept.
Flickr: infinity7664
This is just a demo, it will
never go into production!
PO
Wrote an app that was not going into
production Bad Luck Brian
Wrote an app that was not going into
production
It went into production
The version 0.01Super simple proof of concept version. Everything in one process.
Store
The version 0.01Super simple proof of concept version. Everything in one process.
Store
new HashMap<Integer, Beer>
The version 0.01Store becomes a wrapper for the HashMap. It is a simple key-value store.
Storenew HashMap<Integer, Beer>
The version 0.01
Storenew HashMap<Integer, Beer>
Great! But how to get beer out of the store?
The version 0.01
Storenew HashMap<Integer, Beer>Beer getBeer(Integer beerId)
The version 0.01
Storenew HashMap<Integer, Beer>Beer getBeer(Integer beerId)
= Ask for beer, get beer immediately
The version 0.01
Storenew HashMap<Integer, Beer>Beer getBeer(Integer beerId)
Not sure if KISS
Or the worst idea ever
SQLite- Can be shared across processes - Allows to track changes - Asynchronous read / write
Bad Luck Brian
Wrote his app with KISS
Wrote his app with KISS
It didn’t scale
What’s the minimum interface for a good Store?
Store interface
StorePut an item at a time
Get a stream of
items
Store interface
StorePut an item at a time
Get a stream of
items(with the same id)
RxJava and Observables
Observables in very short
store.getBeer(beerId)We define a way to get beer from the
Store.
Observables in very short
store.getBeer(beerId)
For this we need to know the beerId
Observables in very short
store.getBeer(beerId) .subscribe(
We will subscribe to the Observable. This
is like a callback.
Observables in very short
store.getBeer(beerId) .subscribe( beer -> drink(beer) );
We define the action that is executed every
time a new beer arrives.
Observables in very short
store.getBeer(beerId) .subscribe( beer -> drink(beer) );
Notice that we will always get updated versions of the beer
with the same id.
How it works in real life.
Store interface
Beer StoreLet’s create a beer Store.
Store interface
Beer Store
First customer!
Store interface
Beer Store
Another subscriber to the same beer!
Store interface
Beer StoreSomeone pushes an update to the Store.
Store interface
Beer StoreThe update is
propagated to all subscribers.
Store interface
Beer Store
Store interface
Beer StoreThe subscribers have processed the latest
update.
What about new subscriber that missed the beer?
Store interface
Beer Store
A new subscriber arrives!
Store interface
Beer StoreThe new subscriber gets the latest value immediately to
get up to date.
Store interface
Beer Store
Store interface
Beer StoreAll subscribers are again on
stand-by for new values.
The reark.io Store design.
Store interfaceinterface StoreInterface <T, U> { void put(T item); Observable<T> get(U id); }
Store interfaceinterface StoreInterface <T, U> { void put(T item); Observable<T> get(U id); }
The put operation is fire and forger.
Store interfaceinterface StoreInterface <T, U> { void put(T item); Observable<T> get(U id); }
The is no synchronous get, only an observable.
The two main reark.io Store types.
MemoryStore
Flickr: infinity7664
MemoryStoreimplements StoreInterface <T, U>
Flickr: infinity7664
MemoryStoreimplements StoreInterface <T, U>
Flickr: infinity7664
Good for:• Getting started• No need to persist data• Only one process running
ContentProviderStoreimplements StoreInterface <T, U>
Flickr: Toti Maragliano
ContentProviderStoreimplements StoreInterface <T, U>
The interface is the same
Flickr: Toti Maragliano
ContentProviderStoreimplements StoreInterface <T, U>
Flickr: Toti Maragliano
Good for:• Persisting data if app is shut down• Sharing data between processes, i.e. widgets• If you have a bit of time to set up the SQLite
Case study: Quickbeer Next
Powered by Spice Program
https://github.com/apoi/quickbeer-next
App for ratebeer.com API
Wikipedia: “RateBeer has over 4.5 million ratings of almost 200,000 beers, from nearly 16,000 breweries”
Hand crafted by: apoi
https://github.com/apoi/quickbeer-next
Powered by Spice Program
Hand crafted by: apoi
https://github.com/apoi/quickbeer-next
Powered by Spice ProgramI have over 1100 beer
ratings on my ratebeer.com account that I use to test the app. You could say it’s well-brewed.
Main Contributors
apoi
Main Contributors
Develops the framework against his beer app as well as (secret) customer projects.
apoi recuutus
Main Contributors
The Dagger master, also does excellent reviews and tests.
apoi tomaszpolanskirecuutus
Main ContributorsFiguring out a way to put his Options library in the example project.
apoi tomaszpolanskirecuutus
Main ContributorsFiguring out a way to put his Options library in the example project.
apoi tomaszpolanskirecuutus
Main ContributorsFiguring out a way to put his Options library in the example project.
apoi tomaszpolanskirecuutus
Main ContributorsFiguring out a way to put his Options library in the example project.
prt2121apoi tomaszpolanskirecuutus
Main Contributors
We don’t really know who he is, but he sometimes updates libraries.
prt2121apoi tomaszpolanskirecuutus
Main Contributors
Started it, now drops in every once in a while and annoys everyone by rewriting stuff.
tehmou
Thank you.
Extra case study: Nautics Sailmate
“More convenient sailing”
This is a sea chart.
An offline package is downloaded with hundreds of Points
of Interest.
The POIs are written all at once
into an SQLite Store.
Store
Every part of the app is updated instantly when a
download finishes.
Store
fin.