CommentLikeHelper.java
3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.people.comment.helper;
import android.text.TextUtils;
import com.people.comment.adapter.MyCommentListAdapter;
import com.people.comment.comment.vm.CommentViewModel;
import com.people.comment.listener.BatchMyCommentListLikeStatusListener;
import com.wd.foundation.bean.comment.CommentStatusBean;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.wdkit.utils.CommonUtil;
import com.wd.foundation.wdkit.utils.SpUtils;
import java.util.ArrayList;
import java.util.List;
/**
* 评论点赞帮助类
*
* @author ouyang
* @version [V1.0.0, 2022/08/18]
* @since V1.0.0
*/
public class CommentLikeHelper {
private static final String TAG = "CommentLikeHelper";
private CommentViewModel mLikeViewModel;
/**
* 请求点赞状态(我的评论列表)
* @param startIndex 刷新的起始位置
* @param dataBeanList 请求数据源
* @param mAdapter 列表adapter
*/
public void getLike(int startIndex, List<CommentItem> dataBeanList, MyCommentListAdapter mAdapter) {
if (dataBeanList == null || dataBeanList.isEmpty()) {
if (0 == startIndex) {
mAdapter.replaceData(dataBeanList);
}
return;
}
if (TextUtils.isEmpty(SpUtils.getUserToken())) {
if (0 == startIndex) {
mAdapter.replaceData(dataBeanList);
}
return;
}
if (mLikeViewModel == null) {
mLikeViewModel = new CommentViewModel();
}
List<Integer> requestParams = new ArrayList<>();
for (CommentItem commentBean:dataBeanList) {
/*if (commentBean.getCheckStatus()==2) {
requestParams.add(commentBean.getId());
}*/
//评论点赞状态不判断审核状态
requestParams.add(commentBean.getId());
}
if (CommonUtil.isEmpty(requestParams)) {
if (startIndex == 0) {
mAdapter.replaceData(dataBeanList);
} else {
mAdapter.notifyItemRangeChanged(startIndex, dataBeanList.size());
}
return;
}
if (!requestParams.isEmpty()) {
mLikeViewModel.getMyCommentListStatusList(requestParams, new BatchMyCommentListLikeStatusListener() {
@Override
public void onGetCommentStatusListSuccess(List<CommentStatusBean> statusList) {
for (CommentItem tempCommentBean : dataBeanList) {
//点赞不判断审核状态
// if (tempCommentBean.getCheckStatus() == 2) {
for (CommentStatusBean tempCommentStatusBean : statusList) {
if (tempCommentBean.getId() == tempCommentStatusBean.getCommentId()) {
tempCommentBean.setLikeStatus(tempCommentStatusBean.getStatus());
}
}
// }
}
if (startIndex == 0) {
mAdapter.replaceData(dataBeanList);
} else {
mAdapter.notifyItemRangeChanged(startIndex, dataBeanList.size());
}
}
@Override
public void onGetCommentStatusListFailure(String errorInfo) {
if (startIndex == 0) {
mAdapter.replaceData(dataBeanList);
} else {
mAdapter.notifyItemRangeChanged(startIndex, dataBeanList.size());
}
}
});
}
}
}