Search in sources :

Example 1 with Key

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);
        }
    }
}
Also used : Backstack(com.zhuinden.simplestack.Backstack) ServiceTree(com.zhuinden.servicetree.ServiceTree) Key(com.zhuinden.simplestackdemonestedstack.application.Key)

Example 2 with Key

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();
}
Also used : Backstack(com.zhuinden.simplestack.Backstack) BackstackManager(com.zhuinden.simplestack.BackstackManager) ServiceTree(com.zhuinden.servicetree.ServiceTree) Key(com.zhuinden.simplestackdemonestedstack.application.Key)

Example 3 with Key

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);
}
Also used : Key(com.zhuinden.simplestackdemonestedstack.application.Key) MailKey(com.zhuinden.simplestackdemonestedstack.presentation.paths.main.mail.MailKey) CloudSyncKey(com.zhuinden.simplestackdemonestedstack.presentation.paths.main.cloudsync.CloudSyncKey) ChromeCastKey(com.zhuinden.simplestackdemonestedstack.presentation.paths.main.chromecast.ChromeCastKey) ListKey(com.zhuinden.simplestackdemonestedstack.presentation.paths.main.list.ListKey)

Example 4 with Key

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);
        }
    }
}
Also used : ServiceTree(com.zhuinden.servicetree.ServiceTree) StateBundle(com.zhuinden.statebundle.StateBundle) Key(com.zhuinden.simplestackdemonestedstack.application.Key)

Aggregations

Key (com.zhuinden.simplestackdemonestedstack.application.Key)4 ServiceTree (com.zhuinden.servicetree.ServiceTree)3 Backstack (com.zhuinden.simplestack.Backstack)2 BackstackManager (com.zhuinden.simplestack.BackstackManager)1 ChromeCastKey (com.zhuinden.simplestackdemonestedstack.presentation.paths.main.chromecast.ChromeCastKey)1 CloudSyncKey (com.zhuinden.simplestackdemonestedstack.presentation.paths.main.cloudsync.CloudSyncKey)1 ListKey (com.zhuinden.simplestackdemonestedstack.presentation.paths.main.list.ListKey)1 MailKey (com.zhuinden.simplestackdemonestedstack.presentation.paths.main.mail.MailKey)1 StateBundle (com.zhuinden.statebundle.StateBundle)1