diff --git a/app/src/main/java/com/gh/common/util/CommentUtils.java b/app/src/main/java/com/gh/common/util/CommentUtils.java index a15ccc1c51..b603369292 100644 --- a/app/src/main/java/com/gh/common/util/CommentUtils.java +++ b/app/src/main/java/com/gh/common/util/CommentUtils.java @@ -12,8 +12,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import androidx.core.content.ContextCompat; - import com.gh.gamecenter.CommentDetailActivity; import com.gh.gamecenter.R; import com.gh.gamecenter.adapter.viewholder.CommentViewHolder; @@ -22,6 +20,7 @@ import com.gh.gamecenter.entity.MeEntity; import com.gh.gamecenter.entity.UserInfoEntity; import com.gh.gamecenter.manager.UserManager; import com.gh.gamecenter.retrofit.BiResponse; +import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.halo.assistant.HaloApp; import com.lightgame.utils.Utils; @@ -40,6 +39,8 @@ import java.util.Date; import java.util.List; import java.util.Locale; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import okhttp3.ResponseBody; @@ -279,6 +280,9 @@ public class CommentUtils { if (TextUtils.isEmpty(articleId)) { entrance = "社区文章详情-评论-点赞"; } + if (TextUtils.isEmpty(videoId)) { + entrance = "视频流-评论-点赞"; + } CheckLoginUtils.checkLogin(context, entrance, () -> { if (commentLikeCountTv.getCurrentTextColor() == ContextCompat.getColor(context, R.color.theme_font)) { ToastUtils.INSTANCE.showToast("已经点过赞啦!"); @@ -331,6 +335,52 @@ public class CommentUtils { }); } + public static void unVoteComment(final Context context, + String videoId, + final CommentEntity commentEntity, + final TextView commentLikeCountTv, + final ImageView commentLikeIv) { + String entrance = "视频流-评论-取消点赞"; + CheckLoginUtils.checkLogin(context, entrance, () -> { + commentEntity.setVote(commentEntity.getVote() - 1); + commentLikeCountTv.setTextColor(ContextCompat.getColor(context, R.color.text_666666)); + commentLikeIv.setImageResource(R.drawable.comment_vote_unselect); + commentLikeCountTv.setText(NumberUtils.transSimpleCount(commentEntity.getVote())); + if (commentEntity.getVote() == 0) { + commentLikeCountTv.setVisibility(View.GONE); + } + + RetrofitManager.getInstance(context).getApi() + .unVoteVideoComment(videoId, commentEntity.getId()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Response() { + @Override + public void onResponse(@Nullable ResponseBody response) { + super.onResponse(response); + } + + @Override + public void onFailure(@Nullable HttpException e) { + super.onFailure(e); + commentEntity.setVote(commentEntity.getVote() + 1); + commentLikeCountTv.setTextColor(ContextCompat.getColor(context, R.color.theme_font)); + commentLikeIv.setImageResource(R.drawable.comment_vote_select); + commentLikeCountTv.setText(NumberUtils.transSimpleCount(commentEntity.getVote())); + commentLikeCountTv.setVisibility(View.VISIBLE); + try { + if (e != null && e.response().errorBody() != null) { + ErrorHelper.handleError(context, e.response().errorBody().string(), false); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + }); + + }); + } + // 设置评论item 用户相关的view(点赞/头像/用户名) public static void setCommentUserView(Context mContext, CommentViewHolder holder, CommentEntity entity) { diff --git a/app/src/main/java/com/gh/gamecenter/qa/comment/StairsCommentViewHolder.kt b/app/src/main/java/com/gh/gamecenter/qa/comment/StairsCommentViewHolder.kt index b34815340c..11d7fea0fc 100644 --- a/app/src/main/java/com/gh/gamecenter/qa/comment/StairsCommentViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/qa/comment/StairsCommentViewHolder.kt @@ -148,8 +148,12 @@ class StairsCommentViewHolder(val binding: StairsCommentItemBinding, val isReply DirectUtils.directToBadgeWall(binding.root.context, commentEntity.user.id, commentEntity.user.name, commentEntity.user.icon) } holder.binding.commentLikeContainer.setOnClickListener { - CommentUtils.likeComment(binding.root.context, mViewModel.answerId, mViewModel.articleId, - mViewModel.communityId, mViewModel.videoId, commentEntity, holder.binding.commentLikeCount, holder.binding.commentLike, null) + if (holder.binding.commentLikeCount.currentTextColor == ContextCompat.getColor(context, R.color.theme_font)) { + CommentUtils.unVoteComment(binding.root.context, mViewModel.videoId, commentEntity, holder.binding.commentLikeCount, holder.binding.commentLike) + } else { + CommentUtils.likeComment(binding.root.context, mViewModel.answerId, mViewModel.articleId, + mViewModel.communityId, mViewModel.videoId, commentEntity, holder.binding.commentLikeCount, holder.binding.commentLike, null) + } } holder.itemView.setOnLongClickListener(View.OnLongClickListener { 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 88a0f68759..05212eabaa 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 @@ -2624,4 +2624,10 @@ public interface ApiService { */ @GET("videos/activity_tags") Observable> getActivityTags(); + + /** + * 取消点赞游戏视频的评论 + */ + @POST("videos/{video_id}/comments/{comment_id}:unvote") + Observable unVoteVideoComment(@Path("video_id") String videoId,@Path("comment_id") String commentId); } \ No newline at end of file