Skip to content

Commit

Permalink
Add 'Copy Link' option to article list menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Jan 16, 2025
1 parent 28469b5 commit 260a9b7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.capyreader.app.ui.articles.list

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ContentCopy
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
Expand All @@ -11,16 +13,17 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import com.jocmp.capy.MarkRead
import com.jocmp.capy.MarkRead.After
import com.jocmp.capy.MarkRead.Before
import com.capyreader.app.R
import com.capyreader.app.ui.articles.LocalArticleActions
import com.capyreader.app.ui.components.ArticleAction
import com.capyreader.app.ui.components.buildCopyToClipboard
import com.capyreader.app.ui.components.readAction
import com.capyreader.app.ui.components.starAction
import com.capyreader.app.ui.fixtures.ArticleSample
import com.jocmp.capy.Article
import com.jocmp.capy.MarkRead
import com.jocmp.capy.MarkRead.After
import com.jocmp.capy.MarkRead.Before

@Composable
fun ArticleActionMenu(
Expand Down Expand Up @@ -56,9 +59,31 @@ fun ArticleActionMenu(
text = { Text(stringResource(R.string.article_actions_mark_below_as_read)) },
onClick = { onMarkAllRead(Before(article.id)) },
)
CopyLinkMenuItem(onDismissRequest, article)
}
}

@Composable
private fun CopyLinkMenuItem(onDismissRequest: () -> Unit, article: Article) {
val url = article.url?.toString() ?: return

val copyToClipboard = buildCopyToClipboard(url)

DropdownMenuItem(
leadingIcon = {
Icon(
Icons.Rounded.ContentCopy,
contentDescription = null
)
},
text = { Text(stringResource(R.string.article_actions_copy_link)) },
onClick = {
copyToClipboard()
onDismissRequest()
},
)
}

@Composable
private fun ToggleReadMenuItem(onDismissRequest: () -> Unit, article: Article) {
val action = readAction(article, LocalArticleActions.current)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.capyreader.app.ui.components

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString

@Composable
fun buildCopyToClipboard(url: String): () -> Unit {
val clipboardManager = LocalClipboardManager.current

fun copy() {
clipboardManager.setText(AnnotatedString(url))
}

return ::copy
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<string name="article_actions_open_menu">Open article actions</string>
<string name="article_actions_mark_below_as_read">Mark below as read</string>
<string name="article_actions_mark_after_as_read">Mark above as read</string>
<string name="article_actions_copy_link">Copy Link</string>
<string name="unauthorized_dialog_title">You\'re logged out</string>
<string name="unauthorized_dialog_description">There was an issue connecting to your account. Please log in again.</string>
<string name="unauthorized_dialog_dismiss_text">Later</string>
Expand Down

0 comments on commit 260a9b7

Please sign in to comment.