Search in sources :

Example 1 with NodeCreationManager

use of com.example.mortar.nodes.NodeCreationManager 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()));
}
Also used : NodeClearManager(com.example.mortar.nodes.NodeClearManager) ServiceTree(com.zhuinden.servicetree.ServiceTree) StateBundle(com.zhuinden.statebundle.StateBundle) NodeStateManager(com.example.mortar.nodes.NodeStateManager) NodeCreationManager(com.example.mortar.nodes.NodeCreationManager)

Aggregations

NodeClearManager (com.example.mortar.nodes.NodeClearManager)1 NodeCreationManager (com.example.mortar.nodes.NodeCreationManager)1 NodeStateManager (com.example.mortar.nodes.NodeStateManager)1 ServiceTree (com.zhuinden.servicetree.ServiceTree)1 StateBundle (com.zhuinden.statebundle.StateBundle)1