pull/32/head
kunfei 5 years ago
parent 71afa982ba
commit a2de255e4a
  1. 11
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 50
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  3. 19
      app/src/main/java/io/legado/app/ui/widget/page/delegate/NoAnmiPageDelegate.kt
  4. 12
      app/src/main/res/layout/dialog_read_book_style.xml

@ -309,7 +309,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
/** /**
* 加载章节内容 * 加载章节内容, index章节序号
*/ */
override fun loadContent(index: Int) { override fun loadContent(index: Int) {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
@ -405,6 +405,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
curPageChanged() curPageChanged()
} }
/**
* chapterOnDur: 0为当前页,1为下一页,-1为上一页
*/
override fun textChapter(chapterOnDur: Int): TextChapter? { override fun textChapter(chapterOnDur: Int): TextChapter? {
return when (chapterOnDur) { return when (chapterOnDur) {
0 -> viewModel.curTextChapter 0 -> viewModel.curTextChapter
@ -414,6 +417,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
/**
* 下一页
*/
override fun moveToNextChapter() { override fun moveToNextChapter() {
viewModel.durPageIndex = 0 viewModel.durPageIndex = 0
viewModel.moveToNextChapter() viewModel.moveToNextChapter()
@ -421,6 +427,9 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
curChapterChanged() curChapterChanged()
} }
/**
* 上一页
*/
override fun moveToPrevChapter(last: Boolean) { override fun moveToPrevChapter(last: Boolean) {
viewModel.durPageIndex = if (last) viewModel.prevTextChapter?.lastIndex() ?: 0 else 0 viewModel.durPageIndex = if (last) viewModel.prevTextChapter?.lastIndex() ?: 0 else 0
viewModel.moveToPrevChapter() viewModel.moveToPrevChapter()

@ -8,11 +8,13 @@ import android.view.MotionEvent
import android.widget.FrameLayout import android.widget.FrameLayout
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.widget.page.delegate.CoverPageDelegate 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.PageDelegate
import io.legado.app.ui.widget.page.delegate.SlidePageDelegate import io.legado.app.ui.widget.page.delegate.SlidePageDelegate
import io.legado.app.utils.getPrefInt 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 var callback: CallBack? = null
private var pageDelegate: PageDelegate? = null private var pageDelegate: PageDelegate? = null
@ -44,7 +46,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
} }
override fun isPrepared(): Boolean { override fun isPrepared(): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. return true
} }
override fun getChapterPosition(): Int { override fun getChapterPosition(): Int {
@ -123,14 +125,10 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
it.moveToNext() it.moveToNext()
} }
else -> { else -> {
} }
} }
prevPage?.setContent(it.previousPage())
curPage?.setContent(it.currentPage())
nextPage?.setContent(it.nextPage())
} }
upContent()
} }
private fun setPageFactory(factory: TextPageFactory) { private fun setPageFactory(factory: TextPageFactory) {
@ -143,6 +141,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
fun upPageAnim() { fun upPageAnim() {
pageDelegate = when (context.getPrefInt("pageAnim")) { pageDelegate = when (context.getPrefInt("pageAnim")) {
1 -> SlidePageDelegate(this) 1 -> SlidePageDelegate(this)
2 -> NoAnmiPageDelegate(this)
else -> CoverPageDelegate(this) else -> CoverPageDelegate(this)
} }
} }
@ -155,12 +154,17 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
} }
} }
override fun hasNext(): Boolean { fun moveToPrevPage(noAnim: Boolean = true) {
return pageFactory?.hasNext() == true if (noAnim) {
fillPage(PageDelegate.Direction.PREV)
}
} }
override fun hasPrev(): Boolean { fun moveToNextPage(noAnim: Boolean = true) {
return pageFactory?.hasPrev() == true if (noAnim) {
fillPage(PageDelegate.Direction.NEXT)
}
} }
fun upStyle() { fun upStyle() {
@ -190,6 +194,14 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
nextPage?.upBattery(battery) nextPage?.upBattery(battery)
} }
override fun hasNext(): Boolean {
return pageFactory?.hasNext() == true
}
override fun hasPrev(): Boolean {
return pageFactory?.hasPrev() == true
}
override fun clickCenter() { override fun clickCenter() {
callback?.clickCenter() callback?.clickCenter()
} }
@ -198,10 +210,26 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
fun chapterSize(): Int fun chapterSize(): Int
fun durChapterIndex(): Int fun durChapterIndex(): Int
fun durChapterPos(): Int fun durChapterPos(): Int
/**
* chapterOnDur: 0为当前页,1为下一页,-1为上一页
*/
fun textChapter(chapterOnDur: Int = 0): TextChapter? fun textChapter(chapterOnDur: Int = 0): TextChapter?
/**
* 加载章节内容, index章节序号
*/
fun loadContent(index: Int) fun loadContent(index: Int)
/**
* 下一页
*/
fun moveToNextChapter() fun moveToNextChapter()
/**
* 上一页
*/
fun moveToPrevChapter(last: Boolean = true) fun moveToPrevChapter(last: Boolean = true)
fun setPageIndex(pageIndex: Int) fun setPageIndex(pageIndex: Int)
fun clickCenter() fun clickCenter()
} }

@ -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)
}
}
}

@ -261,6 +261,18 @@
android:singleLine="true" android:singleLine="true"
android:text="@string/page_anim_slide" /> android:text="@string/page_anim_slide" />
<io.legado.app.lib.theme.view.ATERadioNoButton
android:id="@+id/rb_anim3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="5dp"
android:padding="5dp"
android:button="@null"
android:gravity="center"
android:singleLine="true"
android:text="@string/page_anim_none" />
</RadioGroup> </RadioGroup>
<View <View

Loading…
Cancel
Save