|
| 1 | +/* |
| 2 | + * Nextcloud Talk - Android Client |
| 3 | + * |
| 4 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 5 | + * SPDX-License-Identifier: GPL-3.0-or-later |
| 6 | + */ |
| 7 | + |
| 8 | +package com.nextcloud.talk.ui |
| 9 | + |
| 10 | +import androidx.compose.foundation.BorderStroke |
| 11 | +import androidx.compose.foundation.layout.Box |
| 12 | +import androidx.compose.foundation.layout.Column |
| 13 | +import androidx.compose.foundation.layout.Row |
| 14 | +import androidx.compose.foundation.layout.Spacer |
| 15 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 16 | +import androidx.compose.foundation.layout.padding |
| 17 | +import androidx.compose.foundation.layout.size |
| 18 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 19 | +import androidx.compose.material3.Card |
| 20 | +import androidx.compose.material3.CardDefaults |
| 21 | +import androidx.compose.material3.DropdownMenu |
| 22 | +import androidx.compose.material3.DropdownMenuItem |
| 23 | +import androidx.compose.material3.Icon |
| 24 | +import androidx.compose.material3.IconButton |
| 25 | +import androidx.compose.material3.MaterialTheme |
| 26 | +import androidx.compose.material3.Text |
| 27 | +import androidx.compose.runtime.Composable |
| 28 | +import androidx.compose.runtime.getValue |
| 29 | +import androidx.compose.runtime.mutableStateOf |
| 30 | +import androidx.compose.runtime.remember |
| 31 | +import androidx.compose.runtime.setValue |
| 32 | +import androidx.compose.ui.Modifier |
| 33 | +import androidx.compose.ui.graphics.vector.ImageVector |
| 34 | +import androidx.compose.ui.platform.LocalContext |
| 35 | +import androidx.compose.ui.res.pluralStringResource |
| 36 | +import androidx.compose.ui.res.stringResource |
| 37 | +import androidx.compose.ui.res.vectorResource |
| 38 | +import androidx.compose.ui.tooling.preview.Preview |
| 39 | +import androidx.compose.ui.unit.dp |
| 40 | +import com.nextcloud.talk.R |
| 41 | +import com.nextcloud.talk.ui.theme.ViewThemeUtils |
| 42 | +import com.nextcloud.talk.utils.preview.ComposePreviewUtils |
| 43 | + |
| 44 | +@Composable |
| 45 | +fun ConversationDeleteNoticeView( |
| 46 | + data: ConversationDeleteNoticeViewData, |
| 47 | + viewThemeUtils: ViewThemeUtils, |
| 48 | + onDeleteNow: () -> Unit, |
| 49 | + onKeep: () -> Unit, |
| 50 | + onDismiss: () -> Unit |
| 51 | +) { |
| 52 | + val context = LocalContext.current |
| 53 | + val colorScheme = remember { viewThemeUtils.getColorScheme(context) } |
| 54 | + Card( |
| 55 | + modifier = Modifier.fillMaxWidth(), |
| 56 | + shape = RoundedCornerShape(4.dp), |
| 57 | + colors = CardDefaults.cardColors(containerColor = colorScheme.surface), |
| 58 | + border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant) |
| 59 | + ) { |
| 60 | + Row(modifier = Modifier.padding(start = 8.dp, end = 0.dp)) { |
| 61 | + Icon( |
| 62 | + imageVector = ImageVector.vectorResource(R.drawable.baseline_info_24), |
| 63 | + contentDescription = null, |
| 64 | + modifier = Modifier |
| 65 | + .padding(top = 8.dp) |
| 66 | + .size(24.dp) |
| 67 | + ) |
| 68 | + Spacer(modifier = Modifier.size(8.dp)) |
| 69 | + Column( |
| 70 | + modifier = Modifier |
| 71 | + .weight(1f) |
| 72 | + .padding(top = 8.dp, bottom = 8.dp) |
| 73 | + ) { |
| 74 | + Text( |
| 75 | + text = pluralStringResource( |
| 76 | + R.plurals.nc_conversation_auto_delete_info, |
| 77 | + data.retentionDays, |
| 78 | + data.retentionDays |
| 79 | + ), |
| 80 | + style = MaterialTheme.typography.bodyMedium |
| 81 | + ) |
| 82 | + } |
| 83 | + ConversationDeleteNoticeActions( |
| 84 | + isModeratorOrOwner = data.isModeratorOrOwner, |
| 85 | + onDeleteNow = onDeleteNow, |
| 86 | + onKeep = onKeep, |
| 87 | + onDismiss = onDismiss |
| 88 | + ) |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +@Composable |
| 94 | +private fun ConversationDeleteNoticeActions( |
| 95 | + isModeratorOrOwner: Boolean, |
| 96 | + onDeleteNow: () -> Unit, |
| 97 | + onKeep: () -> Unit, |
| 98 | + onDismiss: () -> Unit |
| 99 | +) { |
| 100 | + var expanded by remember { mutableStateOf(false) } |
| 101 | + Column { |
| 102 | + if (isModeratorOrOwner) { |
| 103 | + Box { |
| 104 | + IconButton(onClick = { expanded = true }) { |
| 105 | + Icon( |
| 106 | + imageVector = ImageVector.vectorResource(R.drawable.ic_more_vert_24px), |
| 107 | + contentDescription = null |
| 108 | + ) |
| 109 | + } |
| 110 | + DropdownMenu( |
| 111 | + expanded = expanded, |
| 112 | + onDismissRequest = { expanded = false } |
| 113 | + ) { |
| 114 | + DropdownMenuItem( |
| 115 | + text = { Text(stringResource(R.string.nc_delete_now)) }, |
| 116 | + onClick = { |
| 117 | + expanded = false |
| 118 | + onDeleteNow() |
| 119 | + } |
| 120 | + ) |
| 121 | + DropdownMenuItem( |
| 122 | + text = { |
| 123 | + Text(stringResource(R.string.nc_keep)) |
| 124 | + }, |
| 125 | + onClick = { |
| 126 | + expanded = false |
| 127 | + onKeep() |
| 128 | + } |
| 129 | + ) |
| 130 | + } |
| 131 | + } |
| 132 | + } else { |
| 133 | + IconButton(onClick = onDismiss) { |
| 134 | + Icon( |
| 135 | + imageVector = ImageVector.vectorResource(R.drawable.ic_baseline_close_24), |
| 136 | + contentDescription = stringResource(R.string.nc_common_dismiss) |
| 137 | + ) |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +data class ConversationDeleteNoticeViewData(val retentionDays: Int, val isModeratorOrOwner: Boolean) |
| 144 | + |
| 145 | +@Preview(name = "Dark Mode", uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES) |
| 146 | +@Composable |
| 147 | +fun ConversationDeleteNoticePreviewDark() { |
| 148 | + ConversationDeleteNoticePreview() |
| 149 | +} |
| 150 | + |
| 151 | +@Preview(name = "R-t-L", locale = "ar") |
| 152 | +@Composable |
| 153 | +fun ConversationDeleteNoticePreviewRtl() { |
| 154 | + ConversationDeleteNoticePreview() |
| 155 | +} |
| 156 | + |
| 157 | +@Preview(name = "Light Mode / Read-only") |
| 158 | +@Composable |
| 159 | +fun ConversationDeleteNoticePreviewReadOnly() { |
| 160 | + ConversationDeleteNoticePreview(isModeratorOrOwner = false) |
| 161 | +} |
| 162 | + |
| 163 | +@Preview(name = "Dark Mode / Read-only", uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES) |
| 164 | +@Composable |
| 165 | +fun ConversationDeleteNoticePreviewDarkReadOnly() { |
| 166 | + ConversationDeleteNoticePreview(isModeratorOrOwner = false) |
| 167 | +} |
| 168 | + |
| 169 | +@Preview(name = "R-t-L / Read-only", locale = "ar") |
| 170 | +@Composable |
| 171 | +fun ConversationDeleteNoticePreviewRtlReadOnly() { |
| 172 | + ConversationDeleteNoticePreview(isModeratorOrOwner = false) |
| 173 | +} |
| 174 | + |
| 175 | +@Suppress("MagicNumber") |
| 176 | +@Preview(name = "Light Mode") |
| 177 | +@Composable |
| 178 | +fun ConversationDeleteNoticePreview(retentionDays: Int = 7, isModeratorOrOwner: Boolean = true) { |
| 179 | + val context = LocalContext.current |
| 180 | + val previewUtils = ComposePreviewUtils.getInstance(context) |
| 181 | + val viewThemeUtils = previewUtils.viewThemeUtils |
| 182 | + val colorScheme = viewThemeUtils.getColorScheme(context) |
| 183 | + |
| 184 | + MaterialTheme(colorScheme = colorScheme) { |
| 185 | + ConversationDeleteNoticeView( |
| 186 | + data = ConversationDeleteNoticeViewData( |
| 187 | + retentionDays = retentionDays, |
| 188 | + isModeratorOrOwner = isModeratorOrOwner |
| 189 | + ), |
| 190 | + viewThemeUtils = viewThemeUtils, |
| 191 | + onDeleteNow = {}, |
| 192 | + onKeep = {}, |
| 193 | + onDismiss = {} |
| 194 | + ) |
| 195 | + } |
| 196 | +} |
0 commit comments