Skip to content

Commit

Permalink
[Feat]: 标签详情页
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Dec 10, 2023
1 parent 76e9372 commit a825f54
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 18 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@
android:name="com.xiaoyv.bangumi.ui.feature.summary.SummaryActivity"
android:configChanges="orientation|keyboard|screenSize"
android:exported="false" />
<activity
android:name="com.xiaoyv.bangumi.ui.feature.tag.TagDetailActivity"
android:configChanges="orientation|keyboard|screenSize"
android:exported="false" />
</application>

</manifest>
26 changes: 18 additions & 8 deletions app/src/main/java/com/xiaoyv/bangumi/helper/RouteHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class SearchDetailItemAdapter : BaseQuickDiffBindingAdapter<SearchResultEntity,

if (item.infoTip.time.isNotBlank()) {
binding.tvTime.text = buildString {
append(item.searchType)
append(item.searchTip)
append(" ")
append(item.infoTip.time)
}
} else {
binding.tvTime.text = item.searchType
binding.tvTime.text = item.searchTip
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.xiaoyv.bangumi.ui.feature.tag

import android.content.Intent
import android.os.Bundle
import com.xiaoyv.bangumi.R
import com.xiaoyv.bangumi.base.BaseListActivity
import com.xiaoyv.bangumi.helper.RouteHelper
import com.xiaoyv.bangumi.ui.feature.search.detail.SearchDetailItemAdapter
import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.common.api.parser.entity.SearchResultEntity
import com.xiaoyv.common.config.GlobalConfig
import com.xiaoyv.common.kts.setOnDebouncedChildClickListener
import com.xiaoyv.widget.binder.BaseQuickDiffBindingAdapter

/**
* Class: [TagDetailActivity]
*
* @author why
* @since 12/10/23
*/
class TagDetailActivity : BaseListActivity<SearchResultEntity, TagDetailViewModel>() {

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<SearchResultEntity, *> {
return SearchDetailItemAdapter()
}
}
Original file line number Diff line number Diff line change
@@ -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<SearchResultEntity>() {
internal var mediaType = MediaType.TYPE_UNKNOWN
internal var tag = ""
internal var time = ""

@BrowserSortType
internal var sort = BrowserSortType.TYPE_DEFAULT

override suspend fun onRequestListImpl(): List<SearchResultEntity> {
require(mediaType.isNotBlank()) { "标签条目类型不存在" }
require(tag.isNotBlank()) { "标签不存在" }
return BgmApiManager.bgmWebApi.queryTagDetail(mediaType, tag, time, sort, current)
.parserTagDetail()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class OverviewFragment : BaseViewModelFragment<FragmentOverviewBinding, Overview
RouteHelper.jumpPerson(it.id, true)
},
onClickTagItem = {
RouteHelper.jumpTagDetail(it.tagName)
RouteHelper.jumpTagDetail(it.mediaType, it.tagName)
},
onClickRelatedItem = {
RouteHelper.jumpMediaDetail(it.id)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
<com.xiaoyv.common.widget.state.AnimeStateView
android:id="@+id/state_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_search_detail_tag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_search"
android:id="@+id/item_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/ui_size_8"
Expand All @@ -19,6 +19,7 @@
android:id="@+id/tv_title_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.25"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?attr/colorOnSurface"
android:textStyle="bold"
Expand Down
16 changes: 16 additions & 0 deletions lib-common/src/main/java/com/xiaoyv/common/api/api/BgmWebApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,22 @@ interface BgmWebApi {
@Path("mediaType") mediaType: String,
@Path("keyword") keyword: String
): Document

/**
* 标签详细内容
*
* time 格式
* - /airtime/2024
* - /airtime/2024-12
*/
@GET("/{mediaType}/tag/{tag}{time}")
suspend fun queryTagDetail(
@Path("mediaType") mediaType: String,
@Path("tag") tag: String,
@Path("time", encoded = true) time: String,
@Query("sort") @BrowserSortType sortType: String? = null,
@Query("page") page: Int
): Document
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ data class MediaDetailEntity(
@SerializedName("tagName") var tagName: String = "",
@SerializedName("title") var title: String = "",
@SerializedName("count") var count: Int = 0,
@SerializedName("mediaType") var mediaType: String = "",
@SerializedName("url") var url: String = ""
) : Parcelable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ data class SearchResultEntity(
var infoTip: BrowserEntity.InfoTip = BrowserEntity.InfoTip(),
var rank: String = "",
var coverImage: String = "",
var searchType: String = ""
var searchTip: String = ""
) : IdEntity, Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fun Document.parserBlogDetail(blogId: String): BlogDetailEntity {
tag.tagName = item.attr("href").substringAfterLast("/").decodeUrl()
tag.title = item.text()
tag.url = item.attr("href")
tag.mediaType = item.attr("href").trim('/').substringBefore("/")
tag
}
blogEntity.comments = parserBottomComment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ fun Document.parserMediaDetail(): MediaDetailEntity {
mediaTag.tagName = attr("href").substringAfterLast("/").decodeUrl()
mediaTag.title = select("span").text()
mediaTag.count = select("small").text().parseCount()
mediaTag.mediaType = attr("href").trim('/').substringBefore("/").trim()
mediaTag.url = attr("href")
}

mediaTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.xiaoyv.common.api.parser.requireNoError
import com.xiaoyv.common.config.GlobalConfig
import com.xiaoyv.common.config.annotation.BgmPathType
import com.xiaoyv.common.config.annotation.MediaType
import com.xiaoyv.common.kts.decodeUrl
import com.xiaoyv.common.widget.star.StarCommentView
import org.jsoup.nodes.Element

Expand Down Expand Up @@ -51,7 +52,7 @@ fun Element.parserSearchResult(@BgmPathType pathType: String): List<SearchResult
else -> MediaType.TYPE_UNKNOWN
}
}
entity.searchType = GlobalConfig.mediaTypeName(mediaType)
entity.searchTip = GlobalConfig.mediaTypeName(mediaType)
entity
}
}
Expand All @@ -70,18 +71,18 @@ fun Element.parserSearchResult(@BgmPathType pathType: String): List<SearchResult
}
entity.infoTip =
BrowserParser.parserInfoTip(item.select(".prsn_info .tip").text().trim('/'))
entity.searchType = "人物"
entity.searchTip = "人物"
entity
}
}
// 搜索标签解析
BgmPathType.TYPE_SEARCH_TAG -> {
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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SearchResultEntity> {
// 标签详情页面复用 BgmPathType.TYPE_SEARCH_SUBJECT 的解析逻辑
return parserSearchResult(BgmPathType.TYPE_SEARCH_SUBJECT)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = ""
}
}

0 comments on commit a825f54

Please sign in to comment.