From 79bc1290aedb376fdbf34a19102765290847e44d Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 17 Feb 2020 16:20:12 -0500 Subject: [PATCH] Perform mark as read action in IO coroutine scope to avoid freezing app --- .../data/notification/NotificationReceiver.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index c073bfb4e3..11f5065228 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.notificationManager @@ -170,16 +171,22 @@ class NotificationReceiver : BroadcastReceiver() { val preferences: PreferencesHelper = Injekt.get() val sourceManager: SourceManager = Injekt.get() - chapterUrls.mapNotNull { db.getChapter(it, mangaId).executeAsBlocking() } - .forEach { - it.read = true - db.updateChapterProgress(it).executeAsBlocking() - if (preferences.removeAfterMarkedAsRead()) { - val manga = db.getManga(mangaId).executeAsBlocking() ?: return - val source = sourceManager.get(manga.source) ?: return - downloadManager.deleteChapters(listOf(it), manga, source) + launchIO { + chapterUrls.mapNotNull { db.getChapter(it, mangaId).executeAsBlocking() } + .forEach { + it.read = true + db.updateChapterProgress(it).executeAsBlocking() + if (preferences.removeAfterMarkedAsRead()) { + val manga = db.getManga(mangaId).executeAsBlocking() + if (manga != null) { + val source = sourceManager.get(manga.source) + if (source != null) { + downloadManager.deleteChapters(listOf(it), manga, source) + } + } + } } - } + } } companion object {