|
@@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.data.download.model.Download
|
|
|
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
|
|
import eu.kanade.tachiyomi.util.notificationManager
|
|
|
+import eu.kanade.tachiyomi.util.toast
|
|
|
|
|
|
/**
|
|
|
* DownloadNotifier is used to show notifications when downloading one or multiple chapters.
|
|
@@ -40,6 +41,11 @@ class DownloadNotifier(private val context: Context) {
|
|
|
*/
|
|
|
internal var multipleDownloadThreads = false
|
|
|
|
|
|
+ /**
|
|
|
+ * Value determining if notification should be shown
|
|
|
+ */
|
|
|
+ internal var showNotification = true
|
|
|
+
|
|
|
/**
|
|
|
* Called when download progress changes.
|
|
|
* Note: Only accepted when multi download active.
|
|
@@ -47,9 +53,8 @@ class DownloadNotifier(private val context: Context) {
|
|
|
* @param queue the queue containing downloads.
|
|
|
*/
|
|
|
internal fun onProgressChange(queue: DownloadQueue) {
|
|
|
- if (multipleDownloadThreads) {
|
|
|
+ if (multipleDownloadThreads && showNotification)
|
|
|
doOnProgressChange(null, queue)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -60,9 +65,8 @@ class DownloadNotifier(private val context: Context) {
|
|
|
* @param queue the queue containing downloads
|
|
|
*/
|
|
|
internal fun onProgressChange(download: Download, queue: DownloadQueue) {
|
|
|
- if (!multipleDownloadThreads) {
|
|
|
+ if (!multipleDownloadThreads && showNotification)
|
|
|
doOnProgressChange(download, queue)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -86,7 +90,7 @@ class DownloadNotifier(private val context: Context) {
|
|
|
}
|
|
|
|
|
|
// Create notification
|
|
|
- with (notificationBuilder) {
|
|
|
+ with(notificationBuilder) {
|
|
|
// Check if icon needs refresh
|
|
|
if (!isDownloading) {
|
|
|
setSmallIcon(android.R.drawable.stat_sys_download)
|
|
@@ -127,17 +131,18 @@ class DownloadNotifier(private val context: Context) {
|
|
|
* @param download download object containing download information
|
|
|
*/
|
|
|
private fun onComplete(download: Download?) {
|
|
|
- // Create notification.
|
|
|
- with(notificationBuilder) {
|
|
|
- setContentTitle(download?.chapter?.name ?: context.getString(R.string.app_name))
|
|
|
- setContentText(context.getString(R.string.update_check_notification_download_complete))
|
|
|
- setSmallIcon(android.R.drawable.stat_sys_download_done)
|
|
|
- setProgress(0, 0, false)
|
|
|
- }
|
|
|
-
|
|
|
- // Show notification.
|
|
|
- context.notificationManager.notify(notificationId, notificationBuilder.build())
|
|
|
+ if (showNotification) {
|
|
|
+ // Create notification.
|
|
|
+ with(notificationBuilder) {
|
|
|
+ setContentTitle(download?.chapter?.name ?: context.getString(R.string.app_name))
|
|
|
+ setContentText(context.getString(R.string.update_check_notification_download_complete))
|
|
|
+ setSmallIcon(android.R.drawable.stat_sys_download_done)
|
|
|
+ setProgress(0, 0, false)
|
|
|
+ }
|
|
|
|
|
|
+ // Show notification.
|
|
|
+ context.notificationManager.notify(notificationId, notificationBuilder.build())
|
|
|
+ }
|
|
|
// Reset initial values
|
|
|
isDownloading = false
|
|
|
initialQueueSize = 0
|
|
@@ -158,14 +163,17 @@ class DownloadNotifier(private val context: Context) {
|
|
|
*/
|
|
|
internal fun onError(error: String? = null, chapter: String? = null) {
|
|
|
// Create notification
|
|
|
- with(notificationBuilder) {
|
|
|
- setContentTitle(chapter ?: context.getString(R.string.download_notifier_title_error))
|
|
|
- setContentText(error ?: context.getString(R.string.download_notifier_unkown_error))
|
|
|
- setSmallIcon(android.R.drawable.stat_sys_warning)
|
|
|
- setProgress(0, 0, false)
|
|
|
+ if (showNotification) {
|
|
|
+ with(notificationBuilder) {
|
|
|
+ setContentTitle(chapter ?: context.getString(R.string.download_notifier_title_error))
|
|
|
+ setContentText(error ?: context.getString(R.string.download_notifier_unkown_error))
|
|
|
+ setSmallIcon(android.R.drawable.stat_sys_warning)
|
|
|
+ setProgress(0, 0, false)
|
|
|
+ }
|
|
|
+ context.notificationManager.notify(Constants.NOTIFICATION_DOWNLOAD_CHAPTER_ERROR_ID, notificationBuilder.build())
|
|
|
+ } else {
|
|
|
+ context.toast(error ?: context.getString(R.string.download_notifier_unkown_error))
|
|
|
}
|
|
|
- context.notificationManager.notify(Constants.NOTIFICATION_DOWNLOAD_CHAPTER_ERROR_ID, notificationBuilder.build())
|
|
|
-
|
|
|
// Reset download information
|
|
|
onClear()
|
|
|
isDownloading = false
|