ArticleDetailActivity.java
89.1 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
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
package com.people.webview.ui;
import android.app.Activity;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.lifecycle.Observer;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSONObject;
import com.github.lzyzsd.jsbridge.OnBridgeCallback;
import com.google.gson.Gson;
import com.people.comment.fragment.CommentFragment;
import com.people.musicplayer.PlayerManagerUtils;
import com.people.musicplayer.data.bean.MusicAlbum;
import com.people.musicplayer.player.PlayerManager;
import com.people.webview.R;
import com.people.webview.constant.AppNotifyEventConstant;
import com.people.webview.listener.ChangeScreenListener;
import com.people.webview.util.ArticleTrack;
import com.people.webview.util.ArticleVideoManager;
import com.people.webview.util.JSBridgeUtils;
import com.people.webview.util.WebDataUtils;
import com.people.webview.util.WebUtils;
import com.people.webview.vm.ArticleDetailViewModel;
import com.people.webview.vm.IArticleDetailDataListener;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.wd.base.log.Logger;
import com.people.webview.ui.fragment.RecommendFragment;
import com.wd.foundation.wdkit.constant.EventConstants;
import com.wd.capability.network.constant.ParameterConstant;
import com.wd.capability.network.utils.NetworkUtil;
import com.wd.capability.router.data.ActionBean;
import com.wd.common.base.BaseActivity;
import com.wd.foundation.wdkit.constant.PageNameConstants;
import com.wd.common.constant.RouterConstants;
import com.wd.foundation.wdkit.dialog.EasterEggsDialog;
import com.wd.foundation.wdkit.dialog.PopUpsUtils;
import com.wd.common.floatingview.FloatWindow;
import com.wd.foundation.wdkit.imageglide.ImageUtils;
import com.wd.common.incentive.constants.TaskOperateTypeConstants;
import com.wd.common.incentive.task.TaskManager;
import com.wd.common.interact.collect.CollectTools;
import com.wd.common.interact.collect.callback.CollectCallback;
import com.wd.common.interact.interacts.callback.INewInteractDataListener;
import com.wd.common.interact.interacts.fetcher.InteractDataFetcher;
import com.wd.common.interact.like.LikeTools;
import com.wd.common.interact.like.QueryLikeStatusTools;
import com.wd.common.interact.like.callback.LikeCallback;
import com.wd.common.interact.like.callback.QueryLikeStatusCallback;
import com.wd.common.listener.AddFavoriteLabelCallback;
import com.wd.common.net.NetStateChangeReceiver;
import com.wd.common.utils.CommonVarUtils;
import com.wd.common.utils.HistoryDataHelper;
import com.wd.common.utils.MyShareUtils;
import com.wd.foundation.wdkit.utils.PDUtils;
import com.wd.common.utils.ProcessUtils;
import com.wd.common.utils.ToolsUtil;
import com.wd.common.utils.WorksDataHelper;
import com.wd.foundation.wdkit.view.CommonRefreshHeader;
import com.wd.foundation.wdkit.view.CustomSmartRefreshLayout;
import com.wd.foundation.bean.JsCallAppBean;
import com.wd.foundation.bean.JsShareBean;
import com.wd.foundation.bean.RecListBean;
import com.wd.foundation.bean.analytics.ActionConstants;
import com.wd.foundation.bean.analytics.TraceBean;
import com.wd.foundation.bean.analytics.TrackContentBean;
import com.wd.foundation.bean.comment.DisplayWorkInfoBean;
import com.wd.foundation.bean.comment.TransparentBean;
import com.wd.foundation.bean.custom.MenuBean;
import com.wd.foundation.bean.custom.collect.AddDelCollectBean;
import com.wd.foundation.bean.custom.comp.AudioBean;
import com.wd.foundation.bean.custom.comp.CompDataSourceBean;
import com.wd.foundation.bean.custom.comp.PageBean;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.custom.content.ContentTypeConstant;
import com.wd.foundation.bean.custom.content.PeopleMasterBean;
import com.wd.foundation.bean.custom.content.RelInfoBean;
import com.wd.foundation.bean.custom.share.ShareBean;
import com.wd.foundation.bean.livedate.EventMessage;
import com.wd.foundation.bean.livedate.NetStateMessage;
import com.wd.foundation.bean.mail.ShareInfo;
import com.wd.foundation.bean.music.bean.VoicePlayerBean;
import com.wd.foundation.bean.pop.PopUpsBean;
import com.wd.foundation.bean.response.InteractResponseDataBean;
import com.wd.foundation.bean.response.NewsDetailBean;
import com.wd.foundation.bean.web.AppToH5DataBean;
import com.wd.foundation.bean.web.ArticleVideoBean;
import com.wd.foundation.bean.web.H5FollowBean;
import com.wd.foundation.bean.web.JsPageBean;
import com.wd.foundation.wdkitcore.constant.BaseConstants;
import com.wd.foundation.wdkit.constant.Constants;
import com.wd.foundation.wdkit.constant.IntentConstants;
import com.wd.foundation.wdkit.json.GsonUtils;
import com.wd.foundation.wdkit.mvvm.BaseHandler;
import com.wd.foundation.wdkit.system.FastClickUtil;
import com.wd.foundation.wdkit.system.DeviceUtil;
import com.wd.foundation.wdkit.utils.NumberStrUtils;
import com.wd.foundation.wdkit.utils.SpUtils;
import com.wd.foundation.bean.utils.TimeUtil;
import com.wd.foundation.wdkit.utils.ToastNightUtil;
import com.wd.foundation.wdkit.view.AnimationView;
import com.wd.foundation.wdkit.view.customtextview.StrokeWidthTextView;
import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
import com.wd.foundation.wdkitcore.thread.ThreadPoolUtils;
import com.wd.foundation.wdkitcore.tools.ArrayUtils;
import com.wd.foundation.wdkitcore.tools.JsonUtils;
import com.wd.foundation.wdkitcore.tools.ResUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import com.wd.kittools.density.DensityUtils;
import com.wd.player.widget.AliyunScreenMode;
import org.json.JSONException;
import java.util.ArrayList;
import java.util.List;
/**
* 图文详情页面
*
* @author libo
* @version [V1.0.0, 2022/12/27]
* @since V1.0.0
*/
@Route(path = RouterConstants.PATH_ARTICLE_DETAIL_PAGE)
public class ArticleDetailActivity extends BaseActivity implements View.OnClickListener,
OnRefreshLoadMoreListener {
private static final String TAG = "ArticleDetailActivity";
/**
* 埋点pageName,默认文章稿件
*/
private String articlePageName = PageNameConstants.ARTICLE_DETAIL_PAGE;
private boolean isfirst;
/**
* 顶部标题布局
*/
private LinearLayout topLayout;
/**
* 底部布局
*/
private RelativeLayout bottomLayout;
/**
* 低部分割线
*/
private View bottomLine;
/**
* 左上角图标
*/
private ImageView topLogoImg;
public FrameLayout webViewLayout;
private NativeWebView webView;
private TextView newsTime;
/**
* ScrollView
*/
private NestedScrollView mScrollView;
private ImageView voicePlay;
private AnimationView collect;
private ImageView shareIv;
private JsPageBean mJsPageBean;
private JSONObject jsonObject;
private TextView commentInputTv;
private ImageView commentIv;
private StrokeWidthTextView commentCountTv;
/**
* 评论数、正文布局
*/
private FrameLayout commentCountTextLayout;
/**
* 评论数布局
*/
private LinearLayout commentCountLayout;
/**
* 正文
*/
private StrokeWidthTextView commentTextTv;
/**
* 底部基础互动右边布局
*/
private LinearLayout btmActionRightLayout;
/**
* 内容底部布局(推荐+评论)
*/
private LinearLayout contentBottomLayout;
/**
* webview评论内容布局
*/
private FrameLayout webCommentLayout;
/**
* 点赞布局
*/
private FrameLayout likeLayout;
/**
* 点赞图标
*/
private AnimationView likeImg;
/**
* 点赞数量
*/
private TextView likeTv;
/**
* 点赞底部间距
*/
private View contentBottomSpaceView;
/**
* 返回按钮
*/
private ImageView backBtn;
/**
* 视频悬浮框布局
*/
private FrameLayout videoWindowLayout;
/**
* 相关推荐模块布局
*/
private LinearLayout recommendLayout;
/**
* 相关推荐模块列表布局
*/
private FrameLayout recommendRVLayout;
/**
* -1-不需要收藏图标
* 0,未收藏
* 1,已收藏
*/
private int hasCollection = 0;
private String mContentId;
private String mContentType;
private String mTopicId;
private String mChannelId;
private String mCompId;
private String mSourcePage;
private String contentRelId = "0";
private String contentRelType = "0";
private String likeStatus = "0";
private String collectStatus = "0";
private ArticleDetailViewModel articleDetailViewModel;
private AudioBean currentAudioBean;
private int Voice_Handler = 1007;
/**
* 已经展示过的bean
*/
private PopUpsBean showPopUpsBean;
/**
* 彩蛋弹窗
*/
private EasterEggsDialog eggdialog;
/**
* 详情数据
*/
private NewsDetailBean newsDetailBean;
/**
* 刷新控件、评论列表、评论列表透传对象
*/
CustomSmartRefreshLayout refreshLayout;
CommentFragment commentFragment;
TransparentBean transparentBean = null;
/**
* 分享按钮隐藏、分享对象、新闻详情、
*/
ShareBean mShareBean = null;
/**
* 是否滚动到评论区
*/
boolean scrollToBottom = false;
/**
* webview高度
*/
public int mWebViewHeight;
/**
* 偏移量
*/
private int mScrollY = 0;
/**
* 需要的偏移量
*/
private int mNeedScrollY = 0;
public ArticleVideoManager videoManager;
/**
* 记录开启页面时间
*/
private long startTime;
/**
* 网络变化广播接收
*/
private NetStateChangeReceiver mReceiver;
/**
* 上下文环境
*/
private Activity activity;
/**
* 是否有推荐
*/
private boolean haveRecommend = false;
/**
* 是否有评论布局
*/
private boolean haveComment = false;
/**
* 点赞数
*/
private int mLikeNum = 0;
/**
* 评论数
*/
private int mCommentNum = 0;
/**
* 下拉刷新头
*/
private CommonRefreshHeader refreshHeader;
/**
* 是否开启RefreshLayout 下拉
*/
private boolean openRefreshEnable = false;
/**
* 夜间模式
*/
private String nightMode;
/**
* 相关推荐数据
*/
RecListBean recListBean = new RecListBean();
/**
* 是否从H5回调走到相关推荐
*/
private boolean isSetRecData = false;
/**
* 透传推荐相关数据设置
*/
TraceBean traceBean;
/**
* 展示评论数
*/
private boolean showCommentCount = false;
/**
* 屏幕高度
*/
private int screenHeight;
/**
* 标题下屏幕内可视内容高度
*/
private int contentVisviableHeight;
/**
* 推荐数据是否需要曝光埋点标记
*/
private int recommendShowTrackTag = 0;
/**
* 是否加载异常
*/
private boolean loadError = false;
private List<String> loadStepList = new ArrayList<>();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
nightMode = SpUtils.getNightMode();
// if (settingSwipeBack()){
// // 可以调用该方法,设置是否允许滑动退出
// setSwipeBackEnable(true);
// SwipeBackLayout mSwipeBackLayout = getSwipeBackLayout();
// //设置全屏幕左滑
// mSwipeBackLayout.setSwipeMode(SwipeBackLayout.FULL_SCREEN_LEFT);
// // 设置滑动方向,可设置EDGE_LEFT, EDGE_RIGHT, EDGE_ALL, EDGE_BOTTOM
// mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
// }
}
@Override
protected int getLayoutId() {
return R.layout.activity_web_view;
}
@Override
protected String getTag() {
return TAG;
}
/**
* 初始化控件
*/
@Override
protected void initView() {
activity = this;
// 屏幕的高度
screenHeight = DeviceUtil.getScreenHeight();
contentVisviableHeight = (int) (screenHeight - statusHeight -
ResUtils.getDimension(R.dimen.rmrb_dp112));
topLayout = findViewById(R.id.rl_title);
bottomLayout = findViewById(R.id.ll_bottom_action);
bottomLine = findViewById(R.id.line_bottom);
topLogoImg = findViewById(R.id.iv_title_logo);
mScrollView = findViewById(R.id.scroll_view);
contentBottomLayout = findViewById(R.id.layout_content_bottom);
webCommentLayout = findViewById(R.id.fragment_container_comment);
refreshLayout = findViewById(R.id.layout_refresh);
webViewLayout = findViewById(R.id.layou_webview);
mWebViewHeight = contentVisviableHeight;
webViewLayout.getLayoutParams().height = mWebViewHeight;
Logger.t(TAG).d("webViewHeight=======>initView:"+mWebViewHeight);
// webView = findViewById(R.id.webView);
webView = WebViewPool.getInstance().getWebView(this,WebViewPool.TEMPLATE_ARTICLE);
if (null != webView ) {
JSONObject jsonObject = new JSONObject();
//通知H5进入图文详情页
jsonObject.put("event", AppNotifyEventConstant.EVENT_THIRTEEN);
jsonObject.put(ParameterConstant.DARK_MODE, SpUtils.isNightMode() ?
"dark" : "light");
JSBridgeUtils.jsCall_appNotifyEvent(webView,jsonObject);
}
if (webView != null && webView.getParent() != null) {
((ViewGroup)webView.getParent()).removeView(webView);
}
webViewLayout.addView(webView);
backBtn = findViewById(R.id.iv_back);
newsTime = findViewById(R.id.tv_title_time);
commentCountTv = findViewById(R.id.tv_comment_count);
commentCountTextLayout = findViewById(R.id.layout_comment_count_text);
commentTextTv = findViewById(R.id.tv_comment_text);
commentCountLayout = findViewById(R.id.ll_comment_count);
commentInputTv = findViewById(R.id.tv_comment_edit);
commentIv = findViewById(R.id.iv_comment);
btmActionRightLayout = findViewById(R.id.layout_bottom_action_right);
likeLayout = findViewById(R.id.layout_like);
likeImg = findViewById(R.id.img_like);
likeTv = findViewById(R.id.tv_like);
contentBottomSpaceView = findViewById(R.id.view_content_bottom_space);
voicePlay = findViewById(R.id.iv_voice);
collect = findViewById(R.id.iv_collect);
shareIv = findViewById(R.id.iv_share);
videoWindowLayout = findViewById(R.id.layout_video_window);
recommendLayout = findViewById(R.id.layout_recommend);
recommendRVLayout = findViewById(R.id.layout_rv_recommend);
// 检查登录
collect.setNeedLogin(true);
refreshHeader = new CommonRefreshHeader(this);
refreshLayout.setRefreshHeader(refreshHeader);
refreshLayout.setEnableRefresh(openRefreshEnable);
initListener();
// PlayerManager.getInstance().getDispatcher().output(this, playerEvent -> {
// switch (playerEvent.eventId) {
// case PlayerEvent.EVENT_CHANGE_MUSIC:
// break;
// case PlayerEvent.EVENT_PLAY_STATUS:
// if(!playerEvent.toPause){
// //App开始播放音、视频(处理音视频互斥问题)
// JSBridgeUtils.jsCall_appNotifyEvent(webView, AppNotifyEventConstant.EVENT_FIVE);
// if(videoManager != null){
// videoManager.setVideoPause();
// }
// }
// //刷新底部按钮播放状态
// updateVoicePlayUi(playerEvent.toPause);
// break;
// default:
// break;
// }
// });
}
/**
* 监听
*/
private void initListener() {
refreshLayout.setOnRefreshLoadMoreListener(this);
backBtn.setOnClickListener(this);
likeLayout.setOnClickListener(this);
likeImg.setOnClickListener(this);
commentInputTv.setOnClickListener(this);
commentIv.setOnClickListener(this);
voicePlay.setOnClickListener(this);
collect.setOnClickListener(this);
shareIv.setOnClickListener(this);
mScrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
mScrollY = scrollY;
if(videoManager != null){
videoManager.webVideoScroll(scrollY,oldScrollY);
}
//处理评论
if(commentCountTextLayout != null &&
commentCountTextLayout.getVisibility() == View.VISIBLE){
int scrollableDistance = mScrollView.getChildAt(0).getHeight() -
mScrollView.getHeight();
int commentTop = (int) (webCommentLayout.getTop() + contentBottomLayout.getTop() +
ResUtils.getDimension(R.dimen.rmrb_dp8));
if(scrollableDistance > 0 && scrollableDistance == mScrollY){
//可滑动,且已滑到底部
if(showCommentCount){
commentCountLayout.setVisibility(View.GONE);
}
commentTextTv.setVisibility(View.VISIBLE);
}else if(mScrollY >= commentTop){
if(showCommentCount){
commentCountLayout.setVisibility(View.GONE);
}
commentTextTv.setVisibility(View.VISIBLE);
}else {
if(showCommentCount){
commentCountLayout.setVisibility(View.VISIBLE);
}
commentTextTv.setVisibility(View.GONE);
}
}
//处理推荐
if(recommendShowTrackTag == 1 && recommendLayout != null &&
recommendLayout.getVisibility() == View.VISIBLE){
int recommendTop = contentBottomLayout.getTop() + recommendLayout.getTop();
if(recommendTop > contentVisviableHeight){
//推荐不在首屏
int scrolToRecommendY = recommendTop - contentVisviableHeight;
if(scrollY > scrolToRecommendY){
//滑到了推荐
Logger.t(TAG).d("mScrollView=====>推荐曝光");
if(recListBean != null && ArrayUtils.isNotEmpty(recListBean.getList())){
recommendShowTrackTag = 0;
WebDataUtils.recommendShowTrack(recListBean.getList());
}
}
}
}
Logger.t(TAG).d("mScrollView=====>scrollX:"+scrollX+
",scrollY:"+scrollY+",oldScrollX:"+oldScrollX+",oldScrollY"+oldScrollY);
});
}
/**
* 初始化数据
*/
@Override
protected void initData() {
Object actionBeanObject = getExtrasSerializableObject();
if (actionBeanObject == null) {
return;
}
jsonObject = JsonUtils.convertJsonToObject(((ActionBean) actionBeanObject).paramBean.params, JSONObject.class);
String contentId = jsonObject.getString(IntentConstants.CONTENT_ID);
String contentType = jsonObject.getString(IntentConstants.CONTENT_TYPE);
String topicId = jsonObject.getString(IntentConstants.TOPIC_ID);
String channelId = jsonObject.getString(IntentConstants.CHANNEL_ID);
String compId = jsonObject.getString(IntentConstants.COMP_ID);
String sourcePage = jsonObject.getString(IntentConstants.SOURCE_PAGE);
String relId = jsonObject.getString(IntentConstants.REL_ID);
String relType = jsonObject.getString(IntentConstants.REL_TYPE);
scrollToBottom = jsonObject.getBoolean(IntentConstants.PARAM_BOTTOM_COMMENT_AREA);
mContentId = contentId;
CommonVarUtils.articleDetailMusicObjectId = mContentId;
mContentType = contentType;
mTopicId = topicId;
mChannelId = channelId;
mCompId = compId;
mSourcePage = sourcePage;
if ("3".equals(mSourcePage)){
articlePageName = PageNameConstants.AUDIO_TEXT_PAGE;
}
contentRelType = relType;
contentRelId = relId;
// traceBean = new TraceBean();
// String traceId = jsonObject.getString(IntentConstants.CNSTRACEID);
// if (!TextUtils.isEmpty(traceId)) {
// traceBean.traceId = traceId;
// traceBean.sceneId = jsonObject.getString(IntentConstants.SCENEID);
// traceBean.subSceneId = jsonObject.getString(IntentConstants.SUBSCENEID);
// traceBean.itemId = jsonObject.getString(IntentConstants.ITEMID);
// traceBean.expIds = jsonObject.getString(IntentConstants.EXPIDS);
// } else {
// traceBean.traceId = "selfHold";
// traceBean.sceneId = "9999";
// }
//监听
receiveLiveDataMsg();
// 需要网络监听
setNetStateObserver();
videoManager = new ArticleVideoManager(this,videoWindowLayout,webViewLayout,webView);
// 首次打开文章详情展示”正文增加字号调整引导”
boolean textGuideWithArticleDetail = SpUtils.getTextGuideWithArticleDetail();
// 首次打开文章详情展示”正文增加字号调整引导”
boolean textGuideWithTrendsDetail = SpUtils.getTextGuideWithTrendsDetail();
// 没有展示过,才展示”正文增加字号调整引导”
if (!textGuideWithArticleDetail && !textGuideWithTrendsDetail){
// 标记展示”正文增加字号调整引导”展示过了
SpUtils.saveTextGuideWithArticleDetail(true);
// 展示”正文增加字号调整引导”
// TextGuideDialog textGuideDialog = new TextGuideDialog(this);
// textGuideDialog.show();
}
}
/**
* 广播接收
*/
private void receiveLiveDataMsg() {
//登录成功
LiveDataBus.getInstance().with(EventConstants.USER_ALREADY_LOGIN, Boolean.class).observe(this, aBoolean -> {
if (aBoolean) {
JSBridgeUtils.jsCall_appNotifyEvent(webView,AppNotifyEventConstant.EVENT_ONE);
queryLikeAndCollectStatus();
}
});
// LiveDataBus.getInstance().with(EventConstants.VIDEO_CLICK_EVENT, Boolean.class).observe(this, aBoolean -> {
// initVoiceShow();
// });
LiveDataBus.getInstance().with(EventConstants.CAN_SCROLL_TO_COMMENT, Boolean.class).
observe(this,scroll ->{
if (scroll && scrollToBottom){
if (mScrollView != null){
mScrollView.postDelayed(new Runnable() {
@Override
public void run() {
int commentTop = (int) (webCommentLayout.getTop() + contentBottomLayout.getTop() +
ResUtils.getDimension(R.dimen.rmrb_dp8));
mScrollView.smoothScrollTo(0,commentTop,500);
}
},500);
}
}
});
//接收关注事件
LiveDataBus.getInstance().with(EventConstants.FRESH_FOLLOW_CREATOR_EVENT,
EventMessage.class).observe(this, mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != webView) {
// 同步关注信息
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", AppNotifyEventConstant.EVENT_ELEVEN);
String createId = mEventMessage.getStringExtra(IntentConstants.PARAM_CREATOR_ID);
boolean followStatus = mEventMessage.getBooleanExtra(IntentConstants.IS_FOLLOW, false);
//当 event==11时,被关注的号主id
jsonObject.put("creatorId", createId);
//当 event==11时,1 已关注,0 未关注
jsonObject.put("followStatus", followStatus ? "1" : "0");
JSBridgeUtils.jsCall_appNotifyEvent(webView,jsonObject);
}
});
//接收点赞事件
LiveDataBus.getInstance().with(EventConstants.FRESH_ZAN_CREATOR_EVENT, EventMessage.class).observe(this, mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != webView ) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", AppNotifyEventConstant.EVENT_TWELVE);
String contentId = mEventMessage.getStringExtra(IntentConstants.CONTENT_ID);
String relId = mEventMessage.getStringExtra(IntentConstants.REL_ID);
boolean isZan = mEventMessage.getBooleanExtra(IntentConstants.IS_ZAN, false);
//当 event==12时,被点赞内容id
jsonObject.put("contentId", contentId);
//当 event==12时,1 已点赞,0 未点赞
jsonObject.put("likeStatus", isZan ? "1" : "0");
JSBridgeUtils.jsCall_appNotifyEvent(webView,jsonObject);
//埋点:更多内容点赞(取消)
TrackContentBean trackBean = getTrackContentBean(4);
if(trackBean != null){
trackBean.likeAction(isZan);
// CommonTrack.getInstance().contentLikeTrack(trackBean,isZan);
}
}
});
}
/**
* 监听网络
*/
protected void setNetStateObserver() {
// Create the broadcast receiver instance
mReceiver = new NetStateChangeReceiver();
IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mReceiver, intentFilter);
LiveDataBus.getInstance()
.with(EventConstants.NETWORK_STATE_CHANGE, NetStateMessage.class)
.observe(this, new Observer<NetStateMessage>() {
@Override
public void onChanged(@Nullable NetStateMessage msg) {
Logger.t(TAG).d("Network status" + msg.type);
if (msg == null) {
return;
}
JSBridgeUtils.jsCall_appNetworkStatusChangedEvent(webView);
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// 判断是否可以返回操作
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if(videoManager != null && isFullPlay){
videoManager.setVideoBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
/**
* 设置h5返回的page数据
*/
public void setJSPageData(JsPageBean jsPageBean){
if (jsPageBean == null) {
return;
}
String dataSource = jsPageBean.getDataSource();
if (StringUtils.isEqual("1", dataSource)) {
//1.图文详情数据
Constants.articleBrowseNumber++;
mJsPageBean = jsPageBean;
recommendShowTrackTag = 0;
//执行任务:阅读
TaskManager.getInstance().executePointLevelOperate(TaskOperateTypeConstants.READ);
if (mJsPageBean != null) {
String dataJsonObject = mJsPageBean.getDataJson();
try {
if (StringUtils.isBlank(dataJsonObject)) {
return;
}
org.json.JSONObject jsonObject = new org.json.JSONObject(dataJsonObject);
String appstyle = jsonObject.optString("appstyle");
newsDetailBean = GsonUtils.fromJson(dataJsonObject, NewsDetailBean.class);
//是否展示推荐
String recommendShow = newsDetailBean.getRecommendShow();
if(StringUtils.isEqual("1",recommendShow)){
articleDetailViewModel.getRecList(newsDetailBean.getNewsId(),
contentRelId,mChannelId);
}else{
//没有推荐时,设置下
setRecommendData(null,isSetRecData);
}
likeLayout.setVisibility(View.VISIBLE);
btmActionRightLayout.setVisibility(View.VISIBLE);
startTime = System.currentTimeMillis();
//页面曝光埋点
contentExposure(newsDetailBean,traceBean);
//设置左上角logo
setTopLogoData();
handlerPopUps();
//因为H5的appStyle字段
newsDetailBean.setAppStyle(appstyle);
//点赞设置
setLikeLayoutData();
//一起设置相关推荐和评论数据,避免闪动
setRecommendData(recListBean,isSetRecData);
//设置语音数据
updateVoicePlayUi(!PlayerManager.getInstance().isPlaying());
//分享icon根据开关控制
setShareIcon();
//记录浏览历史
if (!"2".equals(mSourcePage)){
//不是历史页面查看的才添加到历史记录中
HistoryDataHelper.getInstance().addHistoryForNewsDetail(newsDetailBean);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (StringUtils.isEqual("2", dataSource)) {
//2.跳转推荐内容数据
WebUtils.jumpToNewArticle(jsPageBean);
}else if (StringUtils.isEqual("3", dataSource)) {
//3.显示图片预览
ProcessUtils.goToImageSlidePage(jsPageBean.getImgListData());
}else if (StringUtils.isEqual("6", dataSource)) {
//6.图文稿件引用内容
WebUtils.jumpNewLink(jsPageBean);
}
}
/**
* 根据分享开关显示不同的shareIcon
*/
private void setShareIcon(){
ShareInfo mShareInfo = newsDetailBean.getShareInfo();
if (null == mShareInfo || "0".equals(mShareInfo.getShareOpen())) {
//分享数据不存在,图标更换成...
shareIv.setImageResource(R.mipmap.share_more_icon_40);
}
}
private void sendPageDataToH5(String netError, String dataList, String callbackId) {
AppToH5DataBean.DataJson dataJson = new AppToH5DataBean.DataJson();
dataJson.netError = netError;
dataJson.responseMap = dataList;
String data = new Gson().toJson(dataJson);
webView.sendResponse(data, callbackId);
}
/**
* 发送数据到H5
*/
private void sendDataResultToH5(String netError, String dataList) {
final boolean[] jsCallReceiveAppDataSuccess = {false};
AppToH5DataBean contentInfo = new AppToH5DataBean();
contentInfo.dataSource = "2";
AppToH5DataBean.DataJson dataJson = new AppToH5DataBean.DataJson();
dataJson.contentId = mContentId;
dataJson.contentType = mContentType;
dataJson.sourcePage = mSourcePage;
dataJson.topicId = mTopicId;
dataJson.channelId = mChannelId;
dataJson.compId = mCompId;
dataJson.netError = netError;
dataJson.responseMap = dataList;
contentInfo.dataJson = dataJson;
try {
AppToH5DataBean.DataExt dataExt = WebUtils.getInstance().getDataExt();
if(traceBean != null){
//推荐数据
dataExt.cnsTraceId = traceBean.traceId;
}
//屏幕高度-h5需要dp值
dataExt.clientHeight = DensityUtils.INSTANCE.getHeightInDp(this);
contentInfo.dataExt = dataExt;
} catch (Exception e) {
e.printStackTrace();
}
String data = new Gson().toJson(contentInfo);
// JSBridgeUtils.jsCall_receiveAppData(webView,data);
webView.callHandler("jsCall_receiveAppData", data, new OnBridgeCallback() {
@Override
public void onCallBack(String data) {
Logger.t(TAG).d("from js data = " + data);
//增加加载链路步骤
loadStepList.add("jsCall_receiveAppData传递数据至H5完成");
//加载链接埋点
// GeneralTrack.getInstance().appArticlePageLoadInfoTrack(loadStepList,mContentId,
// mContentType,contentRelId,contentRelType,mChannelId);
jsCallReceiveAppDataSuccess[0] = true;
}
});
webView.postDelayed(new Runnable() {
@Override
public void run() {
if(!jsCallReceiveAppDataSuccess[0]){
//增加加载链路步骤
loadStepList.add("jsCall_receiveAppData传递数据至H5超时异常");
//加载链接埋点
// GeneralTrack.getInstance().appArticlePageLoadInfoTrack(loadStepList,mContentId,
// mContentType,contentRelId,contentRelType,mChannelId);
}
}
},5000);
}
/**
* 处理js传递给APP的数据
* @param jsCallAppBean
*/
public void setJsCallAppData(JsCallAppBean jsCallAppBean){
if(jsCallAppBean == null){
return;
}
org.json.JSONObject dataObject = jsCallAppBean.getJsonObject();
try {
String method = dataObject.getString("method");
String url = dataObject.getString("url");
org.json.JSONObject parameters = dataObject.getJSONObject("parameters");
articleDetailViewModel.requestPageData(method, url, parameters, jsCallAppBean.getCallbackId());
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* h5关注创作者
* @param h5FollowBean
*/
public void setH5FollowData(H5FollowBean h5FollowBean){
if(h5FollowBean == null){
return;
}
EventMessage mEventMessage = new EventMessage(EventConstants.FRESH_FOLLOW_CREATOR_EVENT);
mEventMessage.putExtra(IntentConstants.PARAM_CREATOR_ID, h5FollowBean.getCreatorId());
//本地修改状态,点击行为 status 0:取消关注 1:关注
mEventMessage.putExtra(IntentConstants.IS_FOLLOW, StringUtils.isEqual("1",h5FollowBean.getFollowStatus()));
//全局刷新创作者关注状态
LiveDataBus.getInstance().with(EventConstants.FRESH_FOLLOW_CREATOR_EVENT).postValue(mEventMessage);
}
/**
* 显示语音播报图标
*/
private void updateVoicePlayUi(boolean topause) {
if(newsDetailBean == null){
return;
}
String newsType = newsDetailBean.getNewsType();
if(!StringUtils.isEqual("8",newsType)){
//不是图文类型不需要展示语音播报
voicePlay.setVisibility(View.GONE);
return;
}
if(newsDetailBean.getOpenAudio() !=1){
//【图文稿件】语音播报开关 0不播报 1播报
voicePlay.setVisibility(View.GONE);
return;
}
if(ArrayUtils.isEmpty(newsDetailBean.getAudioList())){
voicePlay.setVisibility(View.GONE);
return;
}
currentAudioBean = null;
List<AudioBean> audioList = newsDetailBean.getAudioList();
for (int i = 0; i < audioList.size(); i++) {
AudioBean audioBean = audioList.get(i);
if(StringUtils.isEqual("2",audioBean.getSourceType())){
// 2:语音播报音频【图文稿件使用】
currentAudioBean = audioBean;
break;
}
}
if(currentAudioBean == null || StringUtils.isBlank(currentAudioBean.getVoiceUrl())){
voicePlay.setVisibility(View.GONE);
}else{
voicePlay.setVisibility(View.VISIBLE);
}
if (!topause) {
if (PlayerManager.getInstance().getCurrentPlayingMusic()!= null
&& PlayerManager.getInstance().getCurrentPlayingMusic()
.isSameObject(mContentId,
TextUtils.isEmpty(contentRelType)?0:Integer.parseInt(contentRelType),contentRelId,currentAudioBean.getVoiceUrl())) {
ImageUtils.getInstance().loadImage(voicePlay, SpUtils.isNightMode() ?
R.drawable.ic_voice_playing_40_night : R.drawable.ic_voice_playing_40);
} else {
voicePlay.setImageResource(R.mipmap.icon_play_line_black_40);
}
} else {
voicePlay.setImageResource(R.mipmap.icon_play_line_black_40);
}
}
@Override
protected void initViewModel() {
articleDetailViewModel = getViewModel(ArticleDetailViewModel.class);
articleDetailViewModel.observerDataListener(this, new IArticleDetailDataListener() {
@Override
public void onDetailDataSuccess(String dataList) {
// Log.d(TAG, "onDetailDataSuccess receive data = " + dataList);
sendDataResultToH5("0", dataList);
//增加加载链路步骤
loadStepList.add("接口数据加载完成");
}
@Override
public void onDetailDataError(String errorMsg) {
sendDataResultToH5("1", "");
//增加加载链路步骤
loadStepList.add("接口数据加载失败"+errorMsg);
//加载链接埋点
// GeneralTrack.getInstance().appArticlePageLoadInfoTrack(loadStepList,mContentId,
// mContentType,contentRelId,contentRelType,mChannelId);
}
@Override
public void onPageDataSuccess(String url, String dataList, String callbackId) {
// Log.d(TAG, "onPageDataSuccess request url = " + url);
// Log.d(TAG, "onPageDataSuccess receive data = " + dataList);
sendPageDataToH5("0", dataList, callbackId);
}
@Override
public void onPageDataError(String errorMsg, String callbackId) {
// Log.d(TAG, "onPageDataError page data errorMsg = " + errorMsg);
sendPageDataToH5("1", "", callbackId);
}
@Override
public void onGetNewsDetailSuccess(List<NewsDetailBean> newsDetailBeanList) {
}
@Override
public void onGetNewsDetailFailed(String error) {
}
@Override
public void onGetRecListSuccess(List<ContentBean> operDataList) {
if(!ArrayUtils.isEmpty(operDataList)){
for (ContentBean contentBean : operDataList) {
// 人民号稿件(非动态人民号稿件)需要转换成对应的普通稿件
int appStyle = Integer.parseInt(contentBean.getAppStyle());
String style = String.valueOf(WorksDataHelper.changeCommon(appStyle));
contentBean.setAppStyle(style);
contentBean.setFromPage(articlePageName);
contentBean.setExposure(true);
}
if(recListBean != null ){
recListBean.setList(operDataList);
}else{
recListBean = new RecListBean();
}
setRecommendData(recListBean,isSetRecData);
}else{
setRecommendData(null,isSetRecData);
}
}
@Override
public void onGetRecListFailed(String error) {
setRecommendData(null,isSetRecData);
}
});
articleDetailViewModel.requestDetailData(mContentId, contentRelId, contentRelType);
}
@Override
public void onClick(View v) {
if(FastClickUtil.isFastClick()){
return;
}
int id = v.getId();
if (id == R.id.iv_back) {
if(videoManager != null && isFullPlay){
videoManager.setVideoBack();
}else {
finish();
}
} else if (id == R.id.iv_share) {
//分享
onShareDialog();
} else if (id == R.id.tv_comment_edit) {
//编辑评论
editComment();
}else if (id == R.id.iv_comment) {
//点击底部评论图片,页面与评论内容滑动切换
if(mScrollView != null){
Logger.t(TAG).d("webCommentLayout=====>top:"+webCommentLayout.getTop());
if(webCommentLayout.getVisibility()!=View.VISIBLE){
return;
}
/*mScrollView.scrollTo(0,mScrollY>=webCommentLayout.getTop() ?
0:webCommentLayout.getTop());*/
int scrollableDistance = mScrollView.getChildAt(0).getHeight() -
mScrollView.getHeight();
if(scrollableDistance == 0){
//不可滑动
return;
}
if(scrollableDistance > 0 && scrollableDistance == mScrollY){
//可滑动,且已滑到底部
mScrollView.smoothScrollTo(0,0,800);
}else {
//其他情况需要滑动距离超过评论顶部间距点击回到页面顶部,否则滑动评论顶部
int commentTop = (int) (webCommentLayout.getTop() + contentBottomLayout.getTop() +
ResUtils.getDimension(R.dimen.rmrb_dp8));
mScrollView.smoothScrollTo(0,mScrollY >= commentTop ?
0:commentTop,800);
}
}
} else if (id == R.id.iv_voice) {
//语音
onVoicePlay();
//语音播报埋点
TrackContentBean trackContentBean = ArticleTrack.newsDetailToTrackContent(newsDetailBean,traceBean);
trackContentBean.setAction(ActionConstants.BROWSE);
trackContentBean.setExposure(duration);
//设置推荐字段
if(traceBean != null) {
trackContentBean.setTraceBean(traceBean);
}
// CommonTrack.getInstance().voiceBroadcastClickTrack(trackContentBean);
} else if (id == R.id.iv_collect) {
//收藏
if (null == newsDetailBean) {
ToastNightUtil.showShort("暂时无法收藏");
return;
}
userClickCollectStatus();
}else if (id == R.id.layout_like || id == R.id.img_like) {
//点赞
if (null == newsDetailBean) {
ToastNightUtil.showShort("暂时无法点赞");
return;
}
userClickLikeStatus();
}
}
@Override
protected void onPause() {
super.onPause();
JSBridgeUtils.jsCall_appNotifyEvent(webView,AppNotifyEventConstant.EVENT_TWO);
}
/**
* 用户点赞
*/
private void userClickLikeStatus() {
if (!PDUtils.isLogin()) {
ProcessUtils.toOneKeyLoginActivity();
return;
}
if (StringUtils.isEmpty(mContentId) || StringUtils.isEmpty(newsDetailBean.getNewsType())) {
return;
}
boolean status;
if ("0".equals(likeStatus)) {
likeStatus = "1";
status = true;
} else {
likeStatus = "0";
status = false;
}
//埋点:内容点赞(取消),重复上报,在收到消息时上报
/*TrackContentBean trackBean = getTrackContentBean(4);
if(trackBean != null){
trackBean.likeAction(status);
CommonTrack.getInstance().contentLikeTrack(trackBean,status);
}*/
//不等接口结果
int likeNumInt = mLikeNum;
if ("0".equals(likeStatus)) {
//handleClick会取反
likeImg.setSelected(true);
if(likeNumInt != 0){
likeNumInt = likeNumInt - 1;
}
} else {
//handleClick会取反
likeImg.setSelected(false);
likeNumInt = likeNumInt + 1;
}
likeImg.handleClick();
setLikeNum(likeNumInt+"");
setLikeTvColor();
String channelId = newsDetailBean.getReLInfo()!=null?newsDetailBean.getReLInfo().getChannelId():"";
LikeTools.getInstance().userContentExecuteLike(mContentId, newsDetailBean.getNewsType(),
contentRelId, contentRelType, likeStatus,
newsDetailBean.getNewsTitle(),channelId,
new LikeCallback() {
@Override
public void onSuccess(String msg, String oldLikeStatus, String newLikeStatus) {
}
@Override
public void onFailed(String msg) {
if (NetworkUtil.isNetAvailable() &&
StringUtils.isEqual(ResUtils.getString(R.string.tips_check_network),msg)) {
//有网,不提示网络出小差
return;
}
ToastNightUtil.showShort(msg);
}
});
}
private int getLikeStyleSelIcon(int likeStyle){
// 点赞样式 1:红心(点赞) 2:大拇指(祈福) 3:蜡烛(默哀) 4:置空
int selRes = 4;
if (1 == likeStyle) {
selRes = R.mipmap.ic_red_heart_select_40;
}else if (2 == likeStyle) {
selRes = R.mipmap.ic_red_pray_select_40;
}else if (3 == likeStyle) {
selRes = R.mipmap.ic_red_candle_select_40;
}
return selRes;
}
private String getLikeStyleSelJson(int likeStyle){
// 点赞样式 1:红心(点赞) 2:大拇指(祈福) 3:蜡烛(默哀) 4:置空
String selRes = "";
if (1 == likeStyle) {
selRes = "like_article.json";
}else if (2 == likeStyle) {
selRes = "like_pray_40.json";
}else if (3 == likeStyle) {
selRes = "like_candle_40.json";
}
return selRes;
}
/**
* 用户收藏
*/
private void userClickCollectStatus() {
if (!PDUtils.isLogin()) {
ProcessUtils.toOneKeyLoginActivity();
return;
}
if (StringUtils.isEmpty(mContentId) || StringUtils.isEmpty(newsDetailBean.getNewsType())) {
return;
}
// TrackContentBean trackBean = getTrackContentBean(3);
// if(trackBean != null){
// CommonTrack.getInstance().collectClickTrack(trackBean, collectStatus);
// }
if ("0".equals(collectStatus)) {
collectStatus = "1";
} else {
collectStatus = "0";
}
//添加、删除单个收藏
AddDelCollectBean bean = new AddDelCollectBean();
bean.setStatus(collectStatus);
List<AddDelCollectBean.ContentListBean> beanList = new ArrayList<>();
AddDelCollectBean.ContentListBean listBean = new AddDelCollectBean.ContentListBean();
listBean.setContentId(mContentId);
listBean.setContentType(newsDetailBean.getNewsType());
listBean.setContentRelId(contentRelId);
listBean.setRelType(contentRelType);
beanList.add(listBean);
bean.setContentList(beanList);
//收藏工具类
CollectTools.getInstance().addToDelCollect(this, bean, new CollectCallback() {
@Override
public void onSuccess(String msg) {
if ("0".equals(collectStatus)) {
collect.setSelected(false);
// CollectDialog.dismiss();
} else {
collect.setSelected(true);
//收藏弹框 先注释
// ToolsUtil.showAddCollectLabelDialog(ArticleDetailActivity.this);
}
}
@Override
public void onFailed(String msg) {
ToastNightUtil.showShort(msg);
}
}, new AddFavoriteLabelCallback() {
@Override
public void onAddFavoriteLabel(String favoriteCategoryLabel) {
//埋点:添加收藏标签
// CommonTrack.getInstance().addFavoriteCategoryEventTrack(trackBean,
// favoriteCategoryLabel);
}
});
}
private void editComment() {
if (null != commentFragment) {
commentFragment.showInputDialog(-1);
}
}
/**
* 分享
*/
private void onShareDialog() {
// if (newsDetailBean == null) {
// return;
// }
//
// //分享相关
// if (null == mShareBean) {
// return;
// }
// MoreDialogTools moreDialogTools = new MoreDialogTools(this, true);
// //点赞、收藏状态不查询接口,直接设置
// moreDialogTools.isQueryLikeAndCollectStatus(false);
// if ("0".equals(likeStatus)) {
// mShareBean.setShowLike(0);
// } else if ("1".equals(likeStatus)) {
// mShareBean.setShowLike(1);
// }
// if ("0".equals(collectStatus)) {
// mShareBean.setShowCollect(0);
// } else if ("1".equals(collectStatus)) {
// mShareBean.setShowCollect(1);
// }
// mShareBean.setShowPosterType(PosterTypeEnum.CONTENT);
// //设置分享框中,适老化入口可见
// mShareBean.setShowFontSize(true);
// moreDialogTools.showDialog(mShareBean, new ShareResultCallBack() {
//
// @Override
// public void onComplete(String platform, String msg) {
// if(StringUtils.isEqual(MoreEnum.ADDCOLLECTLABEL+"",platform)){
// if(newsDetailBean == null){
// return;
// }
// TrackContentBean trackContentBean = ArticleTrack.newsDetailToTrackContent(newsDetailBean,traceBean);
// //推荐数据设置
// if(traceBean != null) {
// trackContentBean.setTraceBean(traceBean);
// }
// //埋点:添加收藏标签
// CommonTrack.getInstance().addFavoriteCategoryEventTrack(trackContentBean,
// msg);
// }
// }
//
// @Override
// public void onError(String platform, String msg) {
//
// }
//
// @Override
// public void onCancel(String platform, String msg) {
//
// }
//
// @Override
// public void onShareClick(String platform, String status) {
//
// // 点击曝光埋点
// TrackContentBean trackBean = getTrackContentBean(2);
// trackBean.setShare_type(platform);
// //分享按钮点击埋点
// CommonTrack.getInstance().shareClickTrack(trackBean);
// }
//
// @Override
// public void onCommonClick(String platform, String status) {
// //收藏埋点
// if (platform.equals(ShareTypeConstants.COLLECT)) {
// //用户未登录,不做处理
// if ("-1".equals(status)) {
// return;
// }
// TrackContentBean trackBean = getTrackContentBean(3);
// //collectStatus 0:收藏 1:取消
// trackBean.setBhv_value(ActionConstants.COLLECT);
// CommonTrack.getInstance().collectClickTrack(trackBean, status);
// }else if(StringUtils.isEqual(ShareTypeConstants.REPORT,platform)){
// //埋点:举报
// GeneralTrack.getInstance().commonBtnClickTrack(
// "report",
// articlePageName,
// articlePageName);
// }if (StringUtils.isEqual(ShareTypeConstants.LIKE,platform)) {
// if ("-1".equals(status)) {
// return;
// }
// if(newsDetailBean == null){
// return;
// }
// int likesStyle = newsDetailBean.getLikesStyle();
// if(likesStyle == 4){
// //置空,不展示
// return;
// }
// likeStatus = StringUtils.isEqual("0",status) ? "1" : "0";
// int likeNumInt = mLikeNum;
// if ("0".equals(likeStatus)) {
// likeImg.setSelected(false);
// if(likeNumInt != 0){
// likeNumInt = likeNumInt - 1;
// }
// } else {
// likeImg.setSelected(true);
// likeNumInt = likeNumInt + 1;
// }
// //接口数据有加权,先手动+—1
// setLikeNum(likeNumInt+"");
// }else if(StringUtils.isEqual(ShareTypeConstants.COLLECT,platform)){
// if ("-1".equals(status)) {
// return;
// }
// collectStatus = StringUtils.isEqual("0",status) ? "1" : "0";
// if ("0".equals(collectStatus)) {
// collect.setUnselectImageResId(R.mipmap.icon_collect_unselect_light);
// collect.setSelected(false);
// } else {
// collect.setSelectImageResId(R.mipmap.icon_collect_select_light);
// collect.setSelected(true);
// }
// }else {
// // 点击曝光埋点
// TrackContentBean trackBean = getTrackContentBean(1);
// trackBean.setShare_type(platform);
// //分享按钮点击埋点
// CommonTrack.getInstance().shareClickTrack(trackBean);
// }
// }
// });
// //设置字号大小回调
// setFontSizeSetCallBack(moreDialogTools);
}
// private void setFontSizeSetCallBack(MoreDialogTools moreDialogTools){
// if (moreDialogTools != null){
// moreDialogTools.setFontSizeSetCallBack(new IFontSizeSetCallBack() {
// @Override
// public void onFontSizeSet(String type) {
// // 1、小 2、标准 3、大 4、特大
// if(videoManager != null){
// videoManager.closeVideoWindow();
// }
// updateFontSize(type);
// }
// });
// }
// }
/**
* 适老化-fontSizes变更
* @param type
*/
private void updateFontSize(String type){
Logger.d("设置文字大小级别:" + type);
//通知h5适老化更新
JSONObject jsonObject = new JSONObject();
jsonObject.put("event", AppNotifyEventConstant.EVENT_TEN);
//当 event==10时,small(小)、normalsize(标准)、large(大)、Large(较大)
jsonObject.put("fontSizes", WebUtils.getInstance().getFontSizes(type));
JSBridgeUtils.jsCall_appNotifyEvent(webView,jsonObject);
/*if(mScrollView != null){
mScrollView.smoothScrollTo(0,0,200);
}*/
}
/**
* 点击埋点
* @param type 1:分享点击,2:分享方式点击,3:收藏点击,4:点赞
*/
private TrackContentBean getTrackContentBean(int type){
if(newsDetailBean == null){
return null;
}
TrackContentBean trackBean = new TrackContentBean();
trackBean.setPage_name(articlePageName);
trackBean.setPage_id(articlePageName);
//新闻id
trackBean.setContent_id(newsDetailBean.getNewsId());
//内容类型
trackBean.setContent_type(newsDetailBean.getNewsType());
//内容名字
trackBean.setContent_name(newsDetailBean.getNewsTitle());
//组件样式
trackBean.setContent_style(newsDetailBean.getAppStyle());
//发布标识,0-cms;1-表示号主发布 2-普通用户
if(newsDetailBean.rmhPlatform != -1){
trackBean.setRmhPlatform(newsDetailBean.rmhPlatform);
}
if(type == 1){
//分享按钮点击
trackBean.setAction(ActionConstants.SHARE);
}else if(type == 2){
//分享方式点击
trackBean.setAction(ActionConstants.SHARE);
}
//推荐数据设置
if(traceBean != null) {
trackBean.setTraceBean(traceBean);
}
return trackBean;
}
private void onVoicePlay() {
if (StringUtils.isBlank(currentAudioBean.getVoiceUrl())) {
return;
}
if (PlayerManager.getInstance().getAlbum() == null || TextUtils.isEmpty(PlayerManager.getInstance().getAlbum().getAlbumId()) ||
!PlayerManager.getInstance().getAlbum().getAlbumId().equals(mContentId)) {
VoicePlayerBean voicePlayerBean = new VoicePlayerBean();
voicePlayerBean.setTraceBean(traceBean);
voicePlayerBean.setType(7);
voicePlayerBean.objectType = ContentTypeConstant.URL_TYPE_EIGHT+"";
// id
voicePlayerBean.setObjectId(mContentId);
voicePlayerBean.setContentType(mContentType);
voicePlayerBean.setTopicId(mTopicId);
voicePlayerBean.setChannelId(mChannelId);
voicePlayerBean.setCompId(mCompId);
voicePlayerBean.setSourcePage(mSourcePage);
voicePlayerBean.setScrollToBottom(scrollToBottom);
voicePlayerBean.pageName = articlePageName;
voicePlayerBean.pageId = articlePageName;
if(traceBean != null ) {
voicePlayerBean.setTraceBean(traceBean);
}
// 标题
voicePlayerBean.setTitle(newsDetailBean.getNewsTitle());
voicePlayerBean.setContentRelId(contentRelId);
voicePlayerBean.setChannelId(mChannelId);
voicePlayerBean.setRelType(TextUtils.isEmpty(contentRelType)?0:Integer.parseInt(contentRelType));
if(newsDetailBean.getAudioList() != null && newsDetailBean.getAudioList().size() >0){
for (int i = 0; i < newsDetailBean.getAudioList().size(); i++) {
AudioBean audioBean = newsDetailBean.getAudioList().get(i);
if(StringUtils.isEqual("2",audioBean.getSourceType())){
// 2:语音播报音频【图文稿件使用】
// 参数 1 音频信息如:音频Url、音频时间等信息 参数 2 发布时间 + 音频时长
voicePlayerBean.setVoiceInfo(audioBean, newsDetailBean.getPublishTime());
break;
}
}
}
MusicAlbum musicAlbum = new MusicAlbum(voicePlayerBean);
musicAlbum.setAlbumId(mContentId);
PlayerManager.getInstance().single();
PlayerManager.getInstance().loadAlbum(musicAlbum,0);
if (FloatWindow.get() != null) {
FloatWindow.get().forceShow(this);
}
}else{
if(PlayerManager.getInstance().isPlaying()){
PlayerManager.getInstance().pauseAudio();
}else{
PlayerManager.getInstance().playAudio();
}
}
// initVoiceShow();
}
private BaseHandler mHandler = new BaseHandler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == Voice_Handler) {
if (!isFinishing()) {
PlayerManagerUtils.playAudio();
}
}
}
};
@Override
protected void onDestroy() {
if(mHandler != null){
mHandler.removeMessages(Voice_Handler);
}
if(mReceiver != null) {
unregisterReceiver(mReceiver);
}
if(newsDetailBean == null){
//详情打开异常,清空缓存池
clearCachedWebViewStackArticle();
}
if(!loadError && webView != null){
//复用Webview容器,清除数据
JSBridgeUtils.jsCall_clearAppData(webView);
// webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
webView.clearHistory();
if(webView.getParent() != null){
((ViewGroup) webView.getParent()).removeView(webView);
}
// webView.destroy();
// webView = null;
WebViewPool.getInstance().pushWebview(WebViewPool.TEMPLATE_ARTICLE,webView);
}
//如有视频也释放
if(videoManager != null){
videoManager.closeVideoWindow();
}
super.onDestroy();
//埋点:
channelExposure(newsDetailBean,duration,traceBean);
}
@Override
protected void onResume() {
super.onResume();
CommonVarUtils.articleDetailMusicObjectId = mContentId;
JSBridgeUtils.jsCall_appNotifyEvent(webView,AppNotifyEventConstant.EVENT_ONE);
if(isfirst){
isfirst = false;
return;
}
//刷新底部数据点赞、收藏,音频详情页也需要做同样的处理。
queryLikeAndCollectStatus();
//查询点赞评论数
queryContentDyNumber();
}
/**
* 设置左上角logo
*/
private void setTopLogoData(){
if(newsDetailBean == null){
return;
}
int rmhPlatform = newsDetailBean.rmhPlatform;
if(Constants.CONTENT_SOURCE_RMRB == rmhPlatform){
//人民号
PeopleMasterBean rmhInfo = newsDetailBean.getRmhInfo();
if (rmhInfo != null && "5".equals(rmhInfo.getUserType())){
//内容源账号,左上角不显示logo
topLogoImg.setVisibility(View.INVISIBLE);
}else {
topLogoImg.setBackgroundResource(R.mipmap.ic_article_rmh);
topLogoImg.setVisibility(View.VISIBLE);
}
}else {
//cms创建
topLogoImg.setBackgroundResource(R.mipmap.ic_article_operation);
topLogoImg.setVisibility(View.VISIBLE);
}
if (mShareBean!=null){
mShareBean.setRmhPlatform(rmhPlatform);
}
}
/**
* 处理彩蛋
*/
private void handlerPopUps() {
if (newsDetailBean == null) {
return;
}
String type = newsDetailBean.getNewsType();
if(StringUtils.isEqual(ContentTypeConstant.URL_TYPE_THIRTEEN + "",type)){
//音频不处理彩蛋
return;
}
PopUpsBean popUpsBean = PopUpsUtils.handlerPopUps(newsDetailBean.isHasPopUp(), newsDetailBean.getPopUps(), SpUtils.POPUP_PAGE);
if (popUpsBean == null) {
return;
}
// 展示彩蛋
showEasterEggsDialog(popUpsBean);
}
/**
* 显示彩蛋
*/
private void showEasterEggsDialog(PopUpsBean popUpsBean) {
if (showPopUpsBean != null && eggdialog != null && eggdialog.isShowing()) {
if (showPopUpsBean.getId().equals(popUpsBean.getId())) {
return;
}
}
//彩蛋曝光埋点
PageBean pageBean = new PageBean();
pageBean.setName(articlePageName);
pageBean.setId(articlePageName);
// AdvsTrack.easterEggsContentTrack(0, pageBean, popUpsBean);
showPopUpsBean = popUpsBean;
Constants.isShowingEasterEggs = true;
eggdialog = PopUpsUtils.showEasterEggsDialog(this, popUpsBean, SpUtils.POPUP_PAGE,
new EasterEggsDialog.DialogClickListener() {
@Override
public void onJump() {
Constants.isShowingEasterEggs = false;
//彩蛋点击埋点
// AdvsTrack.easterEggsContentTrack(1, pageBean, popUpsBean);
PopUpsUtils.easterEggsDialogJump(popUpsBean);
}
@Override
public void onClose() {
Constants.isShowingEasterEggs = false;
}
});
}
/**
* 设置点赞相关
*/
private void setLikeLayoutData() {
if (null == newsDetailBean) {
return;
}
int openLikes = newsDetailBean.getOpenLikes();
//点赞不展示
if (openLikes == 0) {
likeLayout.setVisibility(View.GONE);
return;
}else {
likeLayout.setVisibility(View.VISIBLE);
}
int likesStyle = newsDetailBean.getLikesStyle();
if (4 == likesStyle){
//点赞置空
likeLayout.setVisibility(View.GONE);
}else {
//*************************默认(未登录)点赞设置start**************************
likeImg.setSelfClick(false);
//默认展示红心样式
String likeStyleSelJson = getLikeStyleSelJson(likesStyle);
likeImg.setLottieFileName(likeStyleSelJson);
int likeStyleNormalIcon = ToolsUtil.getLikeStyle(likesStyle,2,false);
likeImg.setUnselectImageResId(likeStyleNormalIcon);
likeImg.setSelected(false);
//*************************默认点赞设置end**************************
}
}
/**
* 评论数据相关
*/
private void setCommentLayoutData() {
if (null == newsDetailBean) {
return;
}
//构建透传数据
transparentBean = new TransparentBean();
transparentBean.setPageName(articlePageName);
transparentBean.setPageId(articlePageName);
//统一赋值,减少重复代码,底部评论、互动
MyShareUtils.setTransparentBean(transparentBean,newsDetailBean);
//分享
mShareBean = new ShareBean();
MyShareUtils.setShareData(mShareBean,newsDetailBean);
//隐藏收藏按钮
// mShareBean.setShowCollect(-1);
transparentBean.setShareBean(mShareBean);
//设置游客评论开关
transparentBean.setVisitorComment(newsDetailBean.getVisitorComment());
//评论Fragment
commentFragment = CommentFragment.newInstance(transparentBean, false, false);
commentFragment.setSmartRefreshLayout(refreshLayout);
commentFragment.setCommentInitData(transparentBean,traceBean);
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container_comment, commentFragment).commit();
//**************************评论控制start**************************
/**
* 1、评论总开关:当开关为关时评论展示区、发布评论入口均隐藏
* 2、评论展示开关:当开关为关时发布评论入口隐藏、评论展示区正常展现(评论总开关 打开情况下)
* 3、人民号信息接口已处理
* 4、用户自己被禁言了,不隐藏评论输入框,点击时弹提示“暂时无法评论”;“回复”一样
*/
int openComment = newsDetailBean.getOpenComment();
if(openComment == 0 ){
//评论总开关:当开关为关,评论展示区、发布评论入口均隐藏
haveComment = false;
commentInputTv.setVisibility(View.INVISIBLE);
webCommentLayout.setVisibility(View.GONE);
commentIv.setVisibility(View.INVISIBLE);
commentCountTextLayout.setVisibility(View.INVISIBLE);
}else {
haveComment = true;
if(newsDetailBean.getCommentDisplay() == 2){
//评论展示开关:当开关为关或者内容不可评论时发布评论入口隐藏、评论展示区正常展现(评论总开关 打开情况下)
commentInputTv.setVisibility(View.INVISIBLE);
}else {
commentInputTv.setVisibility(View.VISIBLE);
}
contentBottomLayout.setVisibility(View.VISIBLE);
webCommentLayout.setVisibility(View.VISIBLE);
commentIv.setVisibility(View.VISIBLE);
commentCountTextLayout.setVisibility(View.VISIBLE);
//查询评论个数
commentFragment.setNewsDetailBean(newsDetailBean);
commentFragment.setCommentListener(new CommentFragment.CommentFragmentListener() {
@Override
public void getCommentNum(long commentNum,int type) {
try {
mCommentNum = Integer.parseInt(commentNum+"");
setCommentNum(commentNum+"");
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
@Override
public void submitCommentSuccess(int type) {
if(type == 0){
//评论内容
if (mScrollView != null){
int commentTop = (int) (webCommentLayout.getTop() + contentBottomLayout.getTop() +
ResUtils.getDimension(R.dimen.rmrb_dp8));
if(commentFragment != null){
//加热门评论高度
commentTop = commentTop + commentFragment.getHotHeight();
}
mScrollView.smoothScrollTo(0,commentTop,800);
}
}
//发布就设置评论数
/*mCommentNum ++;
setCommentNum(mCommentNum+"");*/
}
});
webCommentLayout.postDelayed(new Runnable() {
@Override
public void run() {
int scrollableDistance = mScrollView.getChildAt(0).getHeight() -
mScrollView.getHeight();
int commentTop = (int) (webCommentLayout.getTop() + contentBottomLayout.getTop() +
ResUtils.getDimension(R.dimen.rmrb_dp8));
if(scrollableDistance > 0 && scrollableDistance == mScrollY){
//可滑动,且已滑到底部
if(showCommentCount){
commentCountLayout.setVisibility(View.GONE);
}
commentTextTv.setVisibility(View.VISIBLE);
}else if(mScrollY >= commentTop){
if(showCommentCount){
commentCountLayout.setVisibility(View.GONE);
}
commentTextTv.setVisibility(View.VISIBLE);
}else {
if(showCommentCount){
commentCountLayout.setVisibility(View.VISIBLE);
}
commentTextTv.setVisibility(View.GONE);
}
}
},300);
}
//**************************评论控制end**************************
queryContentDyNumber();
//查询收藏、点赞状态
queryLikeAndCollectStatus();
//显示发布时间
if (!StringUtils.isEmpty(newsDetailBean.getPublishTime())) {
try {
//时间格式转换
long timeLong = TimeUtil.jsonToTimeInMillis2(newsDetailBean.getPublishTime());
//详情页展示完整时间 2023年09月01日 12:01
// String timeStr = TimeUtil.getYearDayTimeDetailString(timeLong);
String timeStr = TimeUtil.dataFormat12(timeLong);
newsTime.setText(timeStr);
} catch (Exception e) {
e.printStackTrace();
}
}
ThreadPoolUtils.postToMainDelay(new Runnable() {
@Override
public void run() {
//主动调起评论弹窗
if (BaseConstants.isNeedOpenComment){
//总开关-开启
commentIv.performClick();
BaseConstants.isNeedOpenComment = false;
}
}
},1000);
}
/**
* 查询内容动态评论个数
*/
public void queryContentDyNumber() {
if (null == newsDetailBean) {
return;
}
InteractDataFetcher interactFetcher = new InteractDataFetcher(new INewInteractDataListener() {
@Override
public void onInteractDataSuccess(InteractResponseDataBean interactResponseDataBean) {
if (interactResponseDataBean == null) {
return;
}
try {
String commentNum = interactResponseDataBean.getCommentNum();
int tempCommentNum = Integer.parseInt(commentNum);
if(tempCommentNum > mCommentNum){
//如果接口查询到的评论数比本地大就使用
setCommentNum(commentNum);
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
String likeNum = interactResponseDataBean.getLikeNum()+"";
setLikeNum(likeNum);
}
@Override
public void onInteractDataError(String errorMsg) {
}
});
String type = newsDetailBean.getNewsType();
String readFlag = newsDetailBean.getReadFlag();
boolean isV1 = StringUtils.isEqual(ContentTypeConstant.URL_TYPE_EIGHT+"",type) &&
StringUtils.isEqual("0",readFlag);
RelInfoBean relInfoBean = newsDetailBean.getReLInfo();
String contentRelId = "";
String channelId = "";
if(relInfoBean != null){
contentRelId = relInfoBean.getRelId();
channelId = relInfoBean.getChannelId();
}
interactFetcher.oneInteractData(isV1,newsDetailBean.getNewsId(), type,contentRelId,
channelId,readFlag,"1",newsDetailBean.rmhPlatform);
}
/**
* 设置评论数
*/
public void setCommentNum(String commentNum) {
if(newsDetailBean == null){
commentCountTextLayout.setVisibility(View.GONE);
return;
}
int openComment = newsDetailBean.getOpenComment();
if(openComment == 0 ){
//评论总开关:当开关为关,评论展示区、发布评论入口均隐藏
commentCountTextLayout.setVisibility(View.GONE);
return;
}
commentCountTextLayout.setVisibility(View.VISIBLE);
try {
mCommentNum = Integer.parseInt(commentNum);
} catch (NumberFormatException e) {
e.printStackTrace();
}
String comment = NumberStrUtils.Companion.getINSTANCE().handlerNumber(String.valueOf(commentNum));
if ("0".equals(comment)) {
comment = "";
}
if (!TextUtils.isEmpty(comment)) {
showCommentCount = true;
commentCountTv.setText(comment);
if(commentFragment == null){
return;
}
try {
int tempCommentNum = Integer.parseInt(commentFragment.getCommentNum());
if(tempCommentNum != mCommentNum){
commentFragment.setCommentNum(mCommentNum + "");
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
// commentIv.setImageResource(com.people.daily.common.R.mipmap.icon_bottom_commented);
} else {
showCommentCount = false;
commentCountLayout.setVisibility(View.GONE);
// commentIv.setImageResource(com.people.daily.common.R.mipmap.icon_bottom_comment);
}
}
/**
* 设置点赞数
*/
public void setLikeNum(String likeNum) {
if(!StringUtils.isEmpty(likeNum)){
try {
mLikeNum = Integer.parseInt(likeNum);
if (mLikeNum > 0){
likeTv.setVisibility(View.VISIBLE);
}else {
//防止接口给负数
mLikeNum = 0;
likeTv.setVisibility(View.GONE);
}
likeTv.setText(NumberStrUtils.Companion.getINSTANCE().handlerNumber(likeNum));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
// /**
// * 不同点赞样式的文案
// * @return
// */
// private String getLikeDefaultStr(){
// if (newsDetailBean != null){
// int likesStyle = newsDetailBean.getLikesStyle();
// int circleLikeName = ToolsUtil.getCircleLikeName(likesStyle);
// return ResUtils.getString(circleLikeName);
// }
// return "点赞";
// }
/**
* 查询当前内容、用户点赞、收藏状态
*/
private void queryLikeAndCollectStatus() {
if (newsDetailBean == null ){
return;
}
if (StringUtils.isEmpty(newsDetailBean.getNewsType()) || StringUtils.isEmpty(newsDetailBean.getNewsId())) {
return;
}
List<DisplayWorkInfoBean> workList = new ArrayList<>();
DisplayWorkInfoBean workInfoBean = new DisplayWorkInfoBean();
workInfoBean.setContentId(newsDetailBean.getNewsId());
workInfoBean.setContentSource(newsDetailBean.getNewsType());
workInfoBean.setContentRelId(contentRelId);
workInfoBean.setRelType(String.valueOf(contentRelType));
workList.add(workInfoBean);
QueryLikeStatusTools.getInstance().queryLikeStatus(workList, new QueryLikeStatusCallback() {
@Override
public void onSuccess(List<DisplayWorkInfoBean> dataBeans) {
if (null != dataBeans && dataBeans.size() > 0) {
setLikeAndCollect(dataBeans.get(0));
}
}
@Override
public void onFailed(String msg) {
}
});
}
/**
* 设置点赞、收藏图标状态
*/
private void setLikeAndCollect(DisplayWorkInfoBean infoBean) {
if(infoBean == null){
return;
}
if (!StringUtils.isEmpty(infoBean.getCollectStatus())) {
collectStatus = infoBean.getCollectStatus();
if ("0".equals(collectStatus)) {
collect.setSelected(false);
} else {
collect.setSelected(true);
}
}
int openLikes = newsDetailBean.getOpenLikes();
if (0 == openLikes){
likeLayout.setVisibility(View.GONE);
return;
}
if (!StringUtils.isEmpty(infoBean.getLikeStatus())) {
likeStatus = infoBean.getLikeStatus();
if(newsDetailBean == null){
return;
}
int likesStyle = newsDetailBean.getLikesStyle();
if(likesStyle == 4){
//置空,不展示
likeLayout.setVisibility(View.GONE);
return;
}
String likeStyleSelJson = getLikeStyleSelJson(likesStyle);
likeImg.setLottieFileName(likeStyleSelJson);
int likeStyleNormalIcon = ToolsUtil.getLikeStyle(likesStyle,2,false);
likeImg.setUnselectImageResId(likeStyleNormalIcon);
int likeStyleSelIcon = getLikeStyleSelIcon(likesStyle);
likeImg.setSelectImageResId(likeStyleSelIcon);
if ("0".equals(likeStatus)) {
likeImg.setSelected(false);
} else {
likeImg.setSelected(true);
}
setLikeTvColor();
}
}
/**
* 设置点赞文本色值
*/
private void setLikeTvColor(){
if(newsDetailBean == null){
return;
}
int likesStyle = newsDetailBean.getLikesStyle();
if ("0".equals(likeStatus)) {
likeTv.setTextColor(ContextCompat.getColor(activity,R.color.res_color_common_C3));
} else {
if(likesStyle != 1){
//祈祷、默哀场景文字是黑色
likeTv.setTextColor(ContextCompat.getColor(activity,R.color.res_color_common_C1));
}else {
likeTv.setTextColor(ContextCompat.getColor(activity,R.color.res_color_common_C11));
}
}
}
/**
* 是否视频在全屏展示
*/
boolean isFullPlay = false;
/**
* 显示原生布局
*/
public void showAppLayout(boolean isFullPlay){
this.isFullPlay = isFullPlay;
if(isFullPlay){
//禁止右滑关闭页面
// setSwipeBackEnable(false);
mNeedScrollY = mScrollY;
topLayout.setVisibility(View.GONE);
likeLayout.setVisibility(View.GONE);
contentBottomSpaceView.setVisibility(View.INVISIBLE);
contentBottomLayout.setVisibility(View.GONE);
bottomLine.setVisibility(View.GONE);
bottomLayout.setVisibility(View.GONE);
webView.setVisibility(View.GONE);
PlayerManager.getInstance().clear();
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
webViewLayout.setLayoutParams(lp);
if(commentFragment != null && commentFragment.isShowMore()){
//全屏关闭加载更多
refreshLayout.setEnableLoadMore(false);
}
}else {
//允许右滑关闭页面
// setSwipeBackEnable(true);
topLayout.setVisibility(View.VISIBLE);
setLikeLayoutData();
contentBottomSpaceView.setVisibility(View.VISIBLE);
if(haveComment || haveRecommend){
contentBottomLayout.setVisibility(View.VISIBLE);
}
bottomLine.setVisibility(View.VISIBLE);
bottomLayout.setVisibility(View.VISIBLE);
webView.setVisibility(View.VISIBLE);
if(commentFragment != null && commentFragment.isShowMore()){
//小屏展示加载更多
refreshLayout.setEnableLoadMore(true);
}
// FIXME: 2024/1/15 填充数据
PlayerManager.getInstance().playAudio();
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mWebViewHeight);
webViewLayout.setLayoutParams(lp);
mScrollView.postDelayed(new Runnable() {
@Override
public void run() {
mScrollView.scrollTo(0,mNeedScrollY);
}
},100);
Logger.t(TAG).d("scrollTo======>"+mNeedScrollY);
}
}
public void onClickWebVideo(ArticleVideoBean articleVideoBean){
if(videoManager != null && articleVideoBean != null){
if(PlayerManager.getInstance().isPlaying()){
PlayerManager.getInstance().pauseAudio();
}
articleVideoBean.setWebViewHeight(mWebViewHeight);
videoManager.onClickWebVideo(articleVideoBean);
videoManager.setChangeScreenListener(new MyScreenModeChangeListener());
}
}
/**
* 设置相关推荐模块
*/
private void setRecommendData(RecListBean recListBean,boolean isSetRec){
if(!isSetRec){
//走一次设置为true
isSetRecData = true;
return;
}
if(recListBean == null || ArrayUtils.isEmpty(recListBean.getList())){
recommendLayout.setVisibility(View.GONE);
//推荐数据拿到时,一起设置评论数据
setCommentLayoutData();
return;
}
recommendShowTrackTag = 1;
haveRecommend = true;
MenuBean menuBean = new MenuBean();
menuBean.dataSourceType = CompDataSourceBean.RECOMMEND_LIST;
RecommendFragment recommendFragment = RecommendFragment.newInstance(menuBean,recListBean);
getSupportFragmentManager().beginTransaction().add(R.id.layout_rv_recommend,
recommendFragment).commit();
recommendLayout.setVisibility(View.VISIBLE);
contentBottomLayout.setVisibility(View.VISIBLE);
int recommendTop = contentBottomLayout.getTop() + recommendLayout.getTop();
if(recommendTop < contentVisviableHeight){
//推荐在首屏展示,直接曝光
Logger.t(TAG).d("=====>推荐曝光");
if(recListBean != null && ArrayUtils.isNotEmpty(recListBean.getList())){
recommendShowTrackTag = 0;
WebDataUtils.recommendShowTrack(recListBean.getList());
}
}
//推荐数据拿到时,一起设置评论数据
setCommentLayoutData();
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
if(refreshLayout != null){
refreshLayout.finishRefresh();
}
}
/**
* 横竖屏操作回调
*/
private class MyScreenModeChangeListener implements ChangeScreenListener {
@Override
public void onChangeToScreenMode(AliyunScreenMode currentMode) {// 切换后的模式
if (currentMode == AliyunScreenMode.Full) {
// 小屏变全屏
showAppLayout(true);
} else if(currentMode == AliyunScreenMode.Small){
// 全屏变小屏
showAppLayout(false);
}else if(currentMode == AliyunScreenMode.AMPLIFY){
// 缩小屏变放大屏
showAppLayout(true);
}else {
// 放大屏变缩小屏
showAppLayout(false);
}
}
}
public void articleShare(JsShareBean jsShareBean){
WebUtils.onSingleShare(activity,jsShareBean,newsDetailBean,traceBean);
}
public void reloadData(){
if(articleDetailViewModel != null){
loadStepList.clear();
articleDetailViewModel.requestDetailData(mContentId, contentRelId, contentRelType);
}
}
/**
* 清空缓存模版,并重新预加载
*/
public void clearCachedWebViewStackArticle(){
WebViewPool.getInstance().clearCachedWebViewStackArticle();
WebViewPool.getInstance().preload(null);
loadError = true;
}
/**
* 内容曝光埋点
*/
public void contentExposure(NewsDetailBean newsDetailBean,TraceBean traceBean){
if(newsDetailBean == null){
return;
}
TrackContentBean trackContentBean = ArticleTrack.newsDetailToTrackContent(newsDetailBean,traceBean);
trackContentBean.setAction(ActionConstants.SHOW);
//设置推荐字段
if(traceBean != null) {
trackContentBean.setTraceBean(traceBean);
}
// CommonTrack.getInstance().contentShowTrack(trackContentBean);
}
/**
* 页面浏览埋点
*/
public void channelExposure(NewsDetailBean newsDetailBean, long duration, TraceBean traceBean){
if(newsDetailBean == null){
return;
}
TrackContentBean trackContentBean = ArticleTrack.newsDetailToTrackContent(newsDetailBean,traceBean);
trackContentBean.setAction(ActionConstants.BROWSE);
trackContentBean.setExposure(duration);
//设置推荐字段
if(traceBean != null) {
trackContentBean.setTraceBean(traceBean);
}
/**
* 图文详情页,浏览必传
* 阅读量是否超过1w;(仅图文内容写入) 0:否,1:是
*/
int flag = 0;
try {
flag = Integer.parseInt(newsDetailBean.getReadFlag());
}catch (Exception e){
e.printStackTrace();
}
// CommonTrack.getInstance().channelExposureTrackArticleDetail(trackContentBean,flag);
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//跟随系统,但系统深色模式与当前不一致
boolean isFollowChange = StringUtils.isEqual(SpUtils.FOLLOWUP_SYSTEM,
SpUtils.getNightMode()) && Constants.isNightMode != SpUtils.isNightMode();
boolean isNightModeChange = !StringUtils.isEqual(SpUtils.FOLLOWUP_SYSTEM,
SpUtils.getNightMode()) && !StringUtils.isEqual(nightMode,SpUtils.getNightMode());
if(isFollowChange || isNightModeChange){
//夜间模式变化
JSBridgeUtils.jsCall_appNotifyEvent(webView,AppNotifyEventConstant.EVENT_NINE);
}
}
}