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. 21
      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,10 +13,13 @@ 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 {
textView?.let {
val textPages = arrayListOf<TextPage>() val textPages = arrayListOf<TextPage>()
val pageLines = arrayListOf<Int>() val pageLines = arrayListOf<Int>()
val pageLengths = arrayListOf<Int>() val pageLengths = arrayListOf<Int>()
@ -35,9 +38,9 @@ object ChapterProvider {
) )
} }
} }
textView.text = spannableStringBuilder it.text = spannableStringBuilder
val lastLine = textView.getLineNum() val lastLine = it.getLineNum()
val lastCharNum = textView.getCharNum(lastLine) val lastCharNum = it.getCharNum(lastLine)
if (lastCharNum == 0) { if (lastCharNum == 0) {
break break
} else { } else {
@ -71,6 +74,16 @@ object ChapterProvider {
pageLengths, pageLengths,
chapterSize chapterSize
) )
} ?: return TextChapter(
bookChapter.index,
bookChapter.title,
bookChapter.url,
arrayListOf(),
arrayListOf(),
arrayListOf(),
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