From a1584a047e66b371e7f14e06e50cd0e304cd459a Mon Sep 17 00:00:00 2001 From: ialokim <ialokim@mailbox.org> Date: Fri, 4 Feb 2022 19:39:53 +0100 Subject: [PATCH] allow to select and copy (parts of) messages --- .../conversation/ConversationMessageItemView.kt | 15 +++++++++------ .../conversation/ConversationNoticeItemView.kt | 15 +++++++++------ .../conversation/ConversationRequestItemView.kt | 15 +++++++++------ .../briarproject/briar/desktop/theme/Theme.kt | 17 +++++++++++++---- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt index 1bb873d71e..6d7ad7f27d 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationMessageItemView.kt @@ -21,6 +21,7 @@ package org.briarproject.briar.desktop.conversation import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -78,12 +79,14 @@ fun ConversationMessageItemView( } } if (m.text != null) { - Text( - m.text!!, - fontSize = 16.sp, - color = textColor, - modifier = Modifier.align(Alignment.Start).padding(bottom = 8.dp) - ) + SelectionContainer { + Text( + m.text!!, + fontSize = 16.sp, + color = textColor, + modifier = Modifier.align(Alignment.Start).padding(bottom = 8.dp) + ) + } } ConversationItemStatusView(m) } diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt index 9ab2ebac87..f6ef3e063d 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationNoticeItemView.kt @@ -24,6 +24,7 @@ import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width +import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -84,12 +85,14 @@ fun ConversationNoticeItemView( ConversationItemView(m, onDelete) { Column(Modifier.width(IntrinsicSize.Max)) { if (text != null) { - Text( - text, - fontSize = 16.sp, - color = textColor, - modifier = Modifier.padding(12.dp, 8.dp).align(Alignment.Start) - ) + SelectionContainer { + Text( + text, + fontSize = 16.sp, + color = textColor, + modifier = Modifier.padding(12.dp, 8.dp).align(Alignment.Start) + ) + } } Column( Modifier.fillMaxWidth().background(noticeBackground).padding(12.dp, 8.dp) diff --git a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt index 00e448f28c..1705fd12f9 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationRequestItemView.kt @@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width +import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.ButtonType.DESTRUCTIVE import androidx.compose.material.ButtonType.NEUTRAL import androidx.compose.material.DialogButton @@ -102,12 +103,14 @@ fun ConversationRequestItemView( Column(Modifier.width(IntrinsicSize.Max)) { val text = m.text if (text != null) { - Text( - text, - fontSize = 16.sp, - color = textColor, - modifier = Modifier.padding(12.dp, 8.dp).align(Alignment.Start) - ) + SelectionContainer { + Text( + text, + fontSize = 16.sp, + color = textColor, + modifier = Modifier.padding(12.dp, 8.dp).align(Alignment.Start) + ) + } } Column( Modifier.fillMaxWidth().background(noticeBackground).padding(12.dp, 8.dp) diff --git a/src/main/kotlin/org/briarproject/briar/desktop/theme/Theme.kt b/src/main/kotlin/org/briarproject/briar/desktop/theme/Theme.kt index 1f2f74cfef..eb11d0c35f 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/theme/Theme.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/theme/Theme.kt @@ -19,11 +19,14 @@ package org.briarproject.briar.desktop.theme import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.text.selection.LocalTextSelectionColors +import androidx.compose.foundation.text.selection.TextSelectionColors import androidx.compose.material.Colors import androidx.compose.material.MaterialTheme import androidx.compose.material.darkColors import androidx.compose.material.lightColors import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.graphics.Color val Colors.divider: Color get() = if (isLight) Gray300 else Gray800 @@ -77,8 +80,14 @@ fun BriarTheme( ) { val myColors = colors ?: if (isDarkTheme) DarkColors else LightColors - MaterialTheme( - colors = myColors, - content = content, - ) + MaterialTheme(myColors) { + val customTextSelectionColors = TextSelectionColors( + handleColor = MaterialTheme.colors.secondary, + backgroundColor = MaterialTheme.colors.secondary.copy(alpha = 0.4f) + ) + + CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) { + content() + } + } } -- GitLab