From de23226591376e998e4ff1ff7b2d4c2a0a805b09 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 1 Oct 2022 21:31:07 +0600 Subject: [PATCH] Add methods to get manga and chapter url (#8114) * Add methods to get manga and chapter url Some fork supports directly opening chapters with webview hence `getChapterUrl` * Review Changes * Add since to javadoc --- .../tachiyomi/ui/manga/MangaController.kt | 7 +++--- .../tachiyomi/source/online/HttpSource.kt | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index e6b858505a..0e2860ecee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -17,7 +17,6 @@ import androidx.core.os.bundleOf import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import eu.kanade.data.chapter.NoChaptersException -import eu.kanade.domain.manga.model.toDbManga import eu.kanade.presentation.components.ChangeCategoryDialog import eu.kanade.presentation.components.ChapterDownloadAction import eu.kanade.presentation.components.DuplicateMangaDialog @@ -216,7 +215,7 @@ class MangaController : FullComposeController { val source = presenter.source as? HttpSource ?: return val url = try { - source.mangaDetailsRequest(manga.toDbManga()).url.toString() + source.getMangaUrl(manga.toSManga()) } catch (e: Exception) { return } @@ -226,12 +225,12 @@ class MangaController : FullComposeController { startActivity(intent) } - fun shareManga() { + private fun shareManga() { val context = view?.context ?: return val manga = presenter.manga ?: return val source = presenter.source as? HttpSource ?: return try { - val url = source.mangaDetailsRequest(manga.toDbManga()).url.toString() + val url = source.getMangaUrl(manga.toSManga()) val intent = Intent(Intent.ACTION_SEND).apply { type = "text/plain" putExtra(Intent.EXTRA_TEXT, url) diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt b/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt index e6ae0a2179..a43e84ff8e 100644 --- a/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/source-api/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -356,6 +356,28 @@ abstract class HttpSource : CatalogueSource { } } + /** + * Returns the url of the provided manga + * + * @since extensions-lib 1.4 + * @param manga the manga + * @return url of the manga + */ + open fun getMangaUrl(manga: SManga): String { + return mangaDetailsRequest(manga).url.toString() + } + + /** + * Returns the url of the provided chapter + * + * @since extensions-lib 1.4 + * @param chapter the chapter + * @return url of the chapter + */ + open fun getChapterUrl(chapter: SChapter): String { + return pageListRequest(chapter).url.toString() + } + /** * Called before inserting a new chapter into database. Use it if you need to override chapter * fields, like the title or the chapter number. Do not change anything to [manga].