From d9c55c783df9ef035d303df3b14efb702a0206c5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 5 Jul 2020 11:41:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/DownloadService.kt | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 845f99fc0..2efe2985d 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -89,10 +89,15 @@ class DownloadService : BaseService() { private fun getBook(bookUrl: String): Book? { var book = bookMap[bookUrl] if (book == null) { - book = App.db.bookDao().getBook(bookUrl) - } - if (book == null) { - removeDownload(bookUrl) + synchronized(this) { + book = bookMap[bookUrl] + if (book == null) { + book = App.db.bookDao().getBook(bookUrl) + } + if (book == null) { + removeDownload(bookUrl) + } + } } return book } @@ -100,13 +105,18 @@ class DownloadService : BaseService() { private fun getWebBook(bookUrl: String, origin: String): WebBook? { var webBook = webBookMap[origin] if (webBook == null) { - App.db.bookSourceDao().getBookSource(origin)?.let { - webBook = WebBook(it) + synchronized(this) { + webBook = webBookMap[origin] + if (webBook == null) { + App.db.bookSourceDao().getBookSource(origin)?.let { + webBook = WebBook(it) + } + } + if (webBook == null) { + removeDownload(bookUrl) + } } } - if (webBook == null) { - removeDownload(bookUrl) - } return webBook }