Upload
eyeem
View
952
Download
2
Tags:
Embed Size (px)
Citation preview
POTATO page 2
Why Potato?SQL is so 80’s.
Wake me up before you:
• Map objects to tables
• Write serializers
• Write queries
• Implement content provider schemes
POTATO page 3
Potato v. Android
Application needs:
• Fetch data from web service
• Persistence
• UI that relies on objects
POTATO page 4
Android API
• SQLite - SQLiteOpenHelper - DB Schema - Cursor - ContentValues
• ContentProvider
• Loader
• ListView
• Observer
public class UserStorage extends Storage<User> {.... @Override public String id(User user) { return user.getId(); }...}
Storage• Non-volatile storage via json serialization
• Based on generic lrucache<string,t> (least recently used) - size device dependent
• Push(t object)
• Delete(string id)
POTATO page 6
Storage.List• A section of storage
• Obtain list from storage
• Implements java.Util.List<t>
Storage<User>.List friends = UserStorage.obtainList(Const.LIST_FRIENDS);
Storage<User>.List followers = UserStorage.obtainList(Const.LIST_FOLLOWERS);
POTATO page 7
Storage.Subscription List•Subscribe for a single object or list
•React to different actions (PUSH, DELETE … )
UserStorage.getInstance().obtainList(Const.LIST_FOLLOWERS).subscribe(new Storage.Subscription() {@Override public void onUpdate(Action action) { mFollowerLabel.post(new Runnable() { @Override public void run() { ... } }); }});
POTATO page 8
UserStorage.getInstance().subscribe(mUserId, new Subscription() { @Override public void onUpdate(Action action) { mUserLabel.post(new Runnable() { @Override public void run() { ... } }); }});
Storage.Subscription Object
POTATO page 9
POTATO page 10
Poll
• Associated to a storage.List
• Fetch new data
• Fetch old data
• States OK / NO_CONTENT / ERROR
What can it do for you?
POTATO page 11
Poll
• setStorage(Storage<T>.List storage)
• ArrayList<User> newItems()
• ArrayList<User> oldItems()
• int appendNewItems(ArrayList<T> newItems, Listener listener, boolean cleanUp)
• int appendOldItems(ArrayList<T> newItems, Listener listener)
What you have to do...
POTATO page 12
PollListView• Extends com.handmark.pulltorefresh.PullToRefreshListView
• Bound a poll with a ListView - new data on pull to refresh - old data on scroll
• Subscribes for poll’s Storage.List
• Attached to Activity/Fragment lifecycle - save/load/update
• Different adapters related to poll state
POTATO page 13
Potato structure
object object
object object
object object
object object
object object
object object
object object
object object
object object
object
object
object object
Storage
Storage.List
Storage.List
Sto
rage.L
ist
Sto
rage.L
ist
object object
Less used
Most used
Subscribe to events comingfrom lists or individual items
POTATO page 15
Interaction diagram
API Poll Storage.List PollListView
(UI)
AnimatedPollAdapter
(UI)
2. API call
3. add Upfront
4. notify DataWillUpdate
5. notify DataSetChangedWithAction
notify DataSetChanged
Event is publishedover subscription
model
1. update
return data
{
POTATO page 18
Pota TO DO:
• Object revisioning ( createdAt / updatedAt )
• More work on UI
• Java code generation with universal Boll (to any API)
POTATO page 19
End Fork the potato
Łukasz Wisniewski
Tobias Heine
@vishna
https://github.com/eyeem/PotatoLibrary
@tobias_heine
POTATO page 20
Join us in building the future of photo discovery
We’re always looking for passionate iOs, Android, Backend, Frontend and DevOps engineers.