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;
}
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()));
}
}
}
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;
}
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;
}
Aggregations