diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 4bce347b6..d48ffc8ad 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -387,6 +387,12 @@ class SearchActivity : VMBaseActivity 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) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 5b7acd88a..95678b484 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -20,6 +20,7 @@ import kotlinx.coroutines.launch @OptIn(ExperimentalCoroutinesApi::class) class SearchViewModel(application: Application) : BaseViewModel(application) { val bookshelf = hashSetOf() + val upAdapterLiveData = MutableLiveData() 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") } } }