优化离线下载

pull/275/head
gedoor 4 years ago
parent 81d7fb6ebe
commit 5aa1cc0884
  1. 18
      app/src/main/java/io/legado/app/service/DownloadService.kt

@ -23,6 +23,8 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.isActive
import org.jetbrains.anko.toast
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.Executors
class DownloadService : BaseService() {
@ -32,12 +34,12 @@ class DownloadService : BaseService() {
private var tasks = CompositeCoroutine()
private val handler = Handler()
private var runnable: Runnable = Runnable { upDownload() }
private val bookMap = hashMapOf<String, Book>()
private val webBookMap = hashMapOf<String, WebBook>()
private val downloadMap = hashMapOf<String, LinkedHashSet<BookChapter>>()
private val downloadCount = hashMapOf<String, DownloadCount>()
private val finalMap = hashMapOf<String, LinkedHashSet<BookChapter>>()
private val downloadingList = arrayListOf<String>()
private val bookMap = ConcurrentHashMap<String, Book>()
private val webBookMap = ConcurrentHashMap<String, WebBook>()
private val downloadMap = ConcurrentHashMap<String, CopyOnWriteArraySet<BookChapter>>()
private val downloadCount = ConcurrentHashMap<String, DownloadCount>()
private val finalMap = ConcurrentHashMap<String, CopyOnWriteArraySet<BookChapter>>()
private val downloadingList = CopyOnWriteArraySet<String>()
@Volatile
private var downloadingCount = 0
@ -131,7 +133,7 @@ class DownloadService : BaseService() {
execute {
App.db.bookChapterDao().getChapterList(bookUrl, start, end).let {
if (it.isNotEmpty()) {
val chapters = linkedSetOf<BookChapter>()
val chapters = CopyOnWriteArraySet<BookChapter>()
chapters.addAll(it)
downloadMap[bookUrl] = chapters
}
@ -202,7 +204,7 @@ class DownloadService : BaseService() {
}
val chapterMap =
finalMap[book.bookUrl]
?: linkedSetOf<BookChapter>().apply {
?: CopyOnWriteArraySet<BookChapter>().apply {
finalMap[book.bookUrl] = this
}
chapterMap.add(bookChapter)

Loading…
Cancel
Save