Search in sources :

Example 1 with BackstackManager

use of com.zhuinden.simplestack.BackstackManager in project simple-stack by Zhuinden.

the class Key method bindServices.

public void bindServices(ServiceTree.Node node) {
    if (hasNestedStack()) {
        BackstackManager backstackManager = new BackstackManager();
        backstackManager.setStateClearStrategy(new PreserveTreeScopesStrategy(node.getTree()));
        backstackManager.setup(initialKeys());
        node.bindService(NESTED_STACK, backstackManager);
    }
}
Also used : PreserveTreeScopesStrategy(com.zhuinden.simplestackdemonestedstack.util.PreserveTreeScopesStrategy) BackstackManager(com.zhuinden.simplestack.BackstackManager)

Example 2 with BackstackManager

use of com.zhuinden.simplestack.BackstackManager 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 BackstackManager

use of com.zhuinden.simplestack.BackstackManager in project simple-stack by Zhuinden.

the class BackstackHost method initialize.

Backstack initialize(boolean isInitializeDeferred) {
    if (backstackManager == null) {
        backstackManager = new BackstackManager();
        backstackManager.setKeyFilter(keyFilter);
        backstackManager.setKeyParceler(keyParceler);
        backstackManager.setStateClearStrategy(stateClearStrategy);
        for (BackstackManager.StateChangeCompletionListener completionListener : stateChangeCompletionListeners) {
            backstackManager.addStateChangeCompletionListener(completionListener);
        }
        backstackManager.setup(initialKeys);
        if (savedInstanceState != null) {
            backstackManager.fromBundle(savedInstanceState.<StateBundle>getParcelable("NAVIGATOR_STATE_BUNDLE"));
        }
    }
    if (!isInitializeDeferred) {
        backstackManager.setStateChanger(stateChanger);
    }
    return backstackManager.getBackstack();
}
Also used : BackstackManager(com.zhuinden.simplestack.BackstackManager)

Aggregations

BackstackManager (com.zhuinden.simplestack.BackstackManager)3 ServiceTree (com.zhuinden.servicetree.ServiceTree)1 Backstack (com.zhuinden.simplestack.Backstack)1 Key (com.zhuinden.simplestackdemonestedstack.application.Key)1 PreserveTreeScopesStrategy (com.zhuinden.simplestackdemonestedstack.util.PreserveTreeScopesStrategy)1