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

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

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

@ -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="delete_tag_confirmation">Delete %s?</string>
<string name="delete_comment">comment</string>
<string name="comment">Comment</string>
<string name="TPl_notification">Timers Active for %s!</string>
<string name="TEA_timer_controls">Timer</string>
<string name="TEA_timer_comment_started">started this task:</string>

Loading…
Cancel
Save