Skip to content

Commit

Permalink
Add ability to copy notes related to saving goals (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrghosti3 authored Apr 7, 2024
1 parent 823c0e1 commit 0bcac27
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/starry/greenstash/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<string name="info_goal_no_transactions">Sin transacciones aún.</string>
<string name="info_edit_transaction_button">Actualizar Transacción</string>
<string name="info_transaction_onboarding_tip">Consejo: Desliza las transacciones hacia la izquierda o hacia la derecha para editarlas o eliminarlas.</string>
<string name="info_copy_button">Copy</string>
<string name="info_copy_icon_description">Copy Notes</string>
<string name="info_copy_alert">Copied</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">¡Es momento de ahorrar!</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<string name="info_goal_no_transactions">Henüz İşlem Yok.</string>
<string name="info_edit_transaction_button">İşlemi Güncelle</string>
<string name="info_transaction_onboarding_tip">İpucu: İşlemleri düzenlemek veya silmek için sola veya sağa kaydırın.</string>
<string name="info_copy_button">Copy</string>
<string name="info_copy_icon_description">Copy Notes</string>
<string name="info_copy_alert">Copied</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">Birikim yapma zamanı!</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<string name="info_goal_no_transactions">尚无收支。</string>
<string name="info_edit_transaction_button">更新交易</string>
<string name="info_transaction_onboarding_tip">提示:左右滑动交易以编辑或删除它们。</string>
<string name="info_copy_button">Copy</string>
<string name="info_copy_icon_description">Copy Notes</string>
<string name="info_copy_alert">Copied</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">省钱时间到!</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<string name="info_goal_no_transactions">No Transactions Yet.</string>
<string name="info_edit_transaction_button">Update Transaction</string>
<string name="info_transaction_onboarding_tip">Tip: Swipe transactions left or right to edit or delete them.</string>
<string name="info_copy_button">Copy</string>
<string name="info_copy_icon_description">Copy Notes</string>
<string name="info_copy_alert">Copied Successfully!</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">It\'s time to save!</string>
Expand Down

0 comments on commit 0bcac27

Please sign in to comment.