pull/32/head
kunfei 5 years ago
parent 5800bb9e67
commit 2fd8c5f278
  1. 3
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 1
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  3. 20
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  4. 15
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt
  5. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  6. 1
      app/src/main/res/layout/activity_book_info.xml

@ -6,6 +6,7 @@ import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey
import io.legado.app.constant.BookType
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.android.parcel.IgnoredOnParcel
@ -18,7 +19,7 @@ data class Book(
@PrimaryKey
var bookUrl: String = "", // 详情页Url(本地书源存储完整文件路径)
var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var origin: String = "", // 书源URL(默认BookType.local)
var origin: String = BookType.local, // 书源URL(默认BookType.local)
var name: String? = null, // 书籍名称(书源获取)
var author: String? = null, // 作者名称(书源获取)
var kind: String? = null, // 分类信息(书源获取)

@ -52,6 +52,7 @@ object Restore {
Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}")
continue
}
book.origin = jsonItem.readString("$.bookInfoBean.tag") ?: ""
book.author = jsonItem.readString("$.bookInfoBean.author")
book.type = if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0
book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl

@ -1,16 +1,36 @@
package io.legado.app.ui.bookinfo
import android.os.Bundle
import androidx.lifecycle.Observer
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_book_info.*
class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_book_info) {
override val viewModel: BookInfoViewModel
get() = getViewModel(BookInfoViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
viewModel.bookData.observe(this, Observer { showBook(it) })
viewModel.loadData(intent)
}
private fun showBook(book: Book) {
tv_name.text = book.name
tv_author.text = book.author
tv_origin.text = book.origin
tv_lasted.text = book.latestChapterTitle
tv_intro.text = book.getDisplayIntro()
book.getDisplayCover()?.let {
ImageLoader.load(this, it)
.placeholder(R.drawable.img_cover_default)
.error(R.drawable.img_cover_default)
.centerCrop()
.setAsDrawable(iv_cover)
}
}

@ -1,9 +1,24 @@
package io.legado.app.ui.bookinfo
import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
class BookInfoViewModel(application: Application) : BaseViewModel(application) {
val bookData = MutableLiveData<Book>()
fun loadData(intent: Intent) {
execute {
intent.getStringExtra("bookUrl")?.let {
App.db.bookDao().getBook(it)?.let { book ->
bookData.postValue(book)
}
}
}
}
}

@ -23,8 +23,8 @@ import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.bookinfo.BookInfoActivity
import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.ui.read.ReadActivity
import io.legado.app.ui.search.SearchActivity
import io.legado.app.utils.applyTint
@ -106,11 +106,11 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
}
override fun open(book: Book) {
context?.startActivity<ReadActivity>()
context?.startActivity<ReadActivity>(Pair("bookUrl", book.bookUrl))
}
override fun openBookInfo(book: Book) {
context?.startActivity<ChapterListActivity>(Pair("bookUrl", book.bookUrl))
context?.startActivity<BookInfoActivity>(Pair("bookUrl", book.bookUrl))
}
override fun search() {

@ -17,6 +17,7 @@
android:layout_width="76dp"
android:layout_height="110dp"
android:layout_margin="10dp"
android:src="@drawable/img_cover_default"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/title_bar" />

Loading…
Cancel
Save