涉及到用户操作的加上登录验证, 把评论点赞抽离成工具方法

This commit is contained in:
kehaoyuan
2017-06-28 18:06:36 +08:00
parent 957305d6f5
commit f960b07ee1
17 changed files with 546 additions and 499 deletions

View File

@ -13,7 +13,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.lightgame.adapter.BaseRecyclerAdapter;
import com.gh.common.constant.Config;
import com.gh.common.util.CommentUtils;
import com.gh.common.util.ConcernContentUtils;
@ -23,10 +22,8 @@ import com.gh.common.util.DisplayUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.NewsUtils;
import com.gh.common.util.PostCommentUtils;
import com.gh.common.util.StringUtils;
import com.gh.common.util.TimestampUtils;
import com.gh.common.util.Utils;
import com.gh.gamecenter.MessageDetailActivity;
import com.gh.gamecenter.NewsDetailActivity;
import com.gh.gamecenter.R;
@ -38,7 +35,6 @@ import com.gh.gamecenter.adapter.viewholder.FooterViewHolder;
import com.gh.gamecenter.adapter.viewholder.NewsDigestViewHolder;
import com.gh.gamecenter.db.CommentDao;
import com.gh.gamecenter.db.VoteDao;
import com.gh.gamecenter.db.info.VoteInfo;
import com.gh.gamecenter.entity.CommentEntity;
import com.gh.gamecenter.entity.ConcernEntity;
import com.gh.gamecenter.manager.VisitManager;
@ -46,6 +42,7 @@ import com.gh.gamecenter.retrofit.JSONObjectResponse;
import com.gh.gamecenter.retrofit.OkHttpCache;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.lightgame.adapter.BaseRecyclerAdapter;
import org.json.JSONArray;
import org.json.JSONException;
@ -437,22 +434,10 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
holder.commentLikeIv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.commentLikeCountTv.getCurrentTextColor() == ContextCompat.getColor(mContext, R.color.theme)) {
Utils.toast(mContext, "已经点过赞啦!");
return;
}
finalCommentEntity.setVote(finalCommentEntity.getVote() + 1);
holder.commentLikeCountTv.setTextColor(ContextCompat.getColor(mContext, R.color.theme));
holder.commentLikeIv.setImageResource(R.drawable.ic_like_select);
holder.commentLikeCountTv.setText(String.valueOf(finalCommentEntity.getVote()));
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
PostCommentUtils.addCommentVoto(mContext, finalCommentEntity.getId(), true,
new PostCommentUtils.PostCommentListener() {
CommentUtils.initVote(mContext, finalCommentEntity, mVoteDao, holder.commentLikeCountTv,
holder.commentLikeIv, new CommentUtils.OnVoteListener() {
@Override
public void postSuccess(JSONObject response) {
mVoteDao.add(new VoteInfo(finalCommentEntity.getId()));
public void onVote() {
int index = (finalCommentPosition / 10) * 10;
//获取需要修改缓存的链接
@ -467,35 +452,6 @@ public class MessageDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
modifyVolleyCache(finalCommentEntity.getId(), cacheUrl); //修改缓存
}
@Override
public void postFailed(Throwable e) {
finalCommentEntity.setVote(finalCommentEntity.getVote() - 1);
holder.commentLikeCountTv.setTextColor(ContextCompat.getColor(mContext, R.color.hint));
holder.commentLikeIv.setImageResource(R.drawable.ic_like_unselect);
holder.commentLikeCountTv.setText(String.valueOf(finalCommentEntity.getVote()));
if (finalCommentEntity.getVote() == 0) {
holder.commentLikeCountTv.setVisibility(View.GONE);
} else {
holder.commentLikeCountTv.setVisibility(View.VISIBLE);
}
if (e instanceof HttpException) {
HttpException exception = (HttpException) e;
if (exception.code() == 403) {
try {
if (new JSONObject(exception.response().errorBody().string()).getString("detail").equals("voted")) {
Utils.toast(mContext, "已经点过赞啦!");
}
} catch (Exception ex) {
ex.printStackTrace();
}
return;
}
}
Utils.toast(mContext, "网络异常,点赞失败");
}
});
}