Merge branch 'TonSilver-develop'

pull/3224/head
Alex Baker 11 months ago
commit d09e013ac0

@ -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
@ -12,6 +13,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
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 coil.compose.AsyncImage import coil.compose.AsyncImage
@ -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

@ -33,6 +33,7 @@ import org.tasks.extensions.Context.findActivity
import org.tasks.files.FileHelper import org.tasks.files.FileHelper
import org.tasks.themes.TasksTheme import org.tasks.themes.TasksTheme
import org.tasks.ui.TaskEditViewModel import org.tasks.ui.TaskEditViewModel
import org.tasks.utility.copyToClipboard
@OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class) @OptIn(ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class)
@Composable @Composable
@ -113,6 +114,9 @@ fun TaskEditScreen(
val context = LocalContext.current val context = LocalContext.current
CommentsRow( CommentsRow(
comments = comments, comments = comments,
copyCommentToClipboard = {
copyToClipboard(context, R.string.comment, it)
},
deleteComment = deleteComment, deleteComment = deleteComment,
openImage = { openImage = {
val activity = context.findActivity() ?: return@CommentsRow val activity = context.findActivity() ?: return@CommentsRow

@ -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)
}
}

@ -262,6 +262,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