|
|
@ -36,35 +36,37 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
private val loadingLock = "loadingLock" |
|
|
|
private val loadingLock = "loadingLock" |
|
|
|
|
|
|
|
|
|
|
|
fun initData(intent: Intent) { |
|
|
|
fun initData(intent: Intent) { |
|
|
|
inBookshelf = intent.getBooleanExtra("inBookshelf", true) |
|
|
|
execute { |
|
|
|
val bookUrl = intent.getStringExtra("bookUrl") |
|
|
|
inBookshelf = intent.getBooleanExtra("inBookshelf", true) |
|
|
|
if (!bookUrl.isNullOrEmpty()) { |
|
|
|
val bookUrl = intent.getStringExtra("bookUrl") |
|
|
|
execute { |
|
|
|
val book = if (!bookUrl.isNullOrEmpty()) { |
|
|
|
App.db.bookDao().getBook(bookUrl)?.let { book -> |
|
|
|
App.db.bookDao().getBook(bookUrl) |
|
|
|
durChapterIndex = book.durChapterIndex |
|
|
|
} else { |
|
|
|
durPageIndex = book.durChapterPos |
|
|
|
App.db.bookDao().getLastReadBook() |
|
|
|
isLocalBook = book.origin == BookType.local |
|
|
|
} |
|
|
|
bookData.postValue(book) |
|
|
|
book?.let { |
|
|
|
bookSource = App.db.bookSourceDao().getBookSource(book.origin) |
|
|
|
durChapterIndex = book.durChapterIndex |
|
|
|
bookSource?.let { |
|
|
|
durPageIndex = book.durChapterPos |
|
|
|
webBook = WebBook(it) |
|
|
|
isLocalBook = book.origin == BookType.local |
|
|
|
} |
|
|
|
bookData.postValue(book) |
|
|
|
val count = App.db.bookChapterDao().getChapterCount(bookUrl) |
|
|
|
bookSource = App.db.bookSourceDao().getBookSource(book.origin) |
|
|
|
if (count == 0) { |
|
|
|
bookSource?.let { |
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
webBook = WebBook(it) |
|
|
|
loadBookInfo(book) |
|
|
|
} |
|
|
|
} else { |
|
|
|
val count = App.db.bookChapterDao().getChapterCount(bookUrl) |
|
|
|
loadChapterList(book) |
|
|
|
if (count == 0) { |
|
|
|
} |
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
|
|
|
|
loadBookInfo(book) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (durChapterIndex > count - 1) { |
|
|
|
loadChapterList(book) |
|
|
|
durChapterIndex = count - 1 |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
chapterSize = count |
|
|
|
if (durChapterIndex > count - 1) { |
|
|
|
chapterListFinish.postValue(true) |
|
|
|
durChapterIndex = count - 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
chapterSize = count |
|
|
|
|
|
|
|
chapterListFinish.postValue(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|