|
16 | 16 | import androidx.core.content.res.ResourcesCompat; |
17 | 17 | import androidx.fragment.app.Fragment; |
18 | 18 | import androidx.localbroadcastmanager.content.LocalBroadcastManager; |
19 | | -import androidx.navigation.NavOptions; |
| 19 | +import androidx.navigation.NavGraph; |
| 20 | +import androidx.navigation.NavInflater; |
20 | 21 | import androidx.navigation.fragment.NavHostFragment; |
21 | 22 |
|
22 | 23 | import com.google.common.base.Strings; |
@@ -65,45 +66,46 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { |
65 | 66 |
|
66 | 67 | redirectionAction = getIntent().getStringExtra("action"); |
67 | 68 | opportunityId = getIntent().getStringExtra("opportunity_id"); |
68 | | - if(opportunityId == null) { |
| 69 | + if (opportunityId == null) { |
69 | 70 | opportunityId = ""; |
70 | 71 | } |
71 | 72 |
|
72 | 73 | updateBackButton(); |
73 | 74 |
|
| 75 | + // Wait for fragment to attach |
| 76 | + getSupportFragmentManager().executePendingTransactions(); |
| 77 | + NavInflater inflater = navController.getNavInflater(); |
| 78 | + NavGraph graph = inflater.inflate(R.navigation.nav_graph_connect); |
| 79 | + |
| 80 | + int startDestinationId = R.id.connect_jobs_list_fragment; |
| 81 | + Bundle startArgs = null; |
| 82 | + |
74 | 83 | if (getIntent().getBooleanExtra("info", false)) { |
75 | 84 | ConnectJobRecord job = ConnectJobHelper.INSTANCE.getActiveJob(); |
76 | 85 | Objects.requireNonNull(job); |
77 | 86 |
|
78 | | - int fragmentId = job.getStatus() == ConnectJobRecord.STATUS_DELIVERING ? |
79 | | - R.id.connect_job_delivery_progress_fragment : |
80 | | - R.id.connect_job_learning_progress_fragment; |
| 87 | + startDestinationId = job.getStatus() == ConnectJobRecord.STATUS_DELIVERING |
| 88 | + ? R.id.connect_job_delivery_progress_fragment |
| 89 | + : R.id.connect_job_learning_progress_fragment; |
81 | 90 |
|
82 | 91 | boolean buttons = getIntent().getBooleanExtra("buttons", true); |
| 92 | + startArgs = new Bundle(); |
| 93 | + startArgs.putBoolean("showLaunch", buttons); |
83 | 94 |
|
84 | | - Bundle bundle = new Bundle(); |
85 | | - bundle.putBoolean("showLaunch", buttons); |
86 | | - |
87 | | - NavOptions options = new NavOptions.Builder() |
88 | | - .setPopUpTo(navController.getGraph().getStartDestinationId(), true) |
89 | | - .build(); |
90 | | - navController.navigate(fragmentId, bundle, options); |
91 | 95 | } else if (!Strings.isNullOrEmpty(redirectionAction)) { |
92 | 96 | Logger.log("ConnectActivity", "Redirecting to unlock fragment"); |
93 | 97 | //Entering from a notification, so we may need to initialize |
94 | 98 | PersonalIdManager.getInstance().init(this); |
95 | | - |
96 | | - //Navigate to the unlock fragment first, then it will navigate on as desired |
97 | | - NavOptions options = new NavOptions.Builder() |
98 | | - .setPopUpTo(navController.getGraph().getStartDestinationId(), true) |
99 | | - .build(); |
100 | | - Bundle bundle = new Bundle(); |
101 | | - bundle.putString("action", redirectionAction); |
102 | | - bundle.putString("opportunity_id", opportunityId); |
103 | | - bundle.putBoolean("buttons", getIntent().getBooleanExtra("buttons", true)); |
104 | | - navController.navigate(R.id.connect_unlock_fragment, bundle, options); |
| 99 | + startDestinationId = R.id.connect_unlock_fragment; |
| 100 | + startArgs = new Bundle(); |
| 101 | + startArgs.putString("action", redirectionAction); |
| 102 | + startArgs.putString("opportunity_id", opportunityId); |
| 103 | + startArgs.putBoolean("buttons", getIntent().getBooleanExtra("buttons", true)); |
105 | 104 | } |
106 | 105 |
|
| 106 | + graph.setStartDestination(startDestinationId); |
| 107 | + navController.setGraph(graph, startArgs); |
| 108 | + |
107 | 109 | prepareConnectMessagingScreen(); |
108 | 110 | } |
109 | 111 |
|
|
0 commit comments