Search in sources :

Example 1 with Bundleable

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

the class NestSupportServiceManager method persistStates.

public StateBundle persistStates() {
    StateBundle serviceStates = new StateBundle();
    serviceTree.traverseTree(ServiceTree.Walk.PRE_ORDER, (node, cancellationToken) -> {
        StateBundle keyBundle = new StateBundle();
        for (ServiceTree.Node.Entry entry : node.getBoundServices()) {
            if (entry.getService() instanceof Bundleable) {
                keyBundle.putParcelable(entry.getName(), ((Bundleable) entry.getService()).toBundle());
            }
        }
        serviceStates.putParcelable(node.getKey().toString(), keyBundle);
    });
    return serviceStates;
}
Also used : Bundleable(com.zhuinden.simplestack.Bundleable) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 2 with Bundleable

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

the class NodeStateManager method restoreStatesForNode.

public void restoreStatesForNode(ServiceTree.Node node) {
    StateBundle rootBundle = serviceTree.getRootService(SERVICE_STATES);
    StateBundle localBundle = rootBundle.getBundle(node.getKey().toString());
    Log.i(TAG, "Restoring state for [" + node.getKey().toString() + "] with bundle [" + localBundle + "]");
    for (ServiceTree.Node.Entry entry : node.getBoundServices()) {
        Log.i(TAG, "Restoring state for service [" + entry.getName() + "]");
        if (entry.getService() instanceof Bundleable) {
            ((Bundleable) entry.getService()).fromBundle(localBundle == null ? null : localBundle.getBundle(entry.getName()));
        }
    }
}
Also used : Bundleable(com.zhuinden.simplestack.Bundleable) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 3 with Bundleable

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

the class NodeStateManager method persistStates.

public StateBundle persistStates() {
    final StateBundle rootBundle = serviceTree.getRootService(SERVICE_STATES);
    serviceTree.traverseTree(ServiceTree.Walk.PRE_ORDER, true, new ServiceTree.Walk() {

        @Override
        public void execute(@NonNull ServiceTree.Node node, @NonNull CancellationToken cancellationToken) {
            StateBundle localBundle = rootBundle.getBundle(node.getKey().toString());
            if (localBundle == null) {
                localBundle = new StateBundle();
            }
            for (ServiceTree.Node.Entry entry : node.getBoundServices()) {
                Log.i(TAG, "Persisting state for [" + entry.getName() + "] in [" + node.getKey().toString() + "]");
                if (entry.getService() instanceof Bundleable) {
                    localBundle.putBundle(entry.getName(), ((Bundleable) entry.getService()).toBundle());
                }
            }
            rootBundle.putBundle(node.getKey().toString(), localBundle);
        }
    });
    return rootBundle;
}
Also used : Bundleable(com.zhuinden.simplestack.Bundleable) ServiceTree(com.zhuinden.servicetree.ServiceTree) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 4 with Bundleable

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

the class ServiceManager method persistStates.

public StateBundle persistStates() {
    StateBundle serviceStates = new StateBundle();
    serviceTree.traverseTree(ServiceTree.Walk.PRE_ORDER, (node, cancellationToken) -> {
        StateBundle keyBundle = new StateBundle();
        for (ServiceTree.Node.Entry entry : node.getBoundServices()) {
            if (entry.getService() instanceof Bundleable) {
                keyBundle.putParcelable(entry.getName(), ((Bundleable) entry.getService()).toBundle());
            }
        }
        serviceStates.putParcelable(node.getKey().toString(), keyBundle);
    });
    return serviceStates;
}
Also used : Bundleable(com.zhuinden.simplestack.Bundleable) StateBundle(com.zhuinden.statebundle.StateBundle)

Aggregations

Bundleable (com.zhuinden.simplestack.Bundleable)4 StateBundle (com.zhuinden.statebundle.StateBundle)4 ServiceTree (com.zhuinden.servicetree.ServiceTree)1