|
@ -1,15 +1,16 @@
|
1
|
1
|
package com.electric.chargingpile.fragment;
|
2
|
2
|
|
3
|
3
|
import android.app.Dialog;
|
|
4
|
import android.content.Intent;
|
4
|
5
|
import android.graphics.Color;
|
5
|
6
|
import android.os.Bundle;
|
6
|
7
|
import android.support.annotation.NonNull;
|
7
|
|
import android.support.annotation.Nullable;
|
8
|
8
|
import android.support.constraint.ConstraintLayout;
|
9
|
9
|
import android.support.v4.app.DialogFragment;
|
10
|
10
|
import android.support.v7.widget.LinearLayoutManager;
|
11
|
11
|
import android.support.v7.widget.RecyclerView;
|
12
|
12
|
import android.support.v7.widget.SimpleItemAnimator;
|
|
13
|
import android.text.TextUtils;
|
13
|
14
|
import android.util.Log;
|
14
|
15
|
import android.view.Gravity;
|
15
|
16
|
import android.view.LayoutInflater;
|
|
@ -17,25 +18,28 @@ import android.view.View;
|
17
|
18
|
import android.view.ViewGroup;
|
18
|
19
|
import android.view.Window;
|
19
|
20
|
import android.view.WindowManager;
|
|
21
|
import android.widget.ImageView;
|
20
|
22
|
import android.widget.TextView;
|
21
|
23
|
import android.widget.Toast;
|
22
|
24
|
|
23
|
25
|
import com.andview.refreshview.XRefreshView;
|
24
|
26
|
import com.electric.chargingpile.R;
|
25
|
|
import com.electric.chargingpile.activity.UserPageActivity;
|
|
27
|
import com.electric.chargingpile.activity.LoginActivity;
|
|
28
|
import com.electric.chargingpile.activity.PublishItemsActivity;
|
26
|
29
|
import com.electric.chargingpile.application.MainApplication;
|
27
|
30
|
import com.electric.chargingpile.data.ChatRecommendBean;
|
28
|
31
|
import com.electric.chargingpile.data.CommentBean;
|
29
|
|
import com.electric.chargingpile.data.UserHomePageBean;
|
|
32
|
import com.electric.chargingpile.data.PublishItemSerializable;
|
|
33
|
import com.electric.chargingpile.util.CircleTransform;
|
30
|
34
|
import com.electric.chargingpile.util.CommonParams;
|
31
|
35
|
import com.electric.chargingpile.util.JsonUtils;
|
32
|
36
|
import com.electric.chargingpile.util.ToastUtil;
|
33
|
|
import com.electric.chargingpile.util.Util;
|
34
|
|
import com.electric.chargingpile.view.CircleProgressBar;
|
|
37
|
import com.squareup.picasso.Picasso;
|
35
|
38
|
import com.wang.avi.AVLoadingIndicatorView;
|
36
|
39
|
import com.zhy.http.okhttp.OkHttpUtils;
|
37
|
40
|
import com.zhy.http.okhttp.callback.StringCallback;
|
38
|
41
|
|
|
42
|
import java.util.ArrayList;
|
39
|
43
|
import java.util.HashMap;
|
40
|
44
|
import java.util.List;
|
41
|
45
|
import java.util.Map;
|
|
@ -45,18 +49,21 @@ import okhttp3.Call;
|
45
|
49
|
public class ChatContentCommentListDialogFragment extends DialogFragment implements View.OnClickListener {
|
46
|
50
|
private static final String TAG = "ChatContentCommentListDialogFragment";
|
47
|
51
|
private static final String ARG_BEAN = "bean";
|
48
|
|
private ChatRecommendBean bean;
|
|
52
|
private OnChatContentCommentListDialogFragmentListener chatContentCommentListDialogFragmentListener;
|
|
53
|
private ChatRecommendBean chatRecommendBean;
|
49
|
54
|
private ConstraintLayout allComments;
|
50
|
55
|
private TextView bCommentContent;
|
51
|
56
|
private TextView bPublish;
|
52
|
57
|
private Dialog dialog;
|
53
|
58
|
private TextView allCommentTitle;
|
54
|
59
|
|
55
|
|
private int page = 1;
|
|
60
|
private int page = 0;
|
56
|
61
|
private AVLoadingIndicatorView loadingIndicator;
|
57
|
62
|
private XRefreshView xRefreshView;
|
58
|
63
|
private RecyclerView recyclerView;
|
59
|
64
|
private ConstraintLayout loadingView;
|
|
65
|
private CommentAdapter commentAdapter;
|
|
66
|
private ConstraintLayout noDataView;
|
60
|
67
|
|
61
|
68
|
public static ChatContentCommentListDialogFragment newInstance(ChatRecommendBean bean) {
|
62
|
69
|
Bundle args = new Bundle();
|
|
@ -72,7 +79,6 @@ public class ChatContentCommentListDialogFragment extends DialogFragment impleme
|
72
|
79
|
dialog = new Dialog(getActivity(), R.style.CommentDialog);
|
73
|
80
|
// 外部点击设置为可取消
|
74
|
81
|
|
75
|
|
|
76
|
82
|
dialog.setCancelable(true);
|
77
|
83
|
dialog.setCanceledOnTouchOutside(true);
|
78
|
84
|
|
|
@ -94,7 +100,7 @@ public class ChatContentCommentListDialogFragment extends DialogFragment impleme
|
94
|
100
|
|
95
|
101
|
|
96
|
102
|
private void initDialog() {
|
97
|
|
bean = (ChatRecommendBean) getArguments().getSerializable(ARG_BEAN);
|
|
103
|
chatRecommendBean = (ChatRecommendBean) getArguments().getSerializable(ARG_BEAN);
|
98
|
104
|
|
99
|
105
|
allComments = dialog.findViewById(R.id.allComments);
|
100
|
106
|
bCommentContent = dialog.findViewById(R.id.bCommentContent);
|
|
@ -102,13 +108,33 @@ public class ChatContentCommentListDialogFragment extends DialogFragment impleme
|
102
|
108
|
allCommentTitle = dialog.findViewById(R.id.allCommentTitle);
|
103
|
109
|
loadingView = dialog.findViewById(R.id.loadingView);
|
104
|
110
|
loadingIndicator = dialog.findViewById(R.id.loadingIndicator);
|
|
111
|
noDataView = dialog.findViewById(R.id.noDataView);
|
|
112
|
|
105
|
113
|
showLoading();
|
106
|
114
|
xRefreshView = dialog.findViewById(R.id.xRefreshView);
|
|
115
|
xRefreshView.setPullRefreshEnable(false);
|
|
116
|
xRefreshView.setPullLoadEnable(true);
|
|
117
|
xRefreshView.setPinnedTime(0);
|
107
|
118
|
recyclerView = dialog.findViewById(R.id.recyclerView);
|
|
119
|
recyclerView.setHasFixedSize(true);
|
108
|
120
|
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
109
|
121
|
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
110
|
122
|
|
111
|
|
allCommentTitle.setText("全部评论 " + bean.commentNums);
|
|
123
|
commentAdapter = new CommentAdapter();
|
|
124
|
recyclerView.setAdapter(commentAdapter);
|
|
125
|
|
|
126
|
xRefreshView.setXRefreshViewListener(new XRefreshView.SimpleXRefreshListener() {
|
|
127
|
@Override
|
|
128
|
public void onRefresh(boolean isPullDown) {
|
|
129
|
}
|
|
130
|
|
|
131
|
@Override
|
|
132
|
public void onLoadMore(boolean isSilence) {
|
|
133
|
requestData();
|
|
134
|
}
|
|
135
|
});
|
|
136
|
|
|
137
|
allCommentTitle.setText("全部评论 " + chatRecommendBean.commentNums);
|
112
|
138
|
requestData();
|
113
|
139
|
}
|
114
|
140
|
|
|
@ -126,6 +152,7 @@ public class ChatContentCommentListDialogFragment extends DialogFragment impleme
|
126
|
152
|
allComments.setOnClickListener(this);
|
127
|
153
|
dialog.findViewById(R.id.allCommentsClose).setOnClickListener(this);
|
128
|
154
|
dialog.findViewById(R.id.bWriteComment).setOnClickListener(this);
|
|
155
|
bPublish.setOnClickListener(this);
|
129
|
156
|
}
|
130
|
157
|
|
131
|
158
|
@Override
|
|
@ -148,26 +175,86 @@ public class ChatContentCommentListDialogFragment extends DialogFragment impleme
|
148
|
175
|
|
149
|
176
|
@Override
|
150
|
177
|
public void publish() {
|
|
178
|
if (bCommentContent.getText().toString().length() > 0) {
|
|
179
|
publishComment();
|
|
180
|
}
|
151
|
181
|
}
|
152
|
182
|
});
|
153
|
183
|
break;
|
|
184
|
case R.id.bPublish:
|
|
185
|
if (bCommentContent.getText().toString().length() > 0) {
|
|
186
|
publishComment();
|
|
187
|
}
|
|
188
|
break;
|
154
|
189
|
case R.id.allCommentsClose:
|
155
|
190
|
dialog.dismiss();
|
156
|
191
|
break;
|
157
|
192
|
}
|
158
|
193
|
}
|
159
|
194
|
|
|
195
|
private void publishComment() {
|
|
196
|
if (!MainApplication.isLogin()) {
|
|
197
|
startActivity(new Intent(getActivity().getApplicationContext(), LoginActivity.class));
|
|
198
|
ToastUtil.showToast(getActivity().getApplicationContext(), "请先登录", Toast.LENGTH_SHORT);
|
|
199
|
return;
|
|
200
|
}
|
|
201
|
|
|
202
|
String url = MainApplication.urlNew + "/topic/comments/publish.do";
|
|
203
|
final Map<String, String> map = new HashMap<>();
|
|
204
|
map.put("targetId", chatRecommendBean.targetId + "");
|
|
205
|
map.put("targetType", chatRecommendBean.targetType + "");
|
|
206
|
map.put("userId", MainApplication.userId);
|
|
207
|
map.put("toUserId", chatRecommendBean.addUserId + "");
|
|
208
|
map.put("level", "1");
|
|
209
|
map.put("content", bCommentContent.getText().toString());
|
|
210
|
|
|
211
|
CommonParams.addCommonParams(map);
|
|
212
|
|
|
213
|
OkHttpUtils.post().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
|
|
214
|
@Override
|
|
215
|
public void onError(Call call, Exception e) {
|
|
216
|
ToastUtil.showToast(getContext(), e.getMessage(), Toast.LENGTH_SHORT);
|
|
217
|
}
|
|
218
|
|
|
219
|
@Override
|
|
220
|
public void onResponse(String response) {
|
|
221
|
String code = JsonUtils.getKeyResult(response, "code");
|
|
222
|
String desc = JsonUtils.getKeyResult(response, "desc");
|
|
223
|
if ("1000".equals(code)) {
|
|
224
|
commentAdapter.clearData();
|
|
225
|
requestData();
|
|
226
|
chatRecommendBean.commentNums++;
|
|
227
|
allCommentTitle.setText("全部评论 " + chatRecommendBean.commentNums);
|
|
228
|
if (chatContentCommentListDialogFragmentListener != null) {
|
|
229
|
chatContentCommentListDialogFragmentListener.updateCommentNum(chatRecommendBean.commentNums);
|
|
230
|
}
|
|
231
|
} else {
|
|
232
|
ToastUtil.showToast(getContext(), desc, Toast.LENGTH_SHORT);
|
|
233
|
}
|
|
234
|
}
|
|
235
|
});
|
|
236
|
}
|
|
237
|
|
|
238
|
|
160
|
239
|
private void requestData() {
|
|
240
|
List<CommentBean> beans = commentAdapter.getCurrentData();
|
161
|
241
|
String url = MainApplication.urlNew + "/topic/comments/list.do";
|
162
|
242
|
Map<String, String> map = new HashMap<>();
|
163
|
|
map.put("page", page + "");
|
164
|
243
|
map.put("limit", "20");
|
165
|
|
map.put("targetId", bean.targetId + "");
|
166
|
|
map.put("targetType", bean.targetType + "");
|
|
244
|
map.put("targetId", chatRecommendBean.targetId + "");
|
|
245
|
map.put("targetType", chatRecommendBean.targetType + "");
|
|
246
|
if (beans.size() == 0) {
|
|
247
|
page = 1;
|
|
248
|
} else {
|
|
249
|
page = beans.size() / 10 + beans.size() % 10 == 0 ? 0 : 1;
|
|
250
|
}
|
|
251
|
map.put("page", page + "");
|
|
252
|
|
167
|
253
|
if (page == 1) {
|
168
|
254
|
map.put("commentsId", "0");
|
169
|
255
|
} else {
|
170
|
|
// TODO
|
|
256
|
CommentBean bean = beans.get(beans.size() - 1);
|
|
257
|
map.put("commentsId", bean.commentsId + "");
|
171
|
258
|
}
|
172
|
259
|
|
173
|
260
|
CommonParams.addCommonParams(map);
|
|
@ -187,69 +274,316 @@ public class ChatContentCommentListDialogFragment extends DialogFragment impleme
|
187
|
274
|
|
188
|
275
|
@Override
|
189
|
276
|
public void onResponse(String s) {
|
|
277
|
Log.d(TAG, "onResponse: " + s);
|
190
|
278
|
hideLoading();
|
191
|
279
|
String code = JsonUtils.getKeyResult(s, "code");
|
192
|
|
Log.d(TAG, "onResponse: " + s);
|
193
|
280
|
if ("1000".equals(code)) {
|
194
|
281
|
String data = JsonUtils.getKeyResult(s, "data");
|
195
|
282
|
List<CommentBean> beans = (List<CommentBean>) JsonUtils.parseToObjectList(data, CommentBean.class);
|
|
283
|
|
196
|
284
|
if (page == 1) {
|
197
|
|
xRefreshView.setLoadComplete(false);
|
198
|
|
// userVo = userHomePageBean.userVo;
|
199
|
|
// updateTopView();
|
200
|
|
// if (userHomePageBean.list.size() == 0) {
|
201
|
|
// zeroTopicNum.setVisibility(View.VISIBLE);
|
202
|
|
// xRefreshView.setLoadComplete(true);
|
203
|
|
// } else {
|
204
|
|
// zeroTopicNum.setVisibility(View.GONE);
|
205
|
|
// userPageAdapter.setContentData(userHomePageBean.list);
|
206
|
|
// }
|
207
|
|
// userPageAdapter.setFooterData(false);
|
208
|
|
xRefreshView.stopRefresh();
|
|
285
|
if (beans.size() == 0) {
|
|
286
|
noDataView.setVisibility(View.VISIBLE);
|
|
287
|
} else {
|
|
288
|
noDataView.setVisibility(View.GONE);
|
|
289
|
commentAdapter.setData(beans);
|
|
290
|
}
|
209
|
291
|
} else {
|
210
|
|
// if (userHomePageBean.list.size() == 0) {
|
211
|
|
// xRefreshView.setLoadComplete(true);
|
212
|
|
//// userPageAdapter.setFooterData(true);
|
213
|
|
// } else {
|
214
|
|
// userPageAdapter.addContentData(userHomePageBean.list);
|
215
|
|
// userPageAdapter.setFooterData(false);
|
216
|
|
// }
|
217
|
|
xRefreshView.stopLoadMore();
|
|
292
|
if (beans.size() > 0) {
|
|
293
|
commentAdapter.addData(beans);
|
|
294
|
}
|
|
295
|
}
|
|
296
|
|
|
297
|
if (beans.size() < 20) {
|
|
298
|
xRefreshView.setLoadComplete(true);
|
218
|
299
|
}
|
|
300
|
xRefreshView.stopLoadMore();
|
|
301
|
|
219
|
302
|
} else {
|
220
|
303
|
String desc = JsonUtils.getKeyResult(s, "desc");
|
221
|
304
|
ToastUtil.showToast(getContext(), desc, Toast.LENGTH_SHORT);
|
222
|
|
if (page == 1) {
|
223
|
|
xRefreshView.stopRefresh();
|
224
|
|
} else {
|
225
|
|
page--;
|
226
|
|
xRefreshView.stopLoadMore();
|
227
|
|
}
|
|
305
|
xRefreshView.stopLoadMore();
|
228
|
306
|
}
|
229
|
307
|
|
230
|
308
|
}
|
231
|
309
|
});
|
232
|
310
|
}
|
233
|
311
|
|
234
|
|
private class CommentHolder extends RecyclerView.ViewHolder {
|
|
312
|
private class CommentHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
235
|
313
|
private CommentBean bean;
|
|
314
|
private int position;
|
236
|
315
|
private TextView content;
|
|
316
|
private ImageView headImage;
|
|
317
|
private TextView nickName;
|
|
318
|
private TextView addDate;
|
|
319
|
private ImageView likeIcon;
|
|
320
|
private TextView likeLabel;
|
|
321
|
private ConstraintLayout likeView;
|
|
322
|
private ConstraintLayout replyInfo;
|
|
323
|
private TextView replyLabel;
|
|
324
|
private ConstraintLayout replyAndDeleteView;
|
|
325
|
private TextView deleteComment;
|
237
|
326
|
|
238
|
327
|
public CommentHolder(LayoutInflater layoutInflater, ViewGroup parent) {
|
239
|
328
|
super(layoutInflater.inflate(R.layout.list_item_comment, parent, false));
|
240
|
329
|
|
241
|
330
|
initView();
|
|
331
|
initListener();
|
242
|
332
|
}
|
243
|
333
|
|
244
|
334
|
private void initView() {
|
245
|
335
|
content = itemView.findViewById(R.id.content);
|
|
336
|
headImage = itemView.findViewById(R.id.headImage);
|
|
337
|
nickName = itemView.findViewById(R.id.nickName);
|
|
338
|
addDate = itemView.findViewById(R.id.addDate);
|
|
339
|
likeIcon = itemView.findViewById(R.id.likeIcon);
|
|
340
|
likeLabel = itemView.findViewById(R.id.likeLabel);
|
|
341
|
likeView = itemView.findViewById(R.id.likeView);
|
|
342
|
replyAndDeleteView = itemView.findViewById(R.id.replyAndDeleteView);
|
|
343
|
replyInfo = itemView.findViewById(R.id.replyInfo);
|
|
344
|
replyLabel = itemView.findViewById(R.id.replyLabel);
|
|
345
|
deleteComment = itemView.findViewById(R.id.deleteComment);
|
|
346
|
|
|
347
|
}
|
|
348
|
|
|
349
|
private void initListener() {
|
|
350
|
likeView.setOnClickListener(this);
|
|
351
|
replyInfo.setOnClickListener(this);
|
|
352
|
deleteComment.setOnClickListener(this);
|
|
353
|
}
|
|
354
|
|
|
355
|
@Override
|
|
356
|
public void onClick(View view) {
|
|
357
|
switch (view.getId()) {
|
|
358
|
case R.id.likeView:
|
|
359
|
doLike();
|
|
360
|
break;
|
|
361
|
case R.id.replyInfo: // 点击查看回复列表
|
|
362
|
break;
|
|
363
|
case R.id.deleteComment: // 删除评论操作
|
|
364
|
if (MainApplication.isLogin()) {
|
|
365
|
loginSign();
|
|
366
|
} else {
|
|
367
|
startActivity(new Intent(getActivity().getApplicationContext(), LoginActivity.class));
|
|
368
|
ToastUtil.showToast(getActivity().getApplicationContext(), "请先登录", Toast.LENGTH_SHORT);
|
|
369
|
}
|
|
370
|
break;
|
|
371
|
}
|
246
|
372
|
}
|
247
|
373
|
|
248
|
|
private void bind(CommentBean bean) {
|
|
374
|
private void bindView(CommentBean bean, int position) {
|
249
|
375
|
this.bean = bean;
|
|
376
|
this.position = position;
|
250
|
377
|
content.setText(bean.content);
|
|
378
|
nickName.setText(bean.nickNameFromUser);
|
|
379
|
addDate.setText(bean.addDate);
|
|
380
|
if (bean.likeFlg == 1) {
|
|
381
|
likeIcon.setImageResource(R.drawable.like_red_icon);
|
|
382
|
} else {
|
|
383
|
likeIcon.setImageResource(R.drawable.like_small_icon);
|
|
384
|
}
|
|
385
|
if (bean.likeNums > 0) {
|
|
386
|
likeLabel.setText(bean.likeNums > 999 ? "999+" : bean.likeNums + "");
|
|
387
|
} else {
|
|
388
|
likeLabel.setText("");
|
|
389
|
}
|
|
390
|
|
|
391
|
if (bean.replyNums > 0) {
|
|
392
|
replyInfo.setVisibility(View.VISIBLE);
|
|
393
|
if (MainApplication.userId.equals(bean.userId + "")) {
|
|
394
|
replyAndDeleteView.setVisibility(View.VISIBLE);
|
|
395
|
} else {
|
|
396
|
replyAndDeleteView.setVisibility(View.GONE);
|
|
397
|
replyAndDeleteView.setVisibility(View.VISIBLE);
|
|
398
|
}
|
|
399
|
} else {
|
|
400
|
replyInfo.setVisibility(View.GONE);
|
|
401
|
replyLabel.setText(bean.replyNums + "");
|
|
402
|
if (MainApplication.userId.equals(bean.userId + "")) {
|
|
403
|
replyAndDeleteView.setVisibility(View.VISIBLE);
|
|
404
|
deleteComment.setVisibility(View.VISIBLE);
|
|
405
|
} else {
|
|
406
|
replyAndDeleteView.setVisibility(View.GONE);
|
|
407
|
deleteComment.setVisibility(View.GONE);
|
|
408
|
}
|
|
409
|
}
|
|
410
|
|
|
411
|
if (TextUtils.isEmpty(bean.headImgFromUser)) {
|
|
412
|
Picasso.with(getContext())
|
|
413
|
.load(R.drawable.icon_face2_0)
|
|
414
|
.placeholder(R.drawable.icon_face2_0)
|
|
415
|
.error(R.drawable.icon_face2_0)
|
|
416
|
.transform(new CircleTransform())
|
|
417
|
.into(headImage);
|
|
418
|
} else {
|
|
419
|
Picasso.with(getContext())
|
|
420
|
.load("http://cdz.evcharge.cc/zhannew/uploadfile/" + bean.headImgFromUser)
|
|
421
|
.placeholder(R.drawable.icon_face2_0)
|
|
422
|
.error(R.drawable.icon_face2_0)
|
|
423
|
.transform(new CircleTransform())
|
|
424
|
.into(headImage);
|
|
425
|
}
|
|
426
|
}
|
|
427
|
|
|
428
|
/**
|
|
429
|
* 点赞操作
|
|
430
|
*/
|
|
431
|
private void doLike() {
|
|
432
|
String url = MainApplication.urlNew + "/topic/like.do";
|
|
433
|
Map<String, String> map = new HashMap<>();
|
|
434
|
map.put("targetId", bean.id + "");
|
|
435
|
map.put("targetType", "26");
|
|
436
|
map.put("flag", "1");
|
|
437
|
map.put("authorId", bean.userId + "");
|
|
438
|
CommonParams.addCommonParams(map);
|
|
439
|
|
|
440
|
OkHttpUtils.get().url(url).params(map).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
|
|
441
|
@Override
|
|
442
|
public void onError(Call call, Exception e) {
|
|
443
|
ToastUtil.showToast(getContext(), "点赞失败,请重试", Toast.LENGTH_SHORT);
|
|
444
|
}
|
|
445
|
|
|
446
|
@Override
|
|
447
|
public void onResponse(String res) {
|
|
448
|
String code = JsonUtils.getKeyResult(res, "code");
|
|
449
|
String desc = JsonUtils.getKeyResult(res, "desc");
|
|
450
|
if ("1000".equals(code)) {
|
|
451
|
bean.likeFlg = 1;
|
|
452
|
bean.likeNums += 1;
|
|
453
|
commentAdapter.notifyItemChanged(position);
|
|
454
|
} else {
|
|
455
|
ToastUtil.showToast(getContext(), desc, Toast.LENGTH_SHORT);
|
|
456
|
}
|
|
457
|
}
|
|
458
|
});
|
|
459
|
}
|
|
460
|
|
|
461
|
// 服务器签名验证
|
|
462
|
private void loginSign() {
|
|
463
|
String url = MainApplication.urlNew + "/topic/sign.do";
|
|
464
|
final Map<String, String> map = new HashMap<>();
|
|
465
|
map.put("fileNames", "android");
|
|
466
|
map.put("targetType", ChatRecommendBean.TARGET_TYPE_IMAGE_TEXT + "");
|
|
467
|
CommonParams.addCommonParams(map);
|
|
468
|
|
|
469
|
OkHttpUtils.post().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
|
|
470
|
@Override
|
|
471
|
public void onError(Call call, Exception e) {
|
|
472
|
ToastUtil.showToast(getContext(), e.getMessage(), Toast.LENGTH_SHORT);
|
|
473
|
}
|
|
474
|
|
|
475
|
@Override
|
|
476
|
public void onResponse(String response) {
|
|
477
|
String code = JsonUtils.getKeyResult(response, "code");
|
|
478
|
String desc = JsonUtils.getKeyResult(response, "desc");
|
|
479
|
if ("1000".equals(code)) {
|
|
480
|
deleteComment();
|
|
481
|
} else if ("8010".equals(code)) {
|
|
482
|
startActivity(new Intent(getContext(), LoginActivity.class));
|
|
483
|
ToastUtil.showToast(getContext(), desc, Toast.LENGTH_LONG);
|
|
484
|
} else {
|
|
485
|
ToastUtil.showToast(getContext(), desc, Toast.LENGTH_SHORT);
|
|
486
|
}
|
|
487
|
}
|
|
488
|
});
|
|
489
|
}
|
|
490
|
|
|
491
|
private void deleteComment() {
|
|
492
|
String url = MainApplication.urlNew + "/topic/del.do";
|
|
493
|
final Map<String, String> map = new HashMap<>();
|
|
494
|
map.put("targetId", bean.id + "");
|
|
495
|
map.put("targetType", "25");
|
|
496
|
map.put("userId", bean.userId + "");
|
|
497
|
CommonParams.addCommonParams(map);
|
|
498
|
|
|
499
|
OkHttpUtils.post().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
|
|
500
|
@Override
|
|
501
|
public void onError(Call call, Exception e) {
|
|
502
|
ToastUtil.showToast(getContext(), e.getMessage(), Toast.LENGTH_SHORT);
|
|
503
|
}
|
|
504
|
|
|
505
|
@Override
|
|
506
|
public void onResponse(String response) {
|
|
507
|
String code = JsonUtils.getKeyResult(response, "code");
|
|
508
|
String desc = JsonUtils.getKeyResult(response, "desc");
|
|
509
|
if ("1000".equals(code)) {
|
|
510
|
commentAdapter.removeData(position);
|
|
511
|
commentAdapter.notifyItemRemoved(position);
|
|
512
|
if (chatRecommendBean.commentNums > 0) {
|
|
513
|
chatRecommendBean.commentNums--;
|
|
514
|
}
|
|
515
|
allCommentTitle.setText("全部评论 " + chatRecommendBean.commentNums);
|
|
516
|
if (chatContentCommentListDialogFragmentListener != null) {
|
|
517
|
chatContentCommentListDialogFragmentListener.updateCommentNum(chatRecommendBean.commentNums);
|
|
518
|
}
|
|
519
|
} else {
|
|
520
|
ToastUtil.showToast(getContext(), desc, Toast.LENGTH_SHORT);
|
|
521
|
}
|
|
522
|
}
|
|
523
|
});
|
|
524
|
}
|
|
525
|
|
|
526
|
}
|
|
527
|
|
|
528
|
private class CommentAdapter extends RecyclerView.Adapter<CommentHolder> {
|
|
529
|
private static final String TAG = "CommentAdapter";
|
|
530
|
private List<CommentBean> beans;
|
|
531
|
|
|
532
|
public CommentAdapter() {
|
|
533
|
this.beans = new ArrayList<>();
|
|
534
|
}
|
|
535
|
|
|
536
|
@Override
|
|
537
|
public CommentHolder onCreateViewHolder(ViewGroup parent, int i) {
|
|
538
|
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
|
|
539
|
return new CommentHolder(layoutInflater, parent);
|
|
540
|
}
|
|
541
|
|
|
542
|
@Override
|
|
543
|
public void onBindViewHolder(CommentHolder commentHolder, int i) {
|
|
544
|
CommentBean bean = beans.get(i);
|
|
545
|
commentHolder.bindView(bean, i);
|
|
546
|
}
|
|
547
|
|
|
548
|
@Override
|
|
549
|
public int getItemCount() {
|
|
550
|
return beans.size();
|
|
551
|
}
|
|
552
|
|
|
553
|
public void setData(List<CommentBean> beans) {
|
|
554
|
this.beans.clear();
|
|
555
|
this.beans.addAll(beans);
|
|
556
|
notifyDataSetChanged();
|
|
557
|
}
|
|
558
|
|
|
559
|
public void addData(List<CommentBean> beans) {
|
|
560
|
int size = this.beans.size();
|
|
561
|
this.beans.addAll(beans);
|
|
562
|
notifyItemRangeChanged(size, beans.size());
|
|
563
|
}
|
|
564
|
|
|
565
|
public void clearData() {
|
|
566
|
beans.clear();
|
251
|
567
|
}
|
|
568
|
|
|
569
|
public void removeData(int position) {
|
|
570
|
if (position < beans.size()) {
|
|
571
|
beans.remove(position);
|
|
572
|
}
|
|
573
|
|
|
574
|
}
|
|
575
|
|
|
576
|
public List<CommentBean> getCurrentData() {
|
|
577
|
return beans;
|
|
578
|
}
|
|
579
|
|
252
|
580
|
}
|
253
|
581
|
|
254
|
|
// private class CommentAdapter extends RecyclerView.Adapter
|
|
582
|
public interface OnChatContentCommentListDialogFragmentListener {
|
|
583
|
void updateCommentNum(int num);
|
|
584
|
}
|
|
585
|
|
|
586
|
public void setOnCommonDialogFragmentListener(OnChatContentCommentListDialogFragmentListener listener) {
|
|
587
|
this.chatContentCommentListDialogFragmentListener = listener;
|
|
588
|
}
|
255
|
589
|
}
|