pull/32/head
kunfei 5 years ago
parent c942873352
commit 04376419c3
  1. 7
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 33
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  3. 4
      app/src/main/java/io/legado/app/ui/widget/page/TextPage.kt
  4. 6
      app/src/main/java/io/legado/app/ui/widget/page/TextPageFactory.kt
  5. 3
      app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt
  6. 14
      app/src/main/res/layout/view_book_page.xml

@ -273,6 +273,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(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

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

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

@ -1,7 +1,5 @@
package io.legado.app.ui.widget.page
import android.text.SpannableStringBuilder
class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<TextPage>(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")
}

@ -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
//判断是否下一页存在

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/page_panel"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:showDividers="middle"
app:divider="@drawable/ic_divider">
android:background="@color/background"
android:orientation="vertical"
app:divider="@drawable/ic_divider"
app:showDividers="middle">
<View
android:id="@+id/top_status_bar"
android:layout_width="match_parent"
android:layout_height="25dp"/>
android:layout_height="25dp" />
<FrameLayout
android:id="@+id/content_panel"
@ -30,6 +30,6 @@
<View
android:id="@+id/bottom_status_bar"
android:layout_width="match_parent"
android:layout_height="25dp"/>
android:layout_height="25dp" />
</androidx.appcompat.widget.LinearLayoutCompat>
Loading…
Cancel
Save