diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7fd8b30c8..6a16e962a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -40,7 +40,6 @@ import io.legado.app.ui.widget.page.TextChapter import io.legado.app.ui.widget.page.delegate.PageDelegate import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_read.* -import kotlinx.android.synthetic.main.view_book_page.* import kotlinx.android.synthetic.main.view_read_menu.* import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.coroutines.Dispatchers.IO @@ -272,7 +271,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo when (bookChapter.index) { viewModel.durChapterIndex -> launch { viewModel.curTextChapter = ChapterProvider - .getTextChapter(content_text_view, bookChapter, content, viewModel.chapterSize) + .getTextChapter(bookChapter, content, viewModel.chapterSize) page_view.upContent() curChapterChanged() if (intent.getBooleanExtra("readAloud", false)) { @@ -282,12 +281,12 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } viewModel.durChapterIndex - 1 -> launch { viewModel.prevTextChapter = ChapterProvider - .getTextChapter(content_text_view, bookChapter, content, viewModel.chapterSize) + .getTextChapter(bookChapter, content, viewModel.chapterSize) page_view.upContent(-1) } viewModel.durChapterIndex + 1 -> launch { viewModel.nextTextChapter = ChapterProvider - .getTextChapter(content_text_view, bookChapter, content, viewModel.chapterSize) + .getTextChapter(bookChapter, content, viewModel.chapterSize) page_view.upContent(1) } } @@ -560,7 +559,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEvent(Bus.UP_CONFIG) { upSystemUiVisibility() page_view.upBg() - content_view.upStyle() page_view.upStyle() if (it) { loadContent() diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index adbd87842..0f1d4f0d4 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -97,6 +97,9 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), observeEvent(Bus.RECREATE) { recreate() } + observeEvent(Bus.UP_CONFIG) { + content_view.upStyle() + } } private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt index 09fd9454a..80c21103a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt @@ -13,64 +13,77 @@ object ChapterProvider { var readAloudSpan = ForegroundColorSpan(App.INSTANCE.accentColor) private val titleSpan = RelativeSizeSpan(1.2f) + var textView: ContentTextView? = null + fun getTextChapter( - textView: ContentTextView, bookChapter: BookChapter, + bookChapter: BookChapter, content: String, chapterSize: Int ): TextChapter { - val textPages = arrayListOf() - val pageLines = arrayListOf() - val pageLengths = arrayListOf() - var surplusText = content - var pageIndex = 0 - while (surplusText.isNotEmpty()) { - val spannableStringBuilder = SpannableStringBuilder(surplusText) - if (pageIndex == 0) { - val end = surplusText.indexOf("\n") - if (end > 0) { - spannableStringBuilder.setSpan( - titleSpan, - 0, - end, - Spannable.SPAN_INCLUSIVE_EXCLUSIVE + textView?.let { + val textPages = arrayListOf() + val pageLines = arrayListOf() + val pageLengths = arrayListOf() + var surplusText = content + var pageIndex = 0 + while (surplusText.isNotEmpty()) { + val spannableStringBuilder = SpannableStringBuilder(surplusText) + if (pageIndex == 0) { + val end = surplusText.indexOf("\n") + if (end > 0) { + spannableStringBuilder.setSpan( + titleSpan, + 0, + end, + Spannable.SPAN_INCLUSIVE_EXCLUSIVE + ) + } + } + it.text = spannableStringBuilder + val lastLine = it.getLineNum() + val lastCharNum = it.getCharNum(lastLine) + if (lastCharNum == 0) { + break + } else { + pageLines.add(lastLine) + pageLengths.add(lastCharNum) + textPages.add( + TextPage( + index = pageIndex, + text = spannableStringBuilder.delete( + lastCharNum, + spannableStringBuilder.length + ), + title = bookChapter.title, + chapterSize = chapterSize, + chapterIndex = bookChapter.index + ) ) + surplusText = surplusText.substring(lastCharNum) + pageIndex++ } } - textView.text = spannableStringBuilder - val lastLine = textView.getLineNum() - val lastCharNum = textView.getCharNum(lastLine) - if (lastCharNum == 0) { - break - } else { - pageLines.add(lastLine) - pageLengths.add(lastCharNum) - textPages.add( - TextPage( - index = pageIndex, - text = spannableStringBuilder.delete( - lastCharNum, - spannableStringBuilder.length - ), - title = bookChapter.title, - chapterSize = chapterSize, - chapterIndex = bookChapter.index - ) - ) - surplusText = surplusText.substring(lastCharNum) - pageIndex++ + for (item in textPages) { + item.pageSize = textPages.size } - } - for (item in textPages) { - item.pageSize = textPages.size - } - return TextChapter( + return TextChapter( + bookChapter.index, + bookChapter.title, + bookChapter.url, + textPages, + pageLines, + pageLengths, + chapterSize + ) + } ?: return TextChapter( bookChapter.index, bookChapter.title, bookChapter.url, - textPages, - pageLines, - pageLengths, + arrayListOf(), + arrayListOf(), + arrayListOf(), chapterSize ) + } fun upReadAloudSpan() { diff --git a/app/src/main/res/layout/activity_book_read.xml b/app/src/main/res/layout/activity_book_read.xml index f82b1e06c..52eafcca2 100644 --- a/app/src/main/res/layout/activity_book_read.xml +++ b/app/src/main/res/layout/activity_book_read.xml @@ -4,18 +4,11 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - + +