From 08f91cb90447179eab439c14055b2ca3d3e69dde Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 1 Dec 2019 09:23:49 +0800 Subject: [PATCH] up --- .../io/legado/app/service/help/ReadBook.kt | 17 +++++++++++++ .../app/ui/book/read/ReadBookActivity.kt | 25 ------------------- .../io/legado/app/ui/book/read/ReadMenu.kt | 3 +-- .../io/legado/app/ui/widget/page/PageView.kt | 17 +++++-------- 4 files changed, 24 insertions(+), 38 deletions(-) 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 index 6040c3174..229e1650d 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -114,6 +114,13 @@ object ReadBook { } } + fun skipToPage(page: Int) { + durPageIndex = page + callBack?.upContent() + curPageChanged() + saveRead() + } + fun curPageChanged() { callBack?.upPageProgress() if (BaseReadAloudService.isRun) { @@ -140,6 +147,16 @@ object ReadBook { } } + fun durChapterPos(): Int { + curTextChapter?.let { + if (durPageIndex < it.pageSize()) { + return durPageIndex + } + return it.pageSize() - 1 + } + return durPageIndex + } + fun loadContent(index: Int) { book?.let { book -> if (addLoading(index)) { 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 579de5b2f..332c07219 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 @@ -296,10 +296,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo read_menu.runMenuIn() } - override fun chapterSize(): Int { - return ReadBook.chapterSize - } - override val oldBook: Book? get() = ReadBook.book @@ -307,20 +303,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo viewModel.changeTo(book) } - override fun durChapterIndex(): Int { - return ReadBook.durChapterIndex - } - - override fun durChapterPos(): Int { - ReadBook.curTextChapter?.let { - if (ReadBook.durPageIndex < it.pageSize()) { - return ReadBook.durPageIndex - } - return it.pageSize() - 1 - } - return ReadBook.durPageIndex - } - override fun setPageIndex(pageIndex: Int) { ReadBook.durPageIndex = pageIndex ReadBook.saveRead() @@ -355,13 +337,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } - override fun skipToPage(page: Int) { - ReadBook.durPageIndex = page - page_view.upContent() - ReadBook.curPageChanged() - ReadBook.saveRead() - } - override fun openReplaceRule() { startActivity() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 7b099a7cf..8915057da 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -132,7 +132,7 @@ class ReadMenu : FrameLayout { } override fun onStopTrackingTouch(seekBar: SeekBar) { - callBack?.skipToPage(seekBar.progress) + ReadBook.skipToPage(seekBar.progress) } }) @@ -245,7 +245,6 @@ class ReadMenu : FrameLayout { interface CallBack { fun autoPage() - fun skipToPage(page: Int) fun openReplaceRule() fun openChapterList() fun showReadStyle() 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 573bc13d7..bb6dd7f20 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 @@ -7,6 +7,7 @@ import android.util.AttributeSet import android.view.MotionEvent import android.widget.FrameLayout import io.legado.app.help.ReadBookConfig +import io.legado.app.service.help.ReadBook import io.legado.app.ui.widget.page.curl.CurlView import io.legado.app.ui.widget.page.delegate.* import io.legado.app.utils.activity @@ -113,7 +114,7 @@ class PageView(context: Context, attrs: AttributeSet) : prevPage?.setContent(it.previousPage()) callBack?.let { callback -> if (isScrollDelegate) { - curPage?.scrollTo(callback.textChapter()?.getStartLine(callback.durChapterPos())) + curPage?.scrollTo(callback.textChapter()?.getStartLine(ReadBook.durChapterPos())) } } } @@ -180,14 +181,14 @@ class PageView(context: Context, attrs: AttributeSet) : get() = pageDelegate is ScrollPageDelegate override val pageIndex: Int - get() = callBack?.durChapterPos() ?: 0 + get() = ReadBook.durChapterPos() override fun setPageIndex(pageIndex: Int) { callBack?.setPageIndex(pageIndex) } override fun getChapterPosition(): Int { - return callBack?.durChapterIndex() ?: 0 + return ReadBook.durChapterIndex } override fun getChapter(position: Int): TextChapter? { @@ -207,15 +208,12 @@ class PageView(context: Context, attrs: AttributeSet) : } override fun hasNextChapter(): Boolean { - callBack?.let { - return it.durChapterIndex() < it.chapterSize() - 1 - } - return false + return ReadBook.durChapterIndex < ReadBook.chapterSize - 1 } override fun hasPrevChapter(): Boolean { callBack?.let { - return it.durChapterIndex() > 0 + return ReadBook.durChapterIndex > 0 } return false } @@ -240,9 +238,6 @@ class PageView(context: Context, attrs: AttributeSet) : } interface CallBack { - fun chapterSize(): Int - fun durChapterIndex(): Int - fun durChapterPos(): Int /** * chapterOnDur: 0为当前页,1为下一页,-1为上一页