use of com.zhuinden.servicetree.ServiceTree in project simple-stack by Zhuinden.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
NonConfigurationInstance nonConfigurationInstance = (NonConfigurationInstance) getLastCustomNonConfigurationInstance();
if (nonConfigurationInstance != null) {
serviceManager = nonConfigurationInstance.serviceManager;
serviceTree = serviceManager.getServiceTree();
} else {
serviceTree = new ServiceTree();
serviceTree.createRootNode(TAG);
serviceManager = new NestSupportServiceManager(serviceTree, TAG);
serviceManager.setRestoredStates(savedInstanceState != null ? savedInstanceState.getParcelable("SERVICE_BUNDLE") : new StateBundle());
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
backstack = Navigator.configure().setStateChanger(DefaultStateChanger.configure().setExternalStateChanger(this).create(this, root)).setStateClearStrategy(new PreserveTreeScopesStrategy(serviceTree)).install(this, root, HistoryBuilder.single(MainKey.create()));
}
use of com.zhuinden.servicetree.ServiceTree in project simple-stack by Zhuinden.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
NonConfigurationInstance nonConfigurationInstance = (NonConfigurationInstance) getLastCustomNonConfigurationInstance();
if (nonConfigurationInstance != null) {
serviceManager = nonConfigurationInstance.serviceManager;
serviceTree = serviceManager.getServiceTree();
} else {
serviceTree = new ServiceTree();
serviceTree.createRootNode(TAG);
serviceManager = new ServiceManager(serviceTree, TAG);
}
serviceManager.setRestoredStates(savedInstanceState != null ? savedInstanceState.getParcelable(ServiceManager.SERVICE_STATES) : new StateBundle());
Navigator.configure().setStateChanger(DefaultStateChanger.configure().setExternalStateChanger(this).create(this, root)).install(this, root, HistoryBuilder.single(A.create()));
}
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) {
T t = (T) context.getSystemService(name);
if (t == null) {
// noinspection ResourceType
ServiceTree serviceTree = (ServiceTree) context.getSystemService(SERVICE_TREE);
ServiceTree.Node node = serviceTree.getNode(Backstack.getKey(context));
return node.getService(name);
}
return t;
}
use of com.zhuinden.servicetree.ServiceTree in project simple-stack by Zhuinden.
the class NestSupportServiceManager method handleBack.
public boolean handleBack(Context context) {
ServiceTree serviceTree = ServiceLocator.getService(context, ServiceLocator.SERVICE_TREE);
Object lastKey = activeKeys.get(activeKeys.size() - 1);
Backstack backstack = Navigator.getBackstack(context);
class Cancellation {
private boolean cancelled;
}
Cancellation cancellation = new Cancellation();
serviceTree.traverseChain(serviceTree.getNode(lastKey), (node, cancellationToken) -> {
Object _key = node.getKey();
if (_key instanceof Key) {
// ROOT is defined by Activity's TAG
Key key = (Key) _key;
if (key.hasNestedStack()) {
BackstackManager backstackManager = serviceTree.getNode(key).getService(Key.NESTED_STACK);
if (backstackManager.getBackstack().goBack()) {
cancellation.cancelled = true;
cancellationToken.cancel();
}
}
}
});
if (cancellation.cancelled) {
return true;
}
return backstack.goBack();
}
use of com.zhuinden.servicetree.ServiceTree in project simple-stack by Zhuinden.
the class MortarDemoApplication method getSystemService.
@Override
public Object getSystemService(String name) {
if (serviceTree == null) {
serviceTree = new ServiceTree();
serviceTree.registerRootService(DaggerService.SERVICE_NAME, DaggerSingletonComponent.builder().rootModule(new RootModule(serviceTree)).build());
serviceTree.registerRootService(NodeStateManager.SERVICE_STATES, new StateBundle());
// MortarScope.buildRootScope()
//.withService(ObjectGraphService.SERVICE_NAME, ObjectGraph.create(new RootModule()))
//.build("Root");
}
if (serviceTree.hasRootService(name)) {
return serviceTree.getRootService(name);
}
if (TreeNodes.NODE_TAG.equals(name)) {
return serviceTree.getTreeRoot();
}
return super.getSystemService(name);
}
Aggregations