From 200d39e023af79b02276554a1bef1d7d53e3b903 Mon Sep 17 00:00:00 2001 From: Catting <5874051+mm12@users.noreply.github.com> Date: Sun, 11 Aug 2024 12:10:36 -0500 Subject: [PATCH] Add Copy Tracker URL on icon long press (#1101) * Add Copy Tracker URL on icon long press Signed-off-by: Catt0s <5874051+mm12@users.noreply.github.com> * Add 'Copy To Clipboard' to tracker item menu Signed-off-by: Catt0s <5874051+mm12@users.noreply.github.com> * Add 'Copy link' to locales. Signed-off-by: Catt0s <5874051+mm12@users.noreply.github.com> * Implement code review suggestions > > Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Signed-off-by: Catt0s <5874051+mm12@users.noreply.github.com> * Update app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt --------- Signed-off-by: Catt0s <5874051+mm12@users.noreply.github.com> Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- .../presentation/track/TrackInfoDialogHome.kt | 13 +++++++++++++ .../track/TrackInfoDialogHomePreviewProvider.kt | 2 ++ .../presentation/track/components/TrackLogoIcon.kt | 4 +++- .../tachiyomi/ui/manga/track/TrackInfoDialog.kt | 9 +++++++++ i18n/src/commonMain/moko-resources/base/strings.xml | 1 + 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt index 7ed6b3cc0..4e146c60e 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt @@ -72,6 +72,7 @@ fun TrackInfoDialogHome( onNewSearch: (TrackItem) -> Unit, onOpenInBrowser: (TrackItem) -> Unit, onRemoved: (TrackItem) -> Unit, + onCopyLink: (TrackItem) -> Unit, ) { Column( modifier = Modifier @@ -116,6 +117,7 @@ fun TrackInfoDialogHome( onNewSearch = { onNewSearch(item) }, onOpenInBrowser = { onOpenInBrowser(item) }, onRemoved = { onRemoved(item) }, + onCopyLink = { onCopyLink(item) }, ) } else { TrackInfoItemEmpty( @@ -144,6 +146,7 @@ private fun TrackInfoItem( onNewSearch: () -> Unit, onOpenInBrowser: () -> Unit, onRemoved: () -> Unit, + onCopyLink: () -> Unit, ) { val context = LocalContext.current Column { @@ -153,6 +156,7 @@ private fun TrackInfoItem( TrackLogoIcon( tracker = tracker, onClick = onOpenInBrowser, + onLongClick = onCopyLink, ) Box( modifier = Modifier @@ -179,6 +183,7 @@ private fun TrackInfoItem( TrackInfoItemMenu( onOpenInBrowser = onOpenInBrowser, onRemoved = onRemoved, + onCopyLink = onCopyLink, ) } @@ -287,6 +292,7 @@ private fun TrackInfoItemEmpty( private fun TrackInfoItemMenu( onOpenInBrowser: () -> Unit, onRemoved: () -> Unit, + onCopyLink: () -> Unit, ) { var expanded by remember { mutableStateOf(false) } Box(modifier = Modifier.wrapContentSize(Alignment.TopStart)) { @@ -307,6 +313,13 @@ private fun TrackInfoItemMenu( expanded = false }, ) + DropdownMenuItem( + text = { Text(stringResource(MR.strings.action_copy_link)) }, + onClick = { + onCopyLink() + expanded = false + }, + ) DropdownMenuItem( text = { Text(stringResource(MR.strings.action_remove)) }, onClick = { diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt index aa58403ea..3b60a9277 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHomePreviewProvider.kt @@ -56,6 +56,7 @@ internal class TrackInfoDialogHomePreviewProvider : onNewSearch = {}, onOpenInBrowser = {}, onRemoved = {}, + onCopyLink = {}, ) } @@ -71,6 +72,7 @@ internal class TrackInfoDialogHomePreviewProvider : onNewSearch = {}, onOpenInBrowser = {}, onRemoved = {}, + onCopyLink = {}, ) } diff --git a/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt b/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt index 4dd03ecc7..7488d0da9 100644 --- a/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt +++ b/app/src/main/java/eu/kanade/presentation/track/components/TrackLogoIcon.kt @@ -22,9 +22,10 @@ import tachiyomi.presentation.core.util.clickableNoIndication fun TrackLogoIcon( tracker: Tracker, onClick: (() -> Unit)? = null, + onLongClick: (() -> Unit)? = null, ) { val modifier = if (onClick != null) { - Modifier.clickableNoIndication(onClick = onClick) + Modifier.clickableNoIndication(onClick = onClick, onLongClick = onLongClick) } else { Modifier } @@ -53,6 +54,7 @@ private fun TrackLogoIconPreviews( TrackLogoIcon( tracker = tracker, onClick = null, + onLongClick = null, ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt index 4c66940c9..e8c919c9d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt @@ -54,6 +54,7 @@ import eu.kanade.tachiyomi.data.track.Tracker import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.util.lang.convertEpochMillisZone +import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.toast import kotlinx.collections.immutable.ImmutableList @@ -170,6 +171,7 @@ data class TrackInfoDialogHomeScreen( ), ) }, + onCopyLink = { context.copyTrackerLink(it) }, ) } @@ -183,6 +185,13 @@ data class TrackInfoDialogHomeScreen( } } + private fun Context.copyTrackerLink(trackItem: TrackItem) { + val url = trackItem.track?.remoteUrl ?: return + if (url.isNotBlank()) { + copyToClipboard(url, url) + } + } + private class Model( private val mangaId: Long, private val sourceId: Long, diff --git a/i18n/src/commonMain/moko-resources/base/strings.xml b/i18n/src/commonMain/moko-resources/base/strings.xml index 90719fb92..bdd75f70b 100644 --- a/i18n/src/commonMain/moko-resources/base/strings.xml +++ b/i18n/src/commonMain/moko-resources/base/strings.xml @@ -110,6 +110,7 @@ Open in browser Show entry Copy to clipboard + Copy link Open in WebView WebView