From ef3a6c80a7638209a5a41a0923bd9195380429aa Mon Sep 17 00:00:00 2001 From: Joseph Olugbohunmi <37001871+mayorJAY@users.noreply.github.com> Date: Tue, 22 Nov 2022 05:09:23 +0100 Subject: [PATCH] Implement copying of Manga URL to Clipboard (#8587) feat: Implement copying of Manga URL to Clipboard --- .../java/eu/kanade/presentation/manga/MangaScreen.kt | 7 +++++++ .../presentation/manga/components/MangaInfoHeader.kt | 2 ++ .../java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt index 4747306b58..cb3e9af1e2 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -80,6 +80,7 @@ fun MangaScreen( onDownloadChapter: ((List, ChapterDownloadAction) -> Unit)?, onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, + onWebViewLongClicked: (() -> Unit)?, onTrackingClicked: (() -> Unit)?, onTagClicked: (String) -> Unit, onFilterButtonClicked: () -> Unit, @@ -116,6 +117,7 @@ fun MangaScreen( onDownloadChapter = onDownloadChapter, onAddToLibraryClicked = onAddToLibraryClicked, onWebViewClicked = onWebViewClicked, + onWebViewLongClicked = onWebViewLongClicked, onTrackingClicked = onTrackingClicked, onTagClicked = onTagClicked, onFilterClicked = onFilterButtonClicked, @@ -144,6 +146,7 @@ fun MangaScreen( onDownloadChapter = onDownloadChapter, onAddToLibraryClicked = onAddToLibraryClicked, onWebViewClicked = onWebViewClicked, + onWebViewLongClicked = onWebViewLongClicked, onTrackingClicked = onTrackingClicked, onTagClicked = onTagClicked, onFilterButtonClicked = onFilterButtonClicked, @@ -175,6 +178,7 @@ private fun MangaScreenSmallImpl( onDownloadChapter: ((List, ChapterDownloadAction) -> Unit)?, onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, + onWebViewLongClicked: (() -> Unit)?, onTrackingClicked: (() -> Unit)?, onTagClicked: (String) -> Unit, onFilterClicked: () -> Unit, @@ -332,6 +336,7 @@ private fun MangaScreenSmallImpl( trackingCount = state.trackingCount, onAddToLibraryClicked = onAddToLibraryClicked, onWebViewClicked = onWebViewClicked, + onWebViewLongClicked = onWebViewLongClicked, onTrackingClicked = onTrackingClicked, onEditCategory = onEditCategoryClicked, ) @@ -381,6 +386,7 @@ fun MangaScreenLargeImpl( onDownloadChapter: ((List, ChapterDownloadAction) -> Unit)?, onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, + onWebViewLongClicked: (() -> Unit)?, onTrackingClicked: (() -> Unit)?, onTagClicked: (String) -> Unit, onFilterButtonClicked: () -> Unit, @@ -525,6 +531,7 @@ fun MangaScreenLargeImpl( trackingCount = state.trackingCount, onAddToLibraryClicked = onAddToLibraryClicked, onWebViewClicked = onWebViewClicked, + onWebViewLongClicked = onWebViewLongClicked, onTrackingClicked = onTrackingClicked, onEditCategory = onEditCategoryClicked, ) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt index df3697527f..eda1973f9f 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt @@ -162,6 +162,7 @@ fun MangaActionRow( trackingCount: Int, onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, + onWebViewLongClicked: (() -> Unit)?, onTrackingClicked: (() -> Unit)?, onEditCategory: (() -> Unit)?, ) { @@ -196,6 +197,7 @@ fun MangaActionRow( icon = Icons.Outlined.Public, color = defaultActionButtonColor, onClick = onWebViewClicked, + onLongClick = onWebViewLongClicked, ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt index 6d38c96e70..7bab376d2f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt @@ -61,6 +61,7 @@ import eu.kanade.tachiyomi.ui.manga.track.TrackInfoDialogHomeScreen import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.updates.UpdatesController import eu.kanade.tachiyomi.ui.webview.WebViewActivity +import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toast @@ -101,6 +102,7 @@ class MangaScreen( haptic.performHapticFeedback(HapticFeedbackType.LongPress) }, onWebViewClicked = { openMangaInWebView(context, screenModel.manga, screenModel.source) }.takeIf { isHttpSource }, + onWebViewLongClicked = { copyMangaUrl(context, screenModel.manga, screenModel.source) }.takeIf { isHttpSource }, onTrackingClicked = screenModel::showTrackDialog.takeIf { successState.trackingAvailable }, onTagClicked = { performGenreSearch(router, it, screenModel.source!!) }, onFilterButtonClicked = screenModel::showSettingsDialog, @@ -326,4 +328,14 @@ class MangaScreen( val controller = SearchController(manga) router.pushController(controller) } + + /** + * Copy Manga URL to Clipboard + */ + private fun copyMangaUrl(context: Context, manga_: Manga?, source_: Source?) { + val manga = manga_ ?: return + val source = source_ as? HttpSource ?: return + val url = source.getMangaUrl(manga.toSManga()) + context.copyToClipboard(url, url) + } }