mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 16:41:51 +01:00
Tweak new chapters notification wording
This commit is contained in:
parent
a3dd5c1e92
commit
fef34dfe82
@ -501,7 +501,7 @@ class LibraryUpdateService(
|
|||||||
return notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
return notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
||||||
setContentTitle(manga.title)
|
setContentTitle(manga.title)
|
||||||
|
|
||||||
val description = getChaptersDescriptionString(chapters)
|
val description = getNewChaptersDescription(chapters)
|
||||||
setContentText(description)
|
setContentText(description)
|
||||||
setStyle(NotificationCompat.BigTextStyle().bigText(description))
|
setStyle(NotificationCompat.BigTextStyle().bigText(description))
|
||||||
|
|
||||||
@ -554,28 +554,47 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getChaptersDescriptionString(chapters: Array<Chapter>): String {
|
private fun getNewChaptersDescription(chapters: Array<Chapter>): String {
|
||||||
val formatter = DecimalFormat("#.###", DecimalFormatSymbols()
|
val formatter = DecimalFormat("#.###", DecimalFormatSymbols()
|
||||||
.apply { decimalSeparator = '.' })
|
.apply { decimalSeparator = '.' })
|
||||||
|
|
||||||
val chapterNumbers = chapters
|
val displayableChapterNumbers = chapters
|
||||||
|
.filter { it.chapter_number >= 0 }
|
||||||
.sortedBy { it.chapter_number }
|
.sortedBy { it.chapter_number }
|
||||||
.map { formatter.format(it.chapter_number) }
|
.map { formatter.format(it.chapter_number) }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
val shouldTruncate = chapterNumbers.size > NOTIF_MAX_CHAPTERS
|
return when (displayableChapterNumbers.size) {
|
||||||
val chaptersDescription = if (shouldTruncate) {
|
// No sensible chapter numbers to show (i.e. no chapters have parsed chapter number)
|
||||||
chapterNumbers.take(NOTIF_MAX_CHAPTERS - 1).joinToString(", ")
|
0 -> {
|
||||||
} else {
|
// "1 new chapter" or "5 new chapters"
|
||||||
chapterNumbers.joinToString(", ")
|
resources.getQuantityString(R.plurals.notification_chapters_generic, chapters.size, chapters.size)
|
||||||
|
}
|
||||||
|
// Only 1 chapter has a parsed chapter number
|
||||||
|
1 -> {
|
||||||
|
val remaining = chapters.size - displayableChapterNumbers.size
|
||||||
|
if (remaining == 0) {
|
||||||
|
// "Chapter 2.5"
|
||||||
|
resources.getString(R.string.notification_chapters_single, displayableChapterNumbers.first())
|
||||||
|
} else {
|
||||||
|
// "Chapter 2.5 and 10 more"
|
||||||
|
resources.getString(R.string.notification_chapters_single_and_more, displayableChapterNumbers.first(), remaining)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Everything else (i.e. multiple parsed chapter numbers)
|
||||||
|
else -> {
|
||||||
|
val shouldTruncate = displayableChapterNumbers.size > NOTIF_MAX_CHAPTERS
|
||||||
|
if (shouldTruncate) {
|
||||||
|
// "Chapters 1, 2.5, 3, 4, 5 and 10 more"
|
||||||
|
val remaining = displayableChapterNumbers.size - NOTIF_MAX_CHAPTERS
|
||||||
|
val joinedChapterNumbers = displayableChapterNumbers.take(NOTIF_MAX_CHAPTERS).joinToString(", ")
|
||||||
|
resources.getQuantityString(R.plurals.notification_chapters_multiple_and_more, remaining, joinedChapterNumbers, remaining)
|
||||||
|
} else {
|
||||||
|
// "Chapters 1, 2.5, 3"
|
||||||
|
resources.getString(R.string.notification_chapters_multiple, displayableChapterNumbers.joinToString(","))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var description = resources.getQuantityString(R.plurals.notification_chapters, chapters.size, chaptersDescription)
|
|
||||||
if (shouldTruncate) {
|
|
||||||
description += " ${resources.getString(R.string.notification_and_n_more, (chapterNumbers.size - (NOTIF_MAX_CHAPTERS - 1)))}"
|
|
||||||
}
|
|
||||||
|
|
||||||
return description
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -507,14 +507,20 @@
|
|||||||
<string name="notification_update_progress">Update progress: %1$d/%2$d</string>
|
<string name="notification_update_progress">Update progress: %1$d/%2$d</string>
|
||||||
<string name="notification_new_chapters">New chapters found</string>
|
<string name="notification_new_chapters">New chapters found</string>
|
||||||
<plurals name="notification_new_chapters_text">
|
<plurals name="notification_new_chapters_text">
|
||||||
<item quantity="one">For %d title</item>
|
<item quantity="one">For 1 title</item>
|
||||||
<item quantity="other">For %d titles</item>
|
<item quantity="other">For %d titles</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
<plurals name="notification_chapters">
|
<plurals name="notification_chapters_generic">
|
||||||
<item quantity="one">Chapter %1$s</item>
|
<item quantity="one">1 new chapter</item>
|
||||||
<item quantity="other">Chapters %1$s</item>
|
<item quantity="other">%1$d new chapters</item>
|
||||||
|
</plurals>
|
||||||
|
<string name="notification_chapters_single">Chapter %1$s</string>
|
||||||
|
<string name="notification_chapters_single_and_more">Chapter %1$s and %2$d more</string>
|
||||||
|
<string name="notification_chapters_multiple">Chapters %1$s</string>
|
||||||
|
<plurals name="notification_chapters_multiple_and_more">
|
||||||
|
<item quantity="one">Chapter %1$s and 1 more</item>
|
||||||
|
<item quantity="other">Chapters %1$s and %2$d more</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
<string name="notification_and_n_more">and %1$d more</string>
|
|
||||||
<string name="notification_cover_update_failed">Failed to update cover</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="notification_first_add_to_library">Please add the manga to your library before doing this</string>
|
||||||
<string name="notification_not_connected_to_ac_title">Sync canceled</string>
|
<string name="notification_not_connected_to_ac_title">Sync canceled</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user