@Test public void singleInstanceBringsViewToFront() { mockActivity(); final EqualMockView secondView = EqualMockView.createNewView(); final NavigationDetails secondViewNavDetails = secondView.create(); viewManager.navigate(secondViewNavDetails); viewManager.navigate(MockView.createNewView().create()); assertThat(viewManager.viewStack.size()).isEqualTo(3); final EqualMockView secondView2 = EqualMockView.createNewView(); final NavigationDetails secondViewNavDetails2 = NavigationDetails .navigateTo(secondView2) .singleInstance(true) .build(); viewManager.navigate(secondViewNavDetails2); assertThat(viewManager.viewStack.size()).isEqualTo(3); final NavigationDetails top = viewManager.viewStack.peek(); assertThat(top).isEqualTo(secondViewNavDetails); assertThat(top.view() == secondView).isTrue(); assertThat(top.view() != secondView2).isTrue(); }
@MainThread void navigate(@NonNull NavigationDetails navDetails) { boolean newInstance = true; if (navDetails.singleInstance() && !viewStack.isEmpty()) { if (viewStack.peek().equals(navDetails)) { return; } final Dual<NavigationDetails, Boolean> removedViewMetadata = removeViewFromStack(navDetails.view()); if (removedViewMetadata != null) { final NavigationDetails removedViewDetails = removedViewMetadata.first(); if (removedViewDetails.needsRestart()) { navDetails = navDetails.copy() .view(removedViewDetails.view().copy()) .build(); } else { navDetails = navDetails.copy() .view(removedViewDetails.view()) .build(); newInstance = false; } } } if (navDetails.clearStack()) { clearStack(); } if (contentRootView != null && isActivityShown()) { pushViewToStack(navDetails, newInstance); } else { LogUtil.logViewDebug(TAG, "No root view while navigating to view %s. Adding it to stack and waiting for root view to come back", navDetails.view().getClass().getSimpleName()); viewStack.push(navDetails.markRestartNeeded()); } }
ViewManager implements Observer<LifecycleEvent> { @MainThread void navigate(@NonNull NavigationDetails navDetails) { boolean newInstance = true; if (navDetails.singleInstance() && !viewStack.isEmpty()) { if (viewStack.peek().equals(navDetails)) { return; } final Dual<NavigationDetails, Boolean> removedViewMetadata = removeViewFromStack(navDetails.view()); if (removedViewMetadata != null) { final NavigationDetails removedViewDetails = removedViewMetadata.first(); if (removedViewDetails.needsRestart()) { navDetails = navDetails.copy() .view(removedViewDetails.view().copy()) .build(); } else { navDetails = navDetails.copy() .view(removedViewDetails.view()) .build(); newInstance = false; } } } if (navDetails.clearStack()) { clearStack(); } if (contentRootView != null && isActivityShown()) { pushViewToStack(navDetails, newInstance); } else { LogUtil.logViewDebug(TAG, "No root view while navigating to view %s. Adding it to stack and waiting for root view to come back", navDetails.view().getClass().getSimpleName()); viewStack.push(navDetails.markRestartNeeded()); } } }
ViewManager implements Observer<LifecycleEvent> { @MainThread void navigate(@NonNull NavigationDetails navDetails) { boolean newInstance = true; if (navDetails.singleInstance() && !viewStack.isEmpty()) { if (viewStack.peek().equals(navDetails)) { return; } final Dual<NavigationDetails, Boolean> removedViewMetadata = removeViewFromStack(navDetails.view()); if (removedViewMetadata != null) { final NavigationDetails removedViewDetails = removedViewMetadata.first(); if (removedViewDetails.needsRestart()) { navDetails = navDetails.copy() .view(removedViewDetails.view().copy()) .build(); } else { navDetails = navDetails.copy() .view(removedViewDetails.view()) .build(); newInstance = false; } } } if (navDetails.clearStack()) { clearStack(); } if (contentRootView != null && isActivityShown()) { pushViewToStack(navDetails, newInstance); } else { LogUtil.logViewDebug(TAG, "No root view while navigating to view %s. Adding it to stack and waiting for root view to come back", navDetails.view().getClass().getSimpleName()); viewStack.push(navDetails.markRestartNeeded()); } } ViewManager(@NonNull GraphProvider graphProvider); }
ViewManager implements Observer<LifecycleEvent> { @MainThread void navigate(@NonNull NavigationDetails navDetails) { boolean newInstance = true; if (navDetails.singleInstance() && !viewStack.isEmpty()) { if (viewStack.peek().equals(navDetails)) { return; } final Dual<NavigationDetails, Boolean> removedViewMetadata = removeViewFromStack(navDetails.view()); if (removedViewMetadata != null) { final NavigationDetails removedViewDetails = removedViewMetadata.first(); if (removedViewDetails.needsRestart()) { navDetails = navDetails.copy() .view(removedViewDetails.view().copy()) .build(); } else { navDetails = navDetails.copy() .view(removedViewDetails.view()) .build(); newInstance = false; } } } if (navDetails.clearStack()) { clearStack(); } if (contentRootView != null && isActivityShown()) { pushViewToStack(navDetails, newInstance); } else { LogUtil.logViewDebug(TAG, "No root view while navigating to view %s. Adding it to stack and waiting for root view to come back", navDetails.view().getClass().getSimpleName()); viewStack.push(navDetails.markRestartNeeded()); } } ViewManager(@NonNull GraphProvider graphProvider); @MainThread final void registerActivity(@NonNull RootActivityContract activityContract,
                                     @NonNull Activity rootActivity); @MainThread final void unregisterActivity(); @Override void onNext(LifecycleEvent lifecycleEvent); @Override void onCompleted(); @Override void onError(Throwable e); @MainThread final boolean handleBackPress(); }
ViewManager implements Observer<LifecycleEvent> { @MainThread void navigate(@NonNull NavigationDetails navDetails) { boolean newInstance = true; if (navDetails.singleInstance() && !viewStack.isEmpty()) { if (viewStack.peek().equals(navDetails)) { return; } final Dual<NavigationDetails, Boolean> removedViewMetadata = removeViewFromStack(navDetails.view()); if (removedViewMetadata != null) { final NavigationDetails removedViewDetails = removedViewMetadata.first(); if (removedViewDetails.needsRestart()) { navDetails = navDetails.copy() .view(removedViewDetails.view().copy()) .build(); } else { navDetails = navDetails.copy() .view(removedViewDetails.view()) .build(); newInstance = false; } } } if (navDetails.clearStack()) { clearStack(); } if (contentRootView != null && isActivityShown()) { pushViewToStack(navDetails, newInstance); } else { LogUtil.logViewDebug(TAG, "No root view while navigating to view %s. Adding it to stack and waiting for root view to come back", navDetails.view().getClass().getSimpleName()); viewStack.push(navDetails.markRestartNeeded()); } } ViewManager(@NonNull GraphProvider graphProvider); @MainThread final void registerActivity(@NonNull RootActivityContract activityContract,
                                     @NonNull Activity rootActivity); @MainThread final void unregisterActivity(); @Override void onNext(LifecycleEvent lifecycleEvent); @Override void onCompleted(); @Override void onError(Throwable e); @MainThread final boolean handleBackPress();  }