Search in sources :

Example 6 with ServiceTree

use of com.zhuinden.servicetree.ServiceTree 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)

Example 7 with ServiceTree

use of com.zhuinden.servicetree.ServiceTree in project simple-stack by Zhuinden.

the class ServiceLocator method getService.

public static <T> T getService(Context context, String name) {
    // noinspection unchecked
    T service = (T) context.getSystemService(name);
    if (service == null) {
        // noinspection ResourceType
        ServiceTree serviceTree = (ServiceTree) context.getSystemService(SERVICE_TREE);
        ServiceTree.Node node = serviceTree.getNode(Backstack.getKey(context));
        return node.getService(name);
    }
    return service;
}
Also used : ServiceTree(com.zhuinden.servicetree.ServiceTree)

Aggregations

ServiceTree (com.zhuinden.servicetree.ServiceTree)7 StateBundle (com.zhuinden.statebundle.StateBundle)4 NodeClearManager (com.example.mortar.nodes.NodeClearManager)1 NodeCreationManager (com.example.mortar.nodes.NodeCreationManager)1 NodeStateManager (com.example.mortar.nodes.NodeStateManager)1 ServiceManager (com.zhuinden.simpleservicesexample.utils.ServiceManager)1 Backstack (com.zhuinden.simplestack.Backstack)1 BackstackManager (com.zhuinden.simplestack.BackstackManager)1 Key (com.zhuinden.simplestackdemonestedstack.application.Key)1 NestSupportServiceManager (com.zhuinden.simplestackdemonestedstack.util.NestSupportServiceManager)1 PreserveTreeScopesStrategy (com.zhuinden.simplestackdemonestedstack.util.PreserveTreeScopesStrategy)1