From 68db40c4c80b46763cac72d0ce4eac8ae5e74c2d Mon Sep 17 00:00:00 2001 From: lyr <15622190878@163.com> Date: Thu, 18 Nov 2021 10:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=85=89=E7=8E=AF=E5=8A=A9=E6=89=8BV5?= =?UTF-8?q?.5.0=E3=80=91=E6=B8=B8=E6=88=8F=E5=8D=95-=E6=88=91=E7=9A=84?= =?UTF-8?q?=E6=94=B6=E8=97=8F=EF=BC=88=E5=AF=B9=E6=8E=A5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=89=20https://git.ghzs.com/pm/halo-app-issues/-/issues/15?= =?UTF-8?q?92=EF=BC=8C=20=E3=80=90=E5=85=89=E7=8E=AF=E5=8A=A9=E6=89=8BV5.5?= =?UTF-8?q?.0=E3=80=91=E6=B8=B8=E6=88=8F=E5=8D=95=E8=AF=A6=E6=83=85-?= =?UTF-8?q?=E9=A1=B6=E9=83=A8=E5=8C=BA=E5=9F=9F/=E6=B8=B8=E6=88=8F?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=88=E4=BA=8C=E3=80=81=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F-=E9=A1=B6=E9=83=A8=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=EF=BC=88=E8=A7=86=E9=A2=91=E6=95=B0=E6=8D=AE=E6=9C=AA=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=EF=BC=89=EF=BC=89https://git.ghzs.com/pm/halo-app-iss?= =?UTF-8?q?ues/-/issues/1601?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../collection/GamesCollectionAdapter.kt | 40 +- .../collection/GamesCollectionViewModel.kt | 45 ++- .../java/com/gh/gamecenter/entity/MeEntity.kt | 4 +- .../detail/GameCollectionDetailFragment.kt | 369 ++++++++++++++---- .../detail/GameCollectionDetailViewModel.kt | 90 ++++- .../detail/GameCollectionPosterFragment.kt | 6 +- .../retrofit/service/ApiService.java | 30 ++ .../drawable/button_round_black_alpha_10.xml | 9 + .../fragment_game_collection_detail.xml | 1 - .../game_collection_detail_image_item.xml | 7 +- .../game_collection_detail_video_item.xml | 37 +- .../main/res/layout/game_collection_item.xml | 3 +- app/src/main/res/values/colors.xml | 1 + 13 files changed, 541 insertions(+), 101 deletions(-) create mode 100644 app/src/main/res/drawable/button_round_black_alpha_10.xml diff --git a/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionAdapter.kt b/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionAdapter.kt index 9c307cc32c..e2a271e4de 100644 --- a/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionAdapter.kt @@ -14,10 +14,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.RecyclerView import com.gh.common.constant.ItemViewType -import com.gh.common.util.DialogHelper -import com.gh.common.util.goneIf -import com.gh.common.util.safelyGetInRelease -import com.gh.common.util.showAutoOrientation +import com.gh.common.util.* import com.gh.gamecenter.GameDetailActivity import com.gh.gamecenter.R import com.gh.gamecenter.adapter.viewholder.FooterViewHolder @@ -78,6 +75,7 @@ class GamesCollectionAdapter( tagIv.setBackgroundResource(R.drawable.ic_official) } } + if (mViewModel.mIsInsertGameCollection) { when (mViewModel.type) { GamesCollectionFragment.TYPE_COLLECT -> { @@ -134,6 +132,40 @@ class GamesCollectionAdapter( mContext.startActivity(GameCollectionDetailActivity.getIntent(mContext, itemEntity.id)) } } + + voteCountContainer.setOnClickListener { + debounceActionWithInterval(R.id.vote_count_container, 1000) { + mViewModel.postVoteGameCollection(itemEntity.id, !voteIcon.isChecked) { + if (!voteIcon.isChecked) { + voteCount.setTextColor(R.color.theme_font.toColor()) + voteIcon.isChecked = true + voteIcon.visibility = View.GONE + voteAnimation.visibility = View.VISIBLE + voteAnimation.setAnimation("lottie/community_vote.json") + voteAnimation.playAnimation() + voteAnimation.doOnAnimationEnd { + voteAnimation.visibility = View.GONE + voteIcon.visibility = View.VISIBLE + } + + itemEntity.me?.vote = true + itemEntity.count?.run { + vote++ + voteCount.text = vote.toString() + } + } else { + voteIcon.isChecked = false + itemEntity.me?.vote = false + itemEntity.count?.run { + vote-- + if (vote < 0) vote = 0 + voteCount.setTextColor(R.color.text_999999.toColor()) + voteCount.text = vote.toString() + } + } + } + } + } } } diff --git a/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionViewModel.kt b/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionViewModel.kt index 9a31217aa0..47a6adcc17 100644 --- a/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/collection/GamesCollectionViewModel.kt @@ -1,13 +1,18 @@ package com.gh.gamecenter.collection +import android.annotation.SuppressLint import android.app.Application import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider +import com.gh.common.util.ErrorHelper import com.gh.common.util.ToastUtils import com.gh.common.util.observableToMain +import com.gh.common.util.singleToMain import com.gh.gamecenter.baselist.ListViewModel +import com.gh.gamecenter.collection.GamesCollectionFragment.Companion.TYPE_COLLECT import com.gh.gamecenter.entity.GamesCollectionEntity +import com.gh.gamecenter.retrofit.BiResponse import com.gh.gamecenter.retrofit.Response import com.gh.gamecenter.retrofit.RetrofitManager import com.halo.assistant.HaloApp @@ -25,10 +30,14 @@ class GamesCollectionViewModel(application: Application, var userId: String, var override fun provideDataObservable(page: Int) = null override fun provideDataSingle(page: Int): Single> { - val map = if (mIsInsertGameCollection) { - hashMapOf("filter" to "display") - } else mapOf() - return RetrofitManager.getInstance(getApplication()).api.getUserGameCollectionList(userId, map) + return if (type == TYPE_COLLECT) { + mApi.getFavoriteGameCollectionList(userId) + } else { + val map = if (mIsInsertGameCollection) { + hashMapOf("filter" to "display") + } else mapOf() + mApi.getUserGameCollectionList(userId, map) + } } override fun mergeResultLiveData() { @@ -69,6 +78,34 @@ class GamesCollectionViewModel(application: Application, var userId: String, var }) } + @SuppressLint("CheckResult") + fun postVoteGameCollection(gameCollectionId: String, isVote: Boolean, successCallback: (() -> Unit)) { + val single = if (isVote) { + mApi.voteGameCollection(gameCollectionId) + } else { + mApi.unVoteGameCollection(gameCollectionId) + } + single.compose(singleToMain()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: ResponseBody) { + ToastUtils.toast(if (isVote) "点赞成功" else "取消点赞") + successCallback.invoke() + } + + override fun onFailure(exception: Exception) { + super.onFailure(exception) + + if (exception is HttpException) { + ErrorHelper.handleError( + getApplication(), + exception.response()?.errorBody()?.string() + ) + } + } + }) + } + + class Factory(private val mUserId: String, private val mType: String, private val mIsInsertGameCollection: Boolean) : ViewModelProvider.NewInstanceFactory() { override fun create(modelClass: Class): T { diff --git a/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt index e9ac7b7617..9a774510e2 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/MeEntity.kt @@ -116,7 +116,9 @@ class MeEntity(@SerializedName("is_community_voted") var questionDraft: QuestionDraftEntity? = null,//问题详情可能返回草稿 @SerializedName("is_follow_bbs") - var isFollowForum: Boolean = false + var isFollowForum: Boolean = false, + + var vote: Boolean = false ) : Parcelable @Parcelize diff --git a/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailFragment.kt b/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailFragment.kt index 442208839f..a77e94a62e 100644 --- a/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailFragment.kt @@ -3,6 +3,7 @@ package com.gh.gamecenter.gamecollection.detail import android.graphics.Color import android.os.Bundle import android.view.View +import androidx.annotation.ColorRes import androidx.recyclerview.widget.LinearLayoutManager import butterknife.OnClick import com.gh.common.util.* @@ -15,10 +16,14 @@ import com.gh.gamecenter.databinding.FragmentGameCollectionDetailBinding import com.gh.gamecenter.databinding.LayoutGameCollectionTagBinding import com.gh.gamecenter.entity.CommentEntity import com.gh.gamecenter.entity.GamesCollectionDetailEntity +import com.gh.gamecenter.eventbus.EBUserFollow import com.gh.gamecenter.manager.UserManager +import com.gh.gamecenter.qa.comment.base.BaseCommentViewModel import com.google.android.material.appbar.AppBarLayout import com.lightgame.download.DataWatcher import com.lightgame.download.DownloadEntity +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode import kotlin.math.abs class GameCollectionDetailFragment : @@ -27,9 +32,10 @@ class GameCollectionDetailFragment : private var mBinding: FragmentGameCollectionDetailBinding? = null private var mAdapter: GameCollectionDetailAdapter? = null private var mGameAdapter: GameCollectionDetailGameAdapter? = null - private var mEntity = GamesCollectionDetailEntity() + private var mEntity: GamesCollectionDetailEntity? = null private var mGameCollectionId = "" private var mFromSquare = false + private var mIsLight = false private val mDataWatcher = object : DataWatcher() { override fun onDataChanged(downloadEntity: DownloadEntity) { mGameAdapter?.notifyItemByDownload(downloadEntity) @@ -58,44 +64,9 @@ class GameCollectionDetailFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mListViewModel.gameCollectionLiveData.observe(viewLifecycleOwner, { - mEntity = it - initTopView() - }) - - mBinding?.appbar?.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> - if (!isAdded) return@OnOffsetChangedListener - - val absVerticalOffset = abs(verticalOffset) - mListRefresh?.isEnabled = absVerticalOffset <= 2 - - mBinding?.run { - if (mEntity.video == null) { - val bgOffset = imageItem.root.bottom - DisplayUtils.getStatusBarHeight(resources) - 48F.dip2px() - - if (absVerticalOffset >= bgOffset) { - DisplayUtils.setStatusBarColor(requireActivity(), R.color.white, true) - toolbarContainer.setBackgroundColor(Color.WHITE) - backIv.setImageResource(R.drawable.ic_bar_back) - toolbarUserContainer.visibility = View.VISIBLE - toolbarLightUserContainer.visibility = View.GONE - toolbarFollowTv.setBackgroundResource(R.drawable.button_round_1a2496ff) - toolbarFollowTv.setTextColor(R.color.theme.toColor()) - squareIv.setImageResource(R.drawable.ic_game_collection_square) - } else { - DisplayUtils.setStatusBarColor(requireActivity(), R.color.transparent, false) - toolbarContainer.setBackgroundColor(Color.TRANSPARENT) - backIv.setImageResource(R.drawable.ic_bar_back_light) - toolbarUserContainer.visibility = View.GONE - toolbarLightUserContainer.visibility = View.VISIBLE - toolbarFollowTv.setBackgroundResource(R.drawable.button_round_black_alpha_30) - toolbarFollowTv.setTextColor(Color.WHITE) - squareIv.setImageResource(R.drawable.ic_game_collection_square_light) - } - } - } - - }) + initView() + initObserver() + initAppbarListener() } override fun onResume() { @@ -109,28 +80,117 @@ class GameCollectionDetailFragment : DownloadManager.getInstance(context).removeObserver(mDataWatcher) } + private fun initView() { + mBinding?.run { + inputContainer.run { + bottomShareGroup.visibility = View.VISIBLE + replyTv.setBackgroundResource(R.drawable.button_round_f5f5f5) + replyTv.text = "说点什么吧" + replyTv.setDebouncedClickListener { + startCommentActivity() + } + } + } + } + + private fun initObserver() { + mListViewModel.loadResultLiveData.observeNonNull(this) { + when (it) { + BaseCommentViewModel.LoadResult.SUCCESS -> { + mEntity = mListViewModel.gameCollectionDetail + updateView() + } + } + } + + mListViewModel.followLiveData.observeNonNull(this) { + updateFollowView() + } + + mListViewModel.favoriteLiveData.observeNonNull(this) { + updateStartView() + } + + mListViewModel.likeLiveData.observeNonNull(this) { + updateLikeView() + } + } + + private fun initAppbarListener() { + mBinding?.appbar?.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> + if (!isAdded) return@OnOffsetChangedListener + + val absVerticalOffset = abs(verticalOffset) + mListRefresh?.isEnabled = absVerticalOffset <= 2 + + mBinding?.run { + mEntity?.run { + val bgOffset = if (video == null) { + imageItem.root.bottom - DisplayUtils.getStatusBarHeight(resources) - 48F.dip2px() + } else { + videoItem.player.bottom - DisplayUtils.getStatusBarHeight(resources) - 48F.dip2px() + } + mIsLight = absVerticalOffset < bgOffset + updateFollowView() + if (mIsLight) { + DisplayUtils.setStatusBarColor(requireActivity(), R.color.transparent, false) + toolbarContainer.setBackgroundColor(Color.TRANSPARENT) + backIv.setImageResource(R.drawable.ic_bar_back_light) + squareIv.setImageResource(R.drawable.ic_game_collection_square_light) + toolbarUserContainer.visibility = View.GONE + if (video == null) { + toolbarLightUserContainer.visibility = View.VISIBLE + } + } else { + DisplayUtils.setStatusBarColor(requireActivity(), R.color.white, true) + toolbarContainer.setBackgroundColor(Color.WHITE) + backIv.setImageResource(R.drawable.ic_bar_back) + squareIv.setImageResource(R.drawable.ic_game_collection_square) + toolbarUserContainer.visibility = View.VISIBLE + if (video == null) { + toolbarLightUserContainer.visibility = View.GONE + } + } + } + } + }) + } + + private fun updateView() { + initTopView() + updateFollowView() + updateStartView() + updateLikeView() + } + private fun initTopView() { mBinding?.run { mReuseNoConn?.setVisibility(View.GONE) mReuseNoData?.setVisibility(View.GONE) mListLoading?.setVisibility(View.GONE) - if (mEntity.video == null) { + mBinding?.run { + entity = mEntity + executePendingBindings() + squareIv.goneIf(mFromSquare) + } + + if (mEntity?.video == null) { imageItem.root.visibility = View.VISIBLE videoItem.root.visibility = View.GONE - initImageItemView() + initImageTypeView() } else { imageItem.root.visibility = View.GONE videoItem.root.visibility = View.VISIBLE - videoItem.entity = mEntity + initVideoTypeView() } - if (mEntity.games?.size ?: 0 > 0) { + if (mEntity?.games?.size ?: 0 > 0) { noneGameContainer.root.visibility = View.GONE gameListRv.run { visibility = View.VISIBLE layoutManager = LinearLayoutManager(requireContext()) - mGameAdapter = GameCollectionDetailGameAdapter(requireContext(), mEntity.games ?: listOf()) + mGameAdapter = GameCollectionDetailGameAdapter(requireContext(), mEntity?.games ?: listOf()) adapter = mGameAdapter } } else { @@ -140,43 +200,170 @@ class GameCollectionDetailFragment : } } - private fun initImageItemView() { - mBinding?.run { - entity = mEntity - executePendingBindings() - - squareIv.goneIf(mFromSquare) - } + private fun initImageTypeView() { mBinding?.imageItem?.run { - entity = mEntity - executePendingBindings() + mEntity?.run { + entity = this + executePendingBindings() - desTv.text = "游戏单简介:${mEntity.intro}" + desTv.text = "游戏单简介:${intro}" - when (mEntity.stamp) { - "special_choice" -> { - tagIv.setBackgroundResource(R.drawable.ic_chosen_big) + when (stamp) { + "special_choice" -> { + tagIv.setBackgroundResource(R.drawable.ic_chosen_big) + } + "official" -> { + tagIv.setBackgroundResource(R.drawable.ic_official_big) + } } - "official" -> { - tagIv.setBackgroundResource(R.drawable.ic_official_big) - } - } - if (!UserManager.getInstance().isLoggedIn) { - mEntity.tags?.forEachIndexed { index, tag -> - tagContainer.addView(getTagView(tag.name, index == mEntity.tags!!.size - 1)) + if (!UserManager.getInstance().isLoggedIn) { + tags?.forEachIndexed { index, tag -> + tagList.addView( + getTagView( + tag.name, + index == tags!!.size - 1, + R.color.white, + R.color.white_alpha_20 + ) + ) + } } } } } - private fun getTagView(content: String, isLast: Boolean): View { + private fun initVideoTypeView() { + mBinding?.videoItem?.run { + mEntity?.run { + entity = this + executePendingBindings() + + desTv.text = "游戏单简介:${intro}" + + when (stamp) { + "special_choice" -> { + tagIv.setBackgroundResource(R.drawable.ic_chosen_big) + } + "official" -> { + tagIv.setBackgroundResource(R.drawable.ic_official_big) + } + } + + if (!UserManager.getInstance().isLoggedIn) { + tags?.forEachIndexed { index, tag -> + tagList.addView( + getTagView( + tag.name, + index == tags!!.size - 1, + R.color.theme, + R.color.theme_alpha_20 + ) + ) + } + } + + userIcon.display(user?.border, user?.icon, user?.auth?.icon) + } + } + } + + private fun getTagView( + content: String, + isLast: Boolean, + @ColorRes tvColorRes: Int, + @ColorRes dividerColorRes: Int + ): View { return LayoutGameCollectionTagBinding.inflate(layoutInflater).apply { divider.goneIf(isLast) + divider.setBackgroundColor(dividerColorRes.toColor()) contentTv.text = content + contentTv.setTextColor(tvColorRes.toColor()) }.root } + private fun updateFollowView() { + if (mEntity?.video == null) { + updateImageItemFollowView() + } else { + updateVideoItemFollowView() + } + } + + private fun updateImageItemFollowView() { + mBinding?.toolbarFollowTv?.run { + val isFollow = mEntity?.me?.isFollower ?: false + visibility = View.VISIBLE + text = if (isFollow) "已关注" else "关注" + if (mIsLight) { + setBackgroundResource(if (isFollow) R.drawable.button_round_black_alpha_10 else R.drawable.button_round_black_alpha_30) + setTextColor(if (isFollow) R.color.white_alpha_60.toColor() else R.color.white.toColor()) + } else { + setBackgroundResource(if (isFollow) R.drawable.button_round_f5f5f5 else R.drawable.button_round_1a2496ff) + setTextColor(if (isFollow) R.color.text_999999.toColor() else R.color.theme.toColor()) + } + } + } + + private fun updateVideoItemFollowView() { + val isFollow = mEntity?.me?.isFollower ?: false + mBinding?.videoItem?.videoItemFollowTv?.run { + text = if (isFollow) "已关注" else "关注" + setBackgroundResource(if (isFollow) R.drawable.button_round_f5f5f5 else R.drawable.button_round_1a2496ff) + setTextColor(if (isFollow) R.color.text_999999.toColor() else R.color.theme.toColor()) + } + mBinding?.toolbarFollowTv?.run { + if (mIsLight) { + visibility = View.GONE + } else { + visibility = View.VISIBLE + text = if (isFollow) "已关注" else "关注" + setBackgroundResource(if (isFollow) R.drawable.button_round_f5f5f5 else R.drawable.button_round_1a2496ff) + setTextColor(if (isFollow) R.color.text_999999.toColor() else R.color.theme.toColor()) + } + } + } + + private fun updateStartView() { + mBinding?.inputContainer?.run { + bottomStarTv.text = mListViewModel.getStarText() + if (mEntity?.me?.isFavorite == true) { + bottomStarIv.setImageResource(R.drawable.ic_article_detail_stared_bottom_bar) + bottomStarTv.setTextColor(R.color.theme_font.toColor()) + } else { + bottomStarIv.setImageResource(R.drawable.ic_article_detail_star_bottom_bar) + bottomStarTv.setTextColor(R.color.text_666666.toColor()) + } + } + } + + private fun updateLikeView() { + mBinding?.inputContainer?.run { + bottomLikeTv.text = mListViewModel.getLikeText() + if (mEntity?.me?.vote == true) { + bottomLikeIv.setImageResource(R.drawable.ic_article_detail_liked_bottom_bar) + bottomLikeTv.setTextColor(R.color.theme_font.toColor()) + } else { + bottomLikeIv.setImageResource(R.drawable.ic_article_detail_like_bottom_bar) + bottomLikeTv.setTextColor(R.color.text_666666.toColor()) + } + } + } + + private fun startCommentActivity() { + mEntity?.run { +// val intent = CommentActivity.getQuestionCommentIntent( +// requireContext(), +// it.id ?: "", +// it.count.answer, +// true, +// it.community.id, +// true +// ) +// startActivityForResult(intent, CommentActivity.REQUEST_CODE) + } + } + override fun onLoadDone() { super.onLoadDone() } @@ -191,30 +378,70 @@ class GameCollectionDetailFragment : mListRv.visibility = View.VISIBLE } - @OnClick(R.id.desIv, R.id.toolbarLightUserContainer, R.id.toolbarUserContainer, R.id.toolbarFollowTv, R.id.squareIv) + @Subscribe(threadMode = ThreadMode.MAIN) + fun onUserFollow(change: EBUserFollow) { + mEntity?.me?.isFollower = change.isFollow + updateFollowView() + } + + @OnClick(R.id.backIv, R.id.imageDesIv, R.id.videoItemDesIv, R.id.toolbarLightUserContainer, R.id.toolbarUserContainer, + R.id.videoItemUserContainer, R.id.toolbarFollowTv, R.id.videoItemFollowTv, R.id.squareIv, R.id.bottomStarIv, + R.id.bottomLikeIv) override fun onClick(v: View) { when (v.id) { - R.id.desIv -> { - startActivity(GameCollectionPosterActivity.getIntent(requireContext(), mEntity)) + R.id.backIv -> requireActivity().finish() + + R.id.imageDesIv -> { + startActivity(GameCollectionPosterActivity.getIntent(requireContext(), mEntity ?: GamesCollectionDetailEntity())) + } + + R.id.videoItemDesIv -> { + startActivity(GameCollectionPosterActivity.getIntent(requireContext(), mEntity ?: GamesCollectionDetailEntity())) } R.id.toolbarLightUserContainer -> { - DirectUtils.directToHomeActivity(requireContext(), mEntity.user?.id, "", "游戏单详情-导航栏") + DirectUtils.directToHomeActivity(requireContext(), mEntity?.user?.id, "", "游戏单详情-导航栏") } R.id.toolbarUserContainer -> { - DirectUtils.directToHomeActivity(requireContext(), mEntity.user?.id, "", "游戏单详情-导航栏") + DirectUtils.directToHomeActivity(requireContext(), mEntity?.user?.id, "", "游戏单详情-导航栏") + } + + R.id.videoItemUserContainer -> { + DirectUtils.directToHomeActivity(requireContext(), mEntity?.user?.id, "", "游戏单详情-导航栏") } R.id.toolbarFollowTv -> { ifLogin("游戏单详情") { - mListViewModel?.followingCommand(mEntity.user?.id ?: "", mEntity.me?.isFollower == false) + mListViewModel?.followingCommand(mEntity?.user?.id ?: "", mEntity?.me?.isFollower == false) + } + } + + R.id.videoItemFollowTv -> { + ifLogin("游戏单详情") { + mListViewModel?.followingCommand(mEntity?.user?.id ?: "", mEntity?.me?.isFollower == false) } } R.id.squareIv -> { } + + R.id.bottomStarIv -> { + debounceActionWithInterval(v.id) { + ifLogin("游戏单详情") { + mListViewModel?.postFavoriteGameCollection() + } + } + } + + R.id.bottomLikeIv -> { + debounceActionWithInterval(v.id) { + ifLogin("游戏单详情") { + mListViewModel?.postVoteGameCollection() + } + } + } } } diff --git a/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailViewModel.kt b/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailViewModel.kt index 41c1ad259b..715c3e0b7d 100644 --- a/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionDetailViewModel.kt @@ -11,6 +11,8 @@ import com.gh.gamecenter.baselist.ListViewModel import com.gh.gamecenter.entity.CommentEntity import com.gh.gamecenter.entity.GamesCollectionDetailEntity import com.gh.gamecenter.eventbus.EBUserFollow +import com.gh.gamecenter.manager.UserManager +import com.gh.gamecenter.qa.comment.base.BaseCommentViewModel import com.gh.gamecenter.retrofit.BiResponse import com.gh.gamecenter.retrofit.Response import com.gh.gamecenter.retrofit.RetrofitManager @@ -28,8 +30,11 @@ class GameCollectionDetailViewModel(application: Application, ListViewModel(application) { private val mApi = RetrofitManager.getInstance(getApplication()).api - val gameCollectionLiveData = MutableLiveData() + val loadResultLiveData = MutableLiveData() var followLiveData = MutableLiveData() + val favoriteLiveData = MutableLiveData() + val likeLiveData = MutableLiveData() + var gameCollectionDetail: GamesCollectionDetailEntity? = null init { getGameCollectionDetail() @@ -41,7 +46,19 @@ class GameCollectionDetailViewModel(application: Application, .compose(singleToMain()) .subscribe(object : BiResponse() { override fun onSuccess(data: GamesCollectionDetailEntity) { - gameCollectionLiveData.postValue(data) + gameCollectionDetail = data + loadResultLiveData.postValue(BaseCommentViewModel.LoadResult.SUCCESS) + } + + override fun onFailure(exception: Exception) { + super.onFailure(exception) + if (exception is HttpException) { + if (exception.code().toString().startsWith("404")) { + loadResultLiveData.postValue(BaseCommentViewModel.LoadResult.DELETED) + } else { + loadResultLiveData.postValue(BaseCommentViewModel.LoadResult.NETWORK_ERROR) + } + } } }) } @@ -81,6 +98,8 @@ class GameCollectionDetailViewModel(application: Application, } else { Utils.toast(getApplication(), R.string.concern_cancel) } + gameCollectionDetail?.me?.isFollower = + gameCollectionDetail?.me?.isFollower != true followLiveData.postValue(isFollow) EventBus.getDefault().post(EBUserFollow(userId, isFollow)) } @@ -92,6 +111,73 @@ class GameCollectionDetailViewModel(application: Application, }) } + @SuppressLint("CheckResult") + fun postFavoriteGameCollection() { + if (gameCollectionDetail == null) return + val single = if (gameCollectionDetail?.me?.isFavorite == true) { + mApi.deleteFavoriteGameCollection(UserManager.getInstance().userId, gameCollectionId) + } else { + mApi.favoriteGameCollection(UserManager.getInstance().userId, gameCollectionId) + } + single.compose(singleToMain()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: ResponseBody) { + if (gameCollectionDetail?.me?.isFavorite == true) { + ToastUtils.showToast("取消收藏") + } else { + ToastUtils.showToast("收藏成功") + } + gameCollectionDetail?.me?.isFavorite = + gameCollectionDetail?.me?.isFavorite != true + favoriteLiveData.postValue(true) + } + }) + } + + @SuppressLint("CheckResult") + fun postVoteGameCollection() { + if (gameCollectionDetail == null) return + val single = if (gameCollectionDetail?.me?.vote == true) { + mApi.unVoteGameCollection(gameCollectionId) + } else { + mApi.voteGameCollection(gameCollectionId) + } + single.compose(singleToMain()) + .subscribe(object : BiResponse() { + override fun onSuccess(data: ResponseBody) { + if (gameCollectionDetail?.me?.vote == true) { + gameCollectionDetail!!.count!!.vote-- + ToastUtils.showToast("取消点赞") + } else { + gameCollectionDetail!!.count!!.vote++ + ToastUtils.showToast("点赞成功") + } + gameCollectionDetail?.me?.vote = + gameCollectionDetail?.me?.vote != true + likeLiveData.postValue(true) + } + + override fun onFailure(exception: Exception) { + super.onFailure(exception) + + if (exception is HttpException) { + ErrorHelper.handleError( + getApplication(), + exception.response()?.errorBody()?.string() + ) + } + } + }) + } + + fun getLikeText(): String { + return if (gameCollectionDetail?.count?.vote == 0) "赞同" else "${gameCollectionDetail?.count?.vote}" + } + + fun getStarText(): String { + return if (gameCollectionDetail?.count?.favorite == 0) "收藏" else "${gameCollectionDetail?.count?.favorite}" + } + // override fun hideCommentSuccess() { // questionDetail?.count?.answer = (questionDetail?.count?.answer ?: 0) - 1 // loadResultLiveData.postValue(LoadResult.SUCCESS) diff --git a/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionPosterFragment.kt b/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionPosterFragment.kt index 9582ebab30..ba0f6484cc 100644 --- a/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionPosterFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/gamecollection/detail/GameCollectionPosterFragment.kt @@ -90,16 +90,16 @@ class GameCollectionPosterFragment : NormalFragment() { R.id.backIv -> requireActivity().finish() R.id.userIcon -> { - DirectUtils.directToHomeActivity(requireContext(), mEntity?.user?.id, "", "游戏单详情-封面页") + DirectUtils.directToHomeActivity(requireContext(), mEntity.user?.id, "", "游戏单详情-封面页") } R.id.userName -> { - DirectUtils.directToHomeActivity(requireContext(), mEntity?.user?.id, "", "游戏单详情-封面页") + DirectUtils.directToHomeActivity(requireContext(), mEntity.user?.id, "", "游戏单详情-封面页") } R.id.followTv -> { ifLogin("游戏单详情-封面页") { - mViewModel?.followingCommand(mEntity?.user?.id ?: "", mEntity?.me?.isFollower == false) + mViewModel?.followingCommand(mEntity.user?.id ?: "", mBinding?.followTv?.text == "关注") } } } diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index ac7f3f3336..b5e4a5b990 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -3324,4 +3324,34 @@ public interface ApiService { */ @GET("game_lists/tags") Single> getGameCollectionTagList(); + + /** + * 获取用户收藏的游戏单列表 + */ + @GET("users/{user_id}/favorites/game_list") + Single> getFavoriteGameCollectionList(@Path("user_id") String userId); + + /** + * 添加游戏单收藏 + */ + @POST("users/{user_id}/favorites/game_list/{game_list_id}") + Single favoriteGameCollection(@Path("user_id") String userId, @Path("game_list_id") String id); + + /** + * 取消游戏单收藏 + */ + @DELETE("users/{user_id}/favorites/game_list/{game_list_id}") + Single deleteFavoriteGameCollection(@Path("user_id") String userId, @Path("game_list_id") String id); + + /** + * 点赞游戏单 + */ + @POST("game_lists/{game_list_id}:vote") + Single voteGameCollection(@Path("game_list_id") String id); + + /** + * 取消点赞游戏单 + */ + @POST("game_lists/{game_list_id}:unvote") + Single unVoteGameCollection(@Path("game_list_id") String id); } \ No newline at end of file diff --git a/app/src/main/res/drawable/button_round_black_alpha_10.xml b/app/src/main/res/drawable/button_round_black_alpha_10.xml new file mode 100644 index 0000000000..b2dd803ce5 --- /dev/null +++ b/app/src/main/res/drawable/button_round_black_alpha_10.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_game_collection_detail.xml b/app/src/main/res/layout/fragment_game_collection_detail.xml index c631cb6d61..204d9bfaa9 100644 --- a/app/src/main/res/layout/fragment_game_collection_detail.xml +++ b/app/src/main/res/layout/fragment_game_collection_detail.xml @@ -163,7 +163,6 @@ + + + @@ -118,11 +132,12 @@ android:layout_height="match_parent" android:paddingLeft="16dp" android:paddingRight="16dp" + android:gravity="center_vertical" android:orientation="horizontal" /> @@ -208,7 +222,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" - android:layout_marginLeft="12dp" + android:layout_marginLeft="5dp" android:includeFontPadding="false" android:textColor="@color/text_cccccc" android:textSize="10sp" @@ -220,15 +234,16 @@ @@ -236,7 +251,7 @@ android:layout_width="match_parent" android:layout_height="8dp" android:background="@color/text_f5f5f5" - app:layout_constraintTop_toBottomOf="@+id/userContainer" /> + app:layout_constraintTop_toBottomOf="@+id/videoItemUserContainer" /> \ No newline at end of file diff --git a/app/src/main/res/layout/game_collection_item.xml b/app/src/main/res/layout/game_collection_item.xml index 66ba66257e..2775743f98 100644 --- a/app/src/main/res/layout/game_collection_item.xml +++ b/app/src/main/res/layout/game_collection_item.xml @@ -248,6 +248,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" + android:checked="@{entity.me.vote}" android:src="@drawable/game_collection_vote_selector" /> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 4aac4429e8..ebd673bd84 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,6 +4,7 @@ #2496FF + #332496FF #FFA142