|
|
@ -31,31 +31,30 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) |
|
|
|
|
|
|
|
|
|
|
|
fun upChapterList() { |
|
|
|
fun upChapterList() { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
App.db.bookDao().getRecentRead().map { book -> |
|
|
|
App.db.bookDao().getRecentRead().forEach { book -> |
|
|
|
if (book.origin != BookType.local) { |
|
|
|
if (book.origin != BookType.local) { |
|
|
|
val bookSource = App.db.bookSourceDao().getBookSource(book.origin) |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
bookSource?.let { |
|
|
|
|
|
|
|
synchronized(this) { |
|
|
|
synchronized(this) { |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
} |
|
|
|
} |
|
|
|
WebBook(bookSource).getChapterList(book) |
|
|
|
WebBook(bookSource).getChapterList(book) |
|
|
|
.onSuccess(IO) { |
|
|
|
.onSuccess(IO) { |
|
|
|
it?.let { |
|
|
|
it?.let { |
|
|
|
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()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.onError { |
|
|
|
.onError { |
|
|
|
it.printStackTrace() |
|
|
|
it.printStackTrace() |
|
|
|
} |
|
|
|
} |
|
|
|
.onFinally { |
|
|
|
.onFinally { |
|
|
|
synchronized(this) { |
|
|
|
synchronized(this) { |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
delay(50) |
|
|
|
delay(50) |
|
|
|