From 085b1012ee6fd650e1456b1cc0214a987e143bae Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 27 Nov 2019 17:28:54 +0800 Subject: [PATCH] up --- .../io/legado/app/service/help/ReadBook.kt | 27 +++ .../app/ui/book/read/ReadBookActivity.kt | 113 ++++++------ .../app/ui/book/read/ReadBookViewModel.kt | 171 ++++++++---------- 3 files changed, 163 insertions(+), 148 deletions(-) create mode 100644 app/src/main/java/io/legado/app/service/help/ReadBook.kt diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt new file mode 100644 index 000000000..6058fb005 --- /dev/null +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -0,0 +1,27 @@ +package io.legado.app.service.help + +import androidx.lifecycle.MutableLiveData +import io.legado.app.data.entities.Book +import io.legado.app.model.WebBook +import io.legado.app.ui.book.read.ReadBookViewModel +import io.legado.app.ui.widget.page.TextChapter + + +object ReadBook { + + var titleDate = MutableLiveData() + var book: Book? = null + var inBookshelf = false + var chapterSize = 0 + var callBack: ReadBookViewModel.CallBack? = null + var durChapterIndex = 0 + var durPageIndex = 0 + var isLocalBook = true + var prevTextChapter: TextChapter? = null + var curTextChapter: TextChapter? = null + var nextTextChapter: TextChapter? = null + var webBook: WebBook? = null + val loadingChapters = arrayListOf() + + +} \ No newline at end of file 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 6a16e962a..fa6dd44eb 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 @@ -25,6 +25,7 @@ import io.legado.app.lib.dialogs.okButton import io.legado.app.receiver.TimeElectricityReceiver import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud +import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR @@ -70,8 +71,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo Help.upLayoutInDisplayCutoutMode(window) setSupportActionBar(toolbar) initView() - viewModel.callBack = this - viewModel.titleDate.observe(this, Observer { title_bar.title = it }) + ReadBook.callBack = this + ReadBook.titleDate.observe(this, Observer { title_bar.title = it }) viewModel.initData(intent) } @@ -101,7 +102,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ private fun initView() { tv_chapter_name.onClick { - viewModel.webBook?.let { + ReadBook.webBook?.let { startActivityForResult( requestCodeEditSource, Pair("data", it.bookSource.bookSourceUrl) @@ -138,13 +139,13 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo when (item.itemId) { R.id.menu_change_source -> { read_menu.runMenuOut() - viewModel.book?.let { + ReadBook.book?.let { ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) } } R.id.menu_refresh -> { - viewModel.book?.let { - viewModel.curTextChapter = null + ReadBook.book?.let { + ReadBook.curTextChapter = null page_view.upContent() viewModel.refreshContent(it) } @@ -252,9 +253,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo * 加载章节内容 */ override fun loadContent() { - viewModel.loadContent(viewModel.durChapterIndex) - viewModel.loadContent(viewModel.durChapterIndex + 1) - viewModel.loadContent(viewModel.durChapterIndex - 1) + viewModel.loadContent(ReadBook.durChapterIndex) + viewModel.loadContent(ReadBook.durChapterIndex + 1) + viewModel.loadContent(ReadBook.durChapterIndex - 1) } /** @@ -269,9 +270,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ override fun contentLoadFinish(bookChapter: BookChapter, content: String) { when (bookChapter.index) { - viewModel.durChapterIndex -> launch { - viewModel.curTextChapter = ChapterProvider - .getTextChapter(bookChapter, content, viewModel.chapterSize) + ReadBook.durChapterIndex -> launch { + ReadBook.curTextChapter = ChapterProvider + .getTextChapter(bookChapter, content, ReadBook.chapterSize) page_view.upContent() curChapterChanged() if (intent.getBooleanExtra("readAloud", false)) { @@ -279,14 +280,14 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo readAloud() } } - viewModel.durChapterIndex - 1 -> launch { - viewModel.prevTextChapter = ChapterProvider - .getTextChapter(bookChapter, content, viewModel.chapterSize) + ReadBook.durChapterIndex - 1 -> launch { + ReadBook.prevTextChapter = ChapterProvider + .getTextChapter(bookChapter, content, ReadBook.chapterSize) page_view.upContent(-1) } - viewModel.durChapterIndex + 1 -> launch { - viewModel.nextTextChapter = ChapterProvider - .getTextChapter(bookChapter, content, viewModel.chapterSize) + ReadBook.durChapterIndex + 1 -> launch { + ReadBook.nextTextChapter = ChapterProvider + .getTextChapter(bookChapter, content, ReadBook.chapterSize) page_view.upContent(1) } } @@ -297,22 +298,22 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } private fun curChapterChanged() { - viewModel.curTextChapter?.let { + ReadBook.curTextChapter?.let { tv_chapter_name.text = it.title tv_chapter_name.visible() - if (!viewModel.isLocalBook) { + if (!ReadBook.isLocalBook) { tv_chapter_url.text = it.url tv_chapter_url.visible() } seek_read_page.max = it.pageSize().minus(1) - tv_pre.isEnabled = viewModel.durChapterIndex != 0 - tv_next.isEnabled = viewModel.durChapterIndex != viewModel.chapterSize - 1 + tv_pre.isEnabled = ReadBook.durChapterIndex != 0 + tv_next.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1 curPageChanged() } } private fun curPageChanged() { - seek_read_page.progress = viewModel.durPageIndex + seek_read_page.progress = ReadBook.durPageIndex when (readAloudStatus) { Status.PLAY -> readAloud() Status.PAUSE -> { @@ -326,35 +327,35 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } override fun chapterSize(): Int { - return viewModel.chapterSize + return ReadBook.chapterSize } override val curOrigin: String? - get() = viewModel.book?.origin + get() = ReadBook.book?.origin override val oldBook: Book? - get() = viewModel.book + get() = ReadBook.book override fun changeTo(book: Book) { viewModel.changeTo(book) } override fun durChapterIndex(): Int { - return viewModel.durChapterIndex + return ReadBook.durChapterIndex } override fun durChapterPos(): Int { - viewModel.curTextChapter?.let { - if (viewModel.durPageIndex < it.pageSize()) { - return viewModel.durPageIndex + ReadBook.curTextChapter?.let { + if (ReadBook.durPageIndex < it.pageSize()) { + return ReadBook.durPageIndex } return it.pageSize() - 1 } - return viewModel.durPageIndex + return ReadBook.durPageIndex } override fun setPageIndex(pageIndex: Int) { - viewModel.durPageIndex = pageIndex + ReadBook.durPageIndex = pageIndex viewModel.saveRead() curPageChanged() } @@ -364,9 +365,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ override fun textChapter(chapterOnDur: Int): TextChapter? { return when (chapterOnDur) { - 0 -> viewModel.curTextChapter - 1 -> viewModel.nextTextChapter - -1 -> viewModel.prevTextChapter + 0 -> ReadBook.curTextChapter + 1 -> ReadBook.nextTextChapter + -1 -> ReadBook.prevTextChapter else -> null } } @@ -375,8 +376,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo * 下一页 */ override fun moveToNextChapter(upContent: Boolean): Boolean { - return if (viewModel.durChapterIndex < viewModel.chapterSize - 1) { - viewModel.durPageIndex = 0 + return if (ReadBook.durChapterIndex < ReadBook.chapterSize - 1) { + ReadBook.durPageIndex = 0 viewModel.moveToNextChapter(upContent) viewModel.saveRead() curChapterChanged() @@ -390,8 +391,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo * 上一页 */ override fun moveToPrevChapter(upContent: Boolean, last: Boolean): Boolean { - return if (viewModel.durChapterIndex > 0) { - viewModel.durPageIndex = if (last) viewModel.prevTextChapter?.lastIndex() ?: 0 else 0 + return if (ReadBook.durChapterIndex > 0) { + ReadBook.durPageIndex = if (last) ReadBook.prevTextChapter?.lastIndex() ?: 0 else 0 viewModel.moveToPrevChapter(upContent) viewModel.saveRead() curChapterChanged() @@ -418,7 +419,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } override fun skipToPage(page: Int) { - viewModel.durPageIndex = page + ReadBook.durPageIndex = page page_view.upContent() curPageChanged() viewModel.saveRead() @@ -429,7 +430,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } override fun openChapterList() { - viewModel.book?.let { + ReadBook.book?.let { startActivityForResult( requestCodeChapterList, Pair("bookUrl", it.bookUrl) @@ -468,15 +469,15 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo * 朗读 */ private fun readAloud(play: Boolean = true) { - val book = viewModel.book - val textChapter = viewModel.curTextChapter + val book = ReadBook.book + val textChapter = ReadBook.curTextChapter if (book != null && textChapter != null) { val key = IntentDataHelp.putData(textChapter) ReadAloud.play( this, book.name, textChapter.title, - viewModel.durPageIndex, + ReadBook.durPageIndex, key, play ) @@ -508,7 +509,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo when (requestCode) { requestCodeEditSource -> viewModel.upBookSource() requestCodeChapterList -> - data?.getIntExtra("index", viewModel.durChapterIndex)?.let { + data?.getIntExtra("index", ReadBook.durChapterIndex)?.let { viewModel.openChapter(it) } } @@ -516,11 +517,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } override fun finish() { - viewModel.book?.let { - if (!viewModel.inBookshelf) { + ReadBook.book?.let { + if (!ReadBook.inBookshelf) { this.alert(title = getString(R.string.add_to_shelf)) { message = getString(R.string.check_add_bookshelf, it.name) - okButton { viewModel.inBookshelf = true } + okButton { ReadBook.inBookshelf = true } noButton { viewModel.removeFromBookshelf { super.finish() } } }.show().applyTint() } else { @@ -534,8 +535,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEvent(Bus.ALOUD_STATE) { readAloudStatus = it if (it == Status.STOP || it == Status.PAUSE) { - viewModel.curTextChapter?.let { textChapter -> - val page = textChapter.page(viewModel.durPageIndex) + ReadBook.curTextChapter?.let { textChapter -> + val page = textChapter.page(ReadBook.durPageIndex) if (page != null && page.text is SpannableStringBuilder) { page.text.removeSpan(ChapterProvider.readAloudSpan) page_view.upContent() @@ -568,9 +569,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } observeEvent(Bus.TTS_START) { chapterStart -> launch(IO) { - viewModel.curTextChapter?.let { - val pageStart = chapterStart - it.getReadLength(viewModel.durPageIndex) - it.page(viewModel.durPageIndex)?.upPageAloudSpan(pageStart) + ReadBook.curTextChapter?.let { + val pageStart = chapterStart - it.getReadLength(ReadBook.durPageIndex) + it.page(ReadBook.durPageIndex)?.upPageAloudSpan(pageStart) withContext(Main) { page_view.upContent() } @@ -583,18 +584,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo if (page_view.isScrollDelegate) { page_view.moveToNextPage() } else { - viewModel.durPageIndex = viewModel.durPageIndex + 1 + ReadBook.durPageIndex = ReadBook.durPageIndex + 1 page_view.upContent() viewModel.saveRead() } } 2 -> if (!moveToNextChapter(true)) ReadAloud.stop(this) -1 -> { - if (viewModel.durPageIndex > 0) { + if (ReadBook.durPageIndex > 0) { if (page_view.isScrollDelegate) { page_view.moveToPrevPage() } else { - viewModel.durPageIndex = viewModel.durPageIndex - 1 + ReadBook.durPageIndex = ReadBook.durPageIndex - 1 page_view.upContent() viewModel.saveRead() } 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 5d44e867e..b13b8800b 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 @@ -2,7 +2,6 @@ package io.legado.app.ui.book.read import android.app.Application import android.content.Intent -import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel @@ -13,7 +12,7 @@ import io.legado.app.help.BookHelp import io.legado.app.help.IntentDataHelp import io.legado.app.model.WebBook import io.legado.app.service.help.ReadAloud -import io.legado.app.ui.widget.page.TextChapter +import io.legado.app.service.help.ReadBook import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay @@ -21,23 +20,10 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext class ReadBookViewModel(application: Application) : BaseViewModel(application) { - var titleDate = MutableLiveData() - var book: Book? = null - var inBookshelf = false - var chapterSize = 0 - var callBack: CallBack? = null - var durChapterIndex = 0 - var durPageIndex = 0 - var isLocalBook = true - var prevTextChapter: TextChapter? = null - var curTextChapter: TextChapter? = null - var nextTextChapter: TextChapter? = null - var webBook: WebBook? = null - private val loadingChapters = arrayListOf() fun initData(intent: Intent) { execute { - inBookshelf = intent.getBooleanExtra("inBookshelf", true) + ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true) IntentDataHelp.getData(intent.getStringExtra("key"))?.let { initBook(it) } ?: intent.getStringExtra("bookUrl")?.let { @@ -51,13 +37,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } private fun initBook(book: Book) { - this.book = book - titleDate.postValue(book.name) - durChapterIndex = book.durChapterIndex - durPageIndex = book.durChapterPos - isLocalBook = book.origin == BookType.local + ReadBook.book = book + ReadBook.titleDate.postValue(book.name) + ReadBook.durChapterIndex = book.durChapterIndex + ReadBook.durPageIndex = book.durChapterPos + ReadBook.isLocalBook = book.origin == BookType.local App.db.bookSourceDao().getBookSource(book.origin)?.let { - webBook = WebBook(it) + ReadBook.webBook = WebBook(it) } val count = App.db.bookChapterDao().getChapterCount(book.bookUrl) if (count == 0) { @@ -67,13 +53,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { loadChapterList(book) } } else { - if (durChapterIndex > count - 1) { - durChapterIndex = count - 1 + if (ReadBook.durChapterIndex > count - 1) { + ReadBook.durChapterIndex = count - 1 } - chapterSize = count - callBack?.loadContent() + ReadBook.chapterSize = count + ReadBook.callBack?.loadContent() } - if (inBookshelf) { + if (ReadBook.inBookshelf) { saveRead() } } @@ -83,7 +69,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { changeDruChapterIndex: ((chapters: List) -> Unit)? = null ) { execute { - webBook?.getBookInfo(book, this) + ReadBook.webBook?.getBookInfo(book, this) ?.onSuccess { loadChapterList(book, changeDruChapterIndex) } @@ -95,13 +81,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { changeDruChapterIndex: ((chapters: List) -> Unit)? = null ) { execute { - webBook?.getChapterList(book, this) + ReadBook.webBook?.getChapterList(book, this) ?.onSuccess(IO) { cList -> if (!cList.isNullOrEmpty()) { if (changeDruChapterIndex == null) { App.db.bookChapterDao().insert(*cList.toTypedArray()) - chapterSize = cList.size - callBack?.loadContent() + ReadBook.chapterSize = cList.size + ReadBook.callBack?.loadContent() } else { changeDruChapterIndex(cList) } @@ -115,49 +101,49 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } fun moveToNextChapter(upContent: Boolean) { - durChapterIndex++ - prevTextChapter = curTextChapter - curTextChapter = nextTextChapter - nextTextChapter = null - book?.let { - if (curTextChapter == null) { - loadContent(durChapterIndex) + ReadBook.durChapterIndex++ + ReadBook.prevTextChapter = ReadBook.curTextChapter + ReadBook.curTextChapter = ReadBook.nextTextChapter + ReadBook.nextTextChapter = null + ReadBook.book?.let { + if (ReadBook.curTextChapter == null) { + loadContent(ReadBook.durChapterIndex) } else if (upContent) { - callBack?.upContent() + ReadBook.callBack?.upContent() } - loadContent(durChapterIndex.plus(1)) + loadContent(ReadBook.durChapterIndex.plus(1)) launch(IO) { for (i in 2..10) { delay(100) - download(durChapterIndex + i) + download(ReadBook.durChapterIndex + i) } } } } fun moveToPrevChapter(upContent: Boolean) { - durChapterIndex-- - nextTextChapter = curTextChapter - curTextChapter = prevTextChapter - prevTextChapter = null - book?.let { - if (curTextChapter == null) { - loadContent(durChapterIndex) + ReadBook.durChapterIndex-- + ReadBook.nextTextChapter = ReadBook.curTextChapter + ReadBook.curTextChapter = ReadBook.prevTextChapter + ReadBook.prevTextChapter = null + ReadBook.book?.let { + if (ReadBook.curTextChapter == null) { + loadContent(ReadBook.durChapterIndex) } else if (upContent) { - callBack?.upContent() + ReadBook.callBack?.upContent() } - loadContent(durChapterIndex.minus(1)) + loadContent(ReadBook.durChapterIndex.minus(1)) launch(IO) { for (i in -5..-2) { delay(100) - download(durChapterIndex + i) + download(ReadBook.durChapterIndex + i) } } } } fun loadContent(index: Int) { - book?.let { book -> + ReadBook.book?.let { book -> if (addLoading(index)) { execute { App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> @@ -174,7 +160,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } private fun download(index: Int) { - book?.let { book -> + ReadBook.book?.let { book -> if (addLoading(index)) { execute { App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> @@ -192,8 +178,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } private fun download(chapter: BookChapter) { - book?.let { book -> - webBook?.getContent(book, chapter, scope = this) + ReadBook.book?.let { book -> + ReadBook.webBook?.getContent(book, chapter, scope = this) ?.onSuccess(IO) { content -> if (content.isNullOrEmpty()) { contentLoadFinish(chapter, context.getString(R.string.content_empty)) @@ -212,48 +198,48 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { private fun addLoading(index: Int): Boolean { synchronized(this) { - if (loadingChapters.contains(index)) return false - loadingChapters.add(index) + if (ReadBook.loadingChapters.contains(index)) return false + ReadBook.loadingChapters.add(index) return true } } private fun removeLoading(index: Int) { synchronized(this) { - loadingChapters.remove(index) + ReadBook.loadingChapters.remove(index) } } private fun contentLoadFinish(chapter: BookChapter, content: String) { execute { - if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { + if (chapter.index in ReadBook.durChapterIndex - 1..ReadBook.durChapterIndex + 1) { val c = BookHelp.disposeContent( chapter.title, - book!!.name, - webBook?.bookSource?.bookSourceUrl, + ReadBook.book!!.name, + ReadBook.webBook?.bookSource?.bookSourceUrl, content, - book!!.useReplaceRule + ReadBook.book!!.useReplaceRule ) - callBack?.contentLoadFinish(chapter, c) + ReadBook.callBack?.contentLoadFinish(chapter, c) } } } fun changeTo(book1: Book) { execute { - book?.let { + ReadBook.book?.let { App.db.bookDao().delete(it.bookUrl) } - prevTextChapter = null - curTextChapter = null - nextTextChapter = null + ReadBook.prevTextChapter = null + ReadBook.curTextChapter = null + ReadBook.nextTextChapter = null withContext(Main) { - callBack?.upContent() + ReadBook.callBack?.upContent() } App.db.bookDao().insert(book1) - book = book1 + ReadBook.book = book1 App.db.bookSourceDao().getBookSource(book1.origin)?.let { - webBook = WebBook(it) + ReadBook.webBook = WebBook(it) } if (book1.tocUrl.isEmpty()) { loadBookInfo(book1) { upChangeDurChapterIndex(book1, it) } @@ -269,41 +255,41 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { private fun upChangeDurChapterIndex(book: Book, chapters: List) { execute { - durChapterIndex = BookHelp.getDurChapterIndexByChapterTitle( + ReadBook.durChapterIndex = BookHelp.getDurChapterIndexByChapterTitle( book.durChapterTitle, book.durChapterIndex, chapters ) - book.durChapterIndex = durChapterIndex - book.durChapterTitle = chapters[durChapterIndex].title + book.durChapterIndex = ReadBook.durChapterIndex + book.durChapterTitle = chapters[ReadBook.durChapterIndex].title App.db.bookDao().update(book) App.db.bookChapterDao().insert(*chapters.toTypedArray()) - chapterSize = chapters.size - callBack?.loadContent() + ReadBook.chapterSize = chapters.size + ReadBook.callBack?.loadContent() } } fun openChapter(index: Int) { - prevTextChapter = null - curTextChapter = null - nextTextChapter = null - callBack?.upContent() - if (index != durChapterIndex) { - durChapterIndex = index - durPageIndex = 0 + ReadBook.prevTextChapter = null + ReadBook.curTextChapter = null + ReadBook.nextTextChapter = null + ReadBook.callBack?.upContent() + if (index != ReadBook.durChapterIndex) { + ReadBook.durChapterIndex = index + ReadBook.durPageIndex = 0 } saveRead() - callBack?.loadContent() + ReadBook.callBack?.loadContent() } fun saveRead() { execute { - book?.let { book -> + ReadBook.book?.let { book -> book.lastCheckCount = 0 book.durChapterTime = System.currentTimeMillis() - book.durChapterIndex = durChapterIndex - book.durChapterPos = durPageIndex - curTextChapter?.let { + book.durChapterIndex = ReadBook.durChapterIndex + book.durChapterPos = ReadBook.durPageIndex + ReadBook.curTextChapter?.let { book.durChapterTitle = it.title } App.db.bookDao().update(book) @@ -313,7 +299,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun removeFromBookshelf(success: (() -> Unit)?) { execute { - book?.let { + ReadBook.book?.let { App.db.bookDao().delete(it.bookUrl) } }.onSuccess { @@ -323,9 +309,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun upBookSource() { execute { - book?.let { book -> + ReadBook.book?.let { book -> App.db.bookSourceDao().getBookSource(book.origin)?.let { - webBook = WebBook(it) + ReadBook.webBook = WebBook(it) } } } @@ -333,9 +319,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun refreshContent(book: Book) { execute { - App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter -> + App.db.bookChapterDao().getChapter(book.bookUrl, ReadBook.durChapterIndex) + ?.let { chapter -> BookHelp.delContent(book, chapter) - loadContent(durChapterIndex) + loadContent(ReadBook.durChapterIndex) } } }