() {
89 | @Override public Wrapper createFromParcel(Parcel in) {
90 | String json = in.readString();
91 | return new Wrapper(json);
92 | }
93 |
94 | @Override public Wrapper[] newArray(int size) {
95 | return new Wrapper[size];
96 | }
97 | };
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/notes/src/main/java/com/eyeem/notes/mortarflow/HandlesBack.java:
--------------------------------------------------------------------------------
1 | package com.eyeem.notes.mortarflow;
2 |
3 | /**
4 | * Implemented by views that want the option to intercept back button taps. If a view has subviews
5 | * that implement this interface their {@link #onBackPressed()} method should be invoked before
6 | * any of this view's own logic.
7 | *
8 | *
9 | * The typical flow of back button handling starts in the {@link android.app.Activity#onBackPressed()}
10 | * calling {@link #onBackPressed()} on its content view. Each view in turn delegates to its
11 | * child views to give them first say.
12 | */
13 | public interface HandlesBack {
14 | /**
15 | * Returns true
if back event was handled, false
if someone higher in
16 | * the chain should.
17 | */
18 | boolean onBackPressed();
19 | }
20 |
--------------------------------------------------------------------------------
/notes/src/main/java/com/eyeem/notes/mortarflow/HandlesUp.java:
--------------------------------------------------------------------------------
1 | package com.eyeem.notes.mortarflow;
2 |
3 | /** Like {@link HandlesBack}, but for the action bar's up button. */
4 | public interface HandlesUp {
5 | boolean onUpPressed();
6 | }
--------------------------------------------------------------------------------
/notes/src/main/java/com/eyeem/notes/mortarflow/HasParent.java:
--------------------------------------------------------------------------------
1 | package com.eyeem.notes.mortarflow;
2 |
3 | import flow.path.Path;
4 |
5 | /**
6 | * Created by vishna on 20/05/15.
7 | */
8 | public interface HasParent {
9 | public Path getParent();
10 | }
11 |
--------------------------------------------------------------------------------
/notes/src/main/java/com/eyeem/notes/mortarflow/Layout.java:
--------------------------------------------------------------------------------
1 | package com.eyeem.notes.mortarflow;
2 |
3 | import java.lang.annotation.Retention;
4 | import java.lang.annotation.Target;
5 |
6 | import static java.lang.annotation.ElementType.TYPE;
7 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
8 |
9 | // copied from FLOW
10 |
11 | /**
12 | * Marks a class that designates a screen and specifies its layout. A screen is a distinct part of
13 | * an application containing all information that describes this state.
14 | *
15 | * For example,
16 | * {@literal@}Layout(R.layout.conversation_screen_layout)
17 | * public class ConversationScreen { ... }
18 | *
19 | */
20 | @Retention(RUNTIME) @Target(TYPE)
21 | public @interface Layout {
22 | int value();
23 | }
--------------------------------------------------------------------------------
/notes/src/main/java/com/eyeem/notes/mortarflow/MortarContextFactory.java:
--------------------------------------------------------------------------------
1 | package com.eyeem.notes.mortarflow;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.ContextWrapper;
6 | import android.view.LayoutInflater;
7 |
8 | import flow.path.Path;
9 | import flow.path.PathContextFactory;
10 | import mortar.MortarScope;
11 |
12 | import static mortar.MortarScope.getScope;
13 |
14 | public final class MortarContextFactory implements PathContextFactory {
15 | private final ScreenScoper screenScoper = new ScreenScoper();
16 |
17 | public MortarContextFactory() {
18 | }
19 |
20 | @Override public Context setUpContext(Path path, Context parentContext) {
21 | MortarScope screenScope =
22 | screenScoper.getScreenScope(parentContext, path.getClass().getName(), path);
23 | return new TearDownContext(parentContext, screenScope);
24 | }
25 |
26 | @Override public void tearDownContext(Context context) {
27 | TearDownContext.destroyScope(context);
28 | }
29 |
30 | static class TearDownContext extends ContextWrapper {
31 | private static final String SERVICE = "SNEAKY_MORTAR_PARENT_HOOK";
32 | private final MortarScope parentScope;
33 | private LayoutInflater inflater;
34 |
35 | static void destroyScope(Context context) {
36 | MortarScope child = getScope(context);
37 | child.destroy();
38 | }
39 |
40 | public TearDownContext(Context context, MortarScope scope) {
41 | super(scope.createContext(context));
42 | this.parentScope = getScope(context);
43 | }
44 |
45 | @Override public Object getSystemService(String name) {
46 | if (LAYOUT_INFLATER_SERVICE.equals(name)) {
47 | if (inflater == null) {
48 | inflater = LayoutInflater.from(getBaseContext()).cloneInContext(this);
49 | }
50 | return inflater;
51 | }
52 |
53 | if (SERVICE.equals(name)) {
54 | return parentScope;
55 | }
56 |
57 | return super.getSystemService(name);
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/notes/src/main/java/com/eyeem/notes/mortarflow/ScopeSingleton.java:
--------------------------------------------------------------------------------
1 | package com.eyeem.notes.mortarflow;
2 |
3 | import javax.inject.Scope;
4 |
5 | @Scope
6 | public @interface ScopeSingleton {
7 | Class> value();
8 | }
9 |
--------------------------------------------------------------------------------
/notes/src/main/java/com/eyeem/notes/mortarflow/ScreenScoper.java:
--------------------------------------------------------------------------------
1 | package com.eyeem.notes.mortarflow;
2 |
3 |
4 | import android.content.Context;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import mortar.MortarScope;
10 |
11 | import static com.eyeem.notes.mortarflow.Utils.DAGGER_SERVICE;
12 | import static com.eyeem.notes.mortarflow.Utils.createComponent;
13 | import static mortar.MortarScope.findChild;
14 | import static mortar.MortarScope.getScope;
15 |
16 | /**
17 | * Creates {@link MortarScope}s for screens that may be annotated with {@link WithComponent},
18 | * {@link WithComponent}.
19 | */
20 | public class ScreenScoper {
21 |
22 | public MortarScope getScreenScope(Context context, String name, Object screen) {
23 | MortarScope parentScope = getScope(context);
24 | return getScreenScope(context, parentScope, name, screen);
25 | }
26 |
27 | /**
28 | * Finds or creates the scope for the given screen, honoring its optional {@link
29 | * DynamicModules} or {@link WithComponent} annotation. Note that scopes are also created
30 | * for unannotated screens.
31 | */
32 | public MortarScope getScreenScope(Context context, MortarScope parentScope, final String name,
33 | final Object screen) {
34 |
35 | Object parentComponent = parentScope.getService(DAGGER_SERVICE);
36 | MortarScope childScope = findChild(context, name);
37 |
38 | if (childScope == null) {
39 | WithComponent withComponent = screen.getClass().getAnnotation(WithComponent.class);
40 | List