diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 01264d61d..dd3965889 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -273,6 +273,13 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea return viewModel.durChapterIndex } + override fun durChapterPos(pageSize: Int): Int { + if (viewModel.durPageIndex < pageSize) { + return viewModel.durPageIndex + } + return pageSize - 1 + } + override fun textChapter(chapterOnDur: Int): TextChapter? { return when (chapterOnDur) { 0 -> viewModel.curTextChapter 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 e567a3090..e02bc8b6d 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 @@ -17,9 +17,9 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att var callBack: CallBack? = null private var pageDelegate: PageDelegate? = null - private var prevPage: ContentView? = null - private var curPage: ContentView? = null - private var nextPage: ContentView? = null + var prevPage: ContentView? = null + var curPage: ContentView? = null + var nextPage: ContentView? = null init { prevPage = ContentView(context) @@ -59,9 +59,29 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) } - fun chapterLoadFinish() { - callBack?.textChapter()?.let { - curPage?.setContent(it.page(0)?.stringBuilder) + fun chapterLoadFinish(chapterOnDur: Int = 0) { + callBack?.let { cb -> + when (chapterOnDur) { + 0 -> { + cb.textChapter()?.let { + curPage?.setContent(it.page(cb.durChapterPos(it.pageSize()))?.text) + if (cb.durChapterPos(it.pageSize()) > 0) { + prevPage?.setContent(it.page(cb.durChapterPos(it.pageSize()) - 1)?.text) + } + if (cb.durChapterPos(it.pageSize()) < it.pageSize() - 1) { + nextPage?.setContent(it.page(cb.durChapterPos(it.pageSize()) + 1)?.text) + } + } + } + 1 -> { + + } + -1 -> { + + } + else -> { + } + } } } @@ -85,6 +105,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att interface CallBack { fun durChapterIndex(): Int + fun durChapterPos(pageSize: Int): Int fun textChapter(chapterOnDur: Int = 0): TextChapter? } } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt index 5c6dc6cdc..202529ca8 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt @@ -1,8 +1,6 @@ package io.legado.app.ui.widget.page -import android.text.SpannableStringBuilder - data class TextPage( val index: Int, - val stringBuilder: SpannableStringBuilder + val text: CharSequence ) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt index 0799d97c2..922423acb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt @@ -1,7 +1,5 @@ package io.legado.app.ui.widget.page -import android.text.SpannableStringBuilder - class TextPageFactory private constructor(dataSource: DataSource) : PageFactory(dataSource) { companion object{ @@ -25,11 +23,11 @@ class TextPageFactory private constructor(dataSource: DataSource) : PageFactory< } override fun nextPage(): TextPage { - return TextPage(index.plus(1), SpannableStringBuilder("index:$index")) + return TextPage(index.plus(1), "index:$index") } override fun previousPage(): TextPage { - return TextPage(index.minus(1), SpannableStringBuilder("index:$index")) + return TextPage(index.minus(1), "index:$index") } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt index 3c1130c9e..14a34e284 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt @@ -198,8 +198,8 @@ abstract class PageDelegate(private val pageView: PageView) { override fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean { if (!isMoved && abs(distanceX) > abs(distanceY)) { //上一页或下一页截图,还未处理 - bitmap = pageView.screenshot() if (distanceX < 0) { + bitmap = pageView.prevPage?.screenshot() //上一页的参数配置 direction = Direction.PREV //判断是否上一页存在 @@ -210,6 +210,7 @@ abstract class PageDelegate(private val pageView: PageView) { return true } } else { + bitmap = pageView.nextPage?.screenshot() //进行下一页的配置 direction = Direction.NEXT //判断是否下一页存在 diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index c86b9d3b7..63efc398b 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -1,24 +1,24 @@ - + + android:id="@+id/top_status_bar" + android:layout_width="match_parent" + android:layout_height="25dp" /> + android:id="@+id/content_panel" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1"> + android:id="@+id/bottom_status_bar" + android:layout_width="match_parent" + android:layout_height="25dp" /> \ No newline at end of file