Comment: copy to clipboard (on long tap)

pull/3212/head
Anton Serebryakov 11 months ago
parent 084a66c630
commit ecb129d5d4

@ -111,6 +111,7 @@ import org.tasks.ui.TaskEditEvent
import org.tasks.ui.TaskEditEventBus import org.tasks.ui.TaskEditEventBus
import org.tasks.ui.TaskEditViewModel import org.tasks.ui.TaskEditViewModel
import org.tasks.ui.TaskEditViewModel.Companion.stripCarriageReturns import org.tasks.ui.TaskEditViewModel.Companion.stripCarriageReturns
import org.tasks.utility.copyToClipboard
import java.util.Locale import java.util.Locale
import javax.inject.Inject import javax.inject.Inject
@ -455,7 +456,7 @@ class TaskEditFragment : Fragment() {
} }
@Composable @Composable
fun CreationRow() { private fun CreationRow() {
InfoRow( InfoRow(
creationDate = editViewModel.creationDate, creationDate = editViewModel.creationDate,
modificationDate = editViewModel.modificationDate, modificationDate = editViewModel.modificationDate,
@ -465,12 +466,15 @@ class TaskEditFragment : Fragment() {
} }
@Composable @Composable
fun Comments() { private fun Comments() {
CommentsRow( CommentsRow(
comments = userActivityDao comments = userActivityDao
.watchComments(editViewModel.task.uuid) .watchComments(editViewModel.task.uuid)
.collectAsStateWithLifecycle(emptyList()) .collectAsStateWithLifecycle(emptyList())
.value, .value,
copyCommentToClipboard = {
copyToClipboard(requireContext(), R.string.comment, it)
},
deleteComment = { deleteComment = {
lifecycleScope.launch { lifecycleScope.launch {
userActivityDao.delete(it) userActivityDao.delete(it)

@ -2,6 +2,7 @@ package org.tasks.compose.edit
import android.net.Uri import android.net.Uri
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -14,6 +15,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.input.pointer.pointerInput
import coil.compose.AsyncImage import coil.compose.AsyncImage
import org.tasks.R import org.tasks.R
import org.tasks.compose.DeleteButton import org.tasks.compose.DeleteButton
@ -25,6 +27,7 @@ import org.tasks.kmp.org.tasks.time.getFullDateTime
@Composable @Composable
fun CommentsRow( fun CommentsRow(
comments: List<UserActivity>, comments: List<UserActivity>,
copyCommentToClipboard: (String) -> Unit,
deleteComment: (UserActivity) -> Unit, deleteComment: (UserActivity) -> Unit,
openImage: (Uri) -> Unit, openImage: (Uri) -> Unit,
) { ) {
@ -41,6 +44,7 @@ fun CommentsRow(
comments.forEach { comments.forEach {
Comment( Comment(
comment = it, comment = it,
copyCommentToClipboard = copyCommentToClipboard,
deleteComment = deleteComment, deleteComment = deleteComment,
openImage = openImage, openImage = openImage,
) )
@ -53,6 +57,7 @@ fun CommentsRow(
@Composable @Composable
fun Comment( fun Comment(
comment: UserActivity, comment: UserActivity,
copyCommentToClipboard: (String) -> Unit,
deleteComment: (UserActivity) -> Unit, deleteComment: (UserActivity) -> Unit,
openImage: (Uri) -> Unit, openImage: (Uri) -> Unit,
) { ) {
@ -60,7 +65,12 @@ fun Comment(
Column( Column(
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.padding(top = 8.dp), .padding(top = 8.dp)
.pointerInput(Unit) {
detectTapGestures(onLongPress = {
comment.message?.let(copyCommentToClipboard)
})
},
) { ) {
comment.message?.let { comment.message?.let {
// TODO: linkify text // TODO: linkify text

@ -1,16 +1,12 @@
package org.tasks.preferences.fragments package org.tasks.preferences.fragments
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.Toast.LENGTH_SHORT
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getSystemService
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
@ -36,6 +32,7 @@ import org.tasks.kmp.org.tasks.time.DateStyle
import org.tasks.kmp.org.tasks.time.getRelativeDay import org.tasks.kmp.org.tasks.time.getRelativeDay
import org.tasks.preferences.IconPreference import org.tasks.preferences.IconPreference
import org.tasks.preferences.fragments.MainSettingsFragment.Companion.REQUEST_TASKS_ORG import org.tasks.preferences.fragments.MainSettingsFragment.Companion.REQUEST_TASKS_ORG
import org.tasks.utility.copyToClipboard
import javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
@ -128,11 +125,10 @@ class TasksAccount : BaseAccountPreference() {
private fun setupTextField(v: View, layout: Int, labelRes: Int, value: String?) { private fun setupTextField(v: View, layout: Int, labelRes: Int, value: String?) {
with(v.findViewById<TextInputLayout>(layout)) { with(v.findViewById<TextInputLayout>(layout)) {
editText?.setText(value) editText?.setText(value)
setEndIconOnClickListener { if (value != null) {
val label = getString(labelRes) setEndIconOnClickListener {
getSystemService(requireContext(), ClipboardManager::class.java) copyToClipboard(requireContext(), labelRes, value)
?.setPrimaryClip(ClipData.newPlainText(label, value)) }
context?.toast(R.string.copied_to_clipboard, label, duration = LENGTH_SHORT)
} }
} }
} }

@ -0,0 +1,18 @@
package org.tasks.utility
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.widget.Toast.LENGTH_SHORT
import androidx.core.content.ContextCompat.getSystemService
import org.tasks.R
import org.tasks.extensions.Context.toast
fun copyToClipboard(context: Context, labelRes: Int, message: String) {
val clipboard = getSystemService(context, ClipboardManager::class.java)
if (clipboard != null) {
val label = context.getString(labelRes)
clipboard.setPrimaryClip(ClipData.newPlainText(label, message))
context.toast(R.string.copied_to_clipboard, label, duration = LENGTH_SHORT)
}
}

@ -263,6 +263,7 @@ File %1$s contained %2$s.\n\n
<string name="new_list">Create new list</string> <string name="new_list">Create new list</string>
<string name="delete_tag_confirmation">Delete %s?</string> <string name="delete_tag_confirmation">Delete %s?</string>
<string name="delete_comment">comment</string> <string name="delete_comment">comment</string>
<string name="comment">Comment</string>
<string name="TPl_notification">Timers Active for %s!</string> <string name="TPl_notification">Timers Active for %s!</string>
<string name="TEA_timer_controls">Timer</string> <string name="TEA_timer_controls">Timer</string>
<string name="TEA_timer_comment_started">started this task:</string> <string name="TEA_timer_comment_started">started this task:</string>

Loading…
Cancel
Save