1 /*
2 * Copyright (C) 2023 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 com.android.permissioncontroller.incident.wear
18
19 import android.app.Activity
20 import android.view.View
21 import androidx.compose.foundation.layout.Box
22 import androidx.compose.foundation.layout.fillMaxSize
23 import androidx.compose.runtime.Composable
24 import androidx.compose.runtime.getValue
25 import androidx.compose.runtime.livedata.observeAsState
26 import androidx.compose.runtime.mutableStateOf
27 import androidx.compose.runtime.saveable.rememberSaveable
28 import androidx.compose.runtime.setValue
29 import androidx.compose.ui.Alignment
30 import androidx.compose.ui.Modifier
31 import androidx.compose.ui.platform.ComposeView
32 import androidx.wear.compose.foundation.lazy.ScalingLazyListState
33 import androidx.wear.compose.material.CircularProgressIndicator
34 import com.android.permissioncontroller.permission.ui.wear.elements.AlertDialog
35 import com.android.permissioncontroller.permission.ui.wear.elements.SingleButtonAlertDialog
36 import com.android.permissioncontroller.permission.ui.wear.theme.WearPermissionTheme
37
38 @Composable
WearConfirmationScreennull39 fun WearConfirmationScreen(viewModel: WearConfirmationActivityViewModel) {
40 // Wear screen doesn't show incident/bug report's optional reasons and images.
41 val showDialog = viewModel.showDialogLiveData.observeAsState(false)
42 val showDenyReport = viewModel.showDenyReportLiveData.observeAsState(false)
43 val contentArgs = viewModel.contentArgsLiveData.observeAsState(null)
44 var isLoading by rememberSaveable { mutableStateOf(true) }
45
46 Box(modifier = Modifier.fillMaxSize()) {
47 if (isLoading) {
48 CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
49 } else {
50 if (showDenyReport.value) {
51 contentArgs.value?.let {
52 SingleButtonAlertDialog(
53 showDialog = showDialog.value,
54 title = it.title,
55 message = it.message,
56 onButtonClick = it.onDenyClick,
57 scalingLazyListState = ScalingLazyListState(0)
58 )
59 }
60 return
61 }
62 contentArgs.value?.let {
63 AlertDialog(
64 showDialog = showDialog.value,
65 title = it.title,
66 message = it.message,
67 onOKButtonClick = it.onOkClick,
68 onCancelButtonClick = it.onCancelClick,
69 scalingLazyListState = ScalingLazyListState(0)
70 )
71 }
72 }
73 }
74
75 if (isLoading && showDialog.value) {
76 isLoading = false
77 }
78 }
79
createViewnull80 fun createView(activity: Activity, viewModel: WearConfirmationActivityViewModel): View {
81 return ComposeView(activity).apply {
82 setContent { WearPermissionTheme { WearConfirmationScreen(viewModel) } }
83 }
84 }
85