|
| 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.conversationlist.ui |
| 9 | + |
| 10 | +import android.content.res.Configuration |
| 11 | +import androidx.compose.foundation.isSystemInDarkTheme |
| 12 | +import androidx.compose.foundation.layout.Column |
| 13 | +import androidx.compose.foundation.layout.PaddingValues |
| 14 | +import androidx.compose.foundation.layout.Spacer |
| 15 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 16 | +import androidx.compose.foundation.layout.height |
| 17 | +import androidx.compose.foundation.layout.navigationBarsPadding |
| 18 | +import androidx.compose.foundation.layout.padding |
| 19 | +import androidx.compose.foundation.layout.width |
| 20 | +import androidx.compose.foundation.rememberScrollState |
| 21 | +import androidx.compose.foundation.verticalScroll |
| 22 | +import androidx.compose.material.icons.Icons |
| 23 | +import androidx.compose.material.icons.automirrored.outlined.Label |
| 24 | +import androidx.compose.material.icons.outlined.Settings |
| 25 | +import androidx.compose.material3.ButtonDefaults |
| 26 | +import androidx.compose.material3.Checkbox |
| 27 | +import androidx.compose.material3.Icon |
| 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.material3.darkColorScheme |
| 33 | +import androidx.compose.material3.lightColorScheme |
| 34 | +import androidx.compose.runtime.Composable |
| 35 | +import androidx.compose.ui.Modifier |
| 36 | +import androidx.compose.ui.graphics.RectangleShape |
| 37 | +import androidx.compose.ui.res.dimensionResource |
| 38 | +import androidx.compose.ui.res.stringResource |
| 39 | +import androidx.compose.ui.text.style.TextAlign |
| 40 | +import androidx.compose.ui.tooling.preview.Preview |
| 41 | +import com.nextcloud.talk.R |
| 42 | +import com.nextcloud.talk.models.domain.ConversationModel |
| 43 | +import com.nextcloud.talk.models.json.conversations.ConversationEnums |
| 44 | +import com.nextcloud.talk.models.json.participants.Participant |
| 45 | +import com.nextcloud.talk.models.json.tags.ConversationTag |
| 46 | + |
| 47 | +@Composable |
| 48 | +fun AssignConversationTagsSheetContent( |
| 49 | + conversation: ConversationModel, |
| 50 | + tags: List<ConversationTag>, |
| 51 | + onToggleTag: (String) -> Unit, |
| 52 | + onManageTagsClick: () -> Unit |
| 53 | +) { |
| 54 | + val headerText = conversation.displayName.takeIf { it.isNotEmpty() } ?: conversation.name |
| 55 | + Column( |
| 56 | + modifier = Modifier |
| 57 | + .fillMaxWidth() |
| 58 | + .verticalScroll(rememberScrollState()) |
| 59 | + .navigationBarsPadding() |
| 60 | + ) { |
| 61 | + Text( |
| 62 | + text = headerText, |
| 63 | + modifier = Modifier |
| 64 | + .fillMaxWidth() |
| 65 | + .padding( |
| 66 | + horizontal = dimensionResource(R.dimen.standard_dialog_padding), |
| 67 | + vertical = dimensionResource(R.dimen.standard_half_padding) |
| 68 | + ), |
| 69 | + style = MaterialTheme.typography.titleLarge, |
| 70 | + color = MaterialTheme.colorScheme.onSurface |
| 71 | + ) |
| 72 | + if (tags.isEmpty()) { |
| 73 | + Text( |
| 74 | + text = stringResource(R.string.nc_conversation_tags_empty), |
| 75 | + modifier = Modifier |
| 76 | + .fillMaxWidth() |
| 77 | + .padding( |
| 78 | + horizontal = dimensionResource(R.dimen.standard_dialog_padding), |
| 79 | + vertical = dimensionResource(R.dimen.standard_half_padding) |
| 80 | + ), |
| 81 | + style = MaterialTheme.typography.bodyMedium, |
| 82 | + color = MaterialTheme.colorScheme.onSurfaceVariant |
| 83 | + ) |
| 84 | + } else { |
| 85 | + tags.forEach { tag -> |
| 86 | + AssignableTagRow( |
| 87 | + tag = tag, |
| 88 | + isAssigned = conversation.tagIds.contains(tag.id), |
| 89 | + onToggleTag = onToggleTag |
| 90 | + ) |
| 91 | + } |
| 92 | + } |
| 93 | + ManageTagsRow(onManageTagsClick) |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +@Composable |
| 98 | +private fun AssignableTagRow(tag: ConversationTag, isAssigned: Boolean, onToggleTag: (String) -> Unit) { |
| 99 | + TextButton( |
| 100 | + onClick = { onToggleTag(tag.id) }, |
| 101 | + modifier = Modifier |
| 102 | + .fillMaxWidth() |
| 103 | + .height(dimensionResource(R.dimen.bottom_sheet_item_height)), |
| 104 | + shape = RectangleShape, |
| 105 | + contentPadding = PaddingValues(horizontal = dimensionResource(R.dimen.standard_dialog_padding)), |
| 106 | + colors = ButtonDefaults.textButtonColors(contentColor = MaterialTheme.colorScheme.onSurface) |
| 107 | + ) { |
| 108 | + Icon( |
| 109 | + imageVector = Icons.AutoMirrored.Outlined.Label, |
| 110 | + contentDescription = null, |
| 111 | + tint = MaterialTheme.colorScheme.onSurfaceVariant |
| 112 | + ) |
| 113 | + Spacer(modifier = Modifier.width(dimensionResource(R.dimen.standard_dialog_padding))) |
| 114 | + Text( |
| 115 | + text = tag.name, |
| 116 | + modifier = Modifier.weight(1f), |
| 117 | + style = MaterialTheme.typography.bodyLarge, |
| 118 | + textAlign = TextAlign.Start |
| 119 | + ) |
| 120 | + Checkbox(checked = isAssigned, onCheckedChange = { onToggleTag(tag.id) }) |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +@Composable |
| 125 | +private fun ManageTagsRow(onManageTagsClick: () -> Unit) { |
| 126 | + TextButton( |
| 127 | + onClick = onManageTagsClick, |
| 128 | + modifier = Modifier |
| 129 | + .fillMaxWidth() |
| 130 | + .height(dimensionResource(R.dimen.bottom_sheet_item_height)), |
| 131 | + shape = RectangleShape, |
| 132 | + contentPadding = PaddingValues(horizontal = dimensionResource(R.dimen.standard_dialog_padding)), |
| 133 | + colors = ButtonDefaults.textButtonColors(contentColor = MaterialTheme.colorScheme.onSurface) |
| 134 | + ) { |
| 135 | + Icon( |
| 136 | + imageVector = Icons.Outlined.Settings, |
| 137 | + contentDescription = null, |
| 138 | + tint = MaterialTheme.colorScheme.onSurfaceVariant |
| 139 | + ) |
| 140 | + Spacer(modifier = Modifier.width(dimensionResource(R.dimen.standard_dialog_padding))) |
| 141 | + Text( |
| 142 | + text = stringResource(R.string.nc_conversation_tags_manage), |
| 143 | + modifier = Modifier.weight(1f), |
| 144 | + style = MaterialTheme.typography.bodyLarge, |
| 145 | + textAlign = TextAlign.Start |
| 146 | + ) |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +private fun previewConversation() = |
| 151 | + ConversationModel( |
| 152 | + internalId = "1@tok", |
| 153 | + accountId = 1L, |
| 154 | + token = "tok", |
| 155 | + name = "alice", |
| 156 | + displayName = "Alice", |
| 157 | + description = "", |
| 158 | + type = ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL, |
| 159 | + participantType = Participant.ParticipantType.USER, |
| 160 | + sessionId = "", |
| 161 | + actorId = "user1", |
| 162 | + actorType = "users", |
| 163 | + objectType = ConversationEnums.ObjectType.DEFAULT, |
| 164 | + notificationLevel = ConversationEnums.NotificationLevel.DEFAULT, |
| 165 | + conversationReadOnlyState = ConversationEnums.ConversationReadOnlyState.CONVERSATION_READ_WRITE, |
| 166 | + lobbyState = ConversationEnums.LobbyState.LOBBY_STATE_ALL_PARTICIPANTS, |
| 167 | + lobbyTimer = 0L, |
| 168 | + canLeaveConversation = true, |
| 169 | + canDeleteConversation = true, |
| 170 | + unreadMentionDirect = false, |
| 171 | + notificationCalls = 0, |
| 172 | + avatarVersion = "", |
| 173 | + hasCustomAvatar = false, |
| 174 | + callStartTime = 0L, |
| 175 | + tagIds = listOf("2") |
| 176 | + ) |
| 177 | + |
| 178 | +private fun previewTags() = |
| 179 | + listOf( |
| 180 | + ConversationTag(id = "1", name = "Work", sortOrder = 0), |
| 181 | + ConversationTag(id = "2", name = "Family", sortOrder = 1) |
| 182 | + ) |
| 183 | + |
| 184 | +@Preview(showBackground = true, name = "Light") |
| 185 | +@Preview(showBackground = true, name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES) |
| 186 | +@Composable |
| 187 | +private fun AssignConversationTagsSheetPreview() { |
| 188 | + val colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme() |
| 189 | + MaterialTheme(colorScheme = colorScheme) { |
| 190 | + Surface(color = MaterialTheme.colorScheme.surfaceContainerLow) { |
| 191 | + AssignConversationTagsSheetContent( |
| 192 | + conversation = previewConversation(), |
| 193 | + tags = previewTags(), |
| 194 | + onToggleTag = {}, |
| 195 | + onManageTagsClick = {} |
| 196 | + ) |
| 197 | + } |
| 198 | + } |
| 199 | +} |
0 commit comments