|
|
|
@ -24,10 +24,10 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
execute { |
|
|
|
|
val name = intent.getStringExtra("name") ?: "" |
|
|
|
|
val author = intent.getStringExtra("author") ?: "" |
|
|
|
|
App.db.bookDao().getBook(name, author)?.let { book -> |
|
|
|
|
App.db.bookDao.getBook(name, author)?.let { book -> |
|
|
|
|
inBookshelf = true |
|
|
|
|
setBook(book) |
|
|
|
|
} ?: App.db.searchBookDao().getFirstByNameAuthor(name, author)?.toBook()?.let { book -> |
|
|
|
|
} ?: App.db.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let { book -> |
|
|
|
|
setBook(book) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -39,7 +39,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
|
loadBookInfo(book) |
|
|
|
|
} else { |
|
|
|
|
val chapterList = App.db.bookChapterDao().getChapterList(book.bookUrl) |
|
|
|
|
val chapterList = App.db.bookChapterDao.getChapterList(book.bookUrl) |
|
|
|
|
if (chapterList.isNotEmpty()) { |
|
|
|
|
chapterListData.postValue(chapterList) |
|
|
|
|
} else { |
|
|
|
@ -56,12 +56,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
if (book.isLocalBook()) { |
|
|
|
|
loadChapter(book, changeDruChapterIndex) |
|
|
|
|
} else { |
|
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
|
App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource -> |
|
|
|
|
WebBook(bookSource).getBookInfo(book, this, canReName = canReName) |
|
|
|
|
.onSuccess(IO) { |
|
|
|
|
bookData.postValue(book) |
|
|
|
|
if (inBookshelf) { |
|
|
|
|
App.db.bookDao().update(book) |
|
|
|
|
App.db.bookDao.update(book) |
|
|
|
|
} |
|
|
|
|
loadChapter(it, changeDruChapterIndex) |
|
|
|
|
}.onError { |
|
|
|
@ -82,18 +82,18 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
execute { |
|
|
|
|
if (book.isLocalBook()) { |
|
|
|
|
LocalBook.getChapterList(book).let { |
|
|
|
|
App.db.bookDao().update(book) |
|
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
|
App.db.bookDao.update(book) |
|
|
|
|
App.db.bookChapterDao.insert(*it.toTypedArray()) |
|
|
|
|
chapterListData.postValue(it) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
|
App.db.bookSourceDao.getBookSource(book.origin)?.let { bookSource -> |
|
|
|
|
WebBook(bookSource).getChapterList(book, this) |
|
|
|
|
.onSuccess(IO) { |
|
|
|
|
if (it.isNotEmpty()) { |
|
|
|
|
if (inBookshelf) { |
|
|
|
|
App.db.bookDao().update(book) |
|
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
|
App.db.bookDao.update(book) |
|
|
|
|
App.db.bookChapterDao.insert(*it.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
if (changeDruChapterIndex == null) { |
|
|
|
|
chapterListData.postValue(it) |
|
|
|
@ -119,7 +119,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
fun loadGroup(groupId: Long, success: ((groupNames: String?) -> Unit)) { |
|
|
|
|
execute { |
|
|
|
|
App.db.bookGroupDao().getGroupNames(groupId).joinToString(",") |
|
|
|
|
App.db.bookGroupDao.getGroupNames(groupId).joinToString(",") |
|
|
|
|
}.onSuccess { |
|
|
|
|
success.invoke(it) |
|
|
|
|
} |
|
|
|
@ -161,8 +161,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
) |
|
|
|
|
book.durChapterTitle = chapters[book.durChapterIndex].title |
|
|
|
|
if (inBookshelf) { |
|
|
|
|
App.db.bookDao().update(book) |
|
|
|
|
App.db.bookChapterDao().insert(*chapters.toTypedArray()) |
|
|
|
|
App.db.bookDao.update(book) |
|
|
|
|
App.db.bookChapterDao.insert(*chapters.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
bookData.postValue(book) |
|
|
|
|
chapterListData.postValue(chapters) |
|
|
|
@ -173,13 +173,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
execute { |
|
|
|
|
bookData.value?.let { book -> |
|
|
|
|
if (book.order == 0) { |
|
|
|
|
book.order = App.db.bookDao().maxOrder + 1 |
|
|
|
|
book.order = App.db.bookDao.maxOrder + 1 |
|
|
|
|
} |
|
|
|
|
App.db.bookDao().getBook(book.name, book.author)?.let { |
|
|
|
|
App.db.bookDao.getBook(book.name, book.author)?.let { |
|
|
|
|
book.durChapterPos = it.durChapterPos |
|
|
|
|
book.durChapterTitle = it.durChapterTitle |
|
|
|
|
} |
|
|
|
|
App.db.bookDao().insert(book) |
|
|
|
|
App.db.bookDao.insert(book) |
|
|
|
|
if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) { |
|
|
|
|
ReadBook.book = book |
|
|
|
|
} |
|
|
|
@ -192,7 +192,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
fun saveChapterList(success: (() -> Unit)?) { |
|
|
|
|
execute { |
|
|
|
|
chapterListData.value?.let { |
|
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
|
App.db.bookChapterDao.insert(*it.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
}.onSuccess { |
|
|
|
|
success?.invoke() |
|
|
|
@ -203,16 +203,16 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
execute { |
|
|
|
|
bookData.value?.let { book -> |
|
|
|
|
if (book.order == 0) { |
|
|
|
|
book.order = App.db.bookDao().maxOrder + 1 |
|
|
|
|
book.order = App.db.bookDao.maxOrder + 1 |
|
|
|
|
} |
|
|
|
|
App.db.bookDao().getBook(book.name, book.author)?.let { |
|
|
|
|
App.db.bookDao.getBook(book.name, book.author)?.let { |
|
|
|
|
book.durChapterPos = it.durChapterPos |
|
|
|
|
book.durChapterTitle = it.durChapterTitle |
|
|
|
|
} |
|
|
|
|
App.db.bookDao().insert(book) |
|
|
|
|
App.db.bookDao.insert(book) |
|
|
|
|
} |
|
|
|
|
chapterListData.value?.let { |
|
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
|
App.db.bookChapterDao.insert(*it.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
inBookshelf = true |
|
|
|
|
}.onSuccess { |
|
|
|
@ -246,7 +246,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
fun upEditBook() { |
|
|
|
|
bookData.value?.let { |
|
|
|
|
App.db.bookDao().getBook(it.bookUrl)?.let { book -> |
|
|
|
|
App.db.bookDao.getBook(it.bookUrl)?.let { book -> |
|
|
|
|
bookData.postValue(book) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|