@Override public void dispatch(Flow.Traversal traversal, final Flow.TraversalCallback callback) { Path path = traversal.destination.top(); setTitle(path.getClass().getSimpleName()); boolean canGoBack = traversal.destination.size() > 1; String title = path.getClass().getSimpleName(); ActionBarOwner.MenuAction menu = canGoBack ? null : new ActionBarOwner.MenuAction("Friends", new Runnable() { @Override public void run() { Flow.get(MortarDemoActivity.this).set(new FriendListScreen()); } }); actionBarOwner.setConfig(new ActionBarOwner.Config(false, canGoBack, title, menu)); container.dispatch(traversal, new Flow.TraversalCallback() { @Override public void onTraversalCompleted() { invalidateOptionsMenu(); callback.onTraversalCompleted(); } }); }
public final void executeTraversal(PathContainerView view, Flow.Traversal traversal, final Flow.TraversalCallback callback) { final View oldChild = view.getCurrentChild(); Path path = traversal.destination.top(); ViewState viewState = traversal.destination.currentViewState(); Path oldPath; ViewGroup containerView = view.getContainerView(); TraversalState traversalState = ensureTag(containerView); // See if we already have the direct child we want, and if so short circuit the traversal. if (oldChild != null) { oldPath = Preconditions.checkNotNull(traversalState.toPath, "Container view has child %s with no path", oldChild.toString()); if (oldPath.equals(path)) { callback.onTraversalCompleted(); return; } } traversalState.setNextEntry(path, viewState); performTraversal(containerView, traversalState, traversal.direction, callback); }
@Override public void dispatch(Flow.Traversal traversal, final Flow.TraversalCallback callback) { MasterDetailPath currentMaster = ((MasterDetailPath) traversal.origin.top()).getMaster(); MasterDetailPath newMaster = ((MasterDetailPath) traversal.destination.top()).getMaster(); // Short circuit if the new screen has the same master. if (getCurrentChild() != null && newMaster.equals(currentMaster)) { callback.onTraversalCompleted(); } else { super.dispatch(traversal, new Flow.TraversalCallback() { @Override public void onTraversalCompleted() { callback.onTraversalCompleted(); } }); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Object appComponent = DaggerService.getDaggerComponent(MortarDemoApplication.instance()); Component component = DaggerService.createComponent(Component.class, appComponent); component.inject(this); String scopeName = getLocalClassName() + "-task-" + getTaskId(); MortarScope parentScope = MortarScope.getScope(getApplication()); activityScope = parentScope.findChild(scopeName); if (activityScope == null) { activityScope = parentScope.buildChild() .withService(BundleServiceRunner.SERVICE_NAME, new BundleServiceRunner()) .withService(DaggerService.SERVICE_NAME, component) .build(scopeName); } BundleServiceRunner.getBundleServiceRunner(activityScope).onCreate(savedInstanceState); actionBarOwner.takeView(this); setContentView(R.layout.root_layout); container = (PathContainerView) findViewById(R.id.container); containerAsBackTarget = (HandlesBack) container; FlowDelegate.NonConfigurationInstance nonConfig = (FlowDelegate.NonConfigurationInstance) getLastCustomNonConfigurationInstance(); History history = History.single(new ChatListScreen()); flowSupport = FlowDelegate.onCreate(nonConfig, getIntent(), savedInstanceState, new GsonParceler(new Gson()), history, this); }
@Override public void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback) { Log.d("BasicDispatcher", "dispatching " + traversal); Object destKey = traversal.destination.top(); traversal.getState(traversal.origin.top()).save(currentView); traversal.getState(traversal.destination.top()).restore(incomingView);