Fixes to new chapters notifcations
Dismissal of notifcations when reading a chapter from a manga
This commit is contained in:
parent
2bb960c24b
commit
ffd1f950d8
@ -454,7 +454,6 @@ class LibraryUpdateService(
|
||||
val manga = it.first
|
||||
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_tachiyomi_icon)
|
||||
try {
|
||||
@ -481,10 +480,10 @@ class LibraryUpdateService(
|
||||
)
|
||||
addAction(R.drawable.ic_glasses_black_24dp, getString(R.string.action_mark_as_read),
|
||||
NotificationReceiver.markAsReadPendingBroadcast(this@LibraryUpdateService,
|
||||
manga, chapters, Notifications.GROUP_NEW_CHAPTERS))
|
||||
manga, chapters, Notifications.ID_NEW_CHAPTERS))
|
||||
addAction(R.drawable.ic_book_white_24dp, getString(R.string.action_view_chapters),
|
||||
NotificationReceiver.openChapterPendingActivity(this@LibraryUpdateService,
|
||||
manga, Notifications.GROUP_NEW_CHAPTERS))
|
||||
manga, Notifications.ID_NEW_CHAPTERS))
|
||||
setAutoCancel(true)
|
||||
}, manga.id.hashCode()))
|
||||
}
|
||||
@ -494,8 +493,6 @@ class LibraryUpdateService(
|
||||
notify(it.second, it.first)
|
||||
}
|
||||
|
||||
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_tachiyomi_icon)
|
||||
setLargeIcon(notificationBitmap)
|
||||
@ -510,7 +507,6 @@ class LibraryUpdateService(
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the progress notification.
|
||||
|
@ -73,7 +73,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
ACTION_MARK_AS_READ -> {
|
||||
val notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1)
|
||||
if (notificationId > -1) dismissNotification(
|
||||
context, notificationId, intent.getStringExtra(EXTRA_GROUP_ID)
|
||||
context, notificationId, intent.getIntExtra(EXTRA_GROUP_ID, 0)
|
||||
)
|
||||
val urls = intent.getStringArrayExtra(EXTRA_CHAPTER_URL) ?: return
|
||||
val mangaId = intent.getLongExtra(EXTRA_MANGA_ID, -1)
|
||||
@ -304,16 +304,23 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
* @param notificationId id of notification
|
||||
* @return [PendingIntent]
|
||||
*/
|
||||
internal fun dismissNotification(context: Context, notificationId: Int, groupId: String?
|
||||
= null) {
|
||||
internal fun dismissNotification(context: Context, notificationId: Int, groupId: Int? =
|
||||
null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val groupKey = context.notificationManager.activeNotifications.find {
|
||||
it.id == notificationId
|
||||
}?.groupKey
|
||||
if (groupId != null && groupId != 0 && groupKey != null && groupKey.isNotEmpty()) {
|
||||
val notifications = context.notificationManager.activeNotifications.filter {
|
||||
it.groupKey == groupKey
|
||||
}
|
||||
if (notifications.size == 2) {
|
||||
context.notificationManager.cancel(groupId)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
context.notificationManager.cancel(notificationId)
|
||||
if (groupId != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val notifications = context.notificationManager.activeNotifications.filter { it
|
||||
.groupKey.contains(groupId) }
|
||||
if (notifications.size == 1) {
|
||||
context.notificationManager.cancel(notifications.first().id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,7 +382,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
* @param context context of application
|
||||
* @param manga manga of chapter
|
||||
*/
|
||||
internal fun openChapterPendingActivity(context: Context, manga: Manga, groupId: String):
|
||||
internal fun openChapterPendingActivity(context: Context, manga: Manga, groupId: Int):
|
||||
PendingIntent {
|
||||
val newIntent =
|
||||
Intent(context, MainActivity::class.java).setAction(MainActivity.SHORTCUT_MANGA)
|
||||
@ -395,7 +402,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
* @param manga manga of chapter
|
||||
*/
|
||||
internal fun markAsReadPendingBroadcast(context: Context, manga: Manga, chapters:
|
||||
Array<Chapter>, groupId: String):
|
||||
Array<Chapter>, groupId: Int):
|
||||
PendingIntent {
|
||||
val newIntent = Intent(context, NotificationReceiver::class.java).apply {
|
||||
action = ACTION_MARK_AS_READ
|
||||
|
@ -257,7 +257,7 @@ class MainActivity : BaseActivity() {
|
||||
private fun handleIntentAction(intent: Intent): Boolean {
|
||||
val notificationId = intent.getIntExtra("notificationId", -1)
|
||||
if (notificationId > -1) NotificationReceiver.dismissNotification(
|
||||
applicationContext, notificationId, intent.getStringExtra("groupId")
|
||||
applicationContext, notificationId, intent.getIntExtra("groupId", 0)
|
||||
)
|
||||
when (intent.action) {
|
||||
SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_drawer_library)
|
||||
|
@ -72,7 +72,7 @@ class MangaController : RxController, TabbedController {
|
||||
val notificationId = bundle.getInt("notificationId", -1)
|
||||
val context = applicationContext ?: return
|
||||
if (notificationId > -1) NotificationReceiver.dismissNotification(
|
||||
context, notificationId, bundle.getString("groupId", "")
|
||||
context, notificationId, bundle.getInt("groupId", 0)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
@ -152,7 +153,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
NotificationReceiver.dismissNotification(this, manga.hashCode(), Notifications.ID_NEW_CHAPTERS)
|
||||
if (chapter > -1) presenter.init(manga, chapter)
|
||||
else presenter.init(manga, chapterUrl)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user