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. 38
      app/src/main/res/layout/view_book_page.xml

@ -273,6 +273,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
return viewModel.durChapterIndex 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? { override fun textChapter(chapterOnDur: Int): TextChapter? {
return when (chapterOnDur) { return when (chapterOnDur) {
0 -> viewModel.curTextChapter 0 -> viewModel.curTextChapter

@ -17,9 +17,9 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
var callBack: CallBack? = null var callBack: CallBack? = null
private var pageDelegate: PageDelegate? = null private var pageDelegate: PageDelegate? = null
private var prevPage: ContentView? = null var prevPage: ContentView? = null
private var curPage: ContentView? = null var curPage: ContentView? = null
private var nextPage: ContentView? = null var nextPage: ContentView? = null
init { init {
prevPage = ContentView(context) prevPage = ContentView(context)
@ -59,9 +59,29 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event)
} }
fun chapterLoadFinish() { fun chapterLoadFinish(chapterOnDur: Int = 0) {
callBack?.textChapter()?.let { callBack?.let { cb ->
curPage?.setContent(it.page(0)?.stringBuilder) 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 { interface CallBack {
fun durChapterIndex(): Int fun durChapterIndex(): Int
fun durChapterPos(pageSize: Int): Int
fun textChapter(chapterOnDur: Int = 0): TextChapter? fun textChapter(chapterOnDur: Int = 0): TextChapter?
} }
} }

@ -1,8 +1,6 @@
package io.legado.app.ui.widget.page package io.legado.app.ui.widget.page
import android.text.SpannableStringBuilder
data class TextPage( data class TextPage(
val index: Int, val index: Int,
val stringBuilder: SpannableStringBuilder val text: CharSequence
) )

@ -1,7 +1,5 @@
package io.legado.app.ui.widget.page package io.legado.app.ui.widget.page
import android.text.SpannableStringBuilder
class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<TextPage>(dataSource) { class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<TextPage>(dataSource) {
companion object{ companion object{
@ -25,11 +23,11 @@ class TextPageFactory private constructor(dataSource: DataSource) : PageFactory<
} }
override fun nextPage(): TextPage { override fun nextPage(): TextPage {
return TextPage(index.plus(1), SpannableStringBuilder("index:$index")) return TextPage(index.plus(1), "index:$index")
} }
override fun previousPage(): TextPage { 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 { override fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean {
if (!isMoved && abs(distanceX) > abs(distanceY)) { if (!isMoved && abs(distanceX) > abs(distanceY)) {
//上一页或下一页截图,还未处理 //上一页或下一页截图,还未处理
bitmap = pageView.screenshot()
if (distanceX < 0) { if (distanceX < 0) {
bitmap = pageView.prevPage?.screenshot()
//上一页的参数配置 //上一页的参数配置
direction = Direction.PREV direction = Direction.PREV
//判断是否上一页存在 //判断是否上一页存在
@ -210,6 +210,7 @@ abstract class PageDelegate(private val pageView: PageView) {
return true return true
} }
} else { } else {
bitmap = pageView.nextPage?.screenshot()
//进行下一页的配置 //进行下一页的配置
direction = Direction.NEXT direction = Direction.NEXT
//判断是否下一页存在 //判断是否下一页存在

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