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 com.android.photopicker.features.preview
18
19 import androidx.compose.foundation.layout.Column
20 import androidx.compose.foundation.layout.Spacer
21 import androidx.compose.foundation.layout.height
22 import androidx.compose.foundation.layout.padding
23 import androidx.compose.foundation.layout.wrapContentHeight
24 import androidx.compose.foundation.layout.wrapContentWidth
25 import androidx.compose.material3.AlertDialogDefaults
26 import androidx.compose.material3.BasicAlertDialog
27 import androidx.compose.material3.ExperimentalMaterial3Api
28 import androidx.compose.material3.MaterialTheme
29 import androidx.compose.material3.Surface
30 import androidx.compose.material3.Text
31 import androidx.compose.material3.TextButton
32 import androidx.compose.runtime.Composable
33 import androidx.compose.runtime.getValue
34 import androidx.compose.runtime.setValue
35 import androidx.compose.ui.Alignment
36 import androidx.compose.ui.Modifier
37 import androidx.compose.ui.res.stringResource
38 import androidx.compose.ui.unit.dp
39 import com.android.photopicker.R
40
41 /* Size of the spacer between dialog elements. */
42 private val MEASUREMENT_ERROR_DIALOG_SPACER_SIZE = 24.dp
43
44 /* Size of the padding around the edge of the dialog. */
45 private val MEASUREMENT_ERROR_DIALOG_PADDING = 16.dp
46
47 /**
48 * Creates an error dialog for the ERROR_RETRIABLE_FAILURE error state. This error state is reached
49 * when the remote preview provider is unable to play the video (most likely related to a connection
50 * issue), but the user can attempt to play the video again.
51 *
52 * @param onDismissRequest Action to take when the dialog is dismissed, most likely via a back
53 * navigation, or by clicking outside of the dialog.
54 * @param onRetry Action to take when the user clicks the "Retry" button on the dialog.
55 */
56 @OptIn(ExperimentalMaterial3Api::class)
57 @Composable
RetriableErrorDialognull58 fun RetriableErrorDialog(
59 onDismissRequest: () -> Unit,
60 onRetry: () -> Unit,
61 ) {
62 BasicAlertDialog(
63 onDismissRequest = onDismissRequest,
64 ) {
65 Surface(
66 modifier = Modifier.wrapContentWidth().wrapContentHeight(),
67 shape = MaterialTheme.shapes.large,
68 tonalElevation = AlertDialogDefaults.TonalElevation
69 ) {
70 Column(modifier = Modifier.padding(MEASUREMENT_ERROR_DIALOG_PADDING)) {
71 Text(
72 stringResource(R.string.photopicker_preview_dialog_error_title),
73 style = MaterialTheme.typography.titleLarge
74 )
75 Spacer(modifier = Modifier.height(MEASUREMENT_ERROR_DIALOG_SPACER_SIZE))
76 Text(
77 stringResource(R.string.photopicker_preview_dialog_error_message),
78 style = MaterialTheme.typography.bodyMedium
79 )
80 Spacer(modifier = Modifier.height(MEASUREMENT_ERROR_DIALOG_SPACER_SIZE))
81 TextButton(
82 modifier = Modifier.align(Alignment.End),
83 onClick = onRetry,
84 ) {
85 Text(
86 stringResource(R.string.photopicker_preview_dialog_error_retry_button_label)
87 )
88 }
89 }
90 }
91 }
92 }
93