New Notifcation Icon

New Chapter Notifcations now show all new chapters when expanded
This commit is contained in:
Jay 2019-11-13 20:41:34 -08:00
parent e2a36e49ce
commit 8936138da5
9 changed files with 38 additions and 30 deletions

View File

@ -278,7 +278,7 @@ class LibraryUpdateService(
// Initialize the variables holding the progress of the updates.
val count = AtomicInteger(0)
// List containing new updates
val newUpdates = ArrayList<Pair<Manga, Chapter>>()
val newUpdates = ArrayList<Pair<Manga, Array<Chapter>>>()
// list containing failed updates
val failedUpdates = ArrayList<Manga>()
// List containing categories that get included in downloads.
@ -311,7 +311,8 @@ class LibraryUpdateService(
}
}
// Convert to the manga that contains new chapters.
.map { Pair(manga, (it.first.maxBy { ch -> ch.source_order }!!)) }
.map { Pair(manga, (it.first.sortedByDescending { ch -> ch
.source_order }.toTypedArray())) }
}
// Add manga with new chapters to the list.
.doOnNext { manga ->
@ -447,13 +448,15 @@ class LibraryUpdateService(
*
* @param updates a list of manga with new updates.
*/
private fun showResultNotification(updates: List<Pair<Manga, Chapter>>) {
private fun showResultNotification(updates: List<Pair<Manga, Array<Chapter>>>) {
val notifications = ArrayList<Pair<Notification, Int>>()
updates.forEach {
val manga = it.first
val chapter = it.second
val chapters = it.second
val chapterNames = chapters.map { chapter -> chapter.name.chop(45) }.toSet()
NotificationReceiver.dismissNotification(this, manga.id.hashCode())
notifications.add(Pair(notification(Notifications.CHANNEL_NEW_CHAPTERS) {
setSmallIcon(R.drawable.ic_book_white_24dp)
setSmallIcon(R.drawable.ic_tachiyomi_icon)
try {
val icon = GlideApp.with(this@LibraryUpdateService)
.asBitmap().load(manga).dontTransform().centerCrop().circleCrop()
@ -463,18 +466,21 @@ class LibraryUpdateService(
catch (e: Exception) { }
setContentTitle(manga.title.chop(45))
color = ContextCompat.getColor(this@LibraryUpdateService, R.color.colorAccentLight)
setContentText(chapter.name)
setContentText(chapterNames.first())
setStyle(NotificationCompat.BigTextStyle().bigText(chapterNames.joinToString("\n")))
priority = NotificationCompat.PRIORITY_HIGH
setGroup(Notifications.GROUP_NEW_CHAPTERS)
setContentIntent(
NotificationReceiver.openChapterPendingActivity(
this@LibraryUpdateService, manga, chapter
this@LibraryUpdateService, manga, chapters.first()
)
)
addAction(R.drawable.ic_in_library_24dp, getString(R.string.action_mark_as_read),
addAction(R.drawable.ic_glasses_black_24dp, getString(
if (chapters.size > 1) R.string.action_mark_all_as_read else R.string
.action_mark_as_read),
NotificationReceiver.markAsReadPendingBroadcast(this@LibraryUpdateService,
manga, chapter, Notifications.GROUP_NEW_CHAPTERS))
addAction(R.drawable.ic_glasses_black_24dp, getString(R.string.action_view_chapters),
manga, chapters, Notifications.GROUP_NEW_CHAPTERS))
addAction(R.drawable.ic_book_white_24dp, getString(R.string.action_view_chapters),
NotificationReceiver.openChapterPendingActivity(this@LibraryUpdateService,
manga, Notifications.GROUP_NEW_CHAPTERS))
setAutoCancel(true)
@ -489,7 +495,7 @@ class LibraryUpdateService(
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || notificationManager
.activeNotifications.find { it.groupKey == Notifications.GROUP_NEW_CHAPTERS } == null) {
notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) {
setSmallIcon(R.drawable.ic_book_white_24dp)
setSmallIcon(R.drawable.ic_tachiyomi_icon)
setLargeIcon(notificationBitmap)
setContentTitle(getString(R.string.notification_new_chapters))
color = ContextCompat.getColor(applicationContext, R.color.colorAccentLight)

View File

@ -75,9 +75,9 @@ class NotificationReceiver : BroadcastReceiver() {
if (notificationId > -1) dismissNotification(
context, notificationId, intent.getStringExtra(EXTRA_GROUP_ID)
)
val url = intent.getStringExtra(EXTRA_CHAPTER_URL) ?: return
val urls = intent.getStringArrayExtra(EXTRA_CHAPTER_URL) ?: return
val mangaId = intent.getLongExtra(EXTRA_MANGA_ID, -1)
markAsRead(url, mangaId)
markAsRead(urls, mangaId)
}
}
}
@ -169,18 +169,19 @@ class NotificationReceiver : BroadcastReceiver() {
* @param context context of application
* @param notificationId id of notification
*/
private fun markAsRead(chapterUrl: String, mangaaId: Long) {
private fun markAsRead(chapterUrls: Array<String>, mangaId: Long) {
val db: DatabaseHelper = Injekt.get()
val chapter = db.getChapter(chapterUrl, mangaaId).executeAsBlocking() ?: return
chapter.read = true
db.updateChapterProgress(chapter).executeAsBlocking()
val preferences: PreferencesHelper = Injekt.get()
if (preferences.removeAfterMarkedAsRead()) {
val mangaId = chapter.manga_id ?: return
val manga = db.getManga(mangaId).executeAsBlocking() ?: return
val sourceManager: SourceManager = Injekt.get()
val source = sourceManager.get(manga.source) ?: return
downloadManager.deleteChapters(listOf(chapter), manga, source)
chapterUrls.forEach {
val chapter = db.getChapter(it, mangaId).executeAsBlocking() ?: return
chapter.read = true
db.updateChapterProgress(chapter).executeAsBlocking()
val preferences: PreferencesHelper = Injekt.get()
if (preferences.removeAfterMarkedAsRead()) {
val manga = db.getManga(mangaId).executeAsBlocking() ?: return
val sourceManager: SourceManager = Injekt.get()
val source = sourceManager.get(manga.source) ?: return
downloadManager.deleteChapters(listOf(chapter), manga, source)
}
}
}
@ -393,12 +394,12 @@ class NotificationReceiver : BroadcastReceiver() {
* @param context context of application
* @param manga manga of chapter
*/
internal fun markAsReadPendingBroadcast(context: Context, manga: Manga, chapter:
Chapter, groupId: String):
internal fun markAsReadPendingBroadcast(context: Context, manga: Manga, chapters:
Array<Chapter>, groupId: String):
PendingIntent {
val newIntent = Intent(context, NotificationReceiver::class.java).apply {
action = ACTION_MARK_AS_READ
putExtra(EXTRA_CHAPTER_URL, chapter.url)
putExtra(EXTRA_CHAPTER_URL, chapters.map { it.url }.toTypedArray())
putExtra(EXTRA_MANGA_ID, manga.id)
putExtra(EXTRA_NOTIFICATION_ID, manga.id.hashCode())
putExtra(EXTRA_GROUP_ID, groupId)

View File

@ -23,14 +23,14 @@ object Notifications {
* Notification channel and ids used by the library updater.
*/
const val CHANNEL_LIBRARY = "library_channel"
const val ID_LIBRARY_PROGRESS = 101
const val ID_LIBRARY_PROGRESS = -101
/**
* Notification channel and ids used by the downloader.
*/
const val CHANNEL_DOWNLOADER = "downloader_channel"
const val ID_DOWNLOAD_CHAPTER = 201
const val ID_DOWNLOAD_CHAPTER_ERROR = 202
const val ID_DOWNLOAD_CHAPTER = -201
const val ID_DOWNLOAD_CHAPTER_ERROR = -202
/**
* Notification channel and ids used by the library updater.

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 597 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -43,6 +43,7 @@
<string name="action_global_search">Global search</string>
<string name="action_select_all">Select all</string>
<string name="action_mark_as_read">Mark as read</string>
<string name="action_mark_all_as_read">Mark all as read</string>
<string name="action_mark_as_unread">Mark as unread</string>
<string name="action_mark_previous_as_read">Mark previous as read</string>
<string name="action_download">Download</string>