mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 16:51:49 +01:00
New Notifcation Icon
New Chapter Notifcations now show all new chapters when expanded
This commit is contained in:
parent
e2a36e49ce
commit
8936138da5
@ -278,7 +278,7 @@ class LibraryUpdateService(
|
|||||||
// Initialize the variables holding the progress of the updates.
|
// Initialize the variables holding the progress of the updates.
|
||||||
val count = AtomicInteger(0)
|
val count = AtomicInteger(0)
|
||||||
// List containing new updates
|
// List containing new updates
|
||||||
val newUpdates = ArrayList<Pair<Manga, Chapter>>()
|
val newUpdates = ArrayList<Pair<Manga, Array<Chapter>>>()
|
||||||
// list containing failed updates
|
// list containing failed updates
|
||||||
val failedUpdates = ArrayList<Manga>()
|
val failedUpdates = ArrayList<Manga>()
|
||||||
// List containing categories that get included in downloads.
|
// List containing categories that get included in downloads.
|
||||||
@ -311,7 +311,8 @@ class LibraryUpdateService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Convert to the manga that contains new chapters.
|
// 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.
|
// Add manga with new chapters to the list.
|
||||||
.doOnNext { manga ->
|
.doOnNext { manga ->
|
||||||
@ -447,13 +448,15 @@ class LibraryUpdateService(
|
|||||||
*
|
*
|
||||||
* @param updates a list of manga with new updates.
|
* @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>>()
|
val notifications = ArrayList<Pair<Notification, Int>>()
|
||||||
updates.forEach {
|
updates.forEach {
|
||||||
val manga = it.first
|
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) {
|
notifications.add(Pair(notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
||||||
setSmallIcon(R.drawable.ic_book_white_24dp)
|
setSmallIcon(R.drawable.ic_tachiyomi_icon)
|
||||||
try {
|
try {
|
||||||
val icon = GlideApp.with(this@LibraryUpdateService)
|
val icon = GlideApp.with(this@LibraryUpdateService)
|
||||||
.asBitmap().load(manga).dontTransform().centerCrop().circleCrop()
|
.asBitmap().load(manga).dontTransform().centerCrop().circleCrop()
|
||||||
@ -463,18 +466,21 @@ class LibraryUpdateService(
|
|||||||
catch (e: Exception) { }
|
catch (e: Exception) { }
|
||||||
setContentTitle(manga.title.chop(45))
|
setContentTitle(manga.title.chop(45))
|
||||||
color = ContextCompat.getColor(this@LibraryUpdateService, R.color.colorAccentLight)
|
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
|
priority = NotificationCompat.PRIORITY_HIGH
|
||||||
setGroup(Notifications.GROUP_NEW_CHAPTERS)
|
setGroup(Notifications.GROUP_NEW_CHAPTERS)
|
||||||
setContentIntent(
|
setContentIntent(
|
||||||
NotificationReceiver.openChapterPendingActivity(
|
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,
|
NotificationReceiver.markAsReadPendingBroadcast(this@LibraryUpdateService,
|
||||||
manga, chapter, Notifications.GROUP_NEW_CHAPTERS))
|
manga, chapters, Notifications.GROUP_NEW_CHAPTERS))
|
||||||
addAction(R.drawable.ic_glasses_black_24dp, getString(R.string.action_view_chapters),
|
addAction(R.drawable.ic_book_white_24dp, getString(R.string.action_view_chapters),
|
||||||
NotificationReceiver.openChapterPendingActivity(this@LibraryUpdateService,
|
NotificationReceiver.openChapterPendingActivity(this@LibraryUpdateService,
|
||||||
manga, Notifications.GROUP_NEW_CHAPTERS))
|
manga, Notifications.GROUP_NEW_CHAPTERS))
|
||||||
setAutoCancel(true)
|
setAutoCancel(true)
|
||||||
@ -489,7 +495,7 @@ class LibraryUpdateService(
|
|||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || notificationManager
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N || notificationManager
|
||||||
.activeNotifications.find { it.groupKey == Notifications.GROUP_NEW_CHAPTERS } == null) {
|
.activeNotifications.find { it.groupKey == Notifications.GROUP_NEW_CHAPTERS } == null) {
|
||||||
notify(Notifications.ID_NEW_CHAPTERS, notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
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)
|
setLargeIcon(notificationBitmap)
|
||||||
setContentTitle(getString(R.string.notification_new_chapters))
|
setContentTitle(getString(R.string.notification_new_chapters))
|
||||||
color = ContextCompat.getColor(applicationContext, R.color.colorAccentLight)
|
color = ContextCompat.getColor(applicationContext, R.color.colorAccentLight)
|
||||||
|
@ -75,9 +75,9 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
if (notificationId > -1) dismissNotification(
|
if (notificationId > -1) dismissNotification(
|
||||||
context, notificationId, intent.getStringExtra(EXTRA_GROUP_ID)
|
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)
|
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 context context of application
|
||||||
* @param notificationId id of notification
|
* @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 db: DatabaseHelper = Injekt.get()
|
||||||
val chapter = db.getChapter(chapterUrl, mangaaId).executeAsBlocking() ?: return
|
chapterUrls.forEach {
|
||||||
chapter.read = true
|
val chapter = db.getChapter(it, mangaId).executeAsBlocking() ?: return
|
||||||
db.updateChapterProgress(chapter).executeAsBlocking()
|
chapter.read = true
|
||||||
val preferences: PreferencesHelper = Injekt.get()
|
db.updateChapterProgress(chapter).executeAsBlocking()
|
||||||
if (preferences.removeAfterMarkedAsRead()) {
|
val preferences: PreferencesHelper = Injekt.get()
|
||||||
val mangaId = chapter.manga_id ?: return
|
if (preferences.removeAfterMarkedAsRead()) {
|
||||||
val manga = db.getManga(mangaId).executeAsBlocking() ?: return
|
val manga = db.getManga(mangaId).executeAsBlocking() ?: return
|
||||||
val sourceManager: SourceManager = Injekt.get()
|
val sourceManager: SourceManager = Injekt.get()
|
||||||
val source = sourceManager.get(manga.source) ?: return
|
val source = sourceManager.get(manga.source) ?: return
|
||||||
downloadManager.deleteChapters(listOf(chapter), manga, source)
|
downloadManager.deleteChapters(listOf(chapter), manga, source)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,12 +394,12 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
* @param context context of application
|
* @param context context of application
|
||||||
* @param manga manga of chapter
|
* @param manga manga of chapter
|
||||||
*/
|
*/
|
||||||
internal fun markAsReadPendingBroadcast(context: Context, manga: Manga, chapter:
|
internal fun markAsReadPendingBroadcast(context: Context, manga: Manga, chapters:
|
||||||
Chapter, groupId: String):
|
Array<Chapter>, groupId: String):
|
||||||
PendingIntent {
|
PendingIntent {
|
||||||
val newIntent = Intent(context, NotificationReceiver::class.java).apply {
|
val newIntent = Intent(context, NotificationReceiver::class.java).apply {
|
||||||
action = ACTION_MARK_AS_READ
|
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_MANGA_ID, manga.id)
|
||||||
putExtra(EXTRA_NOTIFICATION_ID, manga.id.hashCode())
|
putExtra(EXTRA_NOTIFICATION_ID, manga.id.hashCode())
|
||||||
putExtra(EXTRA_GROUP_ID, groupId)
|
putExtra(EXTRA_GROUP_ID, groupId)
|
||||||
|
@ -23,14 +23,14 @@ object Notifications {
|
|||||||
* Notification channel and ids used by the library updater.
|
* Notification channel and ids used by the library updater.
|
||||||
*/
|
*/
|
||||||
const val CHANNEL_LIBRARY = "library_channel"
|
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.
|
* Notification channel and ids used by the downloader.
|
||||||
*/
|
*/
|
||||||
const val CHANNEL_DOWNLOADER = "downloader_channel"
|
const val CHANNEL_DOWNLOADER = "downloader_channel"
|
||||||
const val ID_DOWNLOAD_CHAPTER = 201
|
const val ID_DOWNLOAD_CHAPTER = -201
|
||||||
const val ID_DOWNLOAD_CHAPTER_ERROR = 202
|
const val ID_DOWNLOAD_CHAPTER_ERROR = -202
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification channel and ids used by the library updater.
|
* Notification channel and ids used by the library updater.
|
||||||
|
BIN
app/src/main/res/drawable-hdpi/ic_tachiyomi_icon.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_tachiyomi_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 979 B |
BIN
app/src/main/res/drawable-mdpi/ic_tachiyomi_icon.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_tachiyomi_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 597 B |
BIN
app/src/main/res/drawable-xhdpi/ic_tachiyomi_icon.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_tachiyomi_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-xxhdpi/ic_tachiyomi_icon.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_tachiyomi_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_tachiyomi_icon.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_tachiyomi_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
@ -43,6 +43,7 @@
|
|||||||
<string name="action_global_search">Global search</string>
|
<string name="action_global_search">Global search</string>
|
||||||
<string name="action_select_all">Select all</string>
|
<string name="action_select_all">Select all</string>
|
||||||
<string name="action_mark_as_read">Mark as read</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_as_unread">Mark as unread</string>
|
||||||
<string name="action_mark_previous_as_read">Mark previous as read</string>
|
<string name="action_mark_previous_as_read">Mark previous as read</string>
|
||||||
<string name="action_download">Download</string>
|
<string name="action_download">Download</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user