From ba16beb2ce5a9c3d53daa82454ea56cdf86f9b76 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 30 Oct 2022 23:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/search/SearchActivity.kt | 9 +++++++++ .../app/ui/book/search/SearchAdapter.kt | 20 +++++++++++++++++-- .../app/ui/book/search/SearchViewModel.kt | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) 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") } } }