|
|
@ -68,44 +68,43 @@ class MainViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
private fun updateToc() { |
|
|
|
private fun updateToc() { |
|
|
|
synchronized(this) { |
|
|
|
bookMap.forEach { bookEntry -> |
|
|
|
bookMap.forEach { bookEntry -> |
|
|
|
if (!updateList.contains(bookEntry.key)) { |
|
|
|
if (!updateList.contains(bookEntry.key)) { |
|
|
|
val book = bookEntry.value |
|
|
|
val book = bookEntry.value |
|
|
|
synchronized(this) { |
|
|
|
synchronized(this) { |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
postEvent(EventBus.UP_BOOK, book.bookUrl) |
|
|
|
postEvent(EventBus.UP_BOOK, book.bookUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
val webBook = WebBook(bookSource) |
|
|
|
val webBook = WebBook(bookSource) |
|
|
|
webBook.getChapterList(book, context = upTocPool) |
|
|
|
webBook.getChapterList(book, context = upTocPool) |
|
|
|
.timeout(300000) |
|
|
|
.timeout(300000) |
|
|
|
.onSuccess(IO) { |
|
|
|
.onSuccess(IO) { |
|
|
|
App.db.bookDao().update(book) |
|
|
|
App.db.bookDao().update(book) |
|
|
|
App.db.bookChapterDao().delByBook(book.bookUrl) |
|
|
|
App.db.bookChapterDao().delByBook(book.bookUrl) |
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
cacheBook(webBook, book) |
|
|
|
cacheBook(webBook, book) |
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
it.printStackTrace() |
|
|
|
it.printStackTrace() |
|
|
|
} |
|
|
|
} |
|
|
|
.onFinally { |
|
|
|
.onFinally { |
|
|
|
synchronized(this) { |
|
|
|
synchronized(this) { |
|
|
|
bookMap.remove(bookEntry.key) |
|
|
|
bookMap.remove(bookEntry.key) |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
postEvent(EventBus.UP_BOOK, book.bookUrl) |
|
|
|
postEvent(EventBus.UP_BOOK, book.bookUrl) |
|
|
|
upNext() |
|
|
|
upNext() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} ?: synchronized(this) { |
|
|
|
} |
|
|
|
bookMap.remove(bookEntry.key) |
|
|
|
} ?: synchronized(this) { |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
bookMap.remove(bookEntry.key) |
|
|
|
postEvent(EventBus.UP_BOOK, book.bookUrl) |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
upNext() |
|
|
|
postEvent(EventBus.UP_BOOK, book.bookUrl) |
|
|
|
} |
|
|
|
upNext() |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|