|
@@ -21,16 +21,38 @@ public class ScreenStack extends FrameLayout {
|
21
|
21
|
}
|
22
|
22
|
|
23
|
23
|
public void push(ScreenParams screenParams) {
|
|
24
|
+ Screen previous = stack.peek();
|
|
25
|
+ addScreen(screenParams);
|
|
26
|
+ removePreviousWithoutUnmount(previous);
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+ private void addScreen(ScreenParams screenParams) {
|
24
|
30
|
Screen screen = new ScreenImpl(getContext(), screenParams);
|
25
|
31
|
addView(screen.asView(), new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
26
|
32
|
stack.push(screen);
|
27
|
33
|
}
|
28
|
34
|
|
29
|
|
- public Screen pop() {
|
30
|
|
- Screen popped = stack.pop();
|
31
|
|
- popped.ensureUnmountOnDetachedFromWindow();
|
32
|
|
- removeView(popped.asView());
|
33
|
|
- return popped;
|
|
35
|
+ private void removePreviousWithoutUnmount(Screen previous) {
|
|
36
|
+ previous.preventUnmountOnDetachedFromWindow();
|
|
37
|
+ removeView(previous.asView());
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ public void pop() {
|
|
41
|
+ if (!canPop()) {
|
|
42
|
+ throw new RuntimeException("Can't pop ScreenStack of size " + getStackSize());
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ Screen toRemove = stack.pop();
|
|
46
|
+ Screen previous = stack.peek();
|
|
47
|
+
|
|
48
|
+ readdPrevious(previous);
|
|
49
|
+
|
|
50
|
+ toRemove.ensureUnmountOnDetachedFromWindow();
|
|
51
|
+ removeView(toRemove.asView());
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ private void readdPrevious(Screen previous) {
|
|
55
|
+ addView(previous.asView(), new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
34
|
56
|
}
|
35
|
57
|
|
36
|
58
|
public void popToRoot() {
|
|
@@ -40,9 +62,11 @@ public class ScreenStack extends FrameLayout {
|
40
|
62
|
}
|
41
|
63
|
|
42
|
64
|
public void destroy() {
|
43
|
|
- while (!isEmpty()) {
|
44
|
|
- pop();
|
|
65
|
+ for (Screen screen : stack) {
|
|
66
|
+ screen.ensureUnmountOnDetachedFromWindow();
|
|
67
|
+ removeView(screen.asView());
|
45
|
68
|
}
|
|
69
|
+ stack.clear();
|
46
|
70
|
}
|
47
|
71
|
|
48
|
72
|
public boolean isEmpty() {
|
|
@@ -53,10 +77,6 @@ public class ScreenStack extends FrameLayout {
|
53
|
77
|
return stack.size();
|
54
|
78
|
}
|
55
|
79
|
|
56
|
|
- public Screen peek() {
|
57
|
|
- return stack.peek();
|
58
|
|
- }
|
59
|
|
-
|
60
|
80
|
public boolean canPop() {
|
61
|
81
|
return getStackSize() > 1;
|
62
|
82
|
}
|