feat: improve multi-message copy formatting (#671)

* feat: improve multi-message copy formatting

* use date-first format and preserve blank line separator

Refs: #600
This commit is contained in:
Bram Hagens 2026-01-22 09:59:14 +01:00 committed by GitHub
parent 5adf13bc32
commit fffe72b367
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Made "Add number to contact" option visible for alphanumeric senders ([#232]) - Made "Add number to contact" option visible for alphanumeric senders ([#232])
- Improved multi-message copy formatting with timestamps and sender names
### Fixed ### Fixed
- Fixed missing notifications in some cases ([#159]) - Fixed missing notifications in some cases ([#159])

View file

@ -38,6 +38,7 @@ import org.fossify.commons.extensions.formatDateOrTime
import org.fossify.commons.extensions.getContrastColor import org.fossify.commons.extensions.getContrastColor
import org.fossify.commons.extensions.getProperPrimaryColor import org.fossify.commons.extensions.getProperPrimaryColor
import org.fossify.commons.extensions.getTextSize import org.fossify.commons.extensions.getTextSize
import org.fossify.commons.extensions.getTimeFormat
import org.fossify.commons.extensions.shareTextIntent import org.fossify.commons.extensions.shareTextIntent
import org.fossify.commons.extensions.showErrorToast import org.fossify.commons.extensions.showErrorToast
import org.fossify.commons.extensions.usableScreenSize import org.fossify.commons.extensions.usableScreenSize
@ -85,6 +86,7 @@ import org.fossify.messages.models.ThreadItem.ThreadDateTime
import org.fossify.messages.models.ThreadItem.ThreadError import org.fossify.messages.models.ThreadItem.ThreadError
import org.fossify.messages.models.ThreadItem.ThreadSending import org.fossify.messages.models.ThreadItem.ThreadSending
import org.fossify.messages.models.ThreadItem.ThreadSent import org.fossify.messages.models.ThreadItem.ThreadSent
import org.joda.time.DateTime
class ThreadAdapter( class ThreadAdapter(
activity: SimpleActivity, activity: SimpleActivity,
@ -220,9 +222,18 @@ class ThreadAdapter(
private fun copyToClipboard() { private fun copyToClipboard() {
val selectedMessages = getSelectedItems().filterIsInstance<Message>() val selectedMessages = getSelectedItems().filterIsInstance<Message>()
val textToCopy = selectedMessages if (selectedMessages.isEmpty()) return
.mapNotNull { message -> message.body.takeIf { it.isNotEmpty() } }
.joinToString("\n\n") val textToCopy = if (selectedMessages.size == 1) {
selectedMessages.first().body
} else {
selectedMessages.filter { it.body.isNotEmpty() }.joinToString("\n\n") { message ->
val format = "${activity.config.dateFormat}, ${activity.getTimeFormat()}"
val dateTime = DateTime(message.millis()).toString(format)
val sender = if (message.isReceivedMessage()) message.senderName else activity.getString(R.string.me)
"[$dateTime] $sender: ${message.body}"
}
}
if (textToCopy.isNotEmpty()) { if (textToCopy.isNotEmpty()) {
activity.copyToClipboard(textToCopy) activity.copyToClipboard(textToCopy)