use of com.zhuinden.simplestackdemonestedstack.application.Key in project simple-stack by Zhuinden.
the class NestSupportServiceManager method buildServicesForKey.
private void buildServicesForKey(StateBundle states, Key newKey, ServiceTree.Node node) {
newKey.bindServices(node);
restoreServiceStateForKey(states, newKey, node);
if (newKey instanceof Composite) {
for (Object _nestedKey : ((Composite) newKey).keys()) {
Key nestedKey = (Key) _nestedKey;
ServiceTree.Node nestedNode = serviceTree.createChildNode(node, nestedKey);
buildServicesForKey(states, (Key) _nestedKey, nestedNode);
}
}
if (newKey.hasNestedStack()) {
Backstack nestedStack = serviceTree.getNode(newKey).<BackstackManager>getService(Key.NESTED_STACK).getBackstack();
for (Object _childKey : nestedStack.getInitialParameters()) {
buildServices(states, (Key) _childKey);
}
}
}
use of com.zhuinden.simplestackdemonestedstack.application.Key in project simple-stack by Zhuinden.
the class NestSupportServiceManager method handleBack.
public boolean handleBack(Context context) {
ServiceTree serviceTree = ServiceLocator.getService(context, ServiceLocator.SERVICE_TREE);
Object lastKey = activeKeys.get(activeKeys.size() - 1);
Backstack backstack = Navigator.getBackstack(context);
class Cancellation {
private boolean cancelled;
}
Cancellation cancellation = new Cancellation();
serviceTree.traverseChain(serviceTree.getNode(lastKey), (node, cancellationToken) -> {
Object _key = node.getKey();
if (_key instanceof Key) {
// ROOT is defined by Activity's TAG
Key key = (Key) _key;
if (key.hasNestedStack()) {
BackstackManager backstackManager = serviceTree.getNode(key).getService(Key.NESTED_STACK);
if (backstackManager.getBackstack().goBack()) {
cancellation.cancelled = true;
cancellationToken.cancel();
}
}
}
});
if (cancellation.cancelled) {
return true;
}
return backstack.goBack();
}
use of com.zhuinden.simplestackdemonestedstack.application.Key in project simple-stack by Zhuinden.
the class MainView method handleStateChange.
@Override
public void handleStateChange(StateChange stateChange, Callback completionCallback) {
NestSupportServiceManager.get(getContext()).setupServices(stateChange, true);
if (stateChange.topNewState().equals(stateChange.topPreviousState())) {
// no-op
completionCallback.stateChangeComplete();
return;
}
int direction = StateChange.REPLACE;
Key previousKey = stateChange.topPreviousState();
Key newKey = stateChange.topNewState();
if (root.getChildAt(0) != null) {
StackType newStack = StackType.valueOf(newKey.stackIdentifier());
if (previousKey != null) {
StackType previousStack = StackType.valueOf(previousKey.stackIdentifier());
direction = previousStack.ordinal() < newStack.ordinal() ? StateChange.FORWARD : previousStack.ordinal() > newStack.ordinal() ? StateChange.BACKWARD : StateChange.REPLACE;
}
}
MainActivity.get(getContext()).setAnimating(true);
defaultStateChanger.performViewChange(previousKey, newKey, stateChange, direction, completionCallback);
}
use of com.zhuinden.simplestackdemonestedstack.application.Key in project simple-stack by Zhuinden.
the class NestSupportServiceManager method setupServices.
public void setupServices(StateChange stateChange, boolean isFromCompositeKey) {
StateBundle states = serviceTree.getNode(rootKey).getService(SERVICE_STATES);
for (Object _previousKey : stateChange.getPreviousState()) {
Key previousKey = (Key) _previousKey;
if (!stateChange.getNewState().contains(previousKey)) {
activeKeys.remove(previousKey);
if (!isFromCompositeKey) {
ServiceTree.Node previousNode = serviceTree.getNode(previousKey);
if (states != null) {
serviceTree.traverseSubtree(previousNode, ServiceTree.Walk.POST_ORDER, (node, cancellationToken) -> {
states.remove(node.getKey().toString());
});
}
serviceTree.removeNodeAndChildren(previousNode);
}
}
}
for (Object _newKey : stateChange.getNewState()) {
Key newKey = (Key) _newKey;
activeKeys.remove(newKey);
if (newKey == stateChange.topNewState()) {
activeKeys.add(newKey);
}
if (!isFromCompositeKey) {
buildServices(states, newKey);
}
}
}
Aggregations