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 efafce804..935f17640 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 @@ -309,7 +309,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } /** - * 加载章节内容 + * 加载章节内容, index章节序号 */ override fun loadContent(index: Int) { viewModel.bookData.value?.let { @@ -405,6 +405,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea curPageChanged() } + /** + * chapterOnDur: 0为当前页,1为下一页,-1为上一页 + */ override fun textChapter(chapterOnDur: Int): TextChapter? { return when (chapterOnDur) { 0 -> viewModel.curTextChapter @@ -414,6 +417,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } + /** + * 下一页 + */ override fun moveToNextChapter() { viewModel.durPageIndex = 0 viewModel.moveToNextChapter() @@ -421,6 +427,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea curChapterChanged() } + /** + * 上一页 + */ override fun moveToPrevChapter(last: Boolean) { viewModel.durPageIndex = if (last) viewModel.prevTextChapter?.lastIndex() ?: 0 else 0 viewModel.moveToPrevChapter() 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 3a80a2067..2f27045c9 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 @@ -8,11 +8,13 @@ import android.view.MotionEvent import android.widget.FrameLayout import io.legado.app.help.ReadBookConfig import io.legado.app.ui.widget.page.delegate.CoverPageDelegate +import io.legado.app.ui.widget.page.delegate.NoAnmiPageDelegate import io.legado.app.ui.widget.page.delegate.PageDelegate import io.legado.app.ui.widget.page.delegate.SlidePageDelegate import io.legado.app.utils.getPrefInt -class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), PageDelegate.PageInterface { +class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), + PageDelegate.PageInterface { var callback: CallBack? = null private var pageDelegate: PageDelegate? = null @@ -44,7 +46,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att } override fun isPrepared(): Boolean { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + return true } override fun getChapterPosition(): Int { @@ -123,14 +125,10 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att it.moveToNext() } else -> { - } } - - prevPage?.setContent(it.previousPage()) - curPage?.setContent(it.currentPage()) - nextPage?.setContent(it.nextPage()) } + upContent() } private fun setPageFactory(factory: TextPageFactory) { @@ -143,6 +141,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att fun upPageAnim() { pageDelegate = when (context.getPrefInt("pageAnim")) { 1 -> SlidePageDelegate(this) + 2 -> NoAnmiPageDelegate(this) else -> CoverPageDelegate(this) } } @@ -155,12 +154,17 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att } } - override fun hasNext(): Boolean { - return pageFactory?.hasNext() == true + fun moveToPrevPage(noAnim: Boolean = true) { + if (noAnim) { + fillPage(PageDelegate.Direction.PREV) + } + } - override fun hasPrev(): Boolean { - return pageFactory?.hasPrev() == true + fun moveToNextPage(noAnim: Boolean = true) { + if (noAnim) { + fillPage(PageDelegate.Direction.NEXT) + } } fun upStyle() { @@ -190,6 +194,14 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att nextPage?.upBattery(battery) } + override fun hasNext(): Boolean { + return pageFactory?.hasNext() == true + } + + override fun hasPrev(): Boolean { + return pageFactory?.hasPrev() == true + } + override fun clickCenter() { callback?.clickCenter() } @@ -198,10 +210,26 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att fun chapterSize(): Int fun durChapterIndex(): Int fun durChapterPos(): Int + /** + * chapterOnDur: 0为当前页,1为下一页,-1为上一页 + */ fun textChapter(chapterOnDur: Int = 0): TextChapter? + + /** + * 加载章节内容, index章节序号 + */ fun loadContent(index: Int) + + /** + * 下一页 + */ fun moveToNextChapter() + + /** + * 上一页 + */ fun moveToPrevChapter(last: Boolean = true) + fun setPageIndex(pageIndex: Int) fun clickCenter() } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/NoAnmiPageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/NoAnmiPageDelegate.kt new file mode 100644 index 000000000..89e3d9c0a --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/NoAnmiPageDelegate.kt @@ -0,0 +1,19 @@ +package io.legado.app.ui.widget.page.delegate + +import android.graphics.Canvas +import io.legado.app.ui.widget.page.PageView + +class NoAnmiPageDelegate(pageView: PageView) : PageDelegate(pageView) { + override fun onScrollStart() { + startScroll(touchX.toInt(), 0, 0, 0) + } + + override fun onDraw(canvas: Canvas) { + } + + override fun onScrollStop() { + if (!isCancel) { + pageView.fillPage(direction) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_read_book_style.xml b/app/src/main/res/layout/dialog_read_book_style.xml index 599fe7832..6cec496aa 100644 --- a/app/src/main/res/layout/dialog_read_book_style.xml +++ b/app/src/main/res/layout/dialog_read_book_style.xml @@ -261,6 +261,18 @@ android:singleLine="true" android:text="@string/page_anim_slide" /> + +