mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Using a globalscope instead of current scope for showing new chapters notification
Since it may get called after a cancelled job
This commit is contained in:
parent
7d5fa5a603
commit
3a74c7918d
1 changed files with 88 additions and 87 deletions
|
@ -26,6 +26,8 @@ import eu.kanade.tachiyomi.util.lang.chop
|
|||
import eu.kanade.tachiyomi.util.system.notification
|
||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.ArrayList
|
||||
|
||||
|
@ -119,7 +121,8 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
*
|
||||
* @param updates a list of manga with new updates.
|
||||
*/
|
||||
suspend fun showResultNotification(updates: Map<LibraryManga, Array<Chapter>>) {
|
||||
fun showResultNotification(updates: Map<LibraryManga, Array<Chapter>>) {
|
||||
GlobalScope.launch {
|
||||
val notifications = ArrayList<Pair<Notification, Int>>()
|
||||
updates.forEach {
|
||||
val manga = it.key
|
||||
|
@ -130,14 +133,14 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
try {
|
||||
val request = GetRequest.Builder(context).data(manga)
|
||||
.networkCachePolicy(CachePolicy.DISABLED)
|
||||
.transformations(CircleCropTransformation()).size(width = ICON_SIZE, height = ICON_SIZE)
|
||||
.build()
|
||||
.transformations(CircleCropTransformation())
|
||||
.size(width = ICON_SIZE, height = ICON_SIZE).build()
|
||||
|
||||
Coil.imageLoader(context)
|
||||
.execute(request).drawable?.let { drawable ->
|
||||
Coil.imageLoader(context).execute(request).drawable?.let { drawable ->
|
||||
setLargeIcon((drawable as BitmapDrawable).bitmap)
|
||||
}
|
||||
} catch (e: Exception) { }
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
|
||||
setContentTitle(manga.title)
|
||||
color = ContextCompat.getColor(context, R.color.colorAccent)
|
||||
|
@ -159,17 +162,17 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
)
|
||||
)
|
||||
addAction(
|
||||
R.drawable.ic_eye_24dp, context.getString(R.string.mark_as_read),
|
||||
R.drawable.ic_eye_24dp,
|
||||
context.getString(R.string.mark_as_read),
|
||||
NotificationReceiver.markAsReadPendingBroadcast(
|
||||
context,
|
||||
manga, chapters, Notifications.ID_NEW_CHAPTERS
|
||||
context, manga, chapters, Notifications.ID_NEW_CHAPTERS
|
||||
)
|
||||
)
|
||||
addAction(
|
||||
R.drawable.ic_book_24dp, context.getString(R.string.view_chapters),
|
||||
R.drawable.ic_book_24dp,
|
||||
context.getString(R.string.view_chapters),
|
||||
NotificationReceiver.openChapterPendingActivity(
|
||||
context,
|
||||
manga, Notifications.ID_NEW_CHAPTERS
|
||||
context, manga, Notifications.ID_NEW_CHAPTERS
|
||||
)
|
||||
)
|
||||
setAutoCancel(true)
|
||||
|
@ -178,8 +181,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
|
||||
NotificationManagerCompat.from(context).apply {
|
||||
|
||||
notify(
|
||||
Notifications.ID_NEW_CHAPTERS,
|
||||
notify(Notifications.ID_NEW_CHAPTERS,
|
||||
context.notification(Notifications.CHANNEL_NEW_CHAPTERS) {
|
||||
setSmallIcon(R.drawable.ic_tachi)
|
||||
setLargeIcon(notificationBitmap)
|
||||
|
@ -188,9 +190,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
if (updates.size > 1) {
|
||||
setContentText(
|
||||
context.resources.getQuantityString(
|
||||
R.plurals
|
||||
.for_n_titles,
|
||||
updates.size, updates.size
|
||||
R.plurals.for_n_titles, updates.size, updates.size
|
||||
)
|
||||
)
|
||||
setStyle(
|
||||
|
@ -215,6 +215,7 @@ class LibraryUpdateNotifier(private val context: Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the progress notification.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue