|
|
|
@ -46,11 +46,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
private fun initBook(book: Book) { |
|
|
|
|
if (ReadBook.book?.bookUrl != book.bookUrl) { |
|
|
|
|
ReadBook.resetData(book) |
|
|
|
|
isInitFinish = true |
|
|
|
|
if (!book.isLocalBook() && ReadBook.webBook == null) { |
|
|
|
|
autoChangeSource(book.name, book.author) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
isInitFinish = true |
|
|
|
|
ReadBook.chapterSize = App.db.bookChapterDao().getChapterCount(book.bookUrl) |
|
|
|
|
if (ReadBook.chapterSize == 0) { |
|
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
@ -65,6 +65,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
ReadBook.loadContent(resetPageOffset = true) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
ReadBook.book = book |
|
|
|
|
if (ReadBook.durChapterIndex != book.durChapterIndex) { |
|
|
|
|
ReadBook.durChapterIndex = book.durChapterIndex |
|
|
|
|
ReadBook.durPageIndex = book.durChapterPos |
|
|
|
@ -72,7 +73,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
ReadBook.curTextChapter = null |
|
|
|
|
ReadBook.nextTextChapter = null |
|
|
|
|
} |
|
|
|
|
ReadBook.book!!.group = book.group |
|
|
|
|
ReadBook.titleDate.postValue(book.name) |
|
|
|
|
ReadBook.upWebBook(book) |
|
|
|
|
isInitFinish = true |
|
|
|
@ -160,20 +160,24 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
execute { |
|
|
|
|
ReadBook.upMsg(null) |
|
|
|
|
ReadBook.book?.changeTo(newBook) |
|
|
|
|
ReadBook.book = newBook |
|
|
|
|
App.db.bookSourceDao().getBookSource(newBook.origin)?.let { |
|
|
|
|
ReadBook.webBook = WebBook(it) |
|
|
|
|
} |
|
|
|
|
ReadBook.prevTextChapter = null |
|
|
|
|
ReadBook.curTextChapter = null |
|
|
|
|
ReadBook.nextTextChapter = null |
|
|
|
|
withContext(Main) { |
|
|
|
|
ReadBook.callBack?.upContent() |
|
|
|
|
} |
|
|
|
|
ReadBook.book = newBook |
|
|
|
|
App.db.bookSourceDao().getBookSource(newBook.origin)?.let { |
|
|
|
|
ReadBook.webBook = WebBook(it) |
|
|
|
|
} |
|
|
|
|
if (newBook.tocUrl.isEmpty()) { |
|
|
|
|
loadBookInfo(newBook) { upChangeDurChapterIndex(newBook, it) } |
|
|
|
|
loadBookInfo(newBook) { |
|
|
|
|
upChangeDurChapterIndex(newBook, it) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
loadChapterList(newBook) { upChangeDurChapterIndex(newBook, it) } |
|
|
|
|
loadChapterList(newBook) { |
|
|
|
|
upChangeDurChapterIndex(newBook, it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -188,8 +192,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
.searchBookSuspend(this, name, variableBook = variableBook) |
|
|
|
|
.getOrNull(0)?.let { |
|
|
|
|
if (it.name == name && (it.author == author || author == "")) { |
|
|
|
|
changeTo(it.toBook()) |
|
|
|
|
return@forEach |
|
|
|
|
val book = it.toBook() |
|
|
|
|
book.upInfoFromOld(ReadBook.book) |
|
|
|
|
changeTo(book) |
|
|
|
|
return@execute |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e: Exception) { |
|
|
|
@ -215,6 +221,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
App.db.bookDao().update(book) |
|
|
|
|
App.db.bookChapterDao().insert(*chapters.toTypedArray()) |
|
|
|
|
ReadBook.chapterSize = chapters.size |
|
|
|
|
ReadBook.upMsg(null) |
|
|
|
|
ReadBook.loadContent(resetPageOffset = true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|