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)
This commit is contained in:
arkon 2021-10-18 10:46:07 -04:00
parent f453236840
commit 538dd60580
6 changed files with 17 additions and 26 deletions

View File

@ -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)

View File

@ -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

View File

@ -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.
*

View File

@ -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

View File

@ -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

View File

@ -701,11 +701,12 @@
<!-- Downloads activity and service -->
<string name="download_queue_error">Couldn\'t download chapters. You can try again in the downloads section</string>
<string name="download_insufficient_space">Couldn\'t download chapters due to low storage space</string>
<string name="download_queue_size_warning">Warning: large bulk downloads may lead to sources becoming slower and/or blocking Tachiyomi</string>
<!-- Library update service notifications -->
<string name="notification_check_updates">Checking for new chapters</string>
<string name="notification_updating">Updating library… (%1$d/%2$d)</string>
<string name="notification_size_warning">Large updates may lead to increased battery usage and sources becoming slower</string>
<string name="notification_size_warning">Warning: large updates harm sources and may lead to slower updates and also increased battery usage</string>
<string name="notification_new_chapters">New chapters found</string>
<plurals name="notification_new_chapters_summary">
<item quantity="one">For 1 title</item>