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 2d55f2df0..ad11fb52c 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
@@ -184,16 +184,19 @@ internal class DownloadNotifier(private val context: Context) {
* Called when the downloader receives a warning.
*
* @param reason the text to show.
+ * @param timeout duration after which to automatically dismiss the notification.
+ * Only works on Android 8+.
*/
- fun onWarning(reason: String) {
+ fun onWarning(reason: String, timeout: Long? = null) {
with(errorNotificationBuilder) {
setContentTitle(context.getString(R.string.download_notifier_downloader_title))
- setStyle(NotificationCompat.BigTextStyle().bigText(reason))
+ setContentText(reason)
setSmallIcon(R.drawable.ic_warning_white_24dp)
setAutoCancel(true)
clearActions()
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
setProgress(0, 0, false)
+ timeout?.let { setTimeoutAfter(it) }
show(Notifications.ID_DOWNLOAD_CHAPTER_ERROR)
}
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 a8d4f5a4b..e60046be5 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,7 +2,6 @@ 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
@@ -27,7 +26,6 @@ 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
@@ -274,13 +272,20 @@ class Downloader(
// Start downloader if needed
if (autoStart && wasEmpty) {
+ val queuedDownloads = queue.filter { it.source !is UnmeteredSource }.count()
val maxDownloadsFromSource = queue
.groupBy { it.source }
.filterKeys { it !is UnmeteredSource }
.maxOf { it.value.size }
- if (maxDownloadsFromSource > CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD) {
+ if (
+ queuedDownloads > DOWNLOADS_QUEUED_WARNING_THRESHOLD ||
+ maxDownloadsFromSource > CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD
+ ) {
withUIContext {
- context.toast(R.string.download_queue_size_warning, Toast.LENGTH_LONG)
+ notifier.onWarning(
+ context.getString(R.string.download_queue_size_warning),
+ WARNING_NOTIF_TIMEOUT_MS,
+ )
}
}
DownloadService.start(context)
@@ -559,7 +564,9 @@ class Downloader(
companion object {
const val TMP_DIR_SUFFIX = "_tmp"
+ const val WARNING_NOTIF_TIMEOUT_MS = 30_000L
const val CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD = 15
+ private const val DOWNLOADS_QUEUED_WARNING_THRESHOLD = 30
}
}
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 df2d9450e..7ea91a629 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
@@ -90,6 +90,20 @@ class LibraryUpdateNotifier(private val context: Context) {
)
}
+ fun showQueueSizeWarningNotification() {
+ val notificationBuilder = context.notificationBuilder(Notifications.CHANNEL_LIBRARY_PROGRESS) {
+ setContentTitle(context.getString(R.string.label_warning))
+ setContentText(context.getString(R.string.notification_size_warning))
+ setSmallIcon(R.drawable.ic_warning_white_24dp)
+ setTimeoutAfter(Downloader.WARNING_NOTIF_TIMEOUT_MS)
+ }
+
+ context.notificationManager.notify(
+ Notifications.ID_LIBRARY_SIZE_WARNING,
+ notificationBuilder.build(),
+ )
+ }
+
/**
* 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 22b4d7b13..08861b935 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,7 +5,6 @@ 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
@@ -42,7 +41,6 @@ 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
@@ -271,7 +269,7 @@ class LibraryUpdateService(
.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)
+ notifier.showQueueSizeWarningNotification()
}
}
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 42e9c6d46..f8a74abcd 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
@@ -26,6 +26,7 @@ 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
const val CHANNEL_LIBRARY_SKIPPED = "library_skipped_channel"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f7941e689..b4f4fac49 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -722,7 +722,7 @@
Checking for new chapters
Updating library… (%1$d/%2$d)
- Warning: large updates harm sources and may lead to slower updates and also increased battery usage
+ Large updates harm sources and may lead to slower updates and also increased battery usage
New chapters found
- For %d title