From 5c85dd67a603953d814b4028e67d7a2726cb521c Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 17 Aug 2019 19:03:22 +0800 Subject: [PATCH] up --- .../app/ui/readbook/ReadBookActivity.kt | 22 +++++++++++++++++-- .../io/legado/app/ui/widget/page/PageView.kt | 13 ++++++++++- .../main/res/layout/activity_read_book.xml | 6 +++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index ddf06c871..46f2fa8b4 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -21,6 +21,8 @@ import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity 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 kotlinx.android.synthetic.main.activity_read_book.* 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.startActivity -class ReadBookActivity : VMBaseActivity(R.layout.activity_read_book), ChangeSourceDialog.CallBack, +class ReadBookActivity : VMBaseActivity(R.layout.activity_read_book), + PageView.CallBack, + ChangeSourceDialog.CallBack, ReadBookViewModel.CallBack { override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) @@ -47,6 +51,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea setSupportActionBar(toolbar) initAnimation() initView() + page_view.callBack = this viewModel.callBack = this viewModel.chapterMaxIndex.observe(this, Observer { bookLoadFinish() }) viewModel.bookData.observe(this, Observer { title_bar.title = it.name }) @@ -248,7 +253,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea tv_chapter_url.visible() } 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.prevTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) @@ -264,6 +269,19 @@ class ReadBookActivity : VMBaseActivity(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() { if (!ReadAloudService.isRun) { readAloudStatus = Status.STOP diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index e96545c68..8c44b7dd7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -17,7 +17,7 @@ import org.jetbrains.anko.horizontalPadding class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), PageDelegate.PageInterface { - + var callBack: CallBack? = null private var pageDelegate: PageDelegate? = 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) } + fun chapterLoadFinish() { + callBack?.textChapter()?.let { + content_text_view.text = it.page(0)?.stringBuilder + } + } + fun setPageFactory(factory: PageFactory<*>) { } @@ -70,4 +76,9 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att override fun hasPrev(): Boolean { return true } + + interface CallBack { + fun durChapterIndex(): Int + fun textChapter(chapterOnDur: Int = 0): TextChapter? + } } diff --git a/app/src/main/res/layout/activity_read_book.xml b/app/src/main/res/layout/activity_read_book.xml index 5c666055d..76e164e93 100644 --- a/app/src/main/res/layout/activity_read_book.xml +++ b/app/src/main/res/layout/activity_read_book.xml @@ -4,7 +4,13 @@ android:layout_height="match_parent" android:orientation="vertical"> + +