@Test public void buildDeepLinkIds() { NavDestination destination = new NavDestination(mock(Navigator.class)); destination.setId(DESTINATION_ID); int parentId = 2; NavGraph parent = new NavGraph(mock(Navigator.class)); parent.setId(parentId); destination.setParent(parent); int[] deepLinkIds = destination.buildDeepLinkIds(); assertThat(deepLinkIds.length, is(2)); assertThat(deepLinkIds[0], is(parentId)); assertThat(deepLinkIds[1], is(DESTINATION_ID)); }
@NonNull int[] buildDeepLinkIds() { ArrayDeque<NavDestination> hierarchy = new ArrayDeque<>(); NavDestination current = this; do { NavGraph parent = current.getParent(); if (parent == null || parent.getStartDestination() != current.getId()) { hierarchy.addFirst(current); } current = parent; } while (current != null); int[] deepLinkIds = new int[hierarchy.size()]; int index = 0; for (NavDestination destination : hierarchy) { deepLinkIds[index++] = destination.getId(); } return deepLinkIds; }
NavDestination { @NonNull int[] buildDeepLinkIds() { ArrayDeque<NavDestination> hierarchy = new ArrayDeque<>(); NavDestination current = this; do { NavGraph parent = current.getParent(); if (parent == null || parent.getStartDestination() != current.getId()) { hierarchy.addFirst(current); } current = parent; } while (current != null); int[] deepLinkIds = new int[hierarchy.size()]; int index = 0; for (NavDestination destination : hierarchy) { deepLinkIds[index++] = destination.getId(); } return deepLinkIds; } }
NavDestination { @NonNull int[] buildDeepLinkIds() { ArrayDeque<NavDestination> hierarchy = new ArrayDeque<>(); NavDestination current = this; do { NavGraph parent = current.getParent(); if (parent == null || parent.getStartDestination() != current.getId()) { hierarchy.addFirst(current); } current = parent; } while (current != null); int[] deepLinkIds = new int[hierarchy.size()]; int index = 0; for (NavDestination destination : hierarchy) { deepLinkIds[index++] = destination.getId(); } return deepLinkIds; } NavDestination(@NonNull Navigator<? extends NavDestination> navigator); }
NavDestination { @NonNull int[] buildDeepLinkIds() { ArrayDeque<NavDestination> hierarchy = new ArrayDeque<>(); NavDestination current = this; do { NavGraph parent = current.getParent(); if (parent == null || parent.getStartDestination() != current.getId()) { hierarchy.addFirst(current); } current = parent; } while (current != null); int[] deepLinkIds = new int[hierarchy.size()]; int index = 0; for (NavDestination destination : hierarchy) { deepLinkIds[index++] = destination.getId(); } return deepLinkIds; } NavDestination(@NonNull Navigator<? extends NavDestination> navigator); @CallSuper void onInflate(@NonNull Context context, @NonNull AttributeSet attrs); @Nullable NavGraph getParent(); @IdRes int getId(); void setId(@IdRes int id); void setLabel(@Nullable CharSequence label); @Nullable CharSequence getLabel(); @NonNull Navigator getNavigator(); @NonNull Bundle getDefaultArguments(); void setDefaultArguments(@Nullable Bundle args); void addDefaultArguments(@NonNull Bundle args); void addDeepLink(@NonNull String uriPattern); @Nullable NavAction getAction(@IdRes int id); void putAction(@IdRes int actionId, @IdRes int destId); void putAction(@IdRes int actionId, @NonNull NavAction action); void removeAction(@IdRes int actionId); @SuppressWarnings("unchecked") void navigate(@Nullable Bundle args, @Nullable NavOptions navOptions); }
NavDestination { @NonNull int[] buildDeepLinkIds() { ArrayDeque<NavDestination> hierarchy = new ArrayDeque<>(); NavDestination current = this; do { NavGraph parent = current.getParent(); if (parent == null || parent.getStartDestination() != current.getId()) { hierarchy.addFirst(current); } current = parent; } while (current != null); int[] deepLinkIds = new int[hierarchy.size()]; int index = 0; for (NavDestination destination : hierarchy) { deepLinkIds[index++] = destination.getId(); } return deepLinkIds; } NavDestination(@NonNull Navigator<? extends NavDestination> navigator); @CallSuper void onInflate(@NonNull Context context, @NonNull AttributeSet attrs); @Nullable NavGraph getParent(); @IdRes int getId(); void setId(@IdRes int id); void setLabel(@Nullable CharSequence label); @Nullable CharSequence getLabel(); @NonNull Navigator getNavigator(); @NonNull Bundle getDefaultArguments(); void setDefaultArguments(@Nullable Bundle args); void addDefaultArguments(@NonNull Bundle args); void addDeepLink(@NonNull String uriPattern); @Nullable NavAction getAction(@IdRes int id); void putAction(@IdRes int actionId, @IdRes int destId); void putAction(@IdRes int actionId, @NonNull NavAction action); void removeAction(@IdRes int actionId); @SuppressWarnings("unchecked") void navigate(@Nullable Bundle args, @Nullable NavOptions navOptions);  }