|
|
@ -5,7 +5,6 @@ import android.content.Intent |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.constant.BookType |
|
|
|
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.BookHelp |
|
|
@ -34,30 +33,38 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initBook(book: Book) { |
|
|
|
private fun initBook(book: Book) { |
|
|
|
ReadBook.book = book |
|
|
|
if (ReadBook.book?.bookUrl != book.bookUrl) { |
|
|
|
ReadBook.titleDate.postValue(book.name) |
|
|
|
ReadBook.resetData(book) |
|
|
|
ReadBook.durChapterIndex = book.durChapterIndex |
|
|
|
val count = App.db.bookChapterDao().getChapterCount(book.bookUrl) |
|
|
|
ReadBook.durPageIndex = book.durChapterPos |
|
|
|
if (count == 0) { |
|
|
|
ReadBook.isLocalBook = book.origin == BookType.local |
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { |
|
|
|
loadBookInfo(book) |
|
|
|
ReadBook.webBook = WebBook(it) |
|
|
|
} else { |
|
|
|
} |
|
|
|
loadChapterList(book) |
|
|
|
val count = App.db.bookChapterDao().getChapterCount(book.bookUrl) |
|
|
|
} |
|
|
|
if (count == 0) { |
|
|
|
|
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
|
|
|
|
loadBookInfo(book) |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
loadChapterList(book) |
|
|
|
if (ReadBook.durChapterIndex > count - 1) { |
|
|
|
|
|
|
|
ReadBook.durChapterIndex = count - 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ReadBook.chapterSize = count |
|
|
|
|
|
|
|
ReadBook.callBack?.loadContent() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (ReadBook.inBookshelf) { |
|
|
|
|
|
|
|
ReadBook.saveRead() |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (ReadBook.durChapterIndex > count - 1) { |
|
|
|
ReadBook.titleDate.postValue(book.name) |
|
|
|
ReadBook.durChapterIndex = count - 1 |
|
|
|
if (ReadBook.chapterSize == 0) { |
|
|
|
|
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
|
|
|
|
loadBookInfo(book) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
loadChapterList(book) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (ReadBook.curTextChapter != null) { |
|
|
|
|
|
|
|
ReadBook.callBack?.upContent() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ReadBook.chapterSize = count |
|
|
|
|
|
|
|
ReadBook.callBack?.loadContent() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (ReadBook.inBookshelf) { |
|
|
|
|
|
|
|
ReadBook.saveRead() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|