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
get() = getViewModel(ReadBookViewModel::class.java)
override val isInitFinish: Boolean
get() = viewModel.isInitFinish
private val requestCodeChapterList = 568
private val requestCodeEditSource = 111
private val requestCodeReplace = 31242

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

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

Loading…
Cancel
Save