1 /*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package androidx.core.telecom.test.ui
18
19 import android.content.Intent
20 import androidx.core.telecom.test.ui.calling.AudioRoutePickerDialog
21 import androidx.core.telecom.test.ui.calling.CallsScreen
22 import androidx.core.telecom.test.ui.calling.OngoingCallsViewModel
23 import androidx.navigation.NavController
24 import androidx.navigation.NavGraphBuilder
25 import androidx.navigation.compose.composable
26 import androidx.navigation.compose.dialog
27
28 /* Routes defined by the navgraph */
29 object NavRoute {
30 const val ROLE_REQUESTS = "RoleRequests"
31 const val CALLS = "Calls"
32 const val NOT_SUPPORTED = "NotSupported"
33 const val AUDIO_ROUTE_PICKER = "AudioRoutePicker"
34 const val SETTINGS = "Settings"
35 }
36
37 /** The screen used for devices that do not support this application */
NavGraphBuildernull38 fun NavGraphBuilder.notSupportedDestination() {
39 composable(NavRoute.NOT_SUPPORTED) { UnsupportedDeviceScreen() }
40 }
41
42 /** The screen used for devices that have not set this application to the default dialer yet. */
NavGraphBuildernull43 fun NavGraphBuilder.roleRequestsDestination(
44 roleIntent: Intent,
45 onGrantedStateChanged: (Boolean) -> Unit
46 ) {
47 composable(NavRoute.ROLE_REQUESTS) { RoleRequestScreen(roleIntent, onGrantedStateChanged) }
48 }
49
50 /** The main calling screen, which manages new and ongoing calls. */
NavGraphBuildernull51 fun NavGraphBuilder.callsDestination(
52 ongoingCallsViewModel: OngoingCallsViewModel,
53 onShowAudioRouting: () -> Unit,
54 onMoveToSettings: () -> Unit
55 ) {
56 composable(NavRoute.CALLS) {
57 CallsScreen(
58 ongoingCallsViewModel = ongoingCallsViewModel,
59 onShowAudioRouting = onShowAudioRouting,
60 onMoveToSettings = onMoveToSettings
61 )
62 }
63 }
64
65 /**
66 * The audio routing dialog, which sits on top of the active screen and allows users to change the
67 * active audio route of the active call.
68 */
NavGraphBuildernull69 fun NavGraphBuilder.audioRouteDialog(
70 ongoingCallsViewModel: OngoingCallsViewModel,
71 onDismissDialog: () -> Unit,
72 onChangeAudioRoute: suspend (String) -> Unit
73 ) {
74 dialog(NavRoute.AUDIO_ROUTE_PICKER) {
75 AudioRoutePickerDialog(ongoingCallsViewModel, onDismissDialog, onChangeAudioRoute)
76 }
77 }
78
79 /** Defines the screen used to control app settings. */
NavGraphBuildernull80 fun NavGraphBuilder.settingsDestination() {
81 composable(NavRoute.SETTINGS) { SettingsScreen() }
82 }
83
84 /** Launch the audio routing dialog for the user. */
launchAudioRouteDialognull85 fun NavController.launchAudioRouteDialog() {
86 navigate(route = NavRoute.AUDIO_ROUTE_PICKER)
87 }
88
89 /** Launch the settings screen. */
NavControllernull90 fun NavController.moveToSettingsDestination() {
91 navigate(route = NavRoute.SETTINGS)
92 }
93