mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 17:27:48 +01:00
Split out global library update skipped entries into separate notification (closes #6722)
This commit is contained in:
parent
45da036789
commit
56042ad0b6
5 changed files with 54 additions and 17 deletions
|
@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.R
|
|||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.download.Downloader
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
|
@ -92,19 +93,18 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
/**
|
||||
* Shows notification containing update entries that failed with action to open full log.
|
||||
*
|
||||
* @param skipped Number of entries that were skipped during the update.
|
||||
* @param failed Number of entries that failed to update.
|
||||
* @param uri Uri for error log file containing all titles that failed.
|
||||
*/
|
||||
fun showUpdateErrorNotification(skipped: Int, failed: Int, uri: Uri) {
|
||||
if (skipped == 0 && failed == 0) {
|
||||
fun showUpdateErrorNotification(failed: Int, uri: Uri) {
|
||||
if (failed == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
context.notificationManager.notify(
|
||||
Notifications.ID_LIBRARY_ERROR,
|
||||
context.notificationBuilder(Notifications.CHANNEL_LIBRARY_ERROR) {
|
||||
setContentTitle(context.resources.getString(R.string.notification_update_skipped_error, skipped, failed))
|
||||
setContentTitle(context.resources.getString(R.string.notification_update_error, failed))
|
||||
setContentText(context.getString(R.string.action_show_errors))
|
||||
setSmallIcon(R.drawable.ic_tachi)
|
||||
|
||||
|
@ -114,6 +114,27 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows notification containing update entries that were skipped.
|
||||
*
|
||||
* @param skipped Number of entries that were skipped during the update.
|
||||
*/
|
||||
fun showUpdateSkippedNotification(skipped: Int) {
|
||||
if (skipped == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
context.notificationManager.notify(
|
||||
Notifications.ID_LIBRARY_SKIPPED,
|
||||
context.notificationBuilder(Notifications.CHANNEL_LIBRARY_SKIPPED) {
|
||||
setContentTitle(context.resources.getString(R.string.notification_update_skipped, skipped))
|
||||
setSmallIcon(R.drawable.ic_tachi)
|
||||
addAction(R.drawable.ic_help_24dp, context.getString(R.string.learn_more), NotificationHandler.openUrl(context, HELP_SKIPPED_URL))
|
||||
}
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notification containing the result of the update done by the service.
|
||||
*
|
||||
|
@ -304,10 +325,9 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
}
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val NOTIF_MAX_CHAPTERS = 5
|
||||
private const val NOTIF_TITLE_MAX_LEN = 45
|
||||
private const val NOTIF_ICON_SIZE = 192
|
||||
}
|
||||
}
|
||||
|
||||
private const val NOTIF_MAX_CHAPTERS = 5
|
||||
private const val NOTIF_TITLE_MAX_LEN = 45
|
||||
private const val NOTIF_ICON_SIZE = 192
|
||||
private const val HELP_SKIPPED_URL = "https://tachiyomi.org/help/faq/#why-does-global-update-skip-some-entries"
|
||||
|
|
|
@ -377,14 +377,16 @@ class LibraryUpdateService(
|
|||
}
|
||||
}
|
||||
|
||||
if (skippedUpdates.isNotEmpty() || failedUpdates.isNotEmpty()) {
|
||||
val errorFile = writeErrorFile(skippedUpdates + failedUpdates)
|
||||
if (failedUpdates.isNotEmpty()) {
|
||||
val errorFile = writeErrorFile(failedUpdates)
|
||||
notifier.showUpdateErrorNotification(
|
||||
skippedUpdates.size,
|
||||
failedUpdates.size,
|
||||
errorFile.getUriCompat(this),
|
||||
)
|
||||
}
|
||||
if (skippedUpdates.isNotEmpty()) {
|
||||
notifier.showUpdateSkippedNotification(skippedUpdates.size)
|
||||
}
|
||||
}
|
||||
|
||||
private fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
|
||||
|
|
|
@ -23,7 +23,7 @@ object NotificationHandler {
|
|||
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
action = MainActivity.SHORTCUT_DOWNLOADS
|
||||
}
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ object NotificationHandler {
|
|||
setDataAndType(uri, "image/*")
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
}
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,6 +52,11 @@ object NotificationHandler {
|
|||
setDataAndType(uri, ExtensionInstaller.APK_MIME)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
}
|
||||
return PendingIntent.getActivity(context, 0, intent, 0)
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
|
||||
fun openUrl(context: Context, url: String): PendingIntent {
|
||||
val notificationIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
return PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ object Notifications {
|
|||
const val ID_LIBRARY_PROGRESS = -101
|
||||
const val CHANNEL_LIBRARY_ERROR = "library_errors_channel"
|
||||
const val ID_LIBRARY_ERROR = -102
|
||||
const val CHANNEL_LIBRARY_SKIPPED = "library_skipped_channel"
|
||||
const val ID_LIBRARY_SKIPPED = -103
|
||||
|
||||
/**
|
||||
* Notification channel and ids used by the downloader.
|
||||
|
@ -132,6 +134,11 @@ object Notifications {
|
|||
setGroup(GROUP_LIBRARY)
|
||||
setShowBadge(false)
|
||||
},
|
||||
buildNotificationChannel(CHANNEL_LIBRARY_SKIPPED, IMPORTANCE_LOW) {
|
||||
setName(context.getString(R.string.channel_skipped))
|
||||
setGroup(GROUP_LIBRARY)
|
||||
setShowBadge(false)
|
||||
},
|
||||
buildNotificationChannel(CHANNEL_NEW_CHAPTERS, IMPORTANCE_DEFAULT) {
|
||||
setName(context.getString(R.string.channel_new_chapters))
|
||||
},
|
||||
|
|
|
@ -736,7 +736,9 @@
|
|||
<item quantity="one">Chapters %1$s and 1 more</item>
|
||||
<item quantity="other">Chapters %1$s and %2$d more</item>
|
||||
</plurals>
|
||||
<string name="notification_update_skipped_error">%1$d update(s) skipped and %2$d update(s) failed</string>
|
||||
<string name="notification_update_error">%1$d update(s) failed</string>
|
||||
<string name="notification_update_skipped">%1$d update(s) skipped</string>
|
||||
<string name="learn_more">Learn more</string>
|
||||
<string name="notification_cover_update_failed">Failed to update cover</string>
|
||||
<string name="notification_first_add_to_library">Please add the manga to your library before doing this</string>
|
||||
<string name="library_errors_help">For help on how to fix library update errors, see %1$s</string>
|
||||
|
@ -800,6 +802,7 @@
|
|||
<string name="channel_progress">Progress</string>
|
||||
<string name="channel_complete">Complete</string>
|
||||
<string name="channel_errors">Errors</string>
|
||||
<string name="channel_skipped">Skipped</string>
|
||||
<string name="channel_new_chapters">Chapter updates</string>
|
||||
<string name="channel_app_updates">App updates</string>
|
||||
<string name="channel_ext_updates">Extension updates</string>
|
||||
|
|
Loading…
Reference in a new issue