diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index 291cb666a..71b47f9f9 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -143,6 +143,10 @@ object CacheBook { val successCount get() = successDownloadSet.size val errorCount get() = errorDownloadMap.size + init { + postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) + } + @Synchronized fun isRun(): Boolean { return waitDownloadSet.size > 0 || onDownloadSet.size > 0 @@ -214,9 +218,9 @@ object CacheBook { @Synchronized private fun onFinally() { if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { - postEvent(EventBus.UP_DOWNLOAD, "") cacheBookMap.remove(book.bookUrl) } + postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) } /** @@ -224,6 +228,7 @@ object CacheBook { */ @Synchronized fun download(scope: CoroutineScope, context: CoroutineContext) { + postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) val chapterIndex = waitDownloadSet.firstOrNull() if (chapterIndex == null) { if (onDownloadSet.isEmpty()) { @@ -276,6 +281,7 @@ object CacheBook { if (onDownloadSet.contains(chapter.index)) { return } + postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) onDownloadSet.add(chapter.index) waitDownloadSet.remove(chapter.index) WebBook.getContent(scope, bookSource, book, chapter) @@ -288,9 +294,7 @@ object CacheBook { }.onCancel { onCancel(chapter.index) }.onFinally { - if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { - postEvent(EventBus.UP_DOWNLOAD, "") - } + postEvent(EventBus.UP_DOWNLOAD, book.bookUrl) } } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 26d3e2b90..5b5b1c74b 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -232,12 +232,15 @@ class CacheActivity : VMBaseActivity() } menu?.applyTint(this) } - adapter.notifyItemRangeChanged(0, adapter.itemCount, true) + adapter.getItems().forEachIndexed { index, book -> + if (book.bookUrl == it) { + adapter.notifyItemChanged(index, true) + } + } } observeEvent(EventBus.SAVE_CONTENT) { adapter.cacheChapters[it.bookUrl]?.add(it.url) } - postEventDelay(EventBus.UP_DOWNLOAD, "", 100) } override fun export(position: Int) { diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index ef0dcab63..2d126a25b 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -186,12 +186,6 @@ class MainViewModel(application: Application) : BaseViewModel(application) { private fun cacheBook() { cacheBookJob?.cancel() cacheBookJob = viewModelScope.launch(upTocPool) { - launch { - while (isActive) { - postEvent(EventBus.UP_DOWNLOAD, "") - delay(1000) - } - } while (isActive) { if (CacheBookService.isRun || !CacheBook.isRun) { cacheBookJob?.cancel()