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