pull/32/head
kunfei 5 years ago
parent 8b3d956e7e
commit 5c85dd67a6
  1. 22
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 13
      app/src/main/java/io/legado/app/ui/widget/page/PageView.kt
  3. 6
      app/src/main/res/layout/activity_read_book.xml

@ -21,6 +21,8 @@ import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity
import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.ui.widget.page.ChapterProvider
import io.legado.app.ui.widget.page.PageView
import io.legado.app.ui.widget.page.TextChapter
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_read_book.* import kotlinx.android.synthetic.main.activity_read_book.*
import kotlinx.android.synthetic.main.view_book_page.* import kotlinx.android.synthetic.main.view_book_page.*
@ -29,7 +31,9 @@ import kotlinx.coroutines.launch
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book), ChangeSourceDialog.CallBack, class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book),
PageView.CallBack,
ChangeSourceDialog.CallBack,
ReadBookViewModel.CallBack { ReadBookViewModel.CallBack {
override val viewModel: ReadBookViewModel override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java) get() = getViewModel(ReadBookViewModel::class.java)
@ -47,6 +51,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
initAnimation() initAnimation()
initView() initView()
page_view.callBack = this
viewModel.callBack = this viewModel.callBack = this
viewModel.chapterMaxIndex.observe(this, Observer { bookLoadFinish() }) viewModel.chapterMaxIndex.observe(this, Observer { bookLoadFinish() })
viewModel.bookData.observe(this, Observer { title_bar.title = it.name }) viewModel.bookData.observe(this, Observer { title_bar.title = it.name })
@ -248,7 +253,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
tv_chapter_url.visible() tv_chapter_url.visible()
} }
viewModel.curTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) viewModel.curTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
content_text_view.text = viewModel.curTextChapter?.page(0)?.stringBuilder page_view.chapterLoadFinish()
} }
viewModel.durChapterIndex - 1 -> { viewModel.durChapterIndex - 1 -> {
viewModel.prevTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) viewModel.prevTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
@ -264,6 +269,19 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
override fun durChapterIndex(): Int {
return viewModel.durChapterIndex
}
override fun textChapter(chapterOnDur: Int): TextChapter? {
return when (chapterOnDur) {
0 -> viewModel.curTextChapter
1 -> viewModel.nextTextChapter
-1 -> viewModel.prevTextChapter
else -> null
}
}
private fun onClickReadAloud() { private fun onClickReadAloud() {
if (!ReadAloudService.isRun) { if (!ReadAloudService.isRun) {
readAloudStatus = Status.STOP readAloudStatus = Status.STOP

@ -17,7 +17,7 @@ import org.jetbrains.anko.horizontalPadding
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 private var pageDelegate: PageDelegate? = null
private var prevPage: ContentView? = null private var prevPage: ContentView? = null
@ -59,6 +59,12 @@ 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() {
callBack?.textChapter()?.let {
content_text_view.text = it.page(0)?.stringBuilder
}
}
fun setPageFactory(factory: PageFactory<*>) { fun setPageFactory(factory: PageFactory<*>) {
} }
@ -70,4 +76,9 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
override fun hasPrev(): Boolean { override fun hasPrev(): Boolean {
return true return true
} }
interface CallBack {
fun durChapterIndex(): Int
fun textChapter(chapterOnDur: Int = 0): TextChapter?
}
} }

@ -4,7 +4,13 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<io.legado.app.ui.widget.page.ContentView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
<io.legado.app.ui.widget.page.PageView <io.legado.app.ui.widget.page.PageView
android:id="@+id/page_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

Loading…
Cancel
Save