CommentFragment.java
68.6 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
package com.people.comment.fragment;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;
import com.people.comment.R;
import com.people.comment.adapter.CommentListAdapter;
import com.people.comment.bean.CommentClickShowType;
import com.people.comment.comment.vm.CommentViewModel;
import com.people.comment.dialog.CommentCommitDialog;
import com.people.comment.listener.CommitDialogListener;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.wd.foundation.wdkit.constant.EventConstants;
import com.wd.capability.network.response.ExceptionHandle;
import com.wd.common.base.BaseActivity;
import com.wd.foundation.wdkit.base.fragment.BaseLazyFragment;
import com.wd.foundation.wdkit.dialog.AlertDialog;
import com.wd.common.enums.MoreEnum;
import com.wd.common.enums.PosterTypeEnum;
import com.wd.common.interact.ICommentDataNewListener;
import com.wd.common.manager.WrapContentLinearLayoutManager;
import com.wd.foundation.wdkit.utils.PDUtils;
import com.wd.common.utils.ProcessUtils;
import com.wd.foundation.wdkit.view.CommomLoadMoreFooter;
import com.wd.foundation.wdkit.view.CustomSmartRefreshLayout;
import com.wd.foundation.bean.analytics.TraceBean;
import com.wd.foundation.bean.comment.CommentListBean;
import com.wd.foundation.bean.comment.CommentStatusBean;
import com.wd.foundation.bean.comment.TransparentBean;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.bean.custom.share.ShareBean;
import com.wd.foundation.bean.livedate.CommentOperationBean;
import com.wd.foundation.bean.livedate.EventMessage;
import com.wd.foundation.bean.request.CommentLikeParameterBean;
import com.wd.foundation.bean.request.PublishCommentParameterBean;
import com.wd.foundation.bean.response.NewsDetailBean;
import com.wd.foundation.bean.response.PersonalInfoBean;
import com.wd.foundation.wdkit.constant.IntentConstants;
import com.wd.foundation.wdkit.json.GsonUtils;
import com.wd.foundation.wdkit.utils.CommonUtil;
import com.wd.foundation.wdkit.utils.ToastNightUtil;
import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
import com.wd.foundation.wdkitcore.tools.AppContext;
import com.wd.foundation.wdkitcore.tools.ArrayUtils;
import com.wd.foundation.wdkitcore.tools.ResUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* @author LiuKun
* @date 2023/5/9 9:37
* @Description:详情页的评论,包含图文详情页,动态详情页,我的问政-留言详情页/问政详情页
*
*/
public class CommentFragment extends BaseLazyFragment implements OnLoadMoreListener {
/**
* 透传数据
*/
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private static final String ARG_PARAM3 = "param3";
/**
* 列表
* mCommentData:处理列表数据供adapter使用
*/
CommentCommitDialog commitDialog;
private long totalCommentNum = 0;
private int submitPos;
CommentViewModel commentViewModel;
private int pageNum = 1;
private int pageSize = 10;
private RecyclerView commentRv;
private List<CommentItem> dataList = new ArrayList<>();
/**
* 所有评论包括子评论
*/
private final List<CommentItem> mCommentData = new ArrayList<>();
private CommentListAdapter adapter;
private final List<PersonalInfoBean> mAllMasterInfoList = new ArrayList<>();
/**
* 透传数据
* contentId:内容id
* contentType:内容类型
* targetRelId: 被评论的内容关系id
* targetRelType:被评论的内容关系类型,1.频道关系;2.专题关系
* targetTitle 【迭代二新增】内容的标题,取bff内容详情接口中newsTitle字段
* keyArticle 【迭代二新增】是否是重点稿件 1是 0否
* targetRelObjectId 【迭代二新增】关联的频道id/专题id;
*/
private TransparentBean transparentBean;
private String pageName;
private String pageId;
private String contentId;
private String contentType;
private String targetRelId;
private String targetRelType;
private String targetTitle;
private String keyArticle;
/**
* 是否领导人文章 0 否,1 是,不存在就传0
*/
private String leaderArticle = "0";
private String targetRelObjectId;
private ShareBean mShareBean;
private NewsDetailBean newsDetailBean;
/**
* 透传推荐相关数据设置
*/
TraceBean traceBean;
/**
* 点击当前评论
*/
private int curPosition;
/**
* 是否使用评论列表的条数还是互动接口的条数
*/
private boolean useItCount = true;
/**
* 1 开启,2 关闭
*/
private int bestNoticer = 2;
/**
* 游客评论开关:visitorComment 1:打开;0:关闭
*/
private int visitorComment = 0;
/**
* 是否要加载更多
*/
private boolean showMore = false;
/**
* 已展示全部,是否展示
*/
private boolean noMoreIsShow = false;
/**
* 是否没有最新评论
*/
private boolean noNew = true;
BaseActivity baseActivity;
/**
* 最新评论第一个下标
*/
private int newFirstPosition = 1;
/**
* 热门评论
*/
private List<CommentItem> hotList = new ArrayList<>();
/**
* 热门评论id
*/
private String hotIds = "";
public NewsDetailBean getNewsDetailBean() {
return newsDetailBean;
}
public void setNewsDetailBean(NewsDetailBean newsDetailBean) {
this.newsDetailBean = newsDetailBean;
if (newsDetailBean != null) {
bestNoticer = newsDetailBean.getBestNoticer();
visitorComment = newsDetailBean.getBestNoticer();
}
}
/**
* 刷新控件
*/
private CustomSmartRefreshLayout smartRefreshLayout;
private boolean scrollViewFlag = true;
public void setSmartRefreshLayout(CustomSmartRefreshLayout refreshLayout) {
this.smartRefreshLayout = refreshLayout;
}
/**
* 接口回调
*/
private CommentFragmentListener commentListener;
public void setCommentListener(CommentFragmentListener listener) {
this.commentListener = listener;
}
/**
* 数据
*/
public static CommentFragment newInstance() {
return new CommentFragment();
}
/**
* 透传数据
*/
public static CommentFragment newInstance(TransparentBean transparentBean, boolean isScrollView, boolean useItCount) {
CommentFragment fragment = new CommentFragment();
Bundle args = new Bundle();
args.putSerializable(ARG_PARAM1, transparentBean);
args.putBoolean(ARG_PARAM2, isScrollView);
args.putBoolean(ARG_PARAM3, useItCount);
fragment.setArguments(args);
return fragment;
}
/**
* 透传数据
*/
public static CommentFragment newInstance(boolean isScrollView) {
CommentFragment fragment = new CommentFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_PARAM2, isScrollView);
fragment.setArguments(args);
return fragment;
}
/**
* 透传数据
*/
public void setCommentInitData(TransparentBean bean, TraceBean traceRecommendBean) {
this.transparentBean = bean;
if (null != transparentBean) {
pageName = transparentBean.getPageName();
pageId = transparentBean.getPageId();
targetRelId = transparentBean.getTargetRelId();
targetRelType = transparentBean.getTargetRelType();
contentId = transparentBean.getContentId();
contentType = transparentBean.getContentType();
targetTitle = transparentBean.getContentTitle();
keyArticle = transparentBean.getKeyArticle();
leaderArticle = transparentBean.getLeaderArticle();
targetRelObjectId = transparentBean.getTargetRelObjectId();
mShareBean = transparentBean.getShareBean();
traceBean = traceRecommendBean;
}
if (null != commentViewModel) {
setInitData(transparentBean);
}
}
/**
* 日志
*/
@Override
protected String getLogTag() {
return CommentFragment.class.getSimpleName();
}
/**
* 加载布局
*/
@Override
protected int getLayout() {
return R.layout.fragment_comment;
}
/**
* 初始化
*/
@Override
protected void initView(View rootView) {
//增加底部显示
CommomLoadMoreFooter footView = new CommomLoadMoreFooter(getActivity());
footView.setDescTextColor(ContextCompat.getColor(AppContext.getContext(), R.color.color_93959D));
//列表数据
commentRv = rootView.findViewById(R.id.comment_Rv);
try {
baseActivity = (BaseActivity) getActivity();
} catch (Exception e) {
e.printStackTrace();
}
adapter = new CommentListAdapter(getActivity(), pageName);
// 关闭动画,防止刷新闪烁
RecyclerView.ItemAnimator animator = commentRv.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
//外部ScrollView嵌套recycleView 设置LinearLayoutManager自动监听RecycleView高度
LinearLayoutManager layoutManager = new WrapContentLinearLayoutManager(getActivity());
layoutManager.setAutoMeasureEnabled(true);
layoutManager.setAutoMeasureEnabled(true);
commentRv.setHasFixedSize(false);
commentRv.setLayoutManager(layoutManager);
commentRv.setAdapter(adapter);
//适配器监听
setAdapterListener();
//判断Fragment外层是否包含NestScrollView
if (!scrollViewFlag && smartRefreshLayout != null) {
commentRv.setNestedScrollingEnabled(false);
smartRefreshLayout.setEnableLoadMore(true);
showMore = true;
noMoreIsShow = false;
smartRefreshLayout.setOnLoadMoreListener(this);
smartRefreshLayout.setRefreshFooter(footView);
}
//注册
receiveLiveDataMsg();
}
/**
* 注册用户登录成功接口
*/
private void receiveLiveDataMsg() {
LiveDataBus.getInstance().with(EventConstants.USER_ALREADY_LOGIN, Boolean.class).observe(this, aBoolean -> {
if (aBoolean) {
setInitData(transparentBean);
}
});
//评论操作
LiveDataBus.getInstance()
.with(EventConstants.COMMENT_OPERATION_EVENT, CommentOperationBean.class)
.observe(this, new Observer<CommentOperationBean>() {
@Override
public void onChanged(CommentOperationBean commentOperationBean) {
if (commentOperationBean != null) {
String commentId = commentOperationBean.getCommentId();
int operationType = commentOperationBean.getOperationType();
if (ArrayUtils.isEmpty(mCommentData)) {
return;
}
CommentItem clickObj = mCommentData.get(curPosition);
int clickShowType = 0;
if (operationType == MoreEnum.REPLY) {
clickShowType = CommentClickShowType.reply;
} else if (operationType == MoreEnum.DELETE) {
clickShowType = CommentClickShowType.delete;
} else if (operationType == MoreEnum.COPY_LINK) {
clickShowType = CommentClickShowType.copy;
} else if (operationType == MoreEnum.REPORT) {
clickShowType = CommentClickShowType.report;
}
if (clickObj != null) {
int id = clickObj.getId();
if (commentId.equals(String.valueOf(id))) {
judeClickType(clickObj, curPosition, clickShowType);
}
}
}
}
});
//适老化通知
LiveDataBus.getInstance().with(EventConstants.FONT_SIZE_SET_SUCCESS, Boolean.class).observe(this, aBoolean -> {
if (aBoolean) {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
});
}
/**
* 适配器点击事件
*/
private void setAdapterListener() {
adapter.setCommentAdapterListener(new CommentListAdapter.CommentAdapterListener() {
/**
* 回复
*/
@Override
public void replyComment(int position) {
showInputDialog(position);
}
/**
*点击更多评论
*/
@Override
public void loadSecondLevelComment(int position) {
loadSecondCommentList(position);
}
/**
*关闭评论
*/
@Override
public void closeListComment(int position) {
closeSecondComment(position);
}
/**
* 点赞
*/
@Override
public void commentLike(int position) {
if (!PDUtils.isLogin()) {
ProcessUtils.toOneKeyLoginActivity();
return;
}
if (commentViewModel == null) {
return;
}
if (position >= mCommentData.size()) {
return;
}
CommentItem likeComment = mCommentData.get(position);
if (likeComment == null) {
return;
}
boolean likeStatus = likeComment.getLikeStatus() == 1;
int executeStatus = likeStatus ? 0 : 1;
CommentLikeParameterBean commentLikeParameterBean = new CommentLikeParameterBean();
commentLikeParameterBean.setPosition(position);
commentLikeParameterBean.setUuid(String.valueOf(likeComment.getUuid()));
commentLikeParameterBean.setCommentId(String.valueOf(likeComment.getId()));
commentLikeParameterBean.setTargetId(contentId);
commentLikeParameterBean.setTargetType(contentType);
commentLikeParameterBean.setStatus(executeStatus);
int rootCommentId = likeComment.getParentId() == -1 ?
-1 : likeComment.getRootCommentId();
commentLikeParameterBean.setRootCommentId(rootCommentId);
commentViewModel.commentLike(commentLikeParameterBean);
setCommentLikeStatus(position, executeStatus);
// 评论点赞埋点
// if (transparentBean != null) {
// TrackContentBean trackContentBean = new TrackContentBean();
// trackContentBean.commentItemToBean(likeComment, transparentBean.getPageName(), transparentBean.getPageId());
// trackContentBean.likeAction(!likeStatus);
// CommonTrack.getInstance().contentLikeTrack(trackContentBean, !likeStatus);
// }
}
/**
* 点击评论者头像
*/
@Override
public void clickHead(int position) {
if (commentViewModel == null) {
return;
}
if (position >= mCommentData.size()) {
return;
}
CommentItem clickObj = mCommentData.get(position);
if (clickObj == null) {
return;
}
// //跳转到用户主页
// ProcessUtils.jumpToPersonalCenterActivity(
// clickObj.banControl,
// clickObj.mainControl,
// clickObj.getFromUserId(),
// clickObj.getFromUserType(),
// clickObj.getFromCreatorId());
}
/**
* 显示内容
*/
@Override
public void clickExpandOrShrink(int position, int type) {
if (position >= mCommentData.size() || position < 0) {
return;
}
CommentItem clickObj = mCommentData.get(position);
if (clickObj == null) {
return;
}
clickObj.setExpandableStatus(type);
}
@Override
public void commentLongClick(int position) {
//长按评论
CommentItem clickObj = mCommentData.get(position);
if (clickObj == null) {
return;
}
curPosition = position;
if (newsDetailBean != null) {
clickObj.setTargetTitle(newsDetailBean.getNewsTitle());
}
setCommentDataToShareBean(clickObj);
// UmengProcessUtils.goSharePoster(mShareBean);
}
});
}
/**
* 判断当前点击哪一个
*/
private void judeClickType(CommentItem bean, int position, int showType) {
//回复
if (showType == CommentClickShowType.reply) {
showInputDialog(position);
}
//删除评论
else if (showType == CommentClickShowType.delete) {
// if (bean.getId() == 0) {
// ToastNightUtil.showShort("暂时无法删除");
// return;
// }
new AlertDialog(getActivity()).builder()
.setTitle(ResUtils.getString(R.string.del_comment_tip))
.setPositiveButton(ResUtils.getString(R.string.res_cancel), v -> {
})
.setNegativeButton(ResUtils.getString(R.string.yes_btn), v -> {
delComment(bean, position);
})
.show();
}
//复制信息
else if (showType == CommentClickShowType.copy) {
boolean isCopySuccess = false;
if (!StringUtils.isEmpty(bean.getRealCommentContent())) {
isCopySuccess = true;
StringUtils.copy(bean.getRealCommentContent());
}
//图片评论
else if (!StringUtils.isEmpty(bean.getCommentPics())) {
String path = "";
if (bean.getCommentPics().contains(",")) {
path = bean.getCommentPics().split(",")[0];
} else {
path = bean.getCommentPics();
}
isCopySuccess = true;
StringUtils.copy(path);
}
//是否复制成功
if (isCopySuccess) {
ToastNightUtil.showShort(ResUtils.getString(R.string.comment_copy_success));
} else {
ToastNightUtil.showShort(ResUtils.getString(R.string.comment_copy_fail));
}
}
//举报
else if (showType == CommentClickShowType.report) {
if (!PDUtils.isLogin()) {
ProcessUtils.toOneKeyLoginActivity();
return;
}
if (transparentBean != null) {
transparentBean.setCommentId(String.valueOf(bean.getId()));
ProcessUtils.goReport(GsonUtils.objectToJson(transparentBean), "0");
}
}
}
/**
* 分享平台
* 是否显示海报,根据后台返回值判断,若显示,showPoster传递 1
*/
private void setCommentDataToShareBean(CommentItem bean) {
mShareBean.setShowPoster(1);
mShareBean.setShowPosterType(PosterTypeEnum.COMMENTS);
mShareBean.setFromUserHeader(bean.getFromUserHeader());
mShareBean.setFromUserName(bean.getFromUserName());
mShareBean.setFromUserId(bean.getFromUserId());
//设置评论设备id
mShareBean.setFromDeviceId(bean.getFromDeviceId());
mShareBean.setCommentContent(bean.getRealCommentContent());
mShareBean.setCommentId(bean.getId() + "");
//原文
mShareBean.setOriginalArticle(bean.getTargetTitle());
mShareBean.setLikeNumber(bean.getLikeNum());
//审核状态
mShareBean.setCommentStatus(bean.getCheckStatus());
mShareBean.setPosterNum(1);
}
/**
* 删除评论
*/
private void delComment(CommentItem bean, int position) {
if (null != commentViewModel) {
commentViewModel.delComment(bean.getId() + "", contentId, bean.getUuid(), position);
}
}
/**
* 加载更多数据
*/
@Override
public void onLoadMore(@NonNull @NotNull RefreshLayout refreshLayout) {
loadMoreCommentList();
}
/**
* 分页加载评论列表
*/
public void loadMoreCommentList() {
pageNum++;
if (null != commentViewModel) {
commentViewModel.getCommentList(contentId, contentType, pageNum, pageSize,
"1",hotIds);
}
}
/**
* 发布评论信息
*/
public void showInputDialog(int position) {
if (1 != visitorComment && transparentBean != null){
visitorComment = transparentBean.getVisitorComment();
}
if (visitorComment == 0 && !PDUtils.isLogin()) {
//游客评论开关未开且未登录
ProcessUtils.toOneKeyLoginActivity();
return;
}
this.submitPos = position;
//初始化弹出框
if (commitDialog == null) {
commitDialog = new CommentCommitDialog(getActivity());
// 2023/11/3 设置评论发布点击埋点数据
// if (transparentBean != null) {
// TrackContentBean trackContentBean = CommonTrack.getInstance().getTrackContentBean(pageName,
// pageId, contentId, contentType, targetTitle, "");
// //设置推荐字段
// if(traceBean != null) {
// trackContentBean.setTraceBean(traceBean);
// }
// commitDialog.setTrackContentBean(trackContentBean);
// }
commitDialog.setCommitDialogListener(new CommitDialogListener() {
@Override
public void publish(String text,String gifUrl) {
commitDialog.dismiss();
String comment = text.trim();
if (StringUtils.isEmpty(comment) && StringUtils.isEmpty(gifUrl)) {
ToastNightUtil.showShort("您还未输入任何信息");
return;
}
commitDialog.clearEditText();
//发布评论,3是带定制表情,或定制表情+文字,2是普通表情,或普通表情+文字
if(StringUtils.isEmpty(gifUrl)) {
submitComment(text, "2", "", submitPos);
}else{
submitComment(text, "3", gifUrl, submitPos);
}
}
@Override
public void getUnloadImg(ArrayList<String> images) {
}
});
}
//设置弹出框 hint
if (null != commitDialog) {
if (position == -1) {
if (1 != bestNoticer && transparentBean != null) {
bestNoticer = transparentBean.getBestNoticer();
}
commitDialog.showDefaultHint(bestNoticer);
} else {
if (position >= mCommentData.size()) {
return;
}
commitDialog.showUserName(mCommentData.get(position).getFromUserName());
}
commitDialog.showWithSoftBoard();
}
}
/**
* 发布评论
*
* @param text 内容
* @param commentType
* @param commentPics 图片地址
*/
private void submitComment(String text, String commentType, String commentPics, int position) {
PublishCommentParameterBean parameterBean = new PublishCommentParameterBean();
parameterBean.setCommentContent(text);
parameterBean.setCommentType(commentType);
parameterBean.setCommentPics(commentPics);
parameterBean.setTargetId(contentId);
parameterBean.setTargetType(contentType);
parameterBean.setTargetRelId(targetRelId);
parameterBean.setTargetRelType(targetRelType);
parameterBean.setTargetTitle(targetTitle);
parameterBean.setKeyArticle(keyArticle);
parameterBean.setLeaderArticle(leaderArticle);
parameterBean.setTargetRelObjectId(targetRelObjectId);
if (position == -1) {
if (null != commentViewModel) {
showLoadingView();
parameterBean.setPosition(-1);
parameterBean.setParentId("-1");
parameterBean.setRootCommentId("-1");
commentViewModel.submitComment(parameterBean);
}
} else {
if (position >= mCommentData.size()) {
return;
}
CommentItem covertCommentBean = mCommentData.get(position);
parameterBean.setPosition(position);
parameterBean.setParentId(covertCommentBean.getId() + "");
parameterBean.setRootCommentId(covertCommentBean.getRootCommentId() + "");
if (null != commentViewModel) {
showLoadingView();
commentViewModel.submitComment(parameterBean);
}
}
submitPos = 0;
}
/**
* 点击展开更多评论
*/
public void loadSecondCommentList(int position) {
if (position >= mCommentData.size()) {
return;
}
CommentItem moreCommentObj = mCommentData.get(position);
int id = moreCommentObj.getId();
int rootCommentId = moreCommentObj.getRootCommentId();
CommentItem parentCommentBean = null;
for (CommentItem commentBean : dataList) {
if (commentBean.getId() == rootCommentId && commentBean.getCommentLevel() == CommentListAdapter.COMMENT_TYPE_PARENT) {
parentCommentBean = commentBean;
}
}
StringBuilder excludeIds = new StringBuilder();
// 判断是否有要排除的item 如果item中有父类id与更多条目中id重合,需排除
if (parentCommentBean != null && parentCommentBean.getChildComments() != null) {
int size = parentCommentBean.getChildComments().size();
List<CommentItem> childList = parentCommentBean.getChildComments();
for (int i = 0; i < size; i++) {
if (i == size - 1) {
excludeIds.append(childList.get(i).getId());
} else {
excludeIds.append(childList.get(i).getId()).append(",");
}
}
}
if (commentViewModel != null) {
showLoadingView();
commentViewModel.getSecondCommentList(position, id + "", moreCommentObj.getPageNum() + "",
moreCommentObj.getPageSize() + "", excludeIds.toString(), contentId, contentType);
}
}
/**
* 收起逻辑
*/
public void closeSecondComment(int position) {
if (position >= mCommentData.size()) {
return;
}
CommentItem moreCommentObj = mCommentData.get(position);
if (moreCommentObj == null) {
return;
}
int parentId = moreCommentObj.getId();
int startPosition = 0;
for (int i = 0; i < mCommentData.size(); i++) {
if (mCommentData.get(i).getId() == parentId) {
startPosition = i;
break;
}
}
CommentItem parentComment = null;
for (int i = 0; i < dataList.size(); i++) {
if (dataList.get(i).getId() == parentId) {
parentComment = dataList.get(i);
break;
}
}
int originChildNum = 0;
if (parentComment != null) {
originChildNum = parentComment.getChildComments().size();
}
List<CommentItem> removeSecondList = new ArrayList<>();
int removeItemStartPos = startPosition + originChildNum + 1;
for (int i = removeItemStartPos; i < position; i++) {
CommentItem removeComment = mCommentData.get(i);
removeSecondList.add(removeComment);
}
refreshMoreDataToExpandNumberData(moreCommentObj, position);
mCommentData.removeAll(removeSecondList);
adapter.rangeRemoveData(removeItemStartPos, removeSecondList);
//刷新提交评论下标
if(position > newFirstPosition){
return;
}
for (int i = 0; i < mCommentData.size(); i++) {
CommentItem commentItem = mCommentData.get(i);
if(StringUtils.isEqual(ResUtils.getString(R.string.res_new_comment),
commentItem.getItemTitle())){
//最新评论标题下标
newFirstPosition = i + 1;
}
}
}
/**
* 刷新更多数据变成展开具体多少条回复
*/
private void refreshMoreDataToExpandNumberData(CommentItem moreCommentObj, int position) {
moreCommentObj.setPageNum(CommentItem.INIT_PAGE_NUM);
moreCommentObj.setShowExpandChild(true);
// moreCommentObj.setCommentContent("展开" + NumberStrUtils.Companion.getINSTANCE().handlerNumber(String.valueOf(moreCommentObj.getChildCommentNum())) + "条回复");
moreCommentObj.setCommentContent(ResUtils.getString(R.string.check_all_reply));
moreCommentObj.setShowCloseChild(false);
adapter.notifyItemChanged(position);
}
/**
* 接收参数
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
transparentBean = (TransparentBean) getArguments().getSerializable(ARG_PARAM1);
scrollViewFlag = getArguments().getBoolean(ARG_PARAM2);
useItCount = getArguments().getBoolean(ARG_PARAM3);
}
if (null != transparentBean) {
pageName = transparentBean.getPageName();
pageId = transparentBean.getPageId();
targetRelId = transparentBean.getTargetRelId();
targetRelType = transparentBean.getTargetRelType();
contentId = transparentBean.getContentId();
contentType = transparentBean.getContentType();
targetTitle = transparentBean.getContentTitle();
keyArticle = transparentBean.getKeyArticle();
leaderArticle = transparentBean.getLeaderArticle();
targetRelObjectId = transparentBean.getTargetRelObjectId();
mShareBean = transparentBean.getShareBean();
}
initViewModel();
}
/**
* 初始化接口请求
*/
private void initViewModel() {
commentViewModel = getViewModel(CommentViewModel.class);
commentViewModel.observeCommentListener(getActivity(), new ICommentDataNewListener() {
/**
* 获取评论列表
*/
@Override
public void onGetCommentListSuccess(CommentListBean commentList) {
hideLoadingView();
setCommentData(commentList);
LiveDataBus.getInstance().with(EventConstants.CAN_SCROLL_TO_COMMENT, Boolean.class).postValue(true);
}
/**
*获取评论列表失败
*/
@Override
public void onGetCommentListFail(int code, String msg) {
hideLoadingView();
setNoEmptyView();
LiveDataBus.getInstance().with(EventConstants.CAN_SCROLL_TO_COMMENT, Boolean.class).postValue(true);
}
/**
*获取二级评论成功
*/
@Override
public void onGetSecondCommentListSuccess(int position, CommentListBean childCommentList) {
hideLoadingView();
setSecondData(position, childCommentList);
}
/**
* 获取二级评论
*/
@Override
public void onGetSecondCommentListFail() {
ToastNightUtil.showShort(ExceptionHandle.NET_ERROR_TIPS_IN_PAGE);
hideLoadingView();
}
/**
* 号主认证状态
*/
@Override
public void onGetMastersAuthenticationListSuccess(List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
setMastersAuthenticationList(masterInfoList, originalListData, freshStartIndex, listLevel);
}
/**
* 号主认证状态失败
*/
@Override
public void onGetMastersAuthenticationListFailure(String errorInfo, int listLevel) {
hideLoadingView();
setErrorView(listLevel);
}
/**
* 发布评论
*/
@Override
public void onSubmitPushCommentSuccess(CommentItem pushListBean, int position, String msg) {
hideLoadingView();
if (commentListener != null) {
//一级评论
commentListener.submitCommentSuccess(position == -1 ? 0 : 1);
}
/**
* 1.除直播外所有详情页视频、稿件、图文---评论预显示开关:
* https://pd-apis-uat.pdnews.cn/api/rmrb-comment/comment/zh/c/publish
* 1.data不为空,直接显示评论内容,成功提示语也走message;
* 2.data为空,提交失败不预显示评论,直接以message提示。
*/
if (StringUtils.isNotBlank(msg)){
ToastNightUtil.showShort(msg);
}
if (pushListBean == null) {
return;
}
//第一次发布
if (pushListBean == null) {
setInitData(transparentBean);
} else {
//回复其它人的
submitCommentSuccess(pushListBean, position);
//commentViewModel.oneUserLevelInfor(pushListBean,position);
}
if (null != commitDialog) {
commitDialog.recycler();
}
}
// @Override
// public void onGetLevelInfoBeanSuccess(CommentItem pushListBean, int position) {
// submitCommentSuccess(pushListBean, position);
// }
/**
* 发布评论失败
*/
@Override
public void onSubmitPushCommentFail(int code, String msg) {
hideLoadingView();
ToastNightUtil.showShort(StringUtils.isBlank(msg) ? "发送失败,请重试" : msg);
}
/**
*获取所有数据
*/
@Override
public void onGetAllDataSuccess(List<CommentStatusBean> statusList, List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
setAllList(statusList, masterInfoList, originalListData, freshStartIndex, listLevel);
}
/**
*评论
*/
@Override
public void onGetCommentStatusListFailure(String errorInfo, int listLevel) {
setErrorView(listLevel);
}
/**
* 获取单个认证
*/
@Override
public void onGetSingleMastersAuthenticationDataSuccess(PersonalInfoBean mMasterInfoBean, int freshPosition) {
setSingleMastersAuthentication(mMasterInfoBean, freshPosition);
}
/**
* 批查获取用户等级信息
* @param data
* @param freshStartIndex
* @param listLevel
*/
@Override
public void onGetLevelInfoBeanListSuccess(List<CommentItem> data, int freshStartIndex, int listLevel) {
getMastersAuthenticationList(data, freshStartIndex, listLevel);
}
/**
*删除评论
*/
@Override
public void delCommentSuccess(int freshPosition) {
hideLoadingView();
delCommentSingle(freshPosition);
}
/**
* 删除评论失败
*/
@Override
public void delCommentFail(String e) {
hideLoadingView();
ToastNightUtil.showShort(e);
}
});
}
/**
* 删除评论
*/
public void delCommentSingle(int freshPosition) {
if(freshPosition < 0){
return;
}
if(ArrayUtils.isEmpty(mCommentData)){
return;
}
try {
if (freshPosition < mCommentData.size()) {
if(freshPosition < mCommentData.size()-1){
// 如果父评论被删除,则子评论也一起删除
//获取要删除的评论id
String commentId = mCommentData.get(freshPosition).getCommentId();
int lastPosition = freshPosition;
// 创建一个标记删除的列表
ArrayList<CommentItem> toRemove = new ArrayList<>();
toRemove.add(mCommentData.get(freshPosition));
boolean isCC = false;
if(mCommentData.get(freshPosition).getParentId() > 0 &&
mCommentData.get(freshPosition).getParentId() != mCommentData.get(freshPosition).getRootCommentId()){
//子评论的子评论
isCC = true;
}
//查找子评论
for(int i = freshPosition+1; i < mCommentData.size(); i++){
if(commentId.equals(mCommentData.get(i).getParentId()+"") || (!isCC &&
CommentListAdapter.COMMENT_TYPE_MORE ==
mCommentData.get(i).getCommentLevel())){
lastPosition = i;
toRemove.add(mCommentData.get(i));
}else{
break;
}
}
if(lastPosition == freshPosition){
mCommentData.remove(freshPosition);
adapter.removeSingleData(freshPosition);
totalCommentNum--;
setTotalCount(-1);
}else{
mCommentData.removeAll(toRemove);
adapter.removeData(toRemove);
totalCommentNum = totalCommentNum - toRemove.size();
setTotalCount(- toRemove.size());
}
}else{
mCommentData.remove(freshPosition);
adapter.removeSingleData(freshPosition);
totalCommentNum--;
setTotalCount(-1);
}
if(mCommentData.size() < 2){
//没有评论数据,展示缺省图
setEmptyOrErrorView();
} else if(!noNew){
int newIndex = 0;
for (int i = 0; i < mCommentData.size(); i++) {
CommentItem commentItem = mCommentData.get(i);
if(StringUtils.isEqual(ResUtils.getString(R.string.res_new_comment),
commentItem.getItemTitle())){
//最新评论标题下标
newIndex = i;
}
}
int dataSize = mCommentData.size();
if(newIndex != 0 && newIndex == dataSize -1){
//删的是最新评论最后一条
//移除最新评论标题
mCommentData.remove(dataSize -1);
adapter.removeSingleData(adapter.getItemCount() - 2);
noNew = true;
newFirstPosition--;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 加载数据
*/
@Override
protected void lazyLoadData() {
setInitData(transparentBean);
}
/**
* 接收外部传递数据,进行第一次网络数据请求
*/
public void setInitData(TransparentBean transparentData) {
showLoadingView();
//判断是否为空
if (null == transparentData) {
hideLoadingView();
setNoEmptyView();
return;
}
contentId = transparentData.getContentId();
contentType = transparentData.getContentType();
targetRelId = transparentBean.getTargetRelId();
targetRelType = transparentBean.getTargetRelType();
targetTitle = transparentBean.getContentTitle();
keyArticle = transparentBean.getKeyArticle();
leaderArticle = transparentBean.getLeaderArticle();
targetRelObjectId = transparentBean.getTargetRelObjectId();
mShareBean = transparentBean.getShareBean();
if (StringUtils.isEmpty(contentId) || StringUtils.isEmpty(contentType)) {
hideLoadingView();
setNoEmptyView();
return;
}
pageNum = 1;
if (null != commentViewModel) {
commentViewModel.getCommentList(contentId, contentType, pageNum, pageSize,
"1","");
}
}
/**
* 获取评论列表
*/
private void setCommentData(CommentListBean commentList) {
if (pageNum == 1) {
newFirstPosition = 1;
mCommentData.clear();
dataList.clear();
mAllMasterInfoList.clear();
hotList.clear();
hotIds = "";
noNew = true;
if(commentList == null ||
(ArrayUtils.isEmpty(commentList.getHotList()) &&
ArrayUtils.isEmpty(commentList.getList()))){
//无热门、无最新
hideLoadingView();
// 显示无评论页面
setEmptyOrErrorView();
return;
}
if(ArrayUtils.isNotEmpty(commentList.getHotList())){
//有热门评论
hotList = commentList.getHotList();
if(ArrayUtils.isNotEmpty(commentList.getHotIds())){
for (int i = 0; i < commentList.getHotIds().size(); i++) {
if(StringUtils.isEmpty(hotIds)){
hotIds = commentList.getHotIds().get(i);
}else {
hotIds = hotIds + ","+commentList.getHotIds().get(i);
}
}
}
}
if(ArrayUtils.isNotEmpty(commentList.getList())){
//有最新评论数据
noNew = false;
if (commentList.getTotalCommentNum() < pageSize){
showMore = false;
}else {
if (null != smartRefreshLayout) {
smartRefreshLayout.setEnableLoadMore(true);
showMore = true;
noMoreIsShow = false;
}
}
}else {
//无最新数据
hideLoadingView();
noNew = true;
showMore = false;
if (null != smartRefreshLayout) {
smartRefreshLayout.setEnableLoadMore(false);
}
}
}else {
if(commentList == null || ArrayUtils.isEmpty(commentList.getList())){
pageNum--;
// ToastUtils.showShort("没有更多数据");
setNoMoreData();
return;
}
}
/*if (commentList != null && commentList.getList() != null && commentList.getList().size() > 0) {
if (pageNum == 1) {
newFirstPosition = 1;
mCommentData.clear();
dataList.clear();
mAllMasterInfoList.clear();
if (commentList.getTotalCommentNum() < pageSize){
showMore = false;
}else {
if (null != smartRefreshLayout) {
smartRefreshLayout.setEnableLoadMore(true);
showMore = true;
noMoreIsShow = false;
}
}
}
} else {
if (pageNum == 1) {
hideLoadingView();
// 显示无评论页面
setEmptyOrErrorView();
} else {
pageNum--;
// ToastUtils.showShort("没有更多数据");
setNoMoreData();
}
return;
}*/
//评论实际的数量比较加权的数量取较大的那个
if (commentList.getTotalCommentNum() > totalCommentNum){
totalCommentNum = commentList.getTotalCommentNum();
// 底部互动栏评论按钮上评论总数赋值
setTotalCount(0);
}
//构建数据
List<CommentItem> tempListData = new ArrayList<>();
List<CommentItem> list = commentList.getList();
int startIndex;
if (pageNum == 1) {
//第一页
startIndex = 0;
if(ArrayUtils.isNotEmpty(hotList)){
//有热门评论
CommentItem hotTitleCommentObj = new CommentItem();
hotTitleCommentObj.setCommentLevel(CommentListAdapter.COMMENT_TYPE_TITLE);
hotTitleCommentObj.setItemType(2);
hotTitleCommentObj.setItemTitle(ResUtils.getString(R.string.res_hot_comment));
tempListData.add(hotTitleCommentObj);
addCommentItem(hotList,tempListData);
dataList.addAll(hotList);
}
if(ArrayUtils.isNotEmpty(list)){
// 增加最新评论标题
CommentItem newTitleCommentObj = new CommentItem();
newTitleCommentObj.setCommentLevel(CommentListAdapter.COMMENT_TYPE_TITLE);
newTitleCommentObj.setItemType(1);
newTitleCommentObj.setItemTitle(ResUtils.getString(R.string.res_new_comment));
if(ArrayUtils.isNotEmpty(hotList)){
newTitleCommentObj.setShowTitleTopSpace(true);
}
tempListData.add(newTitleCommentObj);
}
newFirstPosition = tempListData.size();
}else {
startIndex = adapter.getItemCount() - 1;
}
//处理最新评论
if(ArrayUtils.isNotEmpty(list)){
addCommentItem(list,tempListData);
dataList.addAll(list);
}
//正式场景使用
if (useItCount) {
setTotalCount(0);
}
// 批查用户等级信息
commentViewModel.batchUserLevelInfor(tempListData, startIndex, 1);
}
private void addCommentItem(List<CommentItem> list,List<CommentItem> tempListData){
if(ArrayUtils.isEmpty(list) || tempListData == null){
return;
}
for (int i = 0; i < list.size(); i++) {
tempListData.add(list.get(i));
//获取子部数据
if (list.get(i).getChildComments() != null && list.get(i).getChildComments().size() > 0) {
list.get(i).setHasChildComment(true);
tempListData.addAll(list.get(i).getChildComments());
}
// getChildCommentNum = 是总量 - 默认展示的 3
if (list.get(i).getChildCommentNum() >= 1) {
CommentItem moreCommentObj = new CommentItem();
moreCommentObj.setCommentLevel(CommentListAdapter.COMMENT_TYPE_MORE);
moreCommentObj.setShowCloseChild(false);
moreCommentObj.setChildCommentNum(list.get(i).getChildCommentNum());
moreCommentObj.setShowExpandChild(true);
// moreCommentObj.setCommentContent("展开" + NumberStrUtils.Companion.getINSTANCE().handlerNumber(String.valueOf(listBean.getChildCommentNum())) + "条回复");
moreCommentObj.setCommentContent(ResUtils.getString(R.string.check_all_reply));
moreCommentObj.setRootCommentId(list.get(i).getRootCommentId());
// 显示更多id与一级id保持一致,方便收起二级评论判断
moreCommentObj.setId(list.get(i).getId());
tempListData.add(moreCommentObj);
}
}
}
/**
* 显示没有更多数据
*/
private void setNoMoreData() {
hideLoadingView();
if(noMoreIsShow){
return;
}
noMoreIsShow = true;
CommentItem commentObj = new CommentItem();
commentObj.setCommentLevel(CommentListAdapter.COMMENT_TYPE_FOOTER);
commentObj.setCommentContent(ResUtils.getString(R.string.res_show_end));
adapter.addNoMoreData(commentObj);
if (null != smartRefreshLayout) {
smartRefreshLayout.setEnableLoadMore(false);
showMore = false;
}
}
/**
* @param data 原始数据集
* @param freshStartIndex 刷新开始位置
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
private void getMastersAuthenticationList(List<CommentItem> data, int freshStartIndex, int listLevel) {
//批量获取创作者的认证信息
commentViewModel.getMastersAuthenticationList(contentId,data, freshStartIndex, listLevel);
}
/**
* 整合评论数据、号主信息数据
*
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
public void setMastersAuthenticationList(List<PersonalInfoBean> mMasterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
hideLoadingView();
if (!CommonUtil.isEmpty(mMasterInfoList)) {
mAllMasterInfoList.addAll(mMasterInfoList);
for (CommentItem mCovertCommentBean : originalListData) {
for (PersonalInfoBean masterInfoBean : mMasterInfoList) {
String targetId = masterInfoBean.getRmhId();
String fromCreatorId = StringUtils.getStringValue(mCovertCommentBean.getFromCreatorId());
if (fromCreatorId.equals(targetId)) {
mCovertCommentBean.setAuthIcon(masterInfoBean.getAuthIcon());
mCovertCommentBean.mainControl = masterInfoBean.getCnMainControl();
}
}
}
}
refreshData(originalListData, freshStartIndex, listLevel);
}
/**
* 整合评论数据、号主信息数据、点赞状态数据
*
* @param statusList 点赞状态列表
* @param masterInfoList 号主信息列表
* @param originalListData 评论列表
* @param freshStartIndex 刷新起始位置
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
public void setAllList(List<CommentStatusBean> statusList, List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData,
int freshStartIndex, int listLevel) {
hideLoadingView();
boolean masterInfoListIsEmpty = CommonUtil.isEmpty(masterInfoList);
boolean statusListIsEmpty = CommonUtil.isEmpty(statusList);
if (masterInfoListIsEmpty && statusListIsEmpty) {
refreshData(originalListData, freshStartIndex, listLevel);
return;
}
if (!masterInfoListIsEmpty) {
mAllMasterInfoList.addAll(masterInfoList);
}
for (CommentItem mCovertCommentBean : originalListData) {
if (!masterInfoListIsEmpty) {
for (PersonalInfoBean masterInfoBean : masterInfoList) {
String targetId = masterInfoBean.getRmhId();
String fromCreatorId = StringUtils.getStringValue(mCovertCommentBean.getFromCreatorId());
if (fromCreatorId.equals(targetId)) {
mCovertCommentBean.setAuthIcon(masterInfoBean.getAuthIcon());
mCovertCommentBean.mainControl = masterInfoBean.getCnMainControl();
}
}
}
if (!statusListIsEmpty) {
for (CommentStatusBean mCommentStatusBean : statusList) {
int targetId = mCommentStatusBean.getCommentId();
int fromCommentId = mCovertCommentBean.getId();
String uuid = mCommentStatusBean.getUuid();
String muuid = mCovertCommentBean.uuid;
if (targetId != 0 && targetId == fromCommentId) {
mCovertCommentBean.setLikeStatus(mCommentStatusBean.getStatus());
}else if(StringUtils.isEqual(muuid,uuid)){
//预显的没有CommentId,通过uuid匹配
mCovertCommentBean.setLikeStatus(mCommentStatusBean.getStatus());
}
}
}
}
refreshData(originalListData, freshStartIndex, listLevel);
}
/**
* 刷新数据源
*
* @param originalListData 一级评论原始数据
* @param freshStartIndex 刷新起始位置
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
private void refreshData(List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
if (listLevel == 1) {
if (pageNum == 1) {
noMoreIsShow = false;
mCommentData.clear();
adapter.setData(originalListData);
if (!showMore){
setNoMoreData();
}
} else {
adapter.addData(originalListData, mCommentData.size());
}
mCommentData.addAll(originalListData);
} else {
refreshMoreDataToExpandMoreData(freshStartIndex);
adapter.insertData(freshStartIndex, originalListData);
mCommentData.addAll(freshStartIndex, originalListData);
//刷新提交评论下标
if(freshStartIndex > newFirstPosition){
return;
}
for (int i = 0; i < mCommentData.size(); i++) {
CommentItem commentItem = mCommentData.get(i);
if(StringUtils.isEqual(ResUtils.getString(R.string.res_new_comment),
commentItem.getItemTitle())){
//最新评论标题下标
newFirstPosition = i + 1;
}
}
}
}
/**
* 刷新更多数据变成展开更多回复
*/
private void refreshMoreDataToExpandMoreData(int freshStartIndex) {
if (freshStartIndex >= mCommentData.size()) {
return;
}
CommentItem moreCommentObj = mCommentData.get(freshStartIndex);
if (moreCommentObj == null) {
return;
}
if (moreCommentObj.getCommentLevel() == CommentListAdapter.COMMENT_TYPE_MORE) {
moreCommentObj.setCommentContent(ResUtils.getString(R.string.check_all_reply));
adapter.notifyItemChanged(freshStartIndex);
}
}
/**
* 设置二级评论数据
*/
public void setSecondData(int position, CommentListBean videoItemBean) {
//成功以后再设置PageNum
setPageNum(position);
List<CommentItem> list = videoItemBean.getList();
boolean hasMoreComment = (videoItemBean.getHasNext() == 1);
List<CommentItem> secondFilterList = new ArrayList<>();
for (CommentItem bean : list) {
if (bean.getCommentLevel() == CommentListAdapter.COMMENT_TYPE_CHILD) {
secondFilterList.add(bean);
}
}
int parentId = 0;
if (!secondFilterList.isEmpty()) {
parentId = secondFilterList.get(0).getRootCommentId();
}
int targetPos = 0;
for (int j = 0; j < mCommentData.size(); j++) {
CommentItem commentBean = mCommentData.get(j);
if (commentBean.getCommentLevel() == CommentListAdapter.COMMENT_TYPE_MORE
&& commentBean.getId() == parentId) {
targetPos = j;
commentBean.setShowExpandChild(hasMoreComment);
commentBean.setShowCloseChild(true);
break;
}
}
List<CommentItem> data = new ArrayList<>();
for (int j = 0; j < secondFilterList.size(); j++) {
CommentItem childCommentsBeanX = secondFilterList.get(j);
//二级评论要设置ParentId 和 ToUserName
data.add(childCommentsBeanX);
}
// getMastersAuthenticationList(data, targetPos, 2)
// 批查用户等级信息
commentViewModel.batchUserLevelInfor(data, targetPos, 2);
}
/**
* 设置页面
*/
private void setPageNum(int position) {
if (position >= mCommentData.size()) {
return;
}
CommentItem covertCommentBean = mCommentData.get(position);
if (covertCommentBean == null) {
return;
}
covertCommentBean.setPageNum(covertCommentBean.getPageNum() + 1);
}
/**
* 设置评论点赞状态
*/
public void setCommentLikeStatus(int position, int status) {
if (position >= mCommentData.size()) {
return;
}
CommentItem mCurrentDate = mCommentData.get(position);
mCurrentDate.setLikeStatus(status);
long likeNum = Long.parseLong(mCurrentDate.getLikeNum());
if (status == 1) {
likeNum = likeNum + 1;
} else {
if (likeNum > 0) {
likeNum = likeNum - 1;
}
}
mCurrentDate.setLikeNum(likeNum + "");
adapter.notifyItemChanged(position);
}
/**
* 评论发布成功回调
*
* @param submitCommentBean 评论成功接口返回评论数据对象
* @param itemPosition -1 点击输入框评论(1级评论) 否则就是回复某条评论的下标
*/
public void submitCommentSuccess(CommentItem submitCommentBean, int itemPosition) {
if (submitCommentBean == null) {
return;
}
//要提交的评论
//是否需要调接口批量查询
boolean needBatchMastersAuthenticationData = false;
String fromCreatorId = "";
if (submitCommentBean.getCreatorFlag() == 1) {
fromCreatorId = submitCommentBean.getFromCreatorId();
if (!CommonUtil.isEmpty(mAllMasterInfoList)) {
for (PersonalInfoBean masterInfoBean : mAllMasterInfoList) {
String targetId = masterInfoBean.getRmhId();
if (fromCreatorId.equals(targetId)) {
//设置创作者标签
submitCommentBean.setAuthIcon(masterInfoBean.getAuthIcon());
submitCommentBean.mainControl = masterInfoBean.getCnMainControl();
}
}
} else {
needBatchMastersAuthenticationData = true;
}
}
int insertPosition;
//回复某条评论
if (itemPosition != -1) {
//二级评论要设置ParentId
submitCommentBean.setParentId(submitCommentBean.getParentId());
if (itemPosition >= mCommentData.size()) {
return;
}
//被回复的评论
CommentItem byAnswerCommentBean = mCommentData.get(itemPosition);
if (byAnswerCommentBean.getCommentLevel() == CommentListAdapter.COMMENT_TYPE_CHILD) {
//设置被回复人昵称 只有被回复的评论为二级才显示
submitCommentBean.setToUserName(byAnswerCommentBean.getFromUserName());
submitCommentBean.toUserId = byAnswerCommentBean.toUserId;
submitCommentBean.toUserType = byAnswerCommentBean.toUserType;
submitCommentBean.setToCreatorId(byAnswerCommentBean.getToCreatorId());
}
insertPosition = itemPosition + 1;
mCommentData.add(insertPosition, submitCommentBean);
adapter.addPositionData(insertPosition, submitCommentBean);
if (itemPosition == mCommentData.size() - 2 && adapter.getItemCount() > 0) {
commentRv.smoothScrollToPosition(adapter.getItemCount() - 1);
}
//设置父评论的子评论列表
setParentCommentsChildComments(submitCommentBean);
} else {
insertPosition = newFirstPosition;
if(noNew){
//无最新评论到有最新评论,增加最新评论标题
noNew = false;
CommentItem newTitleCommentObj = new CommentItem();
newTitleCommentObj.setCommentLevel(CommentListAdapter.COMMENT_TYPE_TITLE);
newTitleCommentObj.setItemType(1);
newTitleCommentObj.setItemTitle(ResUtils.getString(R.string.res_new_comment));
CommentItem itemBean = adapter.getData().get(0);
if(StringUtils.isEqual("评论",itemBean.getItemTitle())){
//既没有热门,也没有最新
mCommentData.clear();
mCommentData.add(0,newTitleCommentObj);
adapter.setData(mCommentData);
insertPosition = 1;
newFirstPosition = 1;
}else {
//有热门,无最新
newTitleCommentObj.setShowTitleTopSpace(true);
mCommentData.add(insertPosition, newTitleCommentObj);
adapter.addPositionData(insertPosition, newTitleCommentObj);
insertPosition = insertPosition +1;
newFirstPosition++;
}
}
mCommentData.add(insertPosition, submitCommentBean);
adapter.addPositionData(insertPosition, submitCommentBean);
commentRv.smoothScrollToPosition(insertPosition);
if (1 == pageNum){
if (mCommentData.size() < pageSize){
showMore = false;
setNoMoreData();
}
}
}
//调接口批量查询
if (needBatchMastersAuthenticationData && !StringUtils.isBlank(fromCreatorId)) {
commentViewModel.getSingleMastersAuthenticationData(fromCreatorId, insertPosition);
}
totalCommentNum++;
setTotalCount(1);
}
/**
* 设置父评论的子评论列表
*
* @param videoItemBean 需要增加的评论数据
*/
private void setParentCommentsChildComments(CommentItem videoItemBean) {
int rootCommentId = videoItemBean.getRootCommentId();
for (CommentItem mTempObj : dataList) {
if (mTempObj.getId() == rootCommentId && mTempObj.getCommentLevel() == CommentListAdapter.COMMENT_TYPE_PARENT) {
List<CommentItem> mTempList = mTempObj.getChildComments();
mTempList.add(videoItemBean);
mTempObj.setChildComments(mTempList);
}
}
}
/**
* 设置发出去的单条评论数据的号主V
*
* @param mMasterInfoBean 号主对象
* @param freshPosition 后续需要刷新的item的下标
*/
public void setSingleMastersAuthentication(PersonalInfoBean mMasterInfoBean, int freshPosition) {
if (mMasterInfoBean == null) {
return;
}
mAllMasterInfoList.add(mMasterInfoBean);
if (freshPosition >= mCommentData.size()) {
return;
}
CommentItem submitObj = mCommentData.get(freshPosition);
if (submitObj == null) {
return;
}
submitObj.setAuthIcon(mMasterInfoBean.getAuthIcon());
submitObj.mainControl = mMasterInfoBean.getCnMainControl();
adapter.notifyItemChanged(freshPosition);
}
/**
* 透传评论总数
*/
public void setTotalCount(int type) {
if (null != commentListener) {
commentListener.getCommentNum(totalCommentNum, type);
}
EventMessage mEventMessage = new EventMessage(EventConstants.COMMENT_NUM);
mEventMessage.putExtra(IntentConstants.CONTENT_ID, contentId);
mEventMessage.putExtra(IntentConstants.CONTENT_TYPE, contentType);
mEventMessage.putExtra(IntentConstants.COMMENT_NUM, String.valueOf(totalCommentNum));
LiveDataBus.getInstance().with(EventConstants.COMMENT_NUM, EventMessage.class).postValue(mEventMessage);
}
/**
* 设置评论数
* @param commentNum
*/
public void setCommentNum(String commentNum) {
try {
totalCommentNum = Long.parseLong(commentNum);
} catch (NumberFormatException e) {
throw new RuntimeException(e);
}
}
/**
* 获取评论数
* @return
*/
public String getCommentNum() {
return totalCommentNum + "";
}
/**
* 显示加载动效
*/
private void showLoadingView() {
if(baseActivity != null){
baseActivity.startLoading(false);
}
}
/**
* 隐藏加载动效
*/
private void hideLoadingView() {
//刷新控件
if (null != smartRefreshLayout && smartRefreshLayout.isLoading()) {
smartRefreshLayout.finishLoadMore();
}
//隐藏loading框
if(baseActivity != null){
baseActivity.stopLoading();
}
}
/**
* 无数据展示
*/
private void setEmptyOrErrorView() {
CommentItem emptyCommentObj = new CommentItem();
emptyCommentObj.setCommentLevel(CommentListAdapter.COMMENT_TYPE_EMPTY);
adapter.addEmptyOrErrorData(emptyCommentObj,0);
noMoreIsShow = false;
noNew = true;
if (null != smartRefreshLayout) {
smartRefreshLayout.setEnableLoadMore(false);
showMore = false;
}
}
/**
* 设置空布局VIEW
*/
public void setNoEmptyView() {
if (pageNum == 1) {
setEmptyOrErrorView();
}
}
/**
* 设置批量查询接口异常时的布局VIEW 只有一级评论且为第一页时才会显示空布局
*
* @param listLevel 数据类型 1 一级评论 2 二级评论
*/
public void setErrorView(int listLevel) {
hideLoadingView();
if (listLevel == 1 && pageNum == 1) {
//只有一级评论且为第一页时才会显示空布局
setEmptyOrErrorView();
} else {
ToastNightUtil.showShort(ExceptionHandle.NET_ERROR_TIPS_IN_PAGE);
}
}
/**
* 是否需要加载更多
* @return
*/
public boolean isShowMore() {
return showMore;
}
public int getHotHeight(){
if(commentRv == null || newFirstPosition == 0){
return 0;
}
int topHeight = 0;
RecyclerView.LayoutManager layoutManager = commentRv.getLayoutManager();
if (layoutManager != null) {
View view = layoutManager.findViewByPosition(newFirstPosition - 1);
if (view != null) {
// 获取顶部边缘的坐标
topHeight = view.getTop();
}
}
return topHeight;
}
/**
* 设置接口回调
*/
public interface CommentFragmentListener {
/**
* 评论个数
* 0 初始,1:增加,-1减少
*/
void getCommentNum(long commentNum, int type);
/**
* 评论提交成功
*
* @param type 0:1级评论,1:回复别人
*/
void submitCommentSuccess(int type);
}
}