Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Copy Tracker URL on icon long press #1101

Merged
merged 5 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(onLongClick = onLongClick, onClick = onClick)
AntsyLich marked this conversation as resolved.
Show resolved Hide resolved
} 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