From 538dd60580f1b97993620b05d353db883e44b552 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 18 Oct 2021 10:46:07 -0400 Subject: [PATCH] Adjust update/download warnings - Uses toasts now - Adjusted wording to emphasize effect on sources - Download warning has a different threshold (15 chapters per source, vs. 60 entries per source for library update) --- .../tachiyomi/data/download/DownloadNotifier.kt | 2 +- .../kanade/tachiyomi/data/download/Downloader.kt | 15 +++++++++------ .../data/library/LibraryUpdateNotifier.kt | 14 -------------- .../data/library/LibraryUpdateService.kt | 8 +++++--- .../tachiyomi/data/notification/Notifications.kt | 1 - app/src/main/res/values/strings.xml | 3 ++- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt index d3c7b46a8..e73acf1f1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadNotifier.kt @@ -187,7 +187,7 @@ internal class DownloadNotifier(private val context: Context) { */ fun onWarning(reason: String) { with(errorNotificationBuilder) { - setContentTitle(context.getString(R.string.label_warning)) + setContentTitle(context.getString(R.string.download_notifier_downloader_title)) setStyle(NotificationCompat.BigTextStyle().bigText(reason)) setSmallIcon(R.drawable.ic_warning_white_24dp) setAutoCancel(true) 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 8cd520cbf..e58f386dd 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 @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.download import android.content.Context import android.webkit.MimeTypeMap +import android.widget.Toast import com.hippo.unifile.UniFile import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.PublishRelay @@ -11,7 +12,6 @@ import eu.kanade.tachiyomi.data.database.models.Chapter 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.data.library.PER_SOURCE_QUEUE_WARNING_THRESHOLD import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource @@ -24,6 +24,7 @@ import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.saveTo import eu.kanade.tachiyomi.util.system.ImageUtil import eu.kanade.tachiyomi.util.system.logcat +import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.async import logcat.LogPriority import okhttp3.Response @@ -265,8 +266,8 @@ class Downloader( // Start downloader if needed if (autoStart && wasEmpty) { val maxDownloadsFromSource = queue.groupBy { it.source }.maxOf { it.value.size } - if (maxDownloadsFromSource > PER_SOURCE_QUEUE_WARNING_THRESHOLD) { - notifier.onWarning(context.getString(R.string.notification_size_warning)) + if (maxDownloadsFromSource > CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD) { + context.toast(R.string.download_queue_size_warning, Toast.LENGTH_LONG) } DownloadService.start(context) } @@ -506,8 +507,10 @@ class Downloader( companion object { const val TMP_DIR_SUFFIX = "_tmp" - - // Arbitrary minimum required space to start a download: 50 MB - const val MIN_DISK_SPACE = 50 * 1024 * 1024 } } + +private const val CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD = 15 + +// Arbitrary minimum required space to start a download: 50 MB +private const val MIN_DISK_SPACE = 50 * 1024 * 1024 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt index bb8608f91..991ae3011 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt @@ -88,20 +88,6 @@ class LibraryUpdateNotifier(private val context: Context) { ) } - fun showQueueSizeWarningNotification() { - val notification = context.notificationBuilder(Notifications.CHANNEL_LIBRARY_PROGRESS) { - setContentTitle(context.getString(R.string.label_warning)) - setSmallIcon(R.drawable.ic_warning_white_24dp) - setStyle(NotificationCompat.BigTextStyle().bigText(context.getString(R.string.notification_size_warning))) - } - .build() - - context.notificationManager.notify( - Notifications.ID_LIBRARY_SIZE_WARNING, - notification, - ) - } - /** * Shows notification containing update entries that failed with action to open full log. * 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 16ceb85d4..8540038b8 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 @@ -5,6 +5,7 @@ import android.content.Context import android.content.Intent import android.os.IBinder import android.os.PowerManager +import android.widget.Toast import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache @@ -38,6 +39,7 @@ import eu.kanade.tachiyomi.util.system.acquireWakeLock import eu.kanade.tachiyomi.util.system.createFileInCacheDir import eu.kanade.tachiyomi.util.system.isServiceRunning import eu.kanade.tachiyomi.util.system.logcat +import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -267,8 +269,8 @@ class LibraryUpdateService( // Warn when excessively checking a single source val maxUpdatesFromSource = mangaToUpdate.groupBy { it.source }.maxOf { it.value.size } - if (maxUpdatesFromSource > PER_SOURCE_QUEUE_WARNING_THRESHOLD) { - notifier.showQueueSizeWarningNotification() + if (maxUpdatesFromSource > MANGA_PER_SOURCE_QUEUE_WARNING_THRESHOLD) { + toast(R.string.notification_size_warning, Toast.LENGTH_LONG) } } @@ -574,4 +576,4 @@ class LibraryUpdateService( } } -const val PER_SOURCE_QUEUE_WARNING_THRESHOLD = 60 +private const val MANGA_PER_SOURCE_QUEUE_WARNING_THRESHOLD = 60 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt index 753701a7b..c6403a25c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt @@ -27,7 +27,6 @@ object Notifications { private const val GROUP_LIBRARY = "group_library" const val CHANNEL_LIBRARY_PROGRESS = "library_progress_channel" const val ID_LIBRARY_PROGRESS = -101 - const val ID_LIBRARY_SIZE_WARNING = -103 const val CHANNEL_LIBRARY_ERROR = "library_errors_channel" const val ID_LIBRARY_ERROR = -102 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d87ecd186..5e8d7c8cb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -701,11 +701,12 @@ Couldn\'t download chapters. You can try again in the downloads section Couldn\'t download chapters due to low storage space + Warning: large bulk downloads may lead to sources becoming slower and/or blocking Tachiyomi Checking for new chapters Updating library… (%1$d/%2$d) - Large updates may lead to increased battery usage and sources becoming slower + Warning: large updates harm sources and may lead to slower updates and also increased battery usage New chapters found For 1 title