pull/32/head
kunfei 5 years ago
parent 74b69c6918
commit 515b537c9d
  1. 8
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 7
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt
  3. 4
      app/src/main/java/io/legado/app/ui/widget/page/ContentTextView.kt
  4. 20
      app/src/main/java/io/legado/app/ui/widget/page/ContentView.kt
  5. 16
      app/src/main/res/layout/activity_read_book.xml

@ -237,6 +237,14 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun loadContentFinish(bookChapter: BookChapter, content: String) {
launch {
if (viewModel.durChapterIndex == bookChapter.index) {
tv_chapter_name.text = bookChapter.title
tv_chapter_name.visible()
if (!viewModel.isLocalBook) {
tv_chapter_url.text = bookChapter.url
tv_chapter_url.visible()
}
}
val textChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
content_text_view.text = textChapter.pages[0].stringBuilder
}

@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
@ -17,10 +18,12 @@ import kotlinx.coroutines.Dispatchers.IO
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var bookData = MutableLiveData<Book>()
var bookSource: BookSource? = null
var chapterMaxIndex = MediatorLiveData<Int>()
var bookSource: BookSource? = null
var webBook: WebBook? = null
var callBack: CallBack? = null
var durChapterIndex = 0
var isLocalBook = true
fun initData(intent: Intent) {
val bookUrl = intent.getStringExtra("bookUrl")
@ -28,6 +31,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
execute {
App.db.bookDao().getBook(bookUrl)?.let { book ->
bookData.postValue(book)
durChapterIndex = book.durChapterIndex
isLocalBook = book.origin == BookType.local
bookSource = App.db.bookSourceDao().getBookSource(book.origin)
bookSource?.let {
webBook = WebBook(it)

@ -8,9 +8,9 @@ import androidx.appcompat.widget.AppCompatTextView
class ContentTextView : AppCompatTextView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
/**
* 获取当前页总字数

@ -0,0 +1,20 @@
package io.legado.app.ui.widget.page
import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import io.legado.app.R
class ContentView : FrameLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
init {
inflate(context, R.layout.view_book_page, this)
}
}

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<io.legado.app.ui.widget.page.PageView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/fl_menu"
@ -23,8 +23,8 @@
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:theme="?attr/actionBarStyle">
android:theme="?attr/actionBarStyle"
android:visibility="gone">
<TextView
android:id="@+id/tv_chapter_name"
@ -33,7 +33,8 @@
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/chapter"
android:textSize="12sp" />
android:textSize="12sp"
android:visibility="gone" />
<TextView
android:id="@+id/tv_chapter_url"
@ -42,7 +43,8 @@
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/chapter"
android:textSize="12sp" />
android:textSize="12sp"
android:visibility="gone" />
</io.legado.app.ui.widget.TitleBar>

Loading…
Cancel
Save