Browse Source

评论功能开发完成

huyuguo 5 years ago
parent
commit
12bc29be92

+ 10 - 0
app/src/main/java/com/electric/chargingpile/activity/ChatContentListActivity.java

439
                    //setViewPagerScroll(false);
439
                    //setViewPagerScroll(false);
440
                    //allCommentsContainer.setVisibility(View.VISIBLE);
440
                    //allCommentsContainer.setVisibility(View.VISIBLE);
441
                    ChatContentCommentListDialogFragment dialogFragment = ChatContentCommentListDialogFragment.newInstance(bean);
441
                    ChatContentCommentListDialogFragment dialogFragment = ChatContentCommentListDialogFragment.newInstance(bean);
442
                    dialogFragment.setOnCommonDialogFragmentListener(new ChatContentCommentListDialogFragment.OnChatContentCommentListDialogFragmentListener() {
443
                        @Override
444
                        public void updateCommentNum(int num) {
445
                            if (bean.commentNums == 0) {
446
                                commentNumber.setText("");
447
                            } else {
448
                                commentNumber.setText(bean.commentNums < 10000 ? bean.commentNums + "" : String.format("%.1fW",bean.commentNums/10000f));
449
                            }
450
                        }
451
                    });
442
                    dialogFragment.show(getChildFragmentManager(), "评论列表");
452
                    dialogFragment.show(getChildFragmentManager(), "评论列表");
443
                    break;
453
                    break;
444
                case R.id.allCommentsClose: // 关闭评论
454
                case R.id.allCommentsClose: // 关闭评论

+ 1 - 1
app/src/main/java/com/electric/chargingpile/data/ChatRecommendBean.java

11
11
12
    public long targetId;
12
    public long targetId;
13
    public long addUserId;
13
    public long addUserId;
14
    public int targetType;  // 23:app_talk_video_icon 24:图文 25:话题
14
    public int targetType;  // 23:视频 24:图文 25:话题
15
    public String title;
15
    public String title;
16
    public String name;
16
    public String name;
17
    public long addTime;
17
    public long addTime;

+ 378 - 44
app/src/main/java/com/electric/chargingpile/fragment/ChatContentCommentListDialogFragment.java

1
package com.electric.chargingpile.fragment;
1
package com.electric.chargingpile.fragment;
2
2
3
import android.app.Dialog;
3
import android.app.Dialog;
4
import android.content.Intent;
4
import android.graphics.Color;
5
import android.graphics.Color;
5
import android.os.Bundle;
6
import android.os.Bundle;
6
import android.support.annotation.NonNull;
7
import android.support.annotation.NonNull;
7
import android.support.annotation.Nullable;
8
import android.support.constraint.ConstraintLayout;
8
import android.support.constraint.ConstraintLayout;
9
import android.support.v4.app.DialogFragment;
9
import android.support.v4.app.DialogFragment;
10
import android.support.v7.widget.LinearLayoutManager;
10
import android.support.v7.widget.LinearLayoutManager;
11
import android.support.v7.widget.RecyclerView;
11
import android.support.v7.widget.RecyclerView;
12
import android.support.v7.widget.SimpleItemAnimator;
12
import android.support.v7.widget.SimpleItemAnimator;
13
import android.text.TextUtils;
13
import android.util.Log;
14
import android.util.Log;
14
import android.view.Gravity;
15
import android.view.Gravity;
15
import android.view.LayoutInflater;
16
import android.view.LayoutInflater;
17
import android.view.ViewGroup;
18
import android.view.ViewGroup;
18
import android.view.Window;
19
import android.view.Window;
19
import android.view.WindowManager;
20
import android.view.WindowManager;
21
import android.widget.ImageView;
20
import android.widget.TextView;
22
import android.widget.TextView;
21
import android.widget.Toast;
23
import android.widget.Toast;
22
24
23
import com.andview.refreshview.XRefreshView;
25
import com.andview.refreshview.XRefreshView;
24
import com.electric.chargingpile.R;
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
import com.electric.chargingpile.application.MainApplication;
29
import com.electric.chargingpile.application.MainApplication;
27
import com.electric.chargingpile.data.ChatRecommendBean;
30
import com.electric.chargingpile.data.ChatRecommendBean;
28
import com.electric.chargingpile.data.CommentBean;
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
import com.electric.chargingpile.util.CommonParams;
34
import com.electric.chargingpile.util.CommonParams;
31
import com.electric.chargingpile.util.JsonUtils;
35
import com.electric.chargingpile.util.JsonUtils;
32
import com.electric.chargingpile.util.ToastUtil;
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
import com.wang.avi.AVLoadingIndicatorView;
38
import com.wang.avi.AVLoadingIndicatorView;
36
import com.zhy.http.okhttp.OkHttpUtils;
39
import com.zhy.http.okhttp.OkHttpUtils;
37
import com.zhy.http.okhttp.callback.StringCallback;
40
import com.zhy.http.okhttp.callback.StringCallback;
38
41
42
import java.util.ArrayList;
39
import java.util.HashMap;
43
import java.util.HashMap;
40
import java.util.List;
44
import java.util.List;
41
import java.util.Map;
45
import java.util.Map;
45
public class ChatContentCommentListDialogFragment extends DialogFragment implements View.OnClickListener {
49
public class ChatContentCommentListDialogFragment extends DialogFragment implements View.OnClickListener {
46
    private static final String TAG = "ChatContentCommentListDialogFragment";
50
    private static final String TAG = "ChatContentCommentListDialogFragment";
47
    private static final String ARG_BEAN = "bean";
51
    private static final String ARG_BEAN = "bean";
48
    private ChatRecommendBean bean;
52
    private OnChatContentCommentListDialogFragmentListener chatContentCommentListDialogFragmentListener;
53
    private ChatRecommendBean chatRecommendBean;
49
    private ConstraintLayout allComments;
54
    private ConstraintLayout allComments;
50
    private TextView bCommentContent;
55
    private TextView bCommentContent;
51
    private TextView bPublish;
56
    private TextView bPublish;
52
    private Dialog dialog;
57
    private Dialog dialog;
53
    private TextView allCommentTitle;
58
    private TextView allCommentTitle;
54
59
55
    private int page = 1;
60
    private int page = 0;
56
    private AVLoadingIndicatorView loadingIndicator;
61
    private AVLoadingIndicatorView loadingIndicator;
57
    private XRefreshView xRefreshView;
62
    private XRefreshView xRefreshView;
58
    private RecyclerView recyclerView;
63
    private RecyclerView recyclerView;
59
    private ConstraintLayout loadingView;
64
    private ConstraintLayout loadingView;
65
    private CommentAdapter commentAdapter;
66
    private ConstraintLayout noDataView;
60
67
61
    public static ChatContentCommentListDialogFragment newInstance(ChatRecommendBean bean) {
68
    public static ChatContentCommentListDialogFragment newInstance(ChatRecommendBean bean) {
62
        Bundle args = new Bundle();
69
        Bundle args = new Bundle();
72
        dialog = new Dialog(getActivity(), R.style.CommentDialog);
79
        dialog = new Dialog(getActivity(), R.style.CommentDialog);
73
        // 外部点击设置为可取消
80
        // 外部点击设置为可取消
74
81
75
76
        dialog.setCancelable(true);
82
        dialog.setCancelable(true);
77
        dialog.setCanceledOnTouchOutside(true);
83
        dialog.setCanceledOnTouchOutside(true);
78
84
94
100
95
101
96
    private void initDialog() {
102
    private void initDialog() {
97
        bean = (ChatRecommendBean) getArguments().getSerializable(ARG_BEAN);
103
        chatRecommendBean = (ChatRecommendBean) getArguments().getSerializable(ARG_BEAN);
98
104
99
        allComments = dialog.findViewById(R.id.allComments);
105
        allComments = dialog.findViewById(R.id.allComments);
100
        bCommentContent = dialog.findViewById(R.id.bCommentContent);
106
        bCommentContent = dialog.findViewById(R.id.bCommentContent);
102
        allCommentTitle = dialog.findViewById(R.id.allCommentTitle);
108
        allCommentTitle = dialog.findViewById(R.id.allCommentTitle);
103
        loadingView = dialog.findViewById(R.id.loadingView);
109
        loadingView = dialog.findViewById(R.id.loadingView);
104
        loadingIndicator = dialog.findViewById(R.id.loadingIndicator);
110
        loadingIndicator = dialog.findViewById(R.id.loadingIndicator);
111
        noDataView = dialog.findViewById(R.id.noDataView);
112
105
        showLoading();
113
        showLoading();
106
        xRefreshView = dialog.findViewById(R.id.xRefreshView);
114
        xRefreshView = dialog.findViewById(R.id.xRefreshView);
115
        xRefreshView.setPullRefreshEnable(false);
116
        xRefreshView.setPullLoadEnable(true);
117
        xRefreshView.setPinnedTime(0);
107
        recyclerView = dialog.findViewById(R.id.recyclerView);
118
        recyclerView = dialog.findViewById(R.id.recyclerView);
119
        recyclerView.setHasFixedSize(true);
108
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
120
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
109
        ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
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
        requestData();
138
        requestData();
113
    }
139
    }
114
140
126
        allComments.setOnClickListener(this);
152
        allComments.setOnClickListener(this);
127
        dialog.findViewById(R.id.allCommentsClose).setOnClickListener(this);
153
        dialog.findViewById(R.id.allCommentsClose).setOnClickListener(this);
128
        dialog.findViewById(R.id.bWriteComment).setOnClickListener(this);
154
        dialog.findViewById(R.id.bWriteComment).setOnClickListener(this);
155
        bPublish.setOnClickListener(this);
129
    }
156
    }
130
157
131
    @Override
158
    @Override
148
175
149
                    @Override
176
                    @Override
150
                    public void publish() {
177
                    public void publish() {
178
                        if (bCommentContent.getText().toString().length() > 0) {
179
                            publishComment();
180
                        }
151
                    }
181
                    }
152
                });
182
                });
153
                break;
183
                break;
184
            case R.id.bPublish:
185
                if (bCommentContent.getText().toString().length() > 0) {
186
                    publishComment();
187
                }
188
                break;
154
            case R.id.allCommentsClose:
189
            case R.id.allCommentsClose:
155
                dialog.dismiss();
190
                dialog.dismiss();
156
                break;
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
    private void requestData() {
239
    private void requestData() {
240
        List<CommentBean> beans = commentAdapter.getCurrentData();
161
        String url = MainApplication.urlNew + "/topic/comments/list.do";
241
        String url = MainApplication.urlNew + "/topic/comments/list.do";
162
        Map<String, String> map = new HashMap<>();
242
        Map<String, String> map = new HashMap<>();
163
        map.put("page", page + "");
164
        map.put("limit", "20");
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
        if (page == 1) {
253
        if (page == 1) {
168
            map.put("commentsId", "0");
254
            map.put("commentsId", "0");
169
        } else {
255
        } else {
170
            // TODO
256
            CommentBean bean = beans.get(beans.size() - 1);
257
            map.put("commentsId", bean.commentsId + "");
171
        }
258
        }
172
259
173
        CommonParams.addCommonParams(map);
260
        CommonParams.addCommonParams(map);
187
274
188
            @Override
275
            @Override
189
            public void onResponse(String s) {
276
            public void onResponse(String s) {
277
                Log.d(TAG, "onResponse: " + s);
190
                hideLoading();
278
                hideLoading();
191
                String code = JsonUtils.getKeyResult(s, "code");
279
                String code = JsonUtils.getKeyResult(s, "code");
192
                Log.d(TAG, "onResponse: " + s);
193
                if ("1000".equals(code)) {
280
                if ("1000".equals(code)) {
194
                    String data = JsonUtils.getKeyResult(s, "data");
281
                    String data = JsonUtils.getKeyResult(s, "data");
195
                    List<CommentBean> beans = (List<CommentBean>) JsonUtils.parseToObjectList(data, CommentBean.class);
282
                    List<CommentBean> beans = (List<CommentBean>) JsonUtils.parseToObjectList(data, CommentBean.class);
283
196
                    if (page == 1) {
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
                    } else {
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
                } else {
302
                } else {
220
                    String desc = JsonUtils.getKeyResult(s, "desc");
303
                    String desc = JsonUtils.getKeyResult(s, "desc");
221
                    ToastUtil.showToast(getContext(), desc, Toast.LENGTH_SHORT);
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
        private CommentBean bean;
313
        private CommentBean bean;
314
        private int position;
236
        private TextView content;
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
        public CommentHolder(LayoutInflater layoutInflater, ViewGroup parent) {
327
        public CommentHolder(LayoutInflater layoutInflater, ViewGroup parent) {
239
            super(layoutInflater.inflate(R.layout.list_item_comment, parent, false));
328
            super(layoutInflater.inflate(R.layout.list_item_comment, parent, false));
240
329
241
            initView();
330
            initView();
331
            initListener();
242
        }
332
        }
243
333
244
        private void initView() {
334
        private void initView() {
245
            content = itemView.findViewById(R.id.content);
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
            this.bean = bean;
375
            this.bean = bean;
376
            this.position = position;
250
            content.setText(bean.content);
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
}

+ 25 - 2
app/src/main/res/layout/fragment_chat_content_comment_list.xml

100
                app:layout_constraintTop_toBottomOf="@+id/loadingIndicator" />
100
                app:layout_constraintTop_toBottomOf="@+id/loadingIndicator" />
101
        </android.support.constraint.ConstraintLayout>
101
        </android.support.constraint.ConstraintLayout>
102
102
103
        <!-- 检查网络 -->
104
103
        <!-- 没有数据 -->
105
        <android.support.constraint.ConstraintLayout
104
        <android.support.constraint.ConstraintLayout
105
            android:id="@+id/noDataView"
106
            android:layout_width="0dp"
107
            android:layout_height="0dp"
106
            android:visibility="gone"
108
            android:visibility="gone"
109
            app:layout_constraintBottom_toTopOf="@+id/bottomView"
110
            app:layout_constraintEnd_toEndOf="parent"
111
            app:layout_constraintStart_toStartOf="parent"
112
            app:layout_constraintTop_toBottomOf="@+id/titleView">
113
114
            <TextView
115
                android:layout_width="wrap_content"
116
                android:layout_height="wrap_content"
117
                android:layout_marginTop="20dp"
118
                android:text="还没有评论哦,快去抢沙发~"
119
                android:textColor="#ffffff"
120
                android:textSize="14sp"
121
                app:layout_constraintBottom_toBottomOf="parent"
122
                app:layout_constraintEnd_toEndOf="parent"
123
                app:layout_constraintStart_toStartOf="parent"
124
                app:layout_constraintTop_toTopOf="parent" />
125
        </android.support.constraint.ConstraintLayout>
126
127
        <!-- 检查网络 -->
128
        <android.support.constraint.ConstraintLayout
107
            android:id="@+id/noNetView"
129
            android:id="@+id/noNetView"
108
            android:layout_width="0dp"
130
            android:layout_width="0dp"
109
            android:layout_height="wrap_content"
131
            android:layout_height="wrap_content"
132
            android:visibility="gone"
110
            app:layout_constraintBottom_toTopOf="@+id/bottomView"
133
            app:layout_constraintBottom_toTopOf="@+id/bottomView"
111
            app:layout_constraintEnd_toEndOf="parent"
134
            app:layout_constraintEnd_toEndOf="parent"
112
            app:layout_constraintStart_toStartOf="parent"
135
            app:layout_constraintStart_toStartOf="parent"

+ 7 - 5
app/src/main/res/layout/list_item_comment.xml

94
        tools:text="充电桩挺多的,但是油车也多,充电的车也多。园区进门就收费,还好去了两次都充上了。"></TextView>
94
        tools:text="充电桩挺多的,但是油车也多,充电的车也多。园区进门就收费,还好去了两次都充上了。"></TextView>
95
95
96
    <android.support.constraint.ConstraintLayout
96
    <android.support.constraint.ConstraintLayout
97
        android:id="@+id/replyView"
98
        android:layout_width="match_parent"
97
        android:id="@+id/replyAndDeleteView"
98
        android:layout_width="wrap_content"
99
        android:layout_height="42dp"
99
        android:layout_height="42dp"
100
        android:paddingLeft="29dp"
100
        android:paddingLeft="29dp"
101
        app:layout_constraintLeft_toLeftOf="parent"
101
        app:layout_constraintBottom_toBottomOf="parent"
102
        app:layout_constraintBottom_toBottomOf="parent"
102
        app:layout_constraintTop_toBottomOf="@+id/content"
103
        app:layout_constraintTop_toBottomOf="@+id/content"
103
        tools:background="#06648f">
104
        tools:background="#06648f">
104
105
105
        <android.support.constraint.ConstraintLayout
106
        <android.support.constraint.ConstraintLayout
106
            android:id="@+id/replayInfo"
107
            android:id="@+id/replyInfo"
107
            android:layout_width="wrap_content"
108
            android:layout_width="wrap_content"
108
            android:layout_height="match_parent"
109
            android:layout_height="match_parent"
109
            android:layout_marginLeft="10dp"
110
            android:layout_marginLeft="10dp"
138
        </android.support.constraint.ConstraintLayout>
139
        </android.support.constraint.ConstraintLayout>
139
140
140
        <TextView
141
        <TextView
142
            android:id="@+id/deleteComment"
141
            android:layout_width="wrap_content"
143
            android:layout_width="wrap_content"
142
            android:layout_height="42dp"
144
            android:layout_height="42dp"
143
            android:gravity="center"
145
            android:gravity="center"
147
            android:textColor="#c2c2c2"
149
            android:textColor="#c2c2c2"
148
            android:textSize="12sp"
150
            android:textSize="12sp"
149
            app:layout_constraintBottom_toBottomOf="parent"
151
            app:layout_constraintBottom_toBottomOf="parent"
150
            app:layout_constraintLeft_toRightOf="@+id/replayInfo"
152
            app:layout_constraintLeft_toRightOf="@+id/replyInfo"
151
            app:layout_constraintTop_toTopOf="parent"
153
            app:layout_constraintTop_toTopOf="parent"
152
            tools:background="#790f59" />
154
            tools:background="#790f59" />
153
    </android.support.constraint.ConstraintLayout>
155
    </android.support.constraint.ConstraintLayout>
159
        android:layout_marginTop="10dp"
161
        android:layout_marginTop="10dp"
160
        android:background="#505050"
162
        android:background="#505050"
161
        app:layout_constraintBottom_toBottomOf="parent"
163
        app:layout_constraintBottom_toBottomOf="parent"
162
        app:layout_constraintTop_toBottomOf="@+id/replyView" />
164
        app:layout_constraintTop_toBottomOf="@+id/replyAndDeleteView" />
163
</android.support.constraint.ConstraintLayout>
165
</android.support.constraint.ConstraintLayout>