Skip to content

Commit

Permalink
Add Copy Tracker URL on icon long press (#1101)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mm12 and AntsyLich authored Aug 11, 2024
1 parent b1b15a9 commit 200d39e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fun TrackInfoDialogHome(
onNewSearch: (TrackItem) -> Unit,
onOpenInBrowser: (TrackItem) -> Unit,
onRemoved: (TrackItem) -> Unit,
onCopyLink: (TrackItem) -> Unit,
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -116,6 +117,7 @@ fun TrackInfoDialogHome(
onNewSearch = { onNewSearch(item) },
onOpenInBrowser = { onOpenInBrowser(item) },
onRemoved = { onRemoved(item) },
onCopyLink = { onCopyLink(item) },
)
} else {
TrackInfoItemEmpty(
Expand Down Expand Up @@ -144,6 +146,7 @@ private fun TrackInfoItem(
onNewSearch: () -> Unit,
onOpenInBrowser: () -> Unit,
onRemoved: () -> Unit,
onCopyLink: () -> Unit,
) {
val context = LocalContext.current
Column {
Expand All @@ -153,6 +156,7 @@ private fun TrackInfoItem(
TrackLogoIcon(
tracker = tracker,
onClick = onOpenInBrowser,
onLongClick = onCopyLink,
)
Box(
modifier = Modifier
Expand All @@ -179,6 +183,7 @@ private fun TrackInfoItem(
TrackInfoItemMenu(
onOpenInBrowser = onOpenInBrowser,
onRemoved = onRemoved,
onCopyLink = onCopyLink,
)
}

Expand Down Expand Up @@ -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)) {
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ internal class TrackInfoDialogHomePreviewProvider :
onNewSearch = {},
onOpenInBrowser = {},
onRemoved = {},
onCopyLink = {},
)
}

Expand All @@ -71,6 +72,7 @@ internal class TrackInfoDialogHomePreviewProvider :
onNewSearch = {},
onOpenInBrowser = {},
onRemoved = {},
onCopyLink = {},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -53,6 +54,7 @@ private fun TrackLogoIconPreviews(
TrackLogoIcon(
tracker = tracker,
onClick = null,
onLongClick = null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -170,6 +171,7 @@ data class TrackInfoDialogHomeScreen(
),
)
},
onCopyLink = { context.copyTrackerLink(it) },
)
}

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions i18n/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<string name="action_open_in_browser">Open in browser</string>
<string name="action_show_manga">Show entry</string>
<string name="action_copy_to_clipboard">Copy to clipboard</string>
<string name="action_copy_link">Copy link</string>
<!-- Do not translate "WebView" -->
<string name="action_open_in_web_view">Open in WebView</string>
<string name="action_web_view" translatable="false">WebView</string>
Expand Down

0 comments on commit 200d39e

Please sign in to comment.