|
|
@ -58,6 +58,7 @@ class DownloadService : BaseService() { |
|
|
|
intent.getIntExtra("start", 0), |
|
|
|
intent.getIntExtra("start", 0), |
|
|
|
intent.getIntExtra("end", 0) |
|
|
|
intent.getIntExtra("end", 0) |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
IntentAction.remove -> removeDownload(intent.getStringExtra("bookUrl")) |
|
|
|
IntentAction.stop -> stopDownload() |
|
|
|
IntentAction.stop -> stopDownload() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -91,6 +92,11 @@ class DownloadService : BaseService() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun removeDownload(bookUrl: String?) { |
|
|
|
|
|
|
|
downloadMap.remove(bookUrl) |
|
|
|
|
|
|
|
finalMap.remove(bookUrl) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun download() { |
|
|
|
private fun download() { |
|
|
|
val task = Coroutine.async(this, context = searchPool) { |
|
|
|
val task = Coroutine.async(this, context = searchPool) { |
|
|
|
downloadMap.forEach { entry -> |
|
|
|
downloadMap.forEach { entry -> |
|
|
@ -102,30 +108,37 @@ class DownloadService : BaseService() { |
|
|
|
val webBook = WebBook(bookSource) |
|
|
|
val webBook = WebBook(bookSource) |
|
|
|
entry.value.forEach { chapter -> |
|
|
|
entry.value.forEach { chapter -> |
|
|
|
if (!isActive) return@async |
|
|
|
if (!isActive) return@async |
|
|
|
if (!BookHelp.hasContent(book, chapter)) { |
|
|
|
if (downloadMap.containsKey(book.bookUrl)) { |
|
|
|
webBook.getContent(book, chapter, scope = this, context = searchPool) |
|
|
|
if (!BookHelp.hasContent(book, chapter)) { |
|
|
|
.onStart { |
|
|
|
webBook.getContent( |
|
|
|
notificationContent = chapter.title |
|
|
|
book, |
|
|
|
} |
|
|
|
chapter, |
|
|
|
.onSuccess(IO) { content -> |
|
|
|
scope = this, |
|
|
|
content?.let { |
|
|
|
context = searchPool |
|
|
|
BookHelp.saveContent(book, chapter, content) |
|
|
|
) |
|
|
|
|
|
|
|
.onStart { |
|
|
|
|
|
|
|
notificationContent = chapter.title |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.onSuccess(IO) { content -> |
|
|
|
|
|
|
|
content?.let { |
|
|
|
|
|
|
|
BookHelp.saveContent(book, chapter, content) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.onFinally(IO) { |
|
|
|
.onFinally(IO) { |
|
|
|
synchronized(this@DownloadService) { |
|
|
|
synchronized(this@DownloadService) { |
|
|
|
val chapterMap = |
|
|
|
val chapterMap = |
|
|
|
finalMap[book.bookUrl] |
|
|
|
finalMap[book.bookUrl] |
|
|
|
?: linkedSetOf<BookChapter>().apply { |
|
|
|
?: linkedSetOf<BookChapter>().apply { |
|
|
|
finalMap[book.bookUrl] = this |
|
|
|
finalMap[book.bookUrl] = this |
|
|
|
} |
|
|
|
} |
|
|
|
chapterMap.add(chapter) |
|
|
|
chapterMap.add(chapter) |
|
|
|
if (chapterMap.size == entry.value.size) { |
|
|
|
if (chapterMap.size == entry.value.size) { |
|
|
|
downloadMap.remove(book.bookUrl) |
|
|
|
downloadMap.remove(book.bookUrl) |
|
|
|
finalMap.remove(book.bookUrl) |
|
|
|
finalMap.remove(book.bookUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|