From 3ea3b0bf2ecc3f74a790af2012dd4f4a6b2ab3f7 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 28 Nov 2021 14:41:03 -0500 Subject: [PATCH] Add UnmeteredSource interface To be included in extension-lib 1.3 (or whatever it's going to be). This applies to sources like Komga or Lanragi, where large numbers of update/download aren't of concern since they're (usually) self-hosted. --- .../java/eu/kanade/tachiyomi/data/download/Downloader.kt | 6 +++++- .../kanade/tachiyomi/data/library/LibraryUpdateService.kt | 6 +++++- .../main/java/eu/kanade/tachiyomi/source/LocalSource.kt | 3 ++- .../java/eu/kanade/tachiyomi/source/UnmeteredSource.kt | 8 ++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/source/UnmeteredSource.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index 7a75e633b2..5f44ebe012 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.DownloadQueue import eu.kanade.tachiyomi.source.SourceManager +import eu.kanade.tachiyomi.source.UnmeteredSource import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.fetchAllImageUrlsFromPageList @@ -266,7 +267,10 @@ class Downloader( // Start downloader if needed if (autoStart && wasEmpty) { - val maxDownloadsFromSource = queue.groupBy { it.source }.maxOf { it.value.size } + val maxDownloadsFromSource = queue + .groupBy { it.source } + .filterKeys { it !is UnmeteredSource } + .maxOf { it.value.size } if (maxDownloadsFromSource > CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD) { withUIContext { context.toast(R.string.download_queue_size_warning, Toast.LENGTH_LONG) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index 8e2bed25f2..f9370b1b74 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.data.track.EnhancedTrackService import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.source.SourceManager +import eu.kanade.tachiyomi.source.UnmeteredSource import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.toSChapter import eu.kanade.tachiyomi.source.model.toSManga @@ -267,7 +268,10 @@ class LibraryUpdateService( .sortedWith(rankingScheme[selectedScheme]) // Warn when excessively checking a single source - val maxUpdatesFromSource = mangaToUpdate.groupBy { it.source }.maxOfOrNull { it.value.size } ?: 0 + val maxUpdatesFromSource = mangaToUpdate + .groupBy { it.source } + .filterKeys { sourceManager.get(it) !is UnmeteredSource } + .maxOfOrNull { it.value.size } ?: 0 if (maxUpdatesFromSource > MANGA_PER_SOURCE_QUEUE_WARNING_THRESHOLD) { toast(R.string.notification_size_warning, Toast.LENGTH_LONG) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 3f70fccf08..eb98302965 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -38,7 +38,8 @@ import java.util.Locale import java.util.concurrent.TimeUnit import java.util.zip.ZipFile -class LocalSource(private val context: Context) : CatalogueSource { +class LocalSource(private val context: Context) : CatalogueSource, UnmeteredSource { + companion object { const val ID = 0L const val HELP_URL = "https://tachiyomi.org/help/guides/local-manga/" diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/UnmeteredSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/UnmeteredSource.kt new file mode 100644 index 0000000000..7536ccb0ba --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/source/UnmeteredSource.kt @@ -0,0 +1,8 @@ +package eu.kanade.tachiyomi.source + +/** + * A source that explicitly doesn't require traffic considerations. + * + * This typically applies for self-hosted sources. + */ +interface UnmeteredSource