diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index d86bd415f..4d08f9dcb 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -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, // 分类信息(书源获取) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 28cfec374..7eb6c1411 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index b7c553c85..91e2d73a4 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -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(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) + } } diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index 687c04350..296565424 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -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() + + fun loadData(intent: Intent) { + execute { + intent.getStringExtra("bookUrl")?.let { + App.db.bookDao().getBook(it)?.let { book -> + bookData.postValue(book) + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 30cb4e293..2cba38d6d 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -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(R.layout.fragment_b } override fun open(book: Book) { - context?.startActivity() + context?.startActivity(Pair("bookUrl", book.bookUrl)) } override fun openBookInfo(book: Book) { - context?.startActivity(Pair("bookUrl", book.bookUrl)) + context?.startActivity(Pair("bookUrl", book.bookUrl)) } override fun search() { diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 0f2f12be1..80d451fe6 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -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" />