pull/49/head
kunfei 5 years ago
parent 270b78f65e
commit ccea3470fd
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  3. 105
      app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt
  4. 7
      app/src/main/res/layout/activity_book_read.xml
  5. 6
      app/src/main/res/layout/activity_main.xml

@ -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.ui.widget.page.delegate.PageDelegate
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_read.* 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_read_menu.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -272,7 +271,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
when (bookChapter.index) { when (bookChapter.index) {
viewModel.durChapterIndex -> launch { viewModel.durChapterIndex -> launch {
viewModel.curTextChapter = ChapterProvider viewModel.curTextChapter = ChapterProvider
.getTextChapter(content_text_view, bookChapter, content, viewModel.chapterSize) .getTextChapter(bookChapter, content, viewModel.chapterSize)
page_view.upContent() page_view.upContent()
curChapterChanged() curChapterChanged()
if (intent.getBooleanExtra("readAloud", false)) { if (intent.getBooleanExtra("readAloud", false)) {
@ -282,12 +281,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
} }
viewModel.durChapterIndex - 1 -> launch { viewModel.durChapterIndex - 1 -> launch {
viewModel.prevTextChapter = ChapterProvider viewModel.prevTextChapter = ChapterProvider
.getTextChapter(content_text_view, bookChapter, content, viewModel.chapterSize) .getTextChapter(bookChapter, content, viewModel.chapterSize)
page_view.upContent(-1) page_view.upContent(-1)
} }
viewModel.durChapterIndex + 1 -> launch { viewModel.durChapterIndex + 1 -> launch {
viewModel.nextTextChapter = ChapterProvider viewModel.nextTextChapter = ChapterProvider
.getTextChapter(content_text_view, bookChapter, content, viewModel.chapterSize) .getTextChapter(bookChapter, content, viewModel.chapterSize)
page_view.upContent(1) page_view.upContent(1)
} }
} }
@ -560,7 +559,6 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
observeEvent<Boolean>(Bus.UP_CONFIG) { observeEvent<Boolean>(Bus.UP_CONFIG) {
upSystemUiVisibility() upSystemUiVisibility()
page_view.upBg() page_view.upBg()
content_view.upStyle()
page_view.upStyle() page_view.upStyle()
if (it) { if (it) {
loadContent() loadContent()

@ -97,6 +97,9 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
observeEvent<String>(Bus.RECREATE) { observeEvent<String>(Bus.RECREATE) {
recreate() recreate()
} }
observeEvent<Boolean>(Bus.UP_CONFIG) {
content_view.upStyle()
}
} }
private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) :

@ -13,64 +13,77 @@ object ChapterProvider {
var readAloudSpan = ForegroundColorSpan(App.INSTANCE.accentColor) var readAloudSpan = ForegroundColorSpan(App.INSTANCE.accentColor)
private val titleSpan = RelativeSizeSpan(1.2f) private val titleSpan = RelativeSizeSpan(1.2f)
var textView: ContentTextView? = null
fun getTextChapter( fun getTextChapter(
textView: ContentTextView, bookChapter: BookChapter, bookChapter: BookChapter,
content: String, chapterSize: Int content: String, chapterSize: Int
): TextChapter { ): TextChapter {
val textPages = arrayListOf<TextPage>() textView?.let {
val pageLines = arrayListOf<Int>() val textPages = arrayListOf<TextPage>()
val pageLengths = arrayListOf<Int>() val pageLines = arrayListOf<Int>()
var surplusText = content val pageLengths = arrayListOf<Int>()
var pageIndex = 0 var surplusText = content
while (surplusText.isNotEmpty()) { var pageIndex = 0
val spannableStringBuilder = SpannableStringBuilder(surplusText) while (surplusText.isNotEmpty()) {
if (pageIndex == 0) { val spannableStringBuilder = SpannableStringBuilder(surplusText)
val end = surplusText.indexOf("\n") if (pageIndex == 0) {
if (end > 0) { val end = surplusText.indexOf("\n")
spannableStringBuilder.setSpan( if (end > 0) {
titleSpan, spannableStringBuilder.setSpan(
0, titleSpan,
end, 0,
Spannable.SPAN_INCLUSIVE_EXCLUSIVE 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 for (item in textPages) {
val lastLine = textView.getLineNum() item.pageSize = textPages.size
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++
} }
} return TextChapter(
for (item in textPages) { bookChapter.index,
item.pageSize = textPages.size bookChapter.title,
} bookChapter.url,
return TextChapter( textPages,
pageLines,
pageLengths,
chapterSize
)
} ?: return TextChapter(
bookChapter.index, bookChapter.index,
bookChapter.title, bookChapter.title,
bookChapter.url, bookChapter.url,
textPages, arrayListOf(),
pageLines, arrayListOf(),
pageLengths, arrayListOf(),
chapterSize chapterSize
) )
} }
fun upReadAloudSpan() { fun upReadAloudSpan() {

@ -4,18 +4,11 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<io.legado.app.ui.widget.page.ContentView
android:id="@+id/content_view"
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:id="@+id/page_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<io.legado.app.ui.book.read.ReadMenu <io.legado.app.ui.book.read.ReadMenu
android:id="@+id/read_menu" android:id="@+id/read_menu"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -4,6 +4,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<io.legado.app.ui.widget.page.ContentView
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation_view" android:id="@+id/bottom_navigation_view"
android:paddingLeft="5dp" android:paddingLeft="5dp"

Loading…
Cancel
Save