use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class MortarDemoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// no need to restore if no process death could have occurred
DID_RESTORE_AFTER_PROCESS_DEATH = true;
}
if (savedInstanceState != null && !DID_RESTORE_AFTER_PROCESS_DEATH) {
DID_RESTORE_AFTER_PROCESS_DEATH = true;
StateBundle rootBundle = savedInstanceState.getParcelable(NodeStateManager.SERVICE_STATES);
if (rootBundle != null) {
// global service state is restored after process death
// not yet injected by field injection
SingletonComponent singletonComponent = DaggerService.get(this);
ServiceTree _serviceTree = singletonComponent.serviceTree();
NodeStateManager _nodeStateManager = singletonComponent.nodeStateManager();
_serviceTree.registerRootService(NodeStateManager.SERVICE_STATES, rootBundle);
// root services should be restored after process death
_nodeStateManager.restoreStatesForNode(_serviceTree.getTreeRoot());
}
}
ServiceTree.Node parentScope = TreeNodes.getNode(getApplication());
String scopeName = getLocalClassName() + "-task-" + getTaskId();
if (!parentScope.hasChild(scopeName)) {
parentScope.createChild(scopeName);
}
activityScope = parentScope.getChild(scopeName);
DaggerService.<SingletonComponent>get(this).inject(this);
actionBarOwner.takeView(this);
setContentView(R.layout.root_layout);
container = (FrameLayout) findViewById(R.id.container);
Navigator.configure().setKeyParceler(keyParceler).addStateChangeCompletionListener(new NodeClearManager(serviceTree, // to delete un-used mortar scopes
nodeStateManager)).setStateChanger(DefaultStateChanger.configure().setExternalStateChanger(this).setContextCreationStrategy(new NodeCreationManager(serviceTree, activityScope, nodeStateManager)).create(this, container)).install(this, container, HistoryBuilder.single(ChatListScreen.create()));
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class CloudSyncView method toBundle.
@Override
public StateBundle toBundle() {
StateBundle bundle = new StateBundle();
bundle.putString("HELLO", "WORLD");
StateBundle innerBundle = new StateBundle();
innerBundle.putString("KAPPA", "KAPPA");
bundle.putBundle("GOOMBA", innerBundle);
return bundle;
}
use of com.zhuinden.statebundle.StateBundle 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);
}
}
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class NodeStateManager method clearStatesForKey.
public void clearStatesForKey(Object previousKey) {
final StateBundle rootBundle = serviceTree.getRootService(SERVICE_STATES);
serviceTree.traverseSubtree(serviceTree.getNode(previousKey), ServiceTree.Walk.POST_ORDER, new ServiceTree.Walk() {
@Override
public void execute(@NonNull ServiceTree.Node node, @NonNull CancellationToken cancellationToken) {
Log.i(TAG, "Removing state for [" + node.getKey().toString() + "]");
rootBundle.remove(node.getKey().toString());
}
});
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class BackstackManager method toBundle.
/**
* Persists the backstack history and view state into a StateBundle.
*
* @return the state bundle
*/
@NonNull
@Override
public StateBundle toBundle() {
StateBundle stateBundle = new StateBundle();
ArrayList<Parcelable> history = new ArrayList<>();
for (Object key : backstack.getHistory()) {
history.add(keyParceler.toParcelable(key));
}
stateBundle.putParcelableArrayList(getHistoryTag(), history);
ArrayList<ParcelledState> states = new ArrayList<>();
for (SavedState savedState : keyStateMap.values()) {
ParcelledState parcelledState = new ParcelledState();
parcelledState.parcelableKey = keyParceler.toParcelable(savedState.getKey());
parcelledState.viewHierarchyState = savedState.getViewHierarchyState();
parcelledState.bundle = savedState.getBundle();
states.add(parcelledState);
}
stateBundle.putParcelableArrayList(getStatesTag(), states);
return stateBundle;
}
Aggregations