use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
CustomApplication.get(this).initialize();
CustomApplication.get(this).getComponent().inject(this);
databaseManager.init(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Backstack backstack = Navigator.configure().setDeferredInitialization(true).setStateChanger(DefaultStateChanger.configure().setExternalStateChanger(this).setViewChangeCompletionListener(this).create(this, root)).install(this, root, HistoryBuilder.single(TasksKey.create()));
backstackHolder.setBackstack(backstack);
MainScopeListener mainScopeListener = (MainScopeListener) getSupportFragmentManager().findFragmentByTag("MAIN_SCOPE_LISTENER");
if (mainScopeListener == null) {
mainScopeListener = new MainScopeListener();
getSupportFragmentManager().beginTransaction().add(mainScopeListener, "MAIN_SCOPE_LISTENER").commit();
}
mainView.onCreate();
}
use of com.zhuinden.simplestack.Backstack 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);
defaultStateChanger = DefaultStateChanger.create(this, root);
Backstack backstack = Navigator.configure().setStateChanger(new NoOpStateChanger()).setDeferredInitialization(true).install(this, root, HistoryBuilder.single(FirstKey.create()));
disposable = RxStackObservable.create(backstack).subscribe(stateChange -> {
if (stateChange.topNewState().equals(stateChange.topPreviousState())) {
return;
}
defaultStateChanger.performViewChange(stateChange.topPreviousState(), stateChange.topNewState(), stateChange, () -> {
});
});
Navigator.executeDeferredInitialization(this);
}
use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.
the class NestSupportServiceManager method buildServicesForKey.
private void buildServicesForKey(StateBundle states, Key newKey, ServiceTree.Node node) {
newKey.bindServices(node);
restoreServiceStateForKey(states, newKey, node);
if (newKey instanceof Composite) {
for (Object _nestedKey : ((Composite) newKey).keys()) {
Key nestedKey = (Key) _nestedKey;
ServiceTree.Node nestedNode = serviceTree.createChildNode(node, nestedKey);
buildServicesForKey(states, (Key) _nestedKey, nestedNode);
}
}
if (newKey.hasNestedStack()) {
Backstack nestedStack = serviceTree.getNode(newKey).<BackstackManager>getService(Key.NESTED_STACK).getBackstack();
for (Object _childKey : nestedStack.getInitialParameters()) {
buildServices(states, (Key) _childKey);
}
}
}
use of com.zhuinden.simplestack.Backstack 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.simplestack.Backstack in project simple-stack by Zhuinden.
the class WordListFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final Backstack backstack = Navigator.getBackstack(requireContext());
dataProvider = backstack.lookupService(DataProvider.class.getName());
actionHandler = backstack.lookupService(ActionHandler.class.getName());
controllerEvents = backstack.lookupService("WordEventEmitter");
RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
view.findViewById(R.id.buttonGoToAddNewWord).setOnClickListener(v -> actionHandler.onAddNewWordClicked());
dataProvider.getWordList().observe(getViewLifecycleOwner(), words -> adapter.updateWords(words));
}
Aggregations