Skip to content

Commit

Permalink
[Fix]: 音乐章节评论解析修复
Browse files Browse the repository at this point in the history
  • Loading branch information
why committed Dec 23, 2023
1 parent ccb3c1d commit 1c02c82
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.common.api.parser.entity.MediaChapterEntity
import com.xiaoyv.common.config.annotation.BgmPathType
import com.xiaoyv.common.config.annotation.InterestType
import com.xiaoyv.common.config.annotation.MediaType
import com.xiaoyv.common.config.annotation.TopicType
import com.xiaoyv.common.helper.UserHelper
import com.xiaoyv.common.kts.setOnDebouncedChildClickListener
Expand Down Expand Up @@ -51,6 +52,13 @@ class MediaChapterFragment : BaseListFragment<MediaChapterEntity, MediaChapterVi
contentAdapter.setOnDebouncedChildClickListener(R.id.item_ep) {
if (it.splitter) return@setOnDebouncedChildClickListener

// 不支持编辑进度直接打开讨论话题
if (!MediaType.canEditEpProgress(activityViewModel.requireMediaType)) {
RouteHelper.jumpTopicDetail(it.id, TopicType.TYPE_EP)
return@setOnDebouncedChildClickListener
}

// 校验收藏状态是否可以编辑进度
if (activityViewModel.requireMediaCollectType != InterestType.TYPE_DO) {
requireActivity().showConfirmDialog(
message = "只有收藏为 (在看 | 在玩 | 在读 | 在听) 的条目才可以单独修改章节进度",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.xiaoyv.common.api.response.douban.DouBanPhotoEntity
import com.xiaoyv.common.config.annotation.BgmPathType
import com.xiaoyv.common.config.annotation.InterestType
import com.xiaoyv.common.config.annotation.MediaDetailType
import com.xiaoyv.common.config.annotation.TopicType
import com.xiaoyv.common.config.bean.AdapterTypeItem
import com.xiaoyv.common.helper.UserHelper
import com.xiaoyv.common.helper.callback.RecyclerItemTouchedListener
Expand Down Expand Up @@ -50,8 +51,12 @@ class OverviewFragment : BaseViewModelFragment<FragmentOverviewBinding, Overview
},
onClickEpItem = { adapter, _, position ->
val chapterEntity = adapter.getItem(position)
if (chapterEntity != null && chapterEntity.splitter.not() && viewModel.canChangeEpProgress) {
showEpCollectDialog(chapterEntity)
if (chapterEntity != null && chapterEntity.splitter.not()) {
if (viewModel.canChangeEpProgress) {
showEpCollectDialog(chapterEntity)
} else {
RouteHelper.jumpTopicDetail(chapterEntity.id, TopicType.TYPE_EP)
}
}
},
onClickEpAdd = { entity, isAddEp ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.xiaoyv.bangumi.ui.media.detail.review

import androidx.recyclerview.widget.DiffUtil
import com.xiaoyv.bangumi.databinding.FragmentMediaReviewItemBinding
import com.xiaoyv.common.api.parser.entity.MediaReviewEntity
import com.xiaoyv.common.api.parser.entity.MediaReviewBlogEntity
import com.xiaoyv.common.kts.loadImageAnimate
import com.xiaoyv.widget.binder.BaseQuickBindingHolder
import com.xiaoyv.widget.binder.BaseQuickDiffBindingAdapter
Expand All @@ -13,27 +13,27 @@ import com.xiaoyv.widget.binder.BaseQuickDiffBindingAdapter
* @author why
* @since 11/24/23
*/
class MediaReviewAdapter : BaseQuickDiffBindingAdapter<MediaReviewEntity,
class MediaReviewAdapter : BaseQuickDiffBindingAdapter<MediaReviewBlogEntity,
FragmentMediaReviewItemBinding>(ItemDiffItemCallback) {

override fun BaseQuickBindingHolder<FragmentMediaReviewItemBinding>.converted(item: MediaReviewEntity) {
override fun BaseQuickBindingHolder<FragmentMediaReviewItemBinding>.converted(item: MediaReviewBlogEntity) {
binding.ivAvatar.loadImageAnimate(item.avatar)
binding.tvTitle.text = String.format("日志:%s", item.title)
binding.tvContent.text = item.comment
binding.tvTime.text = item.time
}

private object ItemDiffItemCallback : DiffUtil.ItemCallback<MediaReviewEntity>() {
private object ItemDiffItemCallback : DiffUtil.ItemCallback<MediaReviewBlogEntity>() {
override fun areItemsTheSame(
oldItem: MediaReviewEntity,
newItem: MediaReviewEntity
oldItem: MediaReviewBlogEntity,
newItem: MediaReviewBlogEntity
): Boolean {
return oldItem.id == newItem.id
}

override fun areContentsTheSame(
oldItem: MediaReviewEntity,
newItem: MediaReviewEntity
oldItem: MediaReviewBlogEntity,
newItem: MediaReviewBlogEntity
): Boolean {
return oldItem == newItem
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.xiaoyv.bangumi.R
import com.xiaoyv.bangumi.base.BaseListFragment
import com.xiaoyv.bangumi.helper.RouteHelper
import com.xiaoyv.blueprint.constant.NavKey
import com.xiaoyv.common.api.parser.entity.MediaReviewEntity
import com.xiaoyv.common.api.parser.entity.MediaReviewBlogEntity
import com.xiaoyv.common.kts.setOnDebouncedChildClickListener
import com.xiaoyv.widget.binder.BaseQuickDiffBindingAdapter

Expand All @@ -16,7 +16,7 @@ import com.xiaoyv.widget.binder.BaseQuickDiffBindingAdapter
* @author why
* @since 11/24/23
*/
class MediaReviewFragment : BaseListFragment<MediaReviewEntity, MediaReviewViewModel>() {
class MediaReviewFragment : BaseListFragment<MediaReviewBlogEntity, MediaReviewViewModel>() {
override val isOnlyOnePage: Boolean
get() = false

Expand All @@ -27,7 +27,7 @@ class MediaReviewFragment : BaseListFragment<MediaReviewEntity, MediaReviewViewM
viewModel.mediaId = arguments.getString(NavKey.KEY_STRING).orEmpty()
}

override fun onCreateContentAdapter(): BaseQuickDiffBindingAdapter<MediaReviewEntity, *> {
override fun onCreateContentAdapter(): BaseQuickDiffBindingAdapter<MediaReviewBlogEntity, *> {
return MediaReviewAdapter()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.xiaoyv.bangumi.ui.media.detail.review

import com.xiaoyv.bangumi.base.BaseListViewModel
import com.xiaoyv.common.api.BgmApiManager
import com.xiaoyv.common.api.parser.entity.MediaReviewEntity
import com.xiaoyv.common.api.parser.impl.parserMediaReviews
import com.xiaoyv.common.api.parser.entity.MediaReviewBlogEntity
import com.xiaoyv.common.api.parser.impl.parserMediaBlog
import com.xiaoyv.common.config.annotation.MediaDetailType

/**
Expand All @@ -12,18 +12,18 @@ import com.xiaoyv.common.config.annotation.MediaDetailType
* @author why
* @since 11/24/23
*/
class MediaReviewViewModel : BaseListViewModel<MediaReviewEntity>() {
class MediaReviewViewModel : BaseListViewModel<MediaReviewBlogEntity>() {
/**
* 媒体ID
*/
internal var mediaId: String = ""

override suspend fun onRequestListImpl(): List<MediaReviewEntity> {
override suspend fun onRequestListImpl(): List<MediaReviewBlogEntity> {
require(mediaId.isNotBlank()) { "媒体ID不存在" }
return BgmApiManager.bgmWebApi.queryMediaDetail(
mediaId = mediaId,
type = MediaDetailType.TYPE_REVIEW,
page = current
).parserMediaReviews()
).parserMediaBlog()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class TimelinePageFragment : BaseListFragment<TimelineEntity, TimelinePageViewMo

override val isOnlyOnePage: Boolean
get() = !viewModel.hasMultiPage

override val loadingBias: Float
get() = if (viewModel.userId.isNotBlank()) 0.3f else super.loadingBias

override fun onCreateContentAdapter(): BaseDifferAdapter<TimelineEntity, *> {
return TimelinePageAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TimelinePageViewModel : BaseListViewModel<TimelineEntity>() {
/**
* 是否指定了用户 ID
*/
private val userId: String
internal val userId: String
get() = timelineTab?.userId.orEmpty()

private val timelineType: String
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/res/layout/fragment_media_chapter_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
android:paddingHorizontal="@dimen/ui_layout_margin"
android:paddingVertical="@dimen/ui_size_6"
android:textAppearance="?attr/textAppearanceBodySmall"
android:textColor="?attr/colorOnSurface"
app:layout_constraintTop_toBottomOf="@+id/title_native"
tools:text="@tools:sample/lorem" />

Expand All @@ -52,7 +53,7 @@
android:id="@+id/tv_time"
android:layout_width="@dimen/ui_size_0"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/ui_layout_margin"
android:layout_marginStart="@dimen/ui_layout_margin"
android:layout_marginBottom="@dimen/ui_size_10"
android:paddingVertical="@dimen/ui_size_6"
android:textAppearance="?attr/textAppearanceLabelMedium"
Expand All @@ -67,10 +68,15 @@
android:id="@+id/tv_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/ui_layout_margin"
android:drawablePadding="@dimen/ui_size_4"
android:gravity="center"
android:paddingVertical="@dimen/ui_layout_margin"
android:paddingStart="@dimen/ui_size_12"
android:paddingEnd="@dimen/ui_layout_margin"
android:textAppearance="?attr/textAppearanceLabelSmall"
android:textColor="?attr/colorPrimary"
android:textColor="?attr/colorOnSurface"
app:drawableStartCompat="@drawable/ic_comment_count"
app:drawableTint="?attr/colorOnSurfaceVariant"
app:layout_constraintBaseline_toBaselineOf="@+id/tv_time"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tv_time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ data class MediaDetailEntity(
@SerializedName("characters") var characters: List<MediaCharacter> = emptyList(),
@SerializedName("relativeMedia") var relativeMedia: List<MediaRelative> = emptyList(),
@SerializedName("sameLikes") var sameLikes: List<MediaRelative> = emptyList(),
@SerializedName("reviews") var reviews: List<MediaReviewEntity> = emptyList(),
@SerializedName("reviews") var reviews: List<MediaReviewBlogEntity> = emptyList(),
@SerializedName("boards") var boards: List<MediaBoardEntity> = emptyList(),
@SerializedName("comments") var comments: List<MediaCommentEntity> = emptyList(),
@SerializedName("rating") var rating: MediaRating = MediaRating(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import androidx.annotation.Keep
import kotlinx.parcelize.Parcelize

/**
* Class: [MediaReviewEntity]
* Class: [MediaReviewBlogEntity]
*
* @author why
* @since 11/29/23
*/
@Parcelize
@Keep
data class MediaReviewEntity(
data class MediaReviewBlogEntity(
var id: String = "",
var title: String = "",
var avatar: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class UserDetailEntity(
var book: SaveOverview = SaveOverview(),
var music: SaveOverview = SaveOverview(),
var real: SaveOverview = SaveOverview(),
var blog: List<MediaReviewEntity> = emptyList(),
var blog: List<MediaReviewBlogEntity> = emptyList(),
) {
data class SaveOverview(
var isEmpty: Boolean = true,
Expand Down
Loading

0 comments on commit 1c02c82

Please sign in to comment.