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. 14
      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) { override fun loadContentFinish(bookChapter: BookChapter, content: String) {
launch { 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) val textChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
content_text_view.text = textChapter.pages[0].stringBuilder 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.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel 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.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
@ -17,10 +18,12 @@ import kotlinx.coroutines.Dispatchers.IO
class ReadBookViewModel(application: Application) : BaseViewModel(application) { class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var bookData = MutableLiveData<Book>() var bookData = MutableLiveData<Book>()
var bookSource: BookSource? = null
var chapterMaxIndex = MediatorLiveData<Int>() var chapterMaxIndex = MediatorLiveData<Int>()
var bookSource: BookSource? = null
var webBook: WebBook? = null var webBook: WebBook? = null
var callBack: CallBack? = null var callBack: CallBack? = null
var durChapterIndex = 0
var isLocalBook = true
fun initData(intent: Intent) { fun initData(intent: Intent) {
val bookUrl = intent.getStringExtra("bookUrl") val bookUrl = intent.getStringExtra("bookUrl")
@ -28,6 +31,8 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
App.db.bookDao().getBook(bookUrl)?.let { book -> App.db.bookDao().getBook(bookUrl)?.let { book ->
bookData.postValue(book) bookData.postValue(book)
durChapterIndex = book.durChapterIndex
isLocalBook = book.origin == BookType.local
bookSource = App.db.bookSourceDao().getBookSource(book.origin) bookSource = App.db.bookSourceDao().getBookSource(book.origin)
bookSource?.let { bookSource?.let {
webBook = WebBook(it) webBook = WebBook(it)

@ -8,9 +8,9 @@ import androidx.appcompat.widget.AppCompatTextView
class ContentTextView : AppCompatTextView { class ContentTextView : AppCompatTextView {
constructor(context: Context) : super(context) 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,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" 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 <io.legado.app.ui.widget.page.PageView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -23,8 +23,8 @@
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" android:theme="?attr/actionBarStyle"
android:theme="?attr/actionBarStyle"> android:visibility="gone">
<TextView <TextView
android:id="@+id/tv_chapter_name" android:id="@+id/tv_chapter_name"
@ -33,7 +33,8 @@
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
android:text="@string/chapter" android:text="@string/chapter"
android:textSize="12sp" /> android:textSize="12sp"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/tv_chapter_url" android:id="@+id/tv_chapter_url"
@ -42,7 +43,8 @@
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
android:text="@string/chapter" android:text="@string/chapter"
android:textSize="12sp" /> android:textSize="12sp"
android:visibility="gone" />
</io.legado.app.ui.widget.TitleBar> </io.legado.app.ui.widget.TitleBar>

Loading…
Cancel
Save