From 8990bba2dbbd13e9bc8fc0ed75f663d64c7472d0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 21 Dec 2019 11:13:12 +0800 Subject: [PATCH] up --- .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 3 +++ .../java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 4 ++++ app/src/main/java/io/legado/app/ui/widget/page/PageView.kt | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index f7fd36db6..c166d4b96 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -60,6 +60,9 @@ class ReadBookActivity : VMBaseActivity(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 diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 66d0a0b71..c45095a7e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -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()) { diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 759ee2c46..4dc4193f8 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -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 } }