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);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
binding.navigation.setOnNavigationItemSelectedListener(item -> {
Backstack backstack = Navigator.getBackstack(this);
switch(item.getItemId()) {
case R.id.navigation_home:
backstack.setHistory(History.of(HomeKey.create()), StateChange.REPLACE);
return true;
case R.id.navigation_dashboard:
backstack.setHistory(History.of(DashboardKey.create()), StateChange.REPLACE);
return true;
case R.id.navigation_notifications:
backstack.setHistory(History.of(NotificationKey.create()), StateChange.REPLACE);
return true;
}
return false;
});
fragmentStateChanger = new DefaultFragmentStateChanger(getSupportFragmentManager(), R.id.container);
Navigator.configure().setStateChanger(new SimpleStateChanger(this)).install(this, binding.container, History.single(HomeKey.create()));
}
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);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
binding.navigation.setOnNavigationItemSelectedListener(item -> {
Backstack backstack = Navigator.getBackstack(this);
switch(item.getItemId()) {
case R.id.navigation_home:
backstack.setHistory(History.of(HomeKey.create()), StateChange.REPLACE);
return true;
case R.id.navigation_dashboard:
backstack.setHistory(History.of(DashboardKey.create()), StateChange.REPLACE);
return true;
case R.id.navigation_notifications:
backstack.setHistory(History.of(NotificationKey.create()), StateChange.REPLACE);
return true;
}
return false;
});
Navigator.install(this, binding.container, History.single(HomeKey.create()));
}
use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.
the class BackstackHost method initialize.
Backstack initialize(boolean isInitializeDeferred) {
if (backstack == null) {
backstack = new Backstack();
backstack.setKeyFilter(keyFilter);
backstack.setKeyParceler(keyParceler);
backstack.setStateClearStrategy(stateClearStrategy);
if (scopedServices != null) {
backstack.setScopedServices(scopedServices);
}
if (globalServices != null) {
backstack.setGlobalServices(globalServices);
}
if (globalServiceFactory != null) {
backstack.setGlobalServices(globalServiceFactory);
}
backstack.setup(initialKeys);
for (Backstack.CompletionListener completionListener : stateChangeCompletionListeners) {
backstack.addStateChangeCompletionListener(completionListener);
}
if (savedInstanceState != null) {
backstack.fromBundle(savedInstanceState.<StateBundle>getParcelable("NAVIGATOR_STATE_BUNDLE"));
}
}
if (!isInitializeDeferred) {
backstack.setStateChanger(stateChanger);
}
return backstack;
}
use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.
the class NewWordFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Backstack backstack = Navigator.getBackstack(requireContext());
actionHandler = backstack.lookupService(ActionHandler.class.getName());
view.findViewById(R.id.buttonAddNewWord).setOnClickListener(v -> {
String word = view.<TextView>findViewById(R.id.textInputNewWord).getText().toString().trim();
actionHandler.onAddWordClicked(word);
});
}
use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.
the class WordListKey method bindServices.
@Override
public void bindServices(@Nonnull ServiceBinder serviceBinder) {
final Backstack backstack = serviceBinder.getBackstack();
WordController wordController = new WordController(backstack);
serviceBinder.addService(WordController.class.getName(), wordController);
serviceBinder.addAlias(WordListFragment.DataProvider.class.getName(), wordController);
serviceBinder.addAlias(WordListFragment.ActionHandler.class.getName(), wordController);
serviceBinder.addAlias(NewWordFragment.ActionHandler.class.getName(), wordController);
serviceBinder.addService("WordEventEmitter", wordController.getEventEmitter());
}
Aggregations