pull/67/head
kunfei 5 years ago
parent f8d6aafac1
commit 8990bba2db
  1. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  3. 7
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -60,6 +60,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override val viewModel: ReadBookViewModel override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java) get() = getViewModel(ReadBookViewModel::class.java)
override val isInitFinish: Boolean
get() = viewModel.isInitFinish
private val requestCodeChapterList = 568 private val requestCodeChapterList = 568
private val requestCodeEditSource = 111 private val requestCodeEditSource = 111
private val requestCodeReplace = 31242 private val requestCodeReplace = 31242

@ -19,6 +19,8 @@ import kotlinx.coroutines.withContext
class ReadBookViewModel(application: Application) : BaseViewModel(application) { class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var isInitFinish = false
fun initData(intent: Intent) { fun initData(intent: Intent) {
execute { execute {
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true) ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
@ -37,6 +39,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
private fun initBook(book: Book) { private fun initBook(book: Book) {
if (ReadBook.book?.bookUrl != book.bookUrl) { if (ReadBook.book?.bookUrl != book.bookUrl) {
ReadBook.resetData(book) ReadBook.resetData(book)
isInitFinish = true
val count = App.db.bookChapterDao().getChapterCount(book.bookUrl) val count = App.db.bookChapterDao().getChapterCount(book.bookUrl)
if (count == 0) { if (count == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
@ -55,6 +58,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
ReadBook.saveRead() ReadBook.saveRead()
} }
} else { } else {
isInitFinish = true
ReadBook.titleDate.postValue(book.name) ReadBook.titleDate.postValue(book.name)
if (ReadBook.chapterSize == 0) { if (ReadBook.chapterSize == 0) {
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {

@ -191,15 +191,15 @@ class PageView(context: Context, attrs: AttributeSet) :
} }
override fun getCurrentChapter(): TextChapter? { override fun getCurrentChapter(): TextChapter? {
return ReadBook.textChapter(0) return if (callBack?.isInitFinish == true) ReadBook.textChapter(0) else null
} }
override fun getNextChapter(): TextChapter? { override fun getNextChapter(): TextChapter? {
return ReadBook.textChapter(1) return if (callBack?.isInitFinish == true) ReadBook.textChapter(1) else null
} }
override fun getPreviousChapter(): TextChapter? { override fun getPreviousChapter(): TextChapter? {
return ReadBook.textChapter(-1) return if (callBack?.isInitFinish == true) ReadBook.textChapter(-1) else null
} }
override fun hasNextChapter(): Boolean { override fun hasNextChapter(): Boolean {
@ -244,5 +244,6 @@ class PageView(context: Context, attrs: AttributeSet) :
*/ */
fun clickCenter() fun clickCenter()
val isInitFinish: Boolean
} }
} }

Loading…
Cancel
Save