From a0c257962e907fa050390e735c08080a74c723a9 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Wed, 15 May 2024 17:43:20 +0700 Subject: [PATCH] android, desktop: fix file menu and icon (#4185) * android, desktop: fix file menu and icon * simplify * space --- .../chat/simplex/common/model/ChatModel.kt | 6 +++++ .../common/views/chat/item/CIFileView.kt | 22 ++++++++++++++----- .../common/views/chat/item/ChatItemView.kt | 10 +++------ .../common/views/chat/item/FramedItemView.kt | 3 +-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index 3838cd45a6..441e8e0186 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -2653,6 +2653,12 @@ data class CIFile( return res } + fun forwardingAllowed(): Boolean = when { + chatModel.connectedToRemote() && cachedRemoteFileRequests[fileSource] != false && loaded -> true + getLoadedFilePath(this) != null -> true + else -> false + } + companion object { fun getSample( fileId: Long = 1, diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIFileView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIFileView.kt index 6ad75057f6..f079a152ab 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIFileView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIFileView.kt @@ -1,6 +1,7 @@ package chat.simplex.common.views.chat.item import androidx.compose.foundation.clickable +import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CornerSize import androidx.compose.foundation.shape.RoundedCornerShape @@ -28,6 +29,7 @@ import java.net.URI fun CIFileView( file: CIFile?, edited: Boolean, + showMenu: MutableState, receiveFile: (Long) -> Unit ) { val saveFileLauncher = rememberSaveFileLauncher(ciFile = file) @@ -86,7 +88,7 @@ fun CIFileView( ) FileProtocol.LOCAL -> {} } - file.fileStatus is CIFileStatus.RcvComplete || (file.fileStatus is CIFileStatus.SndStored && file.fileProtocol == FileProtocol.LOCAL) -> { + file.forwardingAllowed() -> { withLongRunningApi(slow = 600_000) { var filePath = getLoadedFilePath(file) if (chatModel.connectedToRemote() && filePath == null) { @@ -136,8 +138,7 @@ fun CIFileView( Box( Modifier .size(42.dp) - .clip(RoundedCornerShape(4.dp)) - .clickable(onClick = { fileAction() }), + .clip(RoundedCornerShape(4.dp)), contentAlignment = Alignment.Center ) { if (file != null) { @@ -154,7 +155,13 @@ fun CIFileView( FileProtocol.SMP -> progressIndicator() FileProtocol.LOCAL -> {} } - is CIFileStatus.SndComplete -> fileIcon(innerIcon = painterResource(MR.images.ic_check_filled)) + is CIFileStatus.SndComplete -> { + if ((file.forwardingAllowed() || (chatModel.connectedToRemote() && CIFile.cachedRemoteFileRequests[file.fileSource] == true))) { + fileIcon() + } else { + fileIcon(innerIcon = painterResource(MR.images.ic_check_filled)) + } + } is CIFileStatus.SndCancelled -> fileIcon(innerIcon = painterResource(MR.images.ic_close)) is CIFileStatus.SndError -> fileIcon(innerIcon = painterResource(MR.images.ic_close)) is CIFileStatus.RcvInvitation -> @@ -181,7 +188,12 @@ fun CIFileView( } Row( - Modifier.clickable(onClick = { fileAction() }).padding(top = 4.dp, bottom = 6.dp, start = 6.dp, end = 12.dp), + Modifier + .combinedClickable( + onClick = { fileAction() }, + onLongClick = { showMenu.value = true } + ) + .padding(top = 4.dp, bottom = 6.dp, start = 6.dp, end = 12.dp), //Modifier.clickable(enabled = file?.fileSource != null) { if (file?.fileSource != null && getLoadedFilePath(file) != null) openFile(file.fileSource) }.padding(top = 4.dp, bottom = 6.dp, start = 6.dp, end = 12.dp), verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.spacedBy(2.dp) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt index 10078dc266..8dc7f8bcea 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt @@ -204,14 +204,10 @@ fun ChatItemView( } val clipboard = LocalClipboardManager.current val cachedRemoteReqs = remember { CIFile.cachedRemoteFileRequests } - fun fileForwardingAllowed() = when { - cItem.file != null && chatModel.connectedToRemote() && cachedRemoteReqs[cItem.file.fileSource] != false && cItem.file.loaded -> true - getLoadedFilePath(cItem.file) != null -> true - else -> false - } + val copyAndShareAllowed = when { cItem.content.text.isNotEmpty() -> true - fileForwardingAllowed() -> true + cItem.file?.forwardingAllowed() == true -> true else -> false } @@ -261,7 +257,7 @@ fun ChatItemView( }) } if (cItem.meta.itemDeleted == null && - (cItem.file == null || fileForwardingAllowed()) && + (cItem.file == null || cItem.file.forwardingAllowed()) && !cItem.isLiveDummy && !live ) { ItemAction(stringResource(MR.strings.forward_chat_item), painterResource(MR.images.ic_forward), onClick = { diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt index 2ac97321c6..09cb1cfd23 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/FramedItemView.kt @@ -23,7 +23,6 @@ import chat.simplex.common.model.* import chat.simplex.common.platform.* import chat.simplex.common.ui.theme.* import chat.simplex.common.views.helpers.* -import chat.simplex.common.views.chat.MEMBER_IMAGE_SIZE import chat.simplex.res.MR import kotlin.math.min @@ -179,7 +178,7 @@ fun FramedItemView( @Composable fun ciFileView(ci: ChatItem, text: String) { - CIFileView(ci.file, ci.meta.itemEdited, receiveFile) + CIFileView(ci.file, ci.meta.itemEdited, showMenu, receiveFile) if (text != "" || ci.meta.isLive) { CIMarkdownText(ci, chatTTL, linkMode = linkMode, uriHandler) }