优化
This commit is contained in:
@@ -387,6 +387,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
binding.fbStop.invisible()
|
binding.fbStop.invisible()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun observeLiveBus() {
|
||||||
|
viewModel.upAdapterLiveData.observe(this) {
|
||||||
|
adapter.notifyItemRangeChanged(0, adapter.itemCount, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示书籍详情
|
* 显示书籍详情
|
||||||
*/
|
*/
|
||||||
@@ -398,6 +404,9 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已经加入书架
|
||||||
|
*/
|
||||||
override fun isInBookshelf(name: String, author: String): Boolean {
|
override fun isInBookshelf(name: String, author: String): Boolean {
|
||||||
return viewModel.bookshelf.contains("$name-$author")
|
return viewModel.bookshelf.contains("$name-$author")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,13 +94,21 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
|
|||||||
|
|
||||||
private fun bindChange(binding: ItemSearchBinding, searchBook: SearchBook, bundle: Bundle) {
|
private fun bindChange(binding: ItemSearchBinding, searchBook: SearchBook, bundle: Bundle) {
|
||||||
binding.run {
|
binding.run {
|
||||||
bundle.keySet().map {
|
bundle.keySet().forEach {
|
||||||
when (it) {
|
when (it) {
|
||||||
"origins" -> bvOriginCount.setBadgeCount(searchBook.origins.size)
|
"origins" -> bvOriginCount.setBadgeCount(searchBook.origins.size)
|
||||||
"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())
|
||||||
"cover" -> ivCover.load(searchBook.coverUrl, searchBook.name, searchBook.author, false, searchBook.origin)
|
"isInBookshelf" -> // todo 添加标志view
|
||||||
|
callBack.isInBookshelf(searchBook.name, searchBook.author)
|
||||||
|
"cover" -> ivCover.load(
|
||||||
|
searchBook.coverUrl,
|
||||||
|
searchBook.name,
|
||||||
|
searchBook.author,
|
||||||
|
false,
|
||||||
|
searchBook.origin
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +136,15 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface CallBack {
|
interface CallBack {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已经加入书架
|
||||||
|
*/
|
||||||
fun isInBookshelf(name: String, author: String): Boolean
|
fun isInBookshelf(name: String, author: String): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示书籍详情
|
||||||
|
*/
|
||||||
fun showBookInfo(name: String, author: String, bookUrl: String)
|
fun showBookInfo(name: String, author: String, bookUrl: String)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ import kotlinx.coroutines.launch
|
|||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
class SearchViewModel(application: Application) : BaseViewModel(application) {
|
class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||||
val bookshelf = hashSetOf<String>()
|
val bookshelf = hashSetOf<String>()
|
||||||
|
val upAdapterLiveData = MutableLiveData<String>()
|
||||||
val searchScope: SearchScope = SearchScope(AppConfig.searchScope)
|
val searchScope: SearchScope = SearchScope(AppConfig.searchScope)
|
||||||
private val searchModel = SearchModel(viewModelScope, object : SearchModel.CallBack {
|
private val searchModel = SearchModel(viewModelScope, object : SearchModel.CallBack {
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}.collect {
|
}.collect {
|
||||||
bookshelf.clear()
|
bookshelf.clear()
|
||||||
bookshelf.addAll(it)
|
bookshelf.addAll(it)
|
||||||
|
upAdapterLiveData.postValue("isInBookshelf")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user