diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e909e0a..65dff596 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -180,6 +180,10 @@ android:name="com.xiaoyv.bangumi.ui.feature.summary.SummaryActivity" android:configChanges="orientation|keyboard|screenSize" android:exported="false" /> + \ No newline at end of file diff --git a/app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt b/app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt index 2a718ec0..844c13da 100644 --- a/app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt +++ b/app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt @@ -20,6 +20,7 @@ import com.xiaoyv.bangumi.ui.feature.search.SearchActivity import com.xiaoyv.bangumi.ui.feature.search.detail.SearchDetailActivity import com.xiaoyv.bangumi.ui.feature.setting.SettingActivity import com.xiaoyv.bangumi.ui.feature.summary.SummaryActivity +import com.xiaoyv.bangumi.ui.feature.tag.TagDetailActivity import com.xiaoyv.bangumi.ui.feature.topic.TopicActivity import com.xiaoyv.bangumi.ui.feature.user.UserActivity import com.xiaoyv.bangumi.ui.media.detail.MediaDetailActivity @@ -28,6 +29,7 @@ import com.xiaoyv.blueprint.constant.NavKey import com.xiaoyv.blueprint.kts.open import com.xiaoyv.common.api.parser.entity.MediaDetailEntity import com.xiaoyv.common.config.annotation.BgmPathType +import com.xiaoyv.common.config.annotation.MediaType import com.xiaoyv.common.config.annotation.TopicType import com.xiaoyv.common.config.bean.SearchItem import com.xiaoyv.common.helper.CacheHelper @@ -56,25 +58,25 @@ object RouteHelper { } // 话题 titleLink.contains(BgmPathType.TYPE_TOPIC) -> { - when{ + when { // 虚拟人物 - titleLink.contains(TopicType.TYPE_CRT)-> { + titleLink.contains(TopicType.TYPE_CRT) -> { jumpTopicDetail(id, TopicType.TYPE_CRT) } // 章节 - titleLink.contains(TopicType.TYPE_EP)-> { + titleLink.contains(TopicType.TYPE_EP) -> { jumpTopicDetail(id, TopicType.TYPE_EP) } // 小组 - titleLink.contains(TopicType.TYPE_GROUP)-> { + titleLink.contains(TopicType.TYPE_GROUP) -> { jumpTopicDetail(id, TopicType.TYPE_GROUP) } // 现实人物 - titleLink.contains(TopicType.TYPE_PERSON)-> { + titleLink.contains(TopicType.TYPE_PERSON) -> { jumpTopicDetail(id, TopicType.TYPE_PERSON) } // 条目 - titleLink.contains(TopicType.TYPE_SUBJECT)-> { + titleLink.contains(TopicType.TYPE_SUBJECT) -> { jumpTopicDetail(id, TopicType.TYPE_SUBJECT) } } @@ -173,8 +175,16 @@ object RouteHelper { } - fun jumpTagDetail(tag: String) { - + /** + * 标签详情页面 + */ + fun jumpTagDetail(@MediaType mediaType: String, tag: String) { + TagDetailActivity::class.open( + bundleOf( + NavKey.KEY_STRING to mediaType, + NavKey.KEY_STRING_SECOND to tag + ) + ) } fun jumpGroupDetail(groupId: String) { diff --git a/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailActivity.kt b/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailActivity.kt index f24fe4de..8bf1f684 100644 --- a/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailActivity.kt +++ b/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailActivity.kt @@ -116,6 +116,15 @@ class SearchDetailActivity : } } } + + contentTagAdapter.setOnDebouncedChildClickListener(R.id.item_tag) { entity -> + useNotNull(viewModel.currentSearchItem.value) { + // 针对标签的搜索结果,SearchItem 的 id 在 SearchViewModel 填充为 MediaType + val tagMediaType = this.id + val tagName = entity.id + RouteHelper.jumpTagDetail(tagMediaType, tagName) + } + } } override fun LifecycleOwner.initViewObserver() { diff --git a/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailItemAdapter.kt b/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailItemAdapter.kt index 66bad799..fa58ef04 100644 --- a/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailItemAdapter.kt +++ b/app/src/main/java/com/xiaoyv/bangumi/ui/feature/search/detail/SearchDetailItemAdapter.kt @@ -30,12 +30,12 @@ class SearchDetailItemAdapter : BaseQuickDiffBindingAdapter() { + + override val isOnlyOnePage: Boolean + get() = false + + override fun initIntentData(intent: Intent, bundle: Bundle, isNewIntent: Boolean) { + viewModel.mediaType = bundle.getString(NavKey.KEY_STRING).orEmpty() + viewModel.tag = bundle.getString(NavKey.KEY_STRING_SECOND).orEmpty() + } + + override fun initView() { + super.initView() + binding.toolbar.title = buildString { + append(GlobalConfig.mediaTypeName(viewModel.mediaType)) + append("标签:") + append(viewModel.tag) + } + } + + override fun initListener() { + super.initListener() + + contentAdapter.setOnDebouncedChildClickListener(R.id.item_search) { + RouteHelper.jumpMediaDetail(it.id) + } + } + + override fun onCreateContentAdapter(): BaseQuickDiffBindingAdapter { + return SearchDetailItemAdapter() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xiaoyv/bangumi/ui/feature/tag/TagDetailViewModel.kt b/app/src/main/java/com/xiaoyv/bangumi/ui/feature/tag/TagDetailViewModel.kt new file mode 100644 index 00000000..0215d621 --- /dev/null +++ b/app/src/main/java/com/xiaoyv/bangumi/ui/feature/tag/TagDetailViewModel.kt @@ -0,0 +1,30 @@ +package com.xiaoyv.bangumi.ui.feature.tag + +import com.xiaoyv.bangumi.base.BaseListViewModel +import com.xiaoyv.common.api.BgmApiManager +import com.xiaoyv.common.api.parser.entity.SearchResultEntity +import com.xiaoyv.common.api.parser.impl.parserTagDetail +import com.xiaoyv.common.config.annotation.BrowserSortType +import com.xiaoyv.common.config.annotation.MediaType + +/** + * Class: [TagDetailViewModel] + * + * @author why + * @since 12/10/23 + */ +class TagDetailViewModel : BaseListViewModel() { + internal var mediaType = MediaType.TYPE_UNKNOWN + internal var tag = "" + internal var time = "" + + @BrowserSortType + internal var sort = BrowserSortType.TYPE_DEFAULT + + override suspend fun onRequestListImpl(): List { + require(mediaType.isNotBlank()) { "标签条目类型不存在" } + require(tag.isNotBlank()) { "标签不存在" } + return BgmApiManager.bgmWebApi.queryTagDetail(mediaType, tag, time, sort, current) + .parserTagDetail() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/xiaoyv/bangumi/ui/media/detail/overview/OverviewFragment.kt b/app/src/main/java/com/xiaoyv/bangumi/ui/media/detail/overview/OverviewFragment.kt index 1a74b367..2f00395f 100644 --- a/app/src/main/java/com/xiaoyv/bangumi/ui/media/detail/overview/OverviewFragment.kt +++ b/app/src/main/java/com/xiaoyv/bangumi/ui/media/detail/overview/OverviewFragment.kt @@ -47,7 +47,7 @@ class OverviewFragment : BaseViewModelFragment + android:layout_height="match_parent" + app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_search_detail_tag.xml b/app/src/main/res/layout/activity_search_detail_tag.xml index b369cc4b..0279a6df 100644 --- a/app/src/main/res/layout/activity_search_detail_tag.xml +++ b/app/src/main/res/layout/activity_search_detail_tag.xml @@ -2,7 +2,7 @@ MediaType.TYPE_UNKNOWN } } - entity.searchType = GlobalConfig.mediaTypeName(mediaType) + entity.searchTip = GlobalConfig.mediaTypeName(mediaType) entity } } @@ -70,7 +71,7 @@ fun Element.parserSearchResult(@BgmPathType pathType: String): List { select("#tagList > a").map { item -> val entity = SearchResultEntity() - entity.id = item.attr("href").substringAfterLast("/") + entity.id = item.attr("href").substringAfterLast("/").decodeUrl() entity.count = item.nextElementSibling()?.text().orEmpty() entity.title = item.text() - entity.searchType = "标签" + entity.searchTip = "标签" entity } } diff --git a/lib-common/src/main/java/com/xiaoyv/common/api/parser/impl/TagParser.kt b/lib-common/src/main/java/com/xiaoyv/common/api/parser/impl/TagParser.kt new file mode 100644 index 00000000..4c0b9e3e --- /dev/null +++ b/lib-common/src/main/java/com/xiaoyv/common/api/parser/impl/TagParser.kt @@ -0,0 +1,14 @@ +package com.xiaoyv.common.api.parser.impl + +import com.xiaoyv.common.api.parser.entity.SearchResultEntity +import com.xiaoyv.common.config.annotation.BgmPathType +import org.jsoup.nodes.Element + +/** + * @author why + * @since 12/10/23 + */ +fun Element.parserTagDetail(): List { + // 标签详情页面复用 BgmPathType.TYPE_SEARCH_SUBJECT 的解析逻辑 + return parserSearchResult(BgmPathType.TYPE_SEARCH_SUBJECT) +} \ No newline at end of file diff --git a/lib-common/src/main/java/com/xiaoyv/common/config/annotation/BrowserSortType.kt b/lib-common/src/main/java/com/xiaoyv/common/config/annotation/BrowserSortType.kt index ea4a7f86..e5d6f33c 100644 --- a/lib-common/src/main/java/com/xiaoyv/common/config/annotation/BrowserSortType.kt +++ b/lib-common/src/main/java/com/xiaoyv/common/config/annotation/BrowserSortType.kt @@ -13,6 +13,7 @@ import androidx.annotation.StringDef BrowserSortType.TYPE_DATE, BrowserSortType.TYPE_TITLE, BrowserSortType.TYPE_RATE, + BrowserSortType.TYPE_COLLECTS, BrowserSortType.TYPE_DEFAULT ) @Retention(AnnotationRetention.SOURCE) @@ -23,6 +24,7 @@ annotation class BrowserSortType { const val TYPE_TITLE = "title" const val TYPE_RATE = "rate" + const val TYPE_COLLECTS = "collects" const val TYPE_DEFAULT = "" } } \ No newline at end of file