|
|
|
@ -19,14 +19,12 @@ import kotlinx.coroutines.delay |
|
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
|
object CacheBook { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
val cacheBookMap = ConcurrentHashMap<String, CacheBook>() |
|
|
|
|
val cacheBookMap = ConcurrentHashMap<String, CacheBookModel>() |
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
|
fun getOrCreate(bookUrl: String): CacheBook? { |
|
|
|
|
fun getOrCreate(bookUrl: String): CacheBookModel? { |
|
|
|
|
val book = appDb.bookDao.getBook(bookUrl) ?: return null |
|
|
|
|
val bookSource = appDb.bookSourceDao.getBookSource(book.origin) ?: return null |
|
|
|
|
var cacheBook = cacheBookMap[bookUrl] |
|
|
|
@ -36,13 +34,13 @@ class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
|
cacheBook.book = book |
|
|
|
|
return cacheBook |
|
|
|
|
} |
|
|
|
|
cacheBook = CacheBook(bookSource, book) |
|
|
|
|
cacheBook = CacheBookModel(bookSource, book) |
|
|
|
|
cacheBookMap[bookUrl] = cacheBook |
|
|
|
|
return cacheBook |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
|
fun getOrCreate(bookSource: BookSource, book: Book): CacheBook { |
|
|
|
|
fun getOrCreate(bookSource: BookSource, book: Book): CacheBookModel { |
|
|
|
|
var cacheBook = cacheBookMap[book.bookUrl] |
|
|
|
|
if (cacheBook != null) { |
|
|
|
|
//存在时更新,书源可能会变化,必须更新 |
|
|
|
@ -50,7 +48,7 @@ class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
|
cacheBook.book = book |
|
|
|
|
return cacheBook |
|
|
|
|
} |
|
|
|
|
cacheBook = CacheBook(bookSource, book) |
|
|
|
|
cacheBook = CacheBookModel(bookSource, book) |
|
|
|
|
cacheBookMap[book.bookUrl] = cacheBook |
|
|
|
|
return cacheBook |
|
|
|
|
} |
|
|
|
@ -126,7 +124,8 @@ class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
|
} |
|
|
|
|
return count |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class CacheBookModel(var bookSource: BookSource, var book: Book) { |
|
|
|
|
|
|
|
|
|
private val waitDownloadSet = hashSetOf<Int>() |
|
|
|
|
private val onDownloadSet = hashSetOf<Int>() |
|
|
|
@ -285,3 +284,5 @@ class CacheBook(var bookSource: BookSource, var book: Book) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |