pull/51/head
kunfei 5 years ago
parent faf98af304
commit 08f91cb904
  1. 17
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 25
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  4. 17
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt

@ -114,6 +114,13 @@ object ReadBook {
}
}
fun skipToPage(page: Int) {
durPageIndex = page
callBack?.upContent()
curPageChanged()
saveRead()
}
fun curPageChanged() {
callBack?.upPageProgress()
if (BaseReadAloudService.isRun) {
@ -140,6 +147,16 @@ object ReadBook {
}
}
fun durChapterPos(): Int {
curTextChapter?.let {
if (durPageIndex < it.pageSize()) {
return durPageIndex
}
return it.pageSize() - 1
}
return durPageIndex
}
fun loadContent(index: Int) {
book?.let { book ->
if (addLoading(index)) {

@ -296,10 +296,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
read_menu.runMenuIn()
}
override fun chapterSize(): Int {
return ReadBook.chapterSize
}
override val oldBook: Book?
get() = ReadBook.book
@ -307,20 +303,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
viewModel.changeTo(book)
}
override fun durChapterIndex(): Int {
return ReadBook.durChapterIndex
}
override fun durChapterPos(): Int {
ReadBook.curTextChapter?.let {
if (ReadBook.durPageIndex < it.pageSize()) {
return ReadBook.durPageIndex
}
return it.pageSize() - 1
}
return ReadBook.durPageIndex
}
override fun setPageIndex(pageIndex: Int) {
ReadBook.durPageIndex = pageIndex
ReadBook.saveRead()
@ -355,13 +337,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
override fun skipToPage(page: Int) {
ReadBook.durPageIndex = page
page_view.upContent()
ReadBook.curPageChanged()
ReadBook.saveRead()
}
override fun openReplaceRule() {
startActivity<ReplaceRuleActivity>()
}

@ -132,7 +132,7 @@ class ReadMenu : FrameLayout {
}
override fun onStopTrackingTouch(seekBar: SeekBar) {
callBack?.skipToPage(seekBar.progress)
ReadBook.skipToPage(seekBar.progress)
}
})
@ -245,7 +245,6 @@ class ReadMenu : FrameLayout {
interface CallBack {
fun autoPage()
fun skipToPage(page: Int)
fun openReplaceRule()
fun openChapterList()
fun showReadStyle()

@ -7,6 +7,7 @@ import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import io.legado.app.help.ReadBookConfig
import io.legado.app.service.help.ReadBook
import io.legado.app.ui.widget.page.curl.CurlView
import io.legado.app.ui.widget.page.delegate.*
import io.legado.app.utils.activity
@ -113,7 +114,7 @@ class PageView(context: Context, attrs: AttributeSet) :
prevPage?.setContent(it.previousPage())
callBack?.let { callback ->
if (isScrollDelegate) {
curPage?.scrollTo(callback.textChapter()?.getStartLine(callback.durChapterPos()))
curPage?.scrollTo(callback.textChapter()?.getStartLine(ReadBook.durChapterPos()))
}
}
}
@ -180,14 +181,14 @@ class PageView(context: Context, attrs: AttributeSet) :
get() = pageDelegate is ScrollPageDelegate
override val pageIndex: Int
get() = callBack?.durChapterPos() ?: 0
get() = ReadBook.durChapterPos()
override fun setPageIndex(pageIndex: Int) {
callBack?.setPageIndex(pageIndex)
}
override fun getChapterPosition(): Int {
return callBack?.durChapterIndex() ?: 0
return ReadBook.durChapterIndex
}
override fun getChapter(position: Int): TextChapter? {
@ -207,15 +208,12 @@ class PageView(context: Context, attrs: AttributeSet) :
}
override fun hasNextChapter(): Boolean {
callBack?.let {
return it.durChapterIndex() < it.chapterSize() - 1
}
return false
return ReadBook.durChapterIndex < ReadBook.chapterSize - 1
}
override fun hasPrevChapter(): Boolean {
callBack?.let {
return it.durChapterIndex() > 0
return ReadBook.durChapterIndex > 0
}
return false
}
@ -240,9 +238,6 @@ class PageView(context: Context, attrs: AttributeSet) :
}
interface CallBack {
fun chapterSize(): Int
fun durChapterIndex(): Int
fun durChapterPos(): Int
/**
* chapterOnDur: 0为当前页,1为下一页,-1为上一页

Loading…
Cancel
Save