From 9de1ef1f99f76ada6077a79093cb3ce6d04b63fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=A8?= Date: Thu, 10 Oct 2024 15:28:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:GHZSCY-6136=20=E7=A4=BE=E5=8C=BA=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E4=BF=A1=E6=81=AF=E6=B5=81=E6=94=B9=E7=89=88&?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9B=BE=E6=96=87=E5=86=85=E5=AE=B9=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E2=80=94=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gamecenter/entity/FollowDynamicEntity.kt | 1 + .../home/ForumArticleAskItemViewHolder.kt | 1 + .../follow/FollowActivityResultLauncher.kt | 9 +++ .../follow/adapter/FollowDynamicAdapter.kt | 2 - .../follow/fragment/FollowHomeFragment.kt | 26 +++++++ .../home/follow/model/FollowRepository.kt | 1 + .../viewholder/FollowPostCardViewHolder.kt | 18 ++++- .../follow/viewmodel/FollowHomeViewModel.kt | 69 +++++++++++++++++++ .../fragment/ImageArticleDetailFragment.kt | 8 +-- .../personalhome/PersonalItemViewHolder.kt | 40 ++++++----- .../BaseAnswerOrArticleItemViewHolder.kt | 1 + 11 files changed, 149 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/gh/gamecenter/entity/FollowDynamicEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/FollowDynamicEntity.kt index d1b4b4b233..438c76fea4 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/FollowDynamicEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/FollowDynamicEntity.kt @@ -43,6 +43,7 @@ data class FollowDynamicEntity( const val FOLLOW_UPDATE_TYPE_LIBAO_EXCHANGE = "libao_exchange" const val FOLLOW_UPDATE_TYPE_ARTICLE = "article" const val FOLLOW_UPDATE_TYPE_USER_POST = "user_post" + const val FOLLOW_UPDATE_TYPE_IMAGE_ARTICLE = "image_article" } @Parcelize diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleAskItemViewHolder.kt b/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleAskItemViewHolder.kt index 8b5b996e70..49a450adeb 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleAskItemViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleAskItemViewHolder.kt @@ -387,6 +387,7 @@ class ForumArticleAskItemViewHolder( voteCountContainer.visibility = View.GONE } + forumNameContainer?.visibleIf(entity.community.id.isNotBlank()) if (entity.community.type == "official_bbs") { forumIcon?.displayGameIcon(entity.community.icon, null) } else { diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/follow/FollowActivityResultLauncher.kt b/app/src/main/java/com/gh/gamecenter/forum/home/follow/FollowActivityResultLauncher.kt index 69c17d4128..2e32d499ec 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/follow/FollowActivityResultLauncher.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/follow/FollowActivityResultLauncher.kt @@ -240,6 +240,15 @@ class FollowActivityResultLauncher( questionsDetailLauncher.launch(LauncherDestination(position, historyEntity = entity)) } + entity.type == ImageArticleEntity.IMAGE_ARTICLE_TYPE -> { + val imageArticleUri = Uri.Builder() + .path(RouteConsts.activity.imageArticleDetailActivity) + .appendQueryParameter(EntranceConsts.KEY_IMAGE_ARTICLE_ID, entity.id) + .appendQueryParameter(EntranceConsts.KEY_SOURCE_ENTRANCE, "关注-个人动态") + .build() + ARouter.getInstance().build(imageArticleUri).navigation() + } + else -> { commentEntityLauncher.launch(LauncherDestination(position, historyEntity = entity)) } diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/follow/adapter/FollowDynamicAdapter.kt b/app/src/main/java/com/gh/gamecenter/forum/home/follow/adapter/FollowDynamicAdapter.kt index 630aacb4aa..75ea3918bf 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/follow/adapter/FollowDynamicAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/follow/adapter/FollowDynamicAdapter.kt @@ -28,8 +28,6 @@ import com.gh.gamecenter.forum.home.follow.FollowDynamicPersonalItem import com.gh.gamecenter.forum.home.follow.viewholder.FollowFooterViewHolder import com.gh.gamecenter.forum.home.follow.viewholder.FollowInvalidViewHolder import com.gh.gamecenter.forum.home.follow.viewmodel.FollowDynamicListViewModel -import com.gh.gamecenter.forum.home.follow.viewmodel.FollowDynamicViewModel -import com.gh.gamecenter.forum.search.CommunitySearchEventListener import com.gh.gamecenter.personalhome.PersonalItemViewHolder class FollowDynamicAdapter( diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/follow/fragment/FollowHomeFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/home/follow/fragment/FollowHomeFragment.kt index fdb45a5a6b..4306193fe8 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/follow/fragment/FollowHomeFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/follow/fragment/FollowHomeFragment.kt @@ -35,6 +35,7 @@ import com.gh.gamecenter.core.provider.IVisitManagerProvider import com.gh.gamecenter.core.utils.MD5Utils import com.gh.gamecenter.databinding.FragmentFollowHomeBinding import com.gh.gamecenter.entity.FollowUserEntity +import com.gh.gamecenter.eventbus.EBImageArticleChanged import com.gh.gamecenter.eventbus.EBUserFollow import com.gh.gamecenter.feature.provider.IMessageDetailProvider import com.gh.gamecenter.forum.home.CommunityHomeFragment @@ -69,6 +70,7 @@ class FollowHomeFragment : LazyFragment(), IScrollable { ownerProducer = { requireParentFragment() } ) + private lateinit var userViewModel: UserViewModel private var userId: String? = null @@ -454,6 +456,30 @@ class FollowHomeFragment : LazyFragment(), IScrollable { } } + @Subscribe(threadMode = ThreadMode.MAIN) + fun onEventMainThread(changed: EBImageArticleChanged) { + when (changed) { + is EBImageArticleChanged.VoteChanged -> { + viewModel.voteChanged(changed) + } + + is EBImageArticleChanged.CommentChanged ->{ + viewModel.commentChanged(changed) + } + + is EBImageArticleChanged.DataChanged -> { + viewModel.itemChanged(changed) + } + + is EBImageArticleChanged.DataDeleted -> { + viewModel.itemDeleted(changed) + } + + else -> Unit + + } + } + override fun onDestroy() { super.onDestroy() mScrollCalculatorHelper?.currentPlayer?.release() diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/follow/model/FollowRepository.kt b/app/src/main/java/com/gh/gamecenter/forum/home/follow/model/FollowRepository.kt index 5426517c85..be3adafcec 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/follow/model/FollowRepository.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/follow/model/FollowRepository.kt @@ -7,6 +7,7 @@ import com.gh.gamecenter.core.utils.UrlFilterUtils import com.gh.gamecenter.entity.FollowCommonContentCollection import com.gh.gamecenter.entity.FollowDynamicEntity import com.gh.gamecenter.entity.FollowDynamicEntity.Companion.FOLLOW_UPDATE_TYPE_ARTICLE +import com.gh.gamecenter.entity.FollowDynamicEntity.Companion.FOLLOW_UPDATE_TYPE_IMAGE_ARTICLE import com.gh.gamecenter.entity.FollowDynamicEntity.Companion.FOLLOW_UPDATE_TYPE_LIBAO import com.gh.gamecenter.entity.FollowDynamicEntity.Companion.FOLLOW_UPDATE_TYPE_LIBAO_EXCHANGE import com.gh.gamecenter.entity.FollowDynamicEntity.Companion.FOLLOW_UPDATE_TYPE_USER_POST diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewholder/FollowPostCardViewHolder.kt b/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewholder/FollowPostCardViewHolder.kt index 16944c9522..8d5fd6771e 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewholder/FollowPostCardViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewholder/FollowPostCardViewHolder.kt @@ -2,12 +2,17 @@ package com.gh.gamecenter.forum.home.follow.viewholder import android.content.Context import android.graphics.Color +import android.net.Uri import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView.ViewHolder +import com.alibaba.android.arouter.launcher.ARouter import com.gh.gamecenter.R +import com.gh.gamecenter.common.constant.EntranceConsts +import com.gh.gamecenter.common.constant.RouteConsts import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.databinding.CommunityAnswerItemBinding +import com.gh.gamecenter.entity.ImageArticleEntity import com.gh.gamecenter.feature.entity.ArticleEntity import com.gh.gamecenter.forum.home.ForumArticleAskItemViewHolder import com.gh.gamecenter.forum.search.CommunitySearchEventListener @@ -29,13 +34,13 @@ class FollowPostCardViewHolder( fun bind(data: ArticleEntity, position: Int) { val articleEntity = data - viewHolder.binding.run { root.layoutParams = (root.layoutParams as ViewGroup.MarginLayoutParams).apply { topMargin = if (position == 0) 8F.dip2px() else 0 } if (position == 0) { - root.background = com.gh.gamecenter.common.R.drawable.background_shape_white_radius_12_top_only.toDrawable(context) + root.background = + com.gh.gamecenter.common.R.drawable.background_shape_white_radius_12_top_only.toDrawable(context) } else { root.setBackgroundColor(com.gh.gamecenter.common.R.color.ui_surface.toColor(context)) } @@ -118,6 +123,15 @@ class FollowPostCardViewHolder( ) ) } + + ImageArticleEntity.IMAGE_ARTICLE_TYPE -> { + val imageArticleUri = Uri.Builder() + .path(RouteConsts.activity.imageArticleDetailActivity) + .appendQueryParameter(EntranceConsts.KEY_IMAGE_ARTICLE_ID, articleEntity.id) + .appendQueryParameter(EntranceConsts.KEY_SOURCE_ENTRANCE, "社区-关注") + .build() + ARouter.getInstance().build(imageArticleUri).navigation() + } } } } diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewmodel/FollowHomeViewModel.kt b/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewmodel/FollowHomeViewModel.kt index f1bb67fab9..2520e89577 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewmodel/FollowHomeViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/follow/viewmodel/FollowHomeViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.MutableLiveData import com.gh.common.util.CheckLoginUtils import com.gh.gamecenter.R import com.gh.gamecenter.common.baselist.LoadStatus +import com.gh.gamecenter.common.entity.CommunityEntity import com.gh.gamecenter.common.entity.LinkEntity import com.gh.gamecenter.common.retrofit.BiResponse import com.gh.gamecenter.common.retrofit.JSONObjectResponse @@ -16,6 +17,8 @@ import com.gh.gamecenter.common.utils.SensorsBridge import com.gh.gamecenter.common.utils.observableToMain import com.gh.gamecenter.common.utils.singleToMain import com.gh.gamecenter.entity.FollowUserEntity +import com.gh.gamecenter.entity.ImageArticleEntity +import com.gh.gamecenter.eventbus.EBImageArticleChanged import com.gh.gamecenter.eventbus.EBUserFollow import com.gh.gamecenter.feature.entity.* import com.gh.gamecenter.feature.exposure.ExposureEvent @@ -312,5 +315,71 @@ class FollowHomeViewModel(application: Application) : AndroidViewModel(applicati compositeDisposable.clear() } + fun voteChanged(changed: EBImageArticleChanged.VoteChanged) { + notifyImageArticleItemChanged(changed.id) { + FollowPostCardItem( + data = it.copy( + _me = it.me.copy(isCommunityArticleVote = changed.isVoted), + _count = it.count.copy(vote = changed.count) + ), + ) + } + } + fun commentChanged(changed: EBImageArticleChanged.CommentChanged) { + notifyImageArticleItemChanged(changed.id) { + FollowPostCardItem( + data = it.copy( + _count = it.count.copy(comment = changed.count) + ) + ) + } + } + + fun itemChanged(changed: EBImageArticleChanged.DataChanged) { + val imageArticle = changed.data + notifyImageArticleItemChanged(imageArticle.id) { _ -> + val newArticle = ArticleEntity( + _id = imageArticle.id, + _title = imageArticle.title, + content = imageArticle.content, + _count = imageArticle.count, + time = imageArticle.time, + _images = imageArticle.images, + imagesInfo = imageArticle.imagesInfos, + _user = imageArticle.user, + _community = imageArticle.community?.toCommunityEntity() ?: CommunityEntity() + ) + FollowPostCardItem(newArticle) + } + } + + private fun notifyImageArticleItemChanged( + imageArticleId: String, + block: (ArticleEntity) -> FollowPostCardItem + ) { + val oldData = dataList.value ?: return + val newData = oldData.toMutableList() + val position = newData.indexOfFirst { + it is FollowPostCardItem && it.data.type == ImageArticleEntity.IMAGE_ARTICLE_TYPE && it.data.id == imageArticleId + } + if (position != -1) { + val oldImageArticle = (newData[position] as FollowPostCardItem).data + val newItem = block(oldImageArticle) + newData[position] = newItem + _dataList.value = newData + } + } + + fun itemDeleted(changed: EBImageArticleChanged.DataDeleted) { + val oldData = dataList.value ?: return + val newData = oldData.toMutableList() + val position = newData.indexOfFirst { + it is FollowPostCardItem && it.data.type == ImageArticleEntity.IMAGE_ARTICLE_TYPE && it.data.id == changed.imageArticleId + } + if (position != -1) { + newData.removeAt(position) + _dataList.value = newData + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/recommend/fragment/ImageArticleDetailFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/home/recommend/fragment/ImageArticleDetailFragment.kt index 7d125866c7..446c5261c6 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/recommend/fragment/ImageArticleDetailFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/recommend/fragment/ImageArticleDetailFragment.kt @@ -789,12 +789,12 @@ class ImageArticleDetailFragment : BaseFragment() { val imageArticle = viewModel.imageArticleDetailEntity.value ?: return var highlightDialogHintContent = "" val permissions = imageArticle.me.moderatorPermissions - if ((isHighlight && permissions.highlightCommunityArticle > Permissions.GUEST) || - (!isHighlight && permissions.cancelHighlightCommunityArticle > Permissions.GUEST) + if ((isHighlight && permissions.choicenessImageArticle > Permissions.GUEST) || + (!isHighlight && permissions.cancelChoicenessImageArticle > Permissions.GUEST) ) { highlightDialogHintContent = - if ((isHighlight && permissions.highlightCommunityArticle == Permissions.REPORTER) || - (!isHighlight && permissions.cancelHighlightCommunityArticle == Permissions.REPORTER) + if ((isHighlight && permissions.choicenessImageArticle == Permissions.REPORTER) || + (!isHighlight && permissions.cancelChoicenessImageArticle == Permissions.REPORTER) ) { "你的操作将提交给小编审核,确定提交吗?" } else { diff --git a/app/src/main/java/com/gh/gamecenter/personalhome/PersonalItemViewHolder.kt b/app/src/main/java/com/gh/gamecenter/personalhome/PersonalItemViewHolder.kt index 67f236ac18..a19b5cb1e9 100644 --- a/app/src/main/java/com/gh/gamecenter/personalhome/PersonalItemViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/personalhome/PersonalItemViewHolder.kt @@ -42,7 +42,7 @@ class PersonalItemViewHolder( position: Int, payloads: List? = null ) { - if(!payloads.isNullOrEmpty()){ + if (!payloads.isNullOrEmpty()) { // 局部更新 commentCount.isClickable = true bindCommendAndVote(historyEntity, entrance) @@ -51,25 +51,27 @@ class PersonalItemViewHolder( commentCount.isClickable = true bindCommendAndVote(historyEntity, entrance) - if (historyEntity.community.type == "official_bbs") { - forumIcon?.displayGameIcon(historyEntity.community.icon, null) - } else { - forumIcon?.displayGameIcon( - historyEntity.community.game?.getIcon(), - historyEntity.community.game?.iconSubscript, - historyEntity.community.game?.iconFloat - ) - } - - forumNameContainer?.setOnClickListener { - MtaHelper.onEvent(getEventId(entrance), getKey(entrance), historyEntity.community.name) - itemView.context.startActivity( - ForumDetailActivity.getIntent( - itemView.context, - historyEntity.community.id, - entrance + forumNameContainer?.visibleIf(historyEntity.community.id.isNotBlank()) { + if (historyEntity.community.type == "official_bbs") { + forumIcon?.displayGameIcon(historyEntity.community.icon, null) + } else { + forumIcon?.displayGameIcon( + historyEntity.community.game?.getIcon(), + historyEntity.community.game?.iconSubscript, + historyEntity.community.game?.iconFloat ) - ) + } + + forumNameContainer?.setOnClickListener { + MtaHelper.onEvent(getEventId(entrance), getKey(entrance), historyEntity.community.name) + itemView.context.startActivity( + ForumDetailActivity.getIntent( + itemView.context, + historyEntity.community.id, + entrance + ) + ) + } } val answer = AnswerEntity() diff --git a/app/src/main/java/com/gh/gamecenter/qa/answer/BaseAnswerOrArticleItemViewHolder.kt b/app/src/main/java/com/gh/gamecenter/qa/answer/BaseAnswerOrArticleItemViewHolder.kt index 18a92845e4..42575a47ee 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/answer/BaseAnswerOrArticleItemViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/answer/BaseAnswerOrArticleItemViewHolder.kt @@ -156,6 +156,7 @@ open class BaseAnswerOrArticleItemViewHolder(itemView: View) : BaseRecyclerViewH open fun bindCommendAndVote(entity: CommunityItemData, entrance: String, position: Int? = null) { binNormalView(entity) + forumNameContainer?.visibleIf(entity.community.id.isNotBlank()) if (entity.community.type == "official_bbs") { forumIcon?.displayGameIcon(entity.community.icon, null) } else {