This commit is contained in:
Horis
2026-01-15 11:21:31 +08:00
parent d9fd278804
commit 5c368d27cd
7 changed files with 35 additions and 29 deletions
@@ -6,7 +6,6 @@ import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.databinding.ActivityExploreShowBinding
import io.legado.app.databinding.ViewLoadMoreBinding
@@ -82,11 +81,11 @@ class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreSh
}
}
override fun isInBookshelf(name: String, author: String): Boolean {
return viewModel.isInBookShelf(name, author)
override fun isInBookshelf(book: SearchBook): Boolean {
return viewModel.isInBookShelf(book)
}
override fun showBookInfo(book: Book) {
override fun showBookInfo(book: SearchBook) {
startActivity<BookInfoActivity> {
putExtra("name", book.name)
putExtra("author", book.author)
@@ -7,7 +7,6 @@ import androidx.core.view.isVisible
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.databinding.ItemSearchBinding
import io.legado.app.help.config.AppConfig
@@ -43,7 +42,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
binding.run {
tvName.text = item.name
tvAuthor.text = context.getString(R.string.author_show, item.author)
ivInBookshelf.isVisible = callBack.isInBookshelf(item.name, item.author)
ivInBookshelf.isVisible = callBack.isInBookshelf(item)
if (item.latestChapterTitle.isNullOrEmpty()) {
tvLasted.gone()
} else {
@@ -73,7 +72,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
bundle.keySet().forEach {
when (it) {
"isInBookshelf" -> ivInBookshelf.isVisible =
callBack.isInBookshelf(item.name, item.author)
callBack.isInBookshelf(item)
}
}
}
@@ -82,7 +81,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) {
holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let {
callBack.showBookInfo(it.toBook())
callBack.showBookInfo(it)
}
}
}
@@ -91,8 +90,8 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
/**
* 是否已经加入书架
*/
fun isInBookshelf(name: String, author: String): Boolean
fun isInBookshelf(book: SearchBook): Boolean
fun showBookInfo(book: Book)
fun showBookInfo(book: SearchBook)
}
}
@@ -40,6 +40,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
.forEach {
keys.add("${it.name}-${it.author}")
keys.add(it.name)
keys.add(it.bookUrl)
}
keys
}.catch {
@@ -82,12 +83,13 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
}
}
fun isInBookShelf(name: String, author: String): Boolean {
return if (author.isNotBlank()) {
bookshelf.contains("$name-$author")
} else {
bookshelf.contains(name)
}
fun isInBookShelf(book: SearchBook): Boolean {
val name = book.name
val author = book.author
val bookUrl = book.bookUrl
return (author.isNotBlank() && bookshelf.contains("$name-$author"))
|| bookshelf.contains(name)
|| bookshelf.contains(bookUrl)
}
}
@@ -65,6 +65,11 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
return@execute
}
if (bookUrl.isNotBlank()) {
appDb.bookDao.getBook(bookUrl)?.let {
inBookshelf = !it.isNotShelf
upBook(it)
return@execute
}
appDb.searchBookDao.getSearchBook(bookUrl)?.toBook()?.let {
upBook(it)
return@execute
@@ -24,6 +24,7 @@ import io.legado.app.constant.AppLog
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchKeyword
import io.legado.app.databinding.ActivityBookSearchBinding
import io.legado.app.lib.dialogs.alert
@@ -470,8 +471,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
/**
* 是否已经加入书架
*/
override fun isInBookshelf(name: String, author: String): Boolean {
return viewModel.isInBookShelf(name, author)
override fun isInBookshelf(book: SearchBook): Boolean {
return viewModel.isInBookShelf(book)
}
/**
@@ -83,8 +83,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
binding.run {
tvName.text = searchBook.name
tvAuthor.text = context.getString(R.string.author_show, searchBook.author)
ivInBookshelf.isVisible =
callBack.isInBookshelf(searchBook.name, searchBook.author)
ivInBookshelf.isVisible = callBack.isInBookshelf(searchBook)
bvOriginCount.setBadgeCount(searchBook.origins.size)
upLasted(binding, searchBook.latestChapterTitle)
tvIntroduce.text = searchBook.trimIntro(context)
@@ -107,8 +106,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
"last" -> upLasted(binding, searchBook.latestChapterTitle)
"intro" -> tvIntroduce.text = searchBook.trimIntro(context)
"kind" -> upKind(binding, searchBook.getKindList())
"isInBookshelf" -> ivInBookshelf.isVisible =
callBack.isInBookshelf(searchBook.name, searchBook.author)
"isInBookshelf" -> ivInBookshelf.isVisible = callBack.isInBookshelf(searchBook)
"cover" -> ivCover.load(
searchBook.coverUrl,
searchBook.name,
@@ -147,7 +145,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
/**
* 是否已经加入书架
*/
fun isInBookshelf(name: String, author: String): Boolean
fun isInBookshelf(book: SearchBook): Boolean
/**
* 显示书籍详情
@@ -69,6 +69,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
.forEach {
keys.add("${it.name}-${it.author}")
keys.add(it.name)
keys.add(it.bookUrl)
}
keys
}.catch {
@@ -83,12 +84,13 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
}
}
fun isInBookShelf(name: String, author: String): Boolean {
return if (author.isNotBlank()) {
bookshelf.contains("$name-$author")
} else {
bookshelf.contains(name)
}
fun isInBookShelf(book: SearchBook): Boolean {
val name = book.name
val author = book.author
val bookUrl = book.bookUrl
return (author.isNotBlank() && bookshelf.contains("$name-$author"))
|| bookshelf.contains(name)
|| bookshelf.contains(bookUrl)
}
/**