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

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

@ -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)
if (value != null) {
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)
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)
}
}

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