mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Tweak new chapters notification wording
This commit is contained in:
		| @@ -501,7 +501,7 @@ class LibraryUpdateService( | ||||
|         return notification(Notifications.CHANNEL_NEW_CHAPTERS) { | ||||
|             setContentTitle(manga.title) | ||||
|  | ||||
|             val description = getChaptersDescriptionString(chapters) | ||||
|             val description = getNewChaptersDescription(chapters) | ||||
|             setContentText(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() | ||||
|                 .apply { decimalSeparator = '.' }) | ||||
|  | ||||
|         val chapterNumbers = chapters | ||||
|         val displayableChapterNumbers = chapters | ||||
|                 .filter { it.chapter_number >= 0 } | ||||
|                 .sortedBy { it.chapter_number } | ||||
|                 .map { formatter.format(it.chapter_number) } | ||||
|                 .toSet() | ||||
|  | ||||
|         val shouldTruncate = chapterNumbers.size > NOTIF_MAX_CHAPTERS | ||||
|         val chaptersDescription = if (shouldTruncate) { | ||||
|             chapterNumbers.take(NOTIF_MAX_CHAPTERS - 1).joinToString(", ") | ||||
|         } else { | ||||
|             chapterNumbers.joinToString(", ") | ||||
|         return when (displayableChapterNumbers.size) { | ||||
|             // No sensible chapter numbers to show (i.e. no chapters have parsed chapter number) | ||||
|             0 -> { | ||||
|                 // "1 new chapter" or "5 new chapters" | ||||
|                 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_new_chapters">New chapters found</string> | ||||
|     <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> | ||||
|     </plurals> | ||||
|     <plurals name="notification_chapters"> | ||||
|         <item quantity="one">Chapter %1$s</item> | ||||
|         <item quantity="other">Chapters %1$s</item> | ||||
|     <plurals name="notification_chapters_generic"> | ||||
|         <item quantity="one">1 new chapter</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> | ||||
|     <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_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> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user