【光环助手V5.5.0】游戏单-我的收藏(对接接口) https://git.ghzs.com/pm/halo-app-issues/-/issues/1592,
【光环助手V5.5.0】游戏单详情-顶部区域/游戏列表(二、视频样式-顶部区域(视频数据未对接))https://git.ghzs.com/pm/halo-app-issues/-/issues/1601
This commit is contained in:
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<MutableList<GamesCollectionEntity>> {
|
||||
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<ResponseBody>() {
|
||||
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 <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<CommentEntity, CommentEntity>(application) {
|
||||
|
||||
private val mApi = RetrofitManager.getInstance(getApplication()).api
|
||||
val gameCollectionLiveData = MutableLiveData<GamesCollectionDetailEntity>()
|
||||
val loadResultLiveData = MutableLiveData<BaseCommentViewModel.LoadResult>()
|
||||
var followLiveData = MutableLiveData<Boolean>()
|
||||
val favoriteLiveData = MutableLiveData<Boolean>()
|
||||
val likeLiveData = MutableLiveData<Boolean>()
|
||||
var gameCollectionDetail: GamesCollectionDetailEntity? = null
|
||||
|
||||
init {
|
||||
getGameCollectionDetail()
|
||||
@ -41,7 +46,19 @@ class GameCollectionDetailViewModel(application: Application,
|
||||
.compose(singleToMain())
|
||||
.subscribe(object : BiResponse<GamesCollectionDetailEntity>() {
|
||||
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<ResponseBody>() {
|
||||
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<ResponseBody>() {
|
||||
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)
|
||||
|
||||
@ -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 == "关注")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3324,4 +3324,34 @@ public interface ApiService {
|
||||
*/
|
||||
@GET("game_lists/tags")
|
||||
Single<ArrayList<GameCollectionTagEntity>> getGameCollectionTagList();
|
||||
|
||||
/**
|
||||
* 获取用户收藏的游戏单列表
|
||||
*/
|
||||
@GET("users/{user_id}/favorites/game_list")
|
||||
Single<List<GamesCollectionEntity>> getFavoriteGameCollectionList(@Path("user_id") String userId);
|
||||
|
||||
/**
|
||||
* 添加游戏单收藏
|
||||
*/
|
||||
@POST("users/{user_id}/favorites/game_list/{game_list_id}")
|
||||
Single<ResponseBody> favoriteGameCollection(@Path("user_id") String userId, @Path("game_list_id") String id);
|
||||
|
||||
/**
|
||||
* 取消游戏单收藏
|
||||
*/
|
||||
@DELETE("users/{user_id}/favorites/game_list/{game_list_id}")
|
||||
Single<ResponseBody> deleteFavoriteGameCollection(@Path("user_id") String userId, @Path("game_list_id") String id);
|
||||
|
||||
/**
|
||||
* 点赞游戏单
|
||||
*/
|
||||
@POST("game_lists/{game_list_id}:vote")
|
||||
Single<ResponseBody> voteGameCollection(@Path("game_list_id") String id);
|
||||
|
||||
/**
|
||||
* 取消点赞游戏单
|
||||
*/
|
||||
@POST("game_lists/{game_list_id}:unvote")
|
||||
Single<ResponseBody> unVoteGameCollection(@Path("game_list_id") String id);
|
||||
}
|
||||
Reference in New Issue
Block a user