From 0bcac273d509ee7ecd6f457c56d5aa8f91805de6 Mon Sep 17 00:00:00 2001 From: ghosti3 Date: Sun, 7 Apr 2024 15:01:23 +0300 Subject: [PATCH] Add ability to copy notes related to saving goals (#95) --- .../greenstash/ui/common/ExpandableCard.kt | 40 +++++++++++++++++++ .../info/composables/GoalInfoScreen.kt | 2 +- .../com/starry/greenstash/utils/Extensions.kt | 4 +- app/src/main/res/values-es/strings.xml | 3 ++ app/src/main/res/values-tr/strings.xml | 3 ++ app/src/main/res/values-zh-rCN/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 3 ++ 7 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/starry/greenstash/ui/common/ExpandableCard.kt b/app/src/main/java/com/starry/greenstash/ui/common/ExpandableCard.kt index 510d1d85..794fc617 100644 --- a/app/src/main/java/com/starry/greenstash/ui/common/ExpandableCard.kt +++ b/app/src/main/java/com/starry/greenstash/ui/common/ExpandableCard.kt @@ -25,21 +25,29 @@ package com.starry.greenstash.ui.common +import android.os.Build +import android.widget.Toast import androidx.compose.animation.animateContentSize import androidx.compose.animation.core.LinearOutSlowInEasing import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowDropDown +import androidx.compose.material.icons.filled.ContentCopy +import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.FilledTonalButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme @@ -54,12 +62,19 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.Shape +import androidx.compose.ui.platform.LocalClipboardManager +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.core.content.ContextCompat.getString +import com.starry.greenstash.R +import com.starry.greenstash.utils.toToast @ExperimentalMaterial3Api @Composable @@ -147,8 +162,12 @@ fun ExpandableTextCard( descriptionFontWeight: FontWeight = FontWeight.Normal, descriptionMaxLines: Int = 10, shape: Shape = RoundedCornerShape(8.dp), + showCopyButton: Boolean = false, padding: Dp = 12.dp, ) { + val context = LocalContext.current + val clipboardManager = LocalClipboardManager.current + ExpandableCard( title = title, titleFontSize = titleFontSize, @@ -164,5 +183,26 @@ fun ExpandableTextCard( overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(start = 12.dp, end = 12.dp) ) + if (showCopyButton) { + FilledTonalButton( + onClick = { + clipboardManager.setText(AnnotatedString(description)) + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) { + getString(context, R.string.info_copy_alert).toToast(context) + } + }, + modifier = Modifier.padding(start = 8.dp, top = 8.dp) + ) { + Row { + Icon( + Icons.Filled.ContentCopy, + contentDescription = stringResource(R.string.info_copy_icon_description), + modifier = Modifier.size(ButtonDefaults.IconSize) + ) + Spacer(Modifier.width(ButtonDefaults.IconSpacing)) + Text(text = stringResource(id = R.string.info_copy_button)) + } + } + } } } diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/info/composables/GoalInfoScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/info/composables/GoalInfoScreen.kt index 1dc29125..3498ba7f 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/info/composables/GoalInfoScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/info/composables/GoalInfoScreen.kt @@ -399,7 +399,7 @@ fun GoalPriorityCard(goalPriority: GoalPriority, reminders: Boolean) { @Composable fun GoalNotesCard(notesText: String) { ExpandableTextCard( - title = stringResource(id = R.string.info_notes_card_title), description = notesText + title = stringResource(id = R.string.info_notes_card_title), description = notesText, showCopyButton = true ) } diff --git a/app/src/main/java/com/starry/greenstash/utils/Extensions.kt b/app/src/main/java/com/starry/greenstash/utils/Extensions.kt index b34878a8..7311b9a3 100644 --- a/app/src/main/java/com/starry/greenstash/utils/Extensions.kt +++ b/app/src/main/java/com/starry/greenstash/utils/Extensions.kt @@ -76,7 +76,9 @@ fun LazyListState.isScrollingUp(): Boolean { }.value } - +/** + * Creates and shows a toast message. + */ fun String.toToast(context: Context, length: Int = Toast.LENGTH_SHORT) { Toast.makeText(context, this, length).show() } diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 259dd3f8..d06c0915 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -92,6 +92,9 @@ Sin transacciones aún. Actualizar Transacción Consejo: Desliza las transacciones hacia la izquierda o hacia la derecha para editarlas o eliminarlas. + Copy + Copy Notes + Copied ¡Es momento de ahorrar! diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 527ddcab..81e46536 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -92,6 +92,9 @@ Henüz İşlem Yok. İşlemi Güncelle İpucu: İşlemleri düzenlemek veya silmek için sola veya sağa kaydırın. + Copy + Copy Notes + Copied Birikim yapma zamanı! diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 2abab73c..6e395365 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -92,6 +92,9 @@ 尚无收支。 更新交易 提示:左右滑动交易以编辑或删除它们。 + Copy + Copy Notes + Copied 省钱时间到! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e15bafcf..d493b06e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -92,6 +92,9 @@ No Transactions Yet. Update Transaction Tip: Swipe transactions left or right to edit or delete them. + Copy + Copy Notes + Copied Successfully! It\'s time to save!