Slide 1

Slide 1 text

Android Apps with Mortar and Flow Edward Dale @scompt

Slide 2

Slide 2 text

Agenda • Motivation • Flow • Mortar http://knowyourmeme.com/memes/business-cat

Slide 3

Slide 3 text

Motivation

Slide 4

Slide 4 text

Motivation • Lots of activities (old) • Lots of fragments (new) • Loaders • Lifecycle fun hell • Fragment transitions • Back stack The Android Way

Slide 5

Slide 5 text

Motivation • Lots of activities (old) • Lots of fragments (new) • Loaders • Lifecycle fun hell • Fragment transitions • Back stack The Android Way • Few activities • No fragments • Fatter views • Dependency injection • RxJava The Square Way

Slide 6

Slide 6 text

Sample App https://github.com/square/flow

Slide 7

Slide 7 text

Sample App https://github.com/square/flow

Slide 8

Slide 8 text

Flow A small library that helps with describing an app as a collection of moderately independent screens.

Slide 9

Slide 9 text

Flow • A screen in a POJO with the @Screen annotation saying which view or layout should be used to display it. • The Backstack is a stack of these objects. • The Flow is the interface for navigating the history of your app. http://www.rluxemburg.com/2013/09/01/kitten-flow-chart/

Slide 10

Slide 10 text

The conversation list screen @Screen(ConversationListView.class) public class ConversationList { }

Slide 11

Slide 11 text

The conversation view screen @Screen(ConversationView.class) public static class Conversation implements HasParent { public final int conversationIndex; ! public Conversation(int conversationIndex) { this.conversationIndex = conversationIndex; } ! @Override public ConversationList getParent() { return new ConversationList(); } }

Slide 12

Slide 12 text

App start Object firstScreen = new ConversationList(); Backstack backstack = Backstack.single(firstScreen); Flow flow = new Flow(backstack, this); go(flow.getBackstack(), Flow.Direction.FORWARD);

Slide 13

Slide 13 text

On conversation tap Flow flow = ...; int position = ; flow.goTo(new Conversation(position));

Slide 14

Slide 14 text

• Controller layer is a bit 
 too ad-hoc But not quite enough This is nice • No fragments • Unified interface for navigating in the app • Power over the back stack http://www.catster.com/molz/happy-cat-is-happy

Slide 15

Slide 15 text

• Controller layer is a bit 
 too ad-hoc But not quite enough This is nice • No fragments • Unified interface for navigating in the app • Power over the back stack

Slide 16

Slide 16 text

Mortar Mortar eases the use of Dagger to divide Android apps into composable modules.

Slide 17

Slide 17 text

Mortar • View and controller destroyed in traditional android MVC • Only view destroyed with MVP under mortar. Presenter stays around. MVC MVP

Slide 18

Slide 18 text

Mortar • Every Screen has an associated Dagger Module • Every View has an associated ViewPresenter Implementation http://animals.desktopnexus.com/wallpaper/1386356/

Slide 19

Slide 19 text

Blueprint @Screen(ChatListView.class) public class ChatListScreen implements Blueprint { @Override public String getMortarScopeName() { return getClass().getName(); } @Override public Object getDaggerModule() { return new Module(); } }

Slide 20

Slide 20 text

ViewPresenter public class ChatListView extends ListView implements ChatListScreen.View { @Inject ChatListScreen.Presenter presenter; ! public ChatListView(Context context, AttributeSet attrs) { super(context, attrs); Mortar.inject(context, this); } ! @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); presenter.takeView(this); } }

Slide 21

Slide 21 text

http://www.catster.com/molz/happy-cat-is-happy This is nice • Screens are self-contained and injected, facilitating testing • Insulated from lifecycle events • Memory efficient

Slide 22

Slide 22 text

Mortar Flow A small library that helps with describing an app as a collection of moderately independent screens. Mortar eases the use of Dagger to divide Android apps into composable modules. Questions? Edward Dale @scompt