Slide 1

Slide 1 text

SIMPLIFY ANDROID UI Steve Zeidner @stevezeidner

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

APPLICATION COMPONENTS • Activities • Services • Content Providers • Broadcast Receivers

Slide 7

Slide 7 text

ACTIVITY “An activity represents a single screen with a user interface. For example, an email app might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email app, each one is independent of the others.”

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

FRAGMENT PROBLEMS • Lifecycle • Fragment Backstack • Tightly coupled View / Controller logic • Default constructor • Memory management + Fragment bugs

Slide 11

Slide 11 text

public static MyFragment newInstance(int index) { MyFragment f = new MyFragment(); Bundle args = new Bundle(); args.putInt("index", index); f.setArguments(args); return f; }

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

FLOW

Slide 17

Slide 17 text

public final class TrackScreen { public final String albumId; public final String trackId; public TrackScreen(String albumId, String trackId) { this.albumId = albumId; this.trackId = trackId; } }

Slide 18

Slide 18 text

flow.set(new TrackScreen(albumId, trackId))

Slide 19

Slide 19 text

flow.goBack();

Slide 20

Slide 20 text

FLOW • Navigate between screens • Manages history and persists state • Subflows - nested flows • Dispatcher - executes state changes

Slide 21

Slide 21 text

MORTAR

Slide 22

Slide 22 text

@dagger.Component(dependencies = MainActivity.Component.class) @DaggerScope(Component.class) public interface Component extends AppDependencies { void inject(TrackView view); } @DaggerScope(Component.class) public static class Presenter extends ViewPresenter { @Override protected void onLoad(Bundle savedInstanceState) { getView().albumTitle.setText("Chalk Dust Torture"); } @Override protected void onSave(Bundle outState) { super.onSave(outState); } }

Slide 23

Slide 23 text

public class TrackView extends FrameLayout { @Bind(R.id.album_title) public TextView albumTitle; @Inject protected TrackScreen.Presenter presenter; public TrackView(Context context, AttributeSet attrs) { super(context, attrs); DaggerService.getDaggerComponent(context).inject(this); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); presenter.takeView(this); } @Override protected void onDetachedFromWindow() { presenter.dropView(this); super.onDetachedFromWindow(); } @Override protected void onFinishInflate() { super.onFinishInflate(); ButterKnife.bind(this); } }

Slide 24

Slide 24 text

onEnterScope(MortarScope scope) onLoad(Bundle savedInstanceState) dropView() onSave(Bundle outState) onExitScope()

Slide 25

Slide 25 text

SCOPING AND DEPENDENCY INJECTION

Slide 26

Slide 26 text

public class TrackView extends FrameLayout { @Bind(R.id.album_title) public TextView albumTitle; @Inject protected TrackScreen.Presenter presenter; public TrackView(Context context, AttributeSet attrs) { super(context, attrs); DaggerService.getDaggerComponent(context).inject(this); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); presenter.takeView(this); } @Override protected void onDetachedFromWindow() { presenter.dropView(this); super.onDetachedFromWindow(); } @Override protected void onFinishInflate() { super.onFinishInflate(); ButterKnife.bind(this); } }

Slide 27

Slide 27 text

"Don't call us, we'll call you."

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

@Layout(R.layout.screen_track) public class TrackScreen extends Path implements ScreenComponentFactory { public final String albumId; public final String trackId; public TrackScreen(String albumId, String trackId) { this.albumId = albumId; this.trackId = trackId; } @Override public Object createComponent(MainActivity.Component parent) { return DaggerPostScreen_Component.builder() .component(parent) .build(); } @dagger.Component(dependencies = MainActivity.Component.class) @DaggerScope(Component.class) public interface Component extends AppDependencies { void inject(TrackView view); } @DaggerScope(Component.class) public static class Presenter extends ViewPresenter { @Override protected void onLoad(Bundle savedInstanceState) { getView().albumTitle.setText("Chalk Dust Torture"); } @Override protected void onSave(Bundle outState) { super.onSave(outState); } } }

Slide 30

Slide 30 text

Flow tells the app where to go while Mortar informs it of what to build and how long to live.

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

CABINLIFE DEMO

Slide 34

Slide 34 text

MORTAR & FLOW ADVANTAGES • MVP pattern • Memory efficient views • No Fragment issues! • Easier Dependency Injection

Slide 35

Slide 35 text

MORTAR & FLOW DOWNSIDES • Steep learning curve • No Material style animations • It's not the Google way

Slide 36

Slide 36 text

Should you convert an existing app?

Slide 37

Slide 37 text

It depends.

Slide 38

Slide 38 text

RESOURCES • [Lukas Piliszczuk] (https://github.com/lukaspili) • Flow Navigation • Mortar Architect
 • [CabinLife] (https://github.com/szeidner/cabinlife-android)

Slide 39

Slide 39 text

QUESTIONS?