Skip to content

Commit dedb347

Browse files
author
Aleksey Malevaniy
committed
Update to latest flow (0.10) and mortar (0.17)
1 parent 4cff772 commit dedb347

27 files changed

+175
-122
lines changed

.idea/codeStyleSettings.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library-additions/src/main/java/io/techery/presenta/addition/DetailContainerView.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import android.content.Context;
44
import android.util.AttributeSet;
55

6-
import flow.Path;
7-
import flow.PathContextFactory;
6+
import flow.path.Path;
7+
import flow.path.PathContextFactory;
88
import io.techery.presenta.addition.flow.container.SimplePathContainer;
99
import io.techery.presenta.addition.flow.path.MasterDetailPath;
1010

library-additions/src/main/java/io/techery/presenta/addition/FramePathContainerView.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import android.widget.FrameLayout;
2424

2525
import flow.Flow;
26-
import flow.Path;
27-
import flow.PathContainer;
28-
import flow.PathContainerView;
26+
import flow.path.Path;
27+
import flow.path.PathContainer;
28+
import flow.path.PathContainerView;
2929
import io.techery.presenta.addition.flow.container.SimplePathContainer;
3030
import io.techery.presenta.addition.flow.util.BackSupport;
3131

@@ -40,7 +40,7 @@ public FramePathContainerView(Context context, AttributeSet attrs) {
4040
}
4141

4242
/**
43-
* Allows subclasses to use custom {@link flow.PathContainer} implementations. Allows the use
43+
* Allows subclasses to use custom {@link PathContainer} implementations. Allows the use
4444
* of more sophisticated transition schemes, and customized context wrappers.
4545
*/
4646
protected FramePathContainerView(Context context, AttributeSet attrs, PathContainer container) {

library-additions/src/main/java/io/techery/presenta/addition/MasterPathContainerView.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
import io.techery.presenta.addition.flow.path.MasterDetailPath;
99

1010
import flow.Flow;
11-
import flow.Path;
12-
import flow.PathContextFactory;
11+
import flow.path.Path;
12+
import flow.path.PathContextFactory;
1313

1414
public class MasterPathContainerView extends FramePathContainerView {
1515

1616
public MasterPathContainerView(Context context, AttributeSet attrs) {
1717
super(context, attrs, new MasterPathContainer(R.id.mortar_screen_switcher_tag, Path.contextFactory()));
1818
}
1919

20-
@Override public void dispatch(Flow.Traversal traversal, final Flow.TraversalCallback callback) {
20+
@Override
21+
public void dispatch(Flow.Traversal traversal, final Flow.TraversalCallback callback) {
2122

22-
MasterDetailPath currentMaster =
23-
((MasterDetailPath) Flow.get(getContext()).getBackstack().current()).getMaster();
23+
MasterDetailPath currentMaster = ((MasterDetailPath) traversal.origin.top()).getMaster();
2424

25-
MasterDetailPath newMaster = ((MasterDetailPath) traversal.destination.current()).getMaster();
25+
MasterDetailPath newMaster = ((MasterDetailPath) traversal.destination.top()).getMaster();
2626

2727
// Short circuit if the new screen has the same master.
2828
if (getCurrentChild() != null && newMaster.equals(currentMaster)) {

library-additions/src/main/java/io/techery/presenta/addition/MortarFramePathContainerView.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import android.content.Context;
1919
import android.util.AttributeSet;
2020

21-
import flow.Path;
21+
import flow.path.Path;
2222
import io.techery.presenta.addition.flow.container.SimplePathContainer;
2323
import io.techery.presenta.mortarflow.MortarContextFactory;
2424

library-additions/src/main/java/io/techery/presenta/addition/TabletMasterDetailRoot.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import io.techery.presenta.addition.flow.util.BackSupport;
1313

1414
import flow.Flow;
15-
import flow.Path;
16-
import flow.PathContainerView;
15+
import flow.path.Path;
16+
import flow.path.PathContainerView;
1717

1818
import static io.techery.presenta.addition.flow.util.BackSupport.HandlesBack;
1919

@@ -53,7 +53,7 @@ public TabletMasterDetailRoot(Context context, AttributeSet attrs) {
5353
return this;
5454
}
5555

56-
@Override public void dispatch(Flow.Traversal traversal, Flow.TraversalCallback callback) {
56+
@Override public void dispatch(final Flow.Traversal traversal, Flow.TraversalCallback callback) {
5757

5858
class CountdownCallback implements Flow.TraversalCallback {
5959
final Flow.TraversalCallback wrapped;
@@ -68,7 +68,8 @@ class CountdownCallback implements Flow.TraversalCallback {
6868
if (countDown == 0) {
6969
disabled = false;
7070
wrapped.onTraversalCompleted();
71-
((IsMasterView) masterContainer.getCurrentChild()).updateSelection();
71+
((IsMasterView) masterContainer.getCurrentChild()).updateSelection(
72+
traversal.destination.<MasterDetailPath>top());
7273
}
7374
}
7475
}

library-additions/src/main/java/io/techery/presenta/addition/flow/container/SimplePathContainer.java

+31-16
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@
2323
import android.view.LayoutInflater;
2424
import android.view.View;
2525
import android.view.ViewGroup;
26-
27-
import io.techery.presenta.flow.Utils;
28-
2926
import flow.Flow;
30-
import flow.Path;
31-
import flow.PathContainer;
32-
import flow.PathContext;
33-
import flow.PathContextFactory;
27+
import flow.path.Path;
28+
import flow.path.PathContainer;
29+
import flow.path.PathContext;
30+
import flow.path.PathContextFactory;
31+
import io.techery.presenta.addition.flow.path.Layout;
32+
import io.techery.presenta.flow.Utils;
33+
import java.util.LinkedHashMap;
34+
import java.util.Map;
3435

3536
import static flow.Flow.Direction.REPLACE;
3637

3738
/**
3839
* Provides basic right-to-left transitions. Saves and restores view state.
39-
* Uses {@link flow.PathContext} to allow customized sub-containers.
40+
* Uses {@link PathContext} to allow customized sub-containers.
4041
*/
4142
public class SimplePathContainer extends PathContainer {
43+
private static final Map<Class, Integer> PATH_LAYOUT_CACHE = new LinkedHashMap<>();
4244
private final PathContextFactory contextFactory;
4345

4446
public SimplePathContainer(int tagKey, PathContextFactory contextFactory) {
@@ -60,12 +62,11 @@ public SimplePathContainer(int tagKey, PathContextFactory contextFactory) {
6062

6163
Path to = traversalState.toPath();
6264

63-
ViewGroup newView;
65+
View newView;
6466
context = PathContext.create(oldPath, to, contextFactory);
6567
int layout = getLayout(to);
66-
newView = (ViewGroup) LayoutInflater.from(context)
67-
.cloneInContext(context)
68-
.inflate(layout, containerView, false);
68+
newView =
69+
LayoutInflater.from(context).cloneInContext(context).inflate(layout, containerView, false);
6970

7071
View fromView = null;
7172
if (traversalState.fromPath() != null) {
@@ -83,11 +84,9 @@ public SimplePathContainer(int tagKey, PathContextFactory contextFactory) {
8384
containerView.addView(newView);
8485
final View finalFromView = fromView;
8586
Utils.waitForMeasure(newView, new Utils.OnMeasuredCallback() {
86-
@Override
87-
public void onMeasured(View view, int width, int height) {
87+
@Override public void onMeasured(View view, int width, int height) {
8888
runAnimation(containerView, finalFromView, view, direction, new Flow.TraversalCallback() {
89-
@Override
90-
public void onTraversalCompleted() {
89+
@Override public void onTraversalCompleted() {
9190
containerView.removeView(finalFromView);
9291
oldPath.destroyNotIn(context, contextFactory);
9392
callback.onTraversalCompleted();
@@ -98,6 +97,22 @@ public void onTraversalCompleted() {
9897
}
9998
}
10099

100+
protected int getLayout(Path path) {
101+
Class pathType = path.getClass();
102+
Integer layoutResId = PATH_LAYOUT_CACHE.get(pathType);
103+
if (layoutResId == null) {
104+
Layout layout = (Layout) pathType.getAnnotation(Layout.class);
105+
if (layout == null) {
106+
throw new IllegalArgumentException(
107+
String.format("@%s annotation not found on class %s", Layout.class.getSimpleName(),
108+
pathType.getName()));
109+
}
110+
layoutResId = layout.value();
111+
PATH_LAYOUT_CACHE.put(pathType, layoutResId);
112+
}
113+
return layoutResId;
114+
}
115+
101116
private void runAnimation(final ViewGroup container, final View from, final View to,
102117
Flow.Direction direction, final Flow.TraversalCallback callback) {
103118
Animator animator = createSegue(from, to, direction);

library-additions/src/main/java/io/techery/presenta/addition/flow/path/EmptyPath.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.techery.presenta.addition.flow.path;
22

3-
import flow.Path;
3+
import flow.path.Path;
44

55
// @Layout(R.layout.no_details)
66
public abstract class EmptyPath extends Path {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package io.techery.presenta.addition.flow.path;
22

33
public interface IsMasterView {
4-
void updateSelection();
4+
void updateSelection(MasterDetailPath newPath);
55
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2013 Square Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.techery.presenta.addition.flow.path;
18+
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.Target;
21+
22+
import static java.lang.annotation.ElementType.TYPE;
23+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
24+
25+
/**
26+
* Marks a class that designates a screen and specifies its layout. A screen is a distinct part of
27+
* an application containing all information that describes this state.
28+
*
29+
* <p>For example, <pre><code>
30+
* {@literal@}Layout(R.layout.conversation_screen_layout)
31+
* public class ConversationScreen { ... }
32+
* </code></pre>
33+
*/
34+
@Retention(RUNTIME) @Target(TYPE)
35+
public @interface Layout {
36+
int value();
37+
}

library-additions/src/main/java/io/techery/presenta/addition/flow/path/MasterDetailPath.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.techery.presenta.addition.flow.path;
22

3-
import flow.Path;
3+
import flow.path.Path;
44

55
/**
66
* Identifies screens in a master / detail relationship. Both master and detail screens

library-additions/src/main/java/io/techery/presenta/addition/flow/util/GsonParceler.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,22 @@
1818

1919
import android.os.Parcel;
2020
import android.os.Parcelable;
21-
2221
import com.google.gson.Gson;
2322
import com.google.gson.stream.JsonReader;
2423
import com.google.gson.stream.JsonWriter;
25-
24+
import flow.StateParceler;
2625
import java.io.IOException;
2726
import java.io.StringReader;
2827
import java.io.StringWriter;
2928

30-
import flow.Parceler;
31-
import flow.Path;
32-
33-
public class GsonParceler implements Parceler {
29+
public class GsonParceler implements StateParceler {
3430
private final Gson gson;
3531

3632
public GsonParceler(Gson gson) {
3733
this.gson = gson;
3834
}
3935

40-
@Override public Parcelable wrap(Path instance) {
36+
@Override public Parcelable wrap(Object instance) {
4137
try {
4238
String json = encode(instance);
4339
return new Wrapper(json);
@@ -46,7 +42,7 @@ public GsonParceler(Gson gson) {
4642
}
4743
}
4844

49-
@Override public Path unwrap(Parcelable parcelable) {
45+
@Override public Object unwrap(Parcelable parcelable) {
5046
Wrapper wrapper = (Wrapper) parcelable;
5147
try {
5248
return decode(wrapper.json);
@@ -55,7 +51,7 @@ public GsonParceler(Gson gson) {
5551
}
5652
}
5753

58-
private String encode(Path instance) throws IOException {
54+
private String encode(Object instance) throws IOException {
5955
StringWriter stringWriter = new StringWriter();
6056
JsonWriter writer = new JsonWriter(stringWriter);
6157

@@ -73,7 +69,7 @@ private String encode(Path instance) throws IOException {
7369
}
7470
}
7571

76-
private Path decode(String json) throws IOException {
72+
private Object decode(String json) throws IOException {
7773
JsonReader reader = new JsonReader(new StringReader(json));
7874

7975
try {
@@ -103,7 +99,7 @@ private static class Wrapper implements Parcelable {
10399
out.writeString(json);
104100
}
105101

106-
public static final Creator<Wrapper> CREATOR = new Creator<Wrapper>() {
102+
public static final Parcelable.Creator<Wrapper> CREATOR = new Parcelable.Creator<Wrapper>() {
107103
@Override public Wrapper createFromParcel(Parcel in) {
108104
String json = in.readString();
109105
return new Wrapper(json);
@@ -114,4 +110,4 @@ private static class Wrapper implements Parcelable {
114110
}
115111
};
116112
}
117-
}
113+
}

library/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ repositories {
1818
}
1919

2020
dependencies {
21-
compile 'com.github.almozavr:flow:8d5d023a34c334ce03d95104434cfc7e0b255823'
22-
compile 'com.squareup.mortar:mortar:0.17-SNAPSHOT'
21+
compile 'com.squareup.flow:flow:0.10'
22+
compile 'com.squareup.flow:flow-path:0.10'
23+
compile 'com.squareup.mortar:mortar:0.17'
2324
provided 'com.google.dagger:dagger:2.0'
2425
provided 'com.google.dagger:dagger-compiler:2.0'
2526
provided 'org.glassfish:javax.annotation:10.0-b28'

library/src/main/java/io/techery/presenta/mortar/DaggerService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class DaggerService {
1212
*/
1313
@SuppressWarnings("unchecked") //
1414
public static <T> T getDaggerComponent(Context context) {
15+
//noinspection ResourceType
1516
return (T) context.getSystemService(SERVICE_NAME);
1617
}
1718

@@ -31,7 +32,7 @@ public static <T> T createComponent(Class<T> componentClass, Object... dependenc
3132
Class<?> generatedClass = Class.forName(generatedName);
3233
Object builder = generatedClass.getMethod("builder").invoke(null);
3334

34-
for (Method method : builder.getClass().getMethods()) {
35+
for (Method method : builder.getClass().getDeclaredMethods()) {
3536
Class<?>[] params = method.getParameterTypes();
3637
if (params.length == 1) {
3738
Class<?> dependencyClass = params[0];

library/src/main/java/io/techery/presenta/mortarflow/MortarContextFactory.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import android.content.ContextWrapper;
55
import android.view.LayoutInflater;
66

7+
import flow.path.Path;
8+
import flow.path.PathContextFactory;
79
import io.techery.presenta.mortarscreen.ScreenScoper;
8-
9-
import flow.Path;
10-
import flow.PathContextFactory;
1110
import mortar.MortarScope;
1211

1312
/**

library/src/main/java/io/techery/presenta/mortarscreen/ScreenScoper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import android.content.Context;
44
import android.util.Log;
55

6-
import flow.Path;
6+
import flow.path.Path;
77
import io.techery.presenta.mortar.DaggerService;
88
import io.techery.presenta.mortar.PresenterService;
99
import io.techery.presenta.mortarscreen.component.ComponentServiceFactoryProvider;

library/src/main/java/io/techery/presenta/mortarscreen/ServiceFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import android.content.Context;
44

5-
import flow.Path;
5+
import flow.path.Path;
66

77
/**
88
* Provides some Service to be used for mortar scope depending on T object.

0 commit comments

Comments
 (0)