mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
a4a7a63b2d
commit
ba16beb2ce
@ -387,6 +387,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
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 {
|
||||
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) {
|
||||
binding.run {
|
||||
bundle.keySet().map {
|
||||
bundle.keySet().forEach {
|
||||
when (it) {
|
||||
"origins" -> bvOriginCount.setBadgeCount(searchBook.origins.size)
|
||||
"last" -> upLasted(binding, searchBook.latestChapterTitle)
|
||||
"intro" -> tvIntroduce.text = searchBook.trimIntro(context)
|
||||
"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 {
|
||||
|
||||
/**
|
||||
* 是否已经加入书架
|
||||
*/
|
||||
fun isInBookshelf(name: String, author: String): Boolean
|
||||
|
||||
/**
|
||||
* 显示书籍详情
|
||||
*/
|
||||
fun showBookInfo(name: String, author: String, bookUrl: String)
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import kotlinx.coroutines.launch
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
val bookshelf = hashSetOf<String>()
|
||||
val upAdapterLiveData = MutableLiveData<String>()
|
||||
val searchScope: SearchScope = SearchScope(AppConfig.searchScope)
|
||||
private val searchModel = SearchModel(viewModelScope, object : SearchModel.CallBack {
|
||||
|
||||
@ -67,6 +68,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
}.collect {
|
||||
bookshelf.clear()
|
||||
bookshelf.addAll(it)
|
||||
upAdapterLiveData.postValue("isInBookshelf")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user