SubjectWebActivity.java
63.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
package com.people.webview.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.webkit.DownloadListener;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.people.comment.comment.vm.CommentViewModel;
import com.people.comment.dialog.CommentCommitDialog;
import com.people.comment.dialog.CommentSheetDialog;
import com.people.comment.listener.CommitDialogListener;
import com.people.webview.R;
import com.people.webview.constant.AppNotifyEventConstant;
import com.people.webview.constant.CallbackHandlerType;
import com.people.webview.javabridge.BridgeJavascriptInterface;
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.wd.capability.network.constant.EventConstants;
import com.wd.capability.network.utils.NetworkUtil;
import com.wd.capability.router.data.ActionBean;
import com.wd.common.adv.CornerAdvLogic;
import com.wd.common.base.BaseActivity;
import com.wd.common.constant.PageNameConstants;
import com.wd.common.constant.RouterConstants;
import com.wd.common.dialog.EasterEggsDialog;
import com.wd.common.dialog.PopUpsUtils;
import com.wd.common.enums.PosterTypeEnum;
import com.wd.common.interact.ICommentDataNewListener;
import com.wd.common.listener.AddFavoriteLabelCallback;
import com.wd.common.net.NetStateChangeReceiver;
import com.wd.common.utils.H5JsApiPermissionUtil;
import com.wd.common.utils.HistoryDataHelper;
import com.wd.common.utils.PDUtils;
import com.wd.common.utils.ProcessUtils;
import com.wd.common.widget.BottomCommentFunctionBar;
import com.wd.common.widget.CommonRefreshHeader;
import com.wd.common.widget.CustomSmartRefreshLayout;
import com.wd.common.widget.DefaultView;
import com.wd.foundation.bean.JsCallAppBean;
import com.wd.foundation.bean.JsImageBean;
import com.wd.foundation.bean.JsScrollBean;
import com.wd.foundation.bean.JsShareBean;
import com.wd.foundation.bean.analytics.TraceBean;
import com.wd.foundation.bean.analytics.TrackContentBean;
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.comp.PageBean;
import com.wd.foundation.bean.custom.comp.TopicInfoBean;
import com.wd.foundation.bean.custom.content.CommentItem;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.custom.content.ContentTypeConstant;
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.pop.PopUpsBean;
import com.wd.foundation.bean.response.NewsDetailBean;
import com.wd.foundation.bean.response.PersonalInfoBean;
import com.wd.foundation.bean.web.AppToH5DataBean;
import com.wd.foundation.bean.web.H5FollowBean;
import com.wd.foundation.bean.web.JSCallbackBean;
import com.wd.foundation.bean.web.JsPageBean;
import com.wd.foundation.bean.web.SubjectBottomMaskBean;
import com.wd.foundation.wdkit.constant.Constants;
import com.wd.foundation.wdkit.constant.DefaultViewConstant;
import com.wd.foundation.wdkit.constant.IntentConstants;
import com.wd.foundation.wdkit.json.GsonUtils;
import com.wd.foundation.wdkit.statusbar.StatusBarCompat;
import com.wd.foundation.wdkit.statusbar.StatusBarStyleEnum;
import com.wd.foundation.wdkit.system.FastClickUtil;
import com.wd.foundation.wdkit.utils.SpUtils;
import com.wd.foundation.wdkit.utils.ToastNightUtil;
import com.wd.foundation.wdkit.utils.UiUtils;
import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
import com.wd.foundation.wdkitcore.tools.AppContext;
import com.wd.foundation.wdkitcore.tools.JsonUtils;
import com.wd.foundation.wdkitcore.tools.ResUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import org.json.JSONException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 专题web页面 H5专题、话题专题、直播专题、时间轴专题
*
* @author baozhaoxin
* @version [V1.0.0, 2023/8/8]
* @since V1.0.0
*/
@Route(path = RouterConstants.PATH_SUBJECT_WEB_PAGE)
public class SubjectWebActivity extends BaseActivity implements View.OnClickListener,
OnRefreshLoadMoreListener {
/**
* tag
*/
private final String TAG = "SubjectWebActivity";
/**
* 刷新控件
*/
private CustomSmartRefreshLayout refreshLayout;
/**
* h5布局
*/
private FrameLayout webLayout;
/**
* webview
*/
private NativeWebView mWebView;
/**
* 底部布局
*/
private FrameLayout bottomLayout;
/**
* 公共评论控件
*/
private BottomCommentFunctionBar functionBar;
/**
* 底部蒙层
*/
private View bottomMaskView;
/**
* 页面传递的数据
*/
private JSONObject pageJSONObject;
/**
* webUrl
*/
private String webUrl = "";
/**
* 上下文环境
*/
private Context mContext;
/**
* 上下文环境
*/
private Activity mActivity;
/**
* viewmoel
*/
private ArticleDetailViewModel articleDetailViewModel;
/**
* webView加载状态 false为加载异常
*/
private boolean webViewLoad;
/**
* 缺省页
*/
private DefaultView defaultView;
/**
* 评论框
*/
private CommentSheetDialog sheetDialog = null;
/**
* 评论需要的数据
*/
CommentViewModel commentViewModel;
/**
*
*/
private TransparentBean transparentBean;
/**
* 是否展示评论区数据
*/
boolean scrollToBottom = false;
/**
* 专题数据
*/
private TopicInfoBean topicInfoBean;
/**
* 解决刚进入,网络变化回调会执行一次
*/
private boolean networkFirst = true;
private NetStateChangeReceiver mReceiver;
/**
* 是否可见
*/
private boolean isVisible = false;
/**
* 当前页数据
*/
private PageBean mPageBean;
/**
* 是否需要处理彩蛋数据
*/
private boolean easterEggsNeedHandler = false;
/**
* 已经展示过的bean
*/
private PopUpsBean showPopUpsBean;
/**
* 彩蛋弹窗
*/
private EasterEggsDialog eggdialog;
/**
* 透传推荐相关数据设置
*/
TraceBean traceBean;
/**
* 挂角广告操作对象
*/
private CornerAdvLogic cornerAdvLogic;
/**
* 当dataSource为7时 数据对象为数组,该数组元素为,:
* http://192.168.1.3:3300/project/3802/interface/api/189235
* 接口的 data下面的operDataList 列表元素对象 json object
*/
private String shareDataJson = "";
/**
* 下拉刷新头
*/
private CommonRefreshHeader refreshHeader;
/**
* 是否开启RefreshLayout 下拉
*/
private boolean openRefreshEnable = false;
/**
* 关闭加载动效标记
*/
private boolean stopLoadingTag = false;
private String topicId;
private String pageId;
/**
* 来自哪个页面跳转
*/
private String fromPage;
/**
* 频道、专题页关系id
*/
private String relId;
/**
* 频道、专题页关系id
*/
private String relType;
/**
* 回调
*/
public Handler callBackHandler = new Handler(Looper.getMainLooper()) {
@SuppressLint("HandlerLeak")
@Override
public void handleMessage(@NonNull Message msg) {
JSCallbackBean jsCallbackBean = null;
if (msg != null && msg.obj != null) {
jsCallbackBean = (JSCallbackBean) msg.obj;
}
Logger.t(TAG).i("msg arg1:" + msg.arg1);
if (CallbackHandlerType.jsCall_openAppShare == msg.arg1) {
if(jsCallbackBean != null) {
//H5调用此方法,启动客户端分享弹窗
JsShareBean jsShareBean = (JsShareBean) jsCallbackBean.getCallbackData();
WebUtils.onSingleShare(mActivity, jsShareBean, null, null);
}
} else if (CallbackHandlerType.jsCall_savePhoto == msg.arg1) {
if(jsCallbackBean != null) {
//保存图片到相册
JsImageBean jsImageBean = (JsImageBean) jsCallbackBean.getCallbackData();
WebUtils.getPermission(mActivity, jsImageBean);
}
} else if (CallbackHandlerType.jsCall_receiveH5Data == msg.arg1) {
if (jsCallbackBean != null) {
//由App预埋,H5加载完成后 主动传递数据用
JsPageBean jsPageBean = (JsPageBean) jsCallbackBean.getCallbackData();
setJSPageData(jsPageBean);
}
} else if (CallbackHandlerType.jsCall_h5ScrollEvent == msg.arg1) {
if(jsCallbackBean != null) {
//滚动事件
JsScrollBean jsScrollBean = (JsScrollBean) jsCallbackBean.getCallbackData();
WebUtils.updateVoiceEasyFloatUi(jsScrollBean);
}
} else if (CallbackHandlerType.jsCall_callAppService == msg.arg1) {
//H5调用App接口
try {
if(jsCallbackBean != null) {
JsCallAppBean jsCallAppBean = (JsCallAppBean) jsCallbackBean.getCallbackData();
//处理数据
setJsCallAppData(jsCallAppBean);
}
} catch (Exception e) {
e.printStackTrace();
}
}else if (CallbackHandlerType.jsCall_receiveSubjectData == msg.arg1){
//这里是业务需要 H5专题获取缓存的接口数据减少加载时间,需要pageId,topicId
try {
if(jsCallbackBean != null) {
JsCallAppBean jsCallAppBean = (JsCallAppBean) jsCallbackBean.getCallbackData();
//处理数据
WebUtils.getInstance().sendH5TopicPageInfo(mWebView,jsCallAppBean,pageId,topicId);
}
} catch (Exception e) {
e.printStackTrace();
}
}else if (CallbackHandlerType.jsCall_getNormalSubjectData == msg.arg1){
//获取App本地通用h5专题数据
if(jsCallbackBean != null) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("pageId",pageId);
jsonObject.put("topicId",topicId);
Logger.t(TAG).d("jsCall_getNormalSubjectData isLogined ,data = " + jsonObject.toString());
mWebView.sendResponse(jsonObject.toString(), jsCallbackBean.getCallbackId());
} catch (Exception e) {
e.printStackTrace();
}
}
}else if (CallbackHandlerType.jsCall_currentPageOperate_12 == msg.arg1) {
// H5调用隐藏公共评论控件
functionBar.setVisibility(View.GONE);
} else if (CallbackHandlerType.jsCall_currentPageOperate_19 == msg.arg1) {
//页面相关操作-19 设置状态栏颜色
try {
if(jsCallbackBean != null) {
String statusBarMode = (String) jsCallbackBean.getCallbackData();
setStatusBarMode(statusBarMode);
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (CallbackHandlerType.jsCall_currentPageOperate_20 == msg.arg1 ||
CallbackHandlerType.jsCall_currentPageOperate_21 == msg.arg1) {
//页面相关操作-20 21 设置底部蒙层颜色
try {
if(jsCallbackBean != null) {
SubjectBottomMaskBean subjectBottomMaskBean = (SubjectBottomMaskBean) jsCallbackBean.getCallbackData();
setBottomMaskShow(subjectBottomMaskBean);
}
} catch (Exception e) {
e.printStackTrace();
}
} else if(CallbackHandlerType.jsCall_currentPageOperate_24 == msg.arg1){
//页面相关操作-24 号主关注操作 状态更新
try {
if(jsCallbackBean != null) {
H5FollowBean h5FollowBean = (H5FollowBean) jsCallbackBean.getCallbackData();
//处理数据
setH5FollowData(h5FollowBean);
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (CallbackHandlerType.jsCall_currentPageOperate_32 == msg.arg1 ||
CallbackHandlerType.jsCall_currentPageOperate_33 == msg.arg1) {
//页面相关操作-32 开始弹全局弹框事件(原生代码确保Webview底部到底)
//页面相关操作-33 结束全局弹框事件(原生代码确保Webview正常恢复)
try {
if(jsCallbackBean != null) {
int type = (int) jsCallbackBean.getCallbackData();
WebUtils.setViewVisibility(bottomLayout, type);
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (CallbackHandlerType.jsCall_currentPageOperate_47 == msg.arg1) {
//页面相关操作-47 显示客户端通用loading动效
startLoading(false);
} else if (CallbackHandlerType.jsCall_currentPageOperate_48 == msg.arg1) {
//页面相关操作-48 关闭客户端通用loading动效
stopLoading();
stopLoadingTag = true;
}
}
};
/**
* 设置h5返回的page数据
*/
private void setJSPageData(JsPageBean jsPageBean) {
if (jsPageBean == null) {
return;
}
String dataSource = jsPageBean.getDataSource();
// Logger.t(TAG).d("dataSource=========>"+dataSource);
// Logger.t(TAG).d("dataJson=========>"+jsPageBean.getDataJson());
if (StringUtils.isEqual("2", dataSource)) {
//2.跳转推荐内容数据
WebUtils.jumpToNewArticle(jsPageBean);
} else if (StringUtils.isEqual("3", dataSource)) {
//3.显示图片预览
ProcessUtils.goToImageSlidePage(jsPageBean.getImgListData());
} else if (StringUtils.isEqual("4", dataSource)) {
//4. 专题pageinfo数据
setPageInfoData(jsPageBean);
} else if (StringUtils.isEqual("5", dataSource)) {
//5、专题comp运营位点击跳转(并记录浏览历史)
WebUtils.setOperDataJump(jsPageBean);
} else if (StringUtils.isEqual("7", dataSource)) {
//7、专题分享海报图上的数据列表(H5可选第一页前5条运营位数据)
shareDataJson = jsPageBean.getDataJson();
}
}
/**
* h5关注创作者
* @param h5FollowBean
*/
private 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);
}
@Override
public void onClick(View v) {
}
@Override
protected int getLayoutId() {
return R.layout.activity_web_subject;
}
@Override
protected String getTag() {
return TAG;
}
@Override
protected void initView() {
mContext = this;
mActivity = this;
int statusHeight = StatusBarCompat.getStatusBarHeight(this);
cornerAdvLogic = new CornerAdvLogic(mActivity);
defaultView = findViewById(R.id.default_view);
refreshLayout = findViewById(R.id.layout_refresh);
webLayout = findViewById(R.id.flparent_webview);
mWebView = findViewById(R.id.web_view);
bottomLayout = findViewById(R.id.layout_bottom);
functionBar = findViewById(R.id.bottom_comment_bar);
bottomMaskView = findViewById(R.id.view_bottom_mask);
setFunctionBarListener();
// 添加彩蛋回调
addEasterEggsCallBack();
// mWebView = WebViewPool.getInstance().getWebView(this,WebViewPool.TEMPLATE_SUBJECT);
// flPaerntWebview.addView(mWebView);
refreshHeader = new CommonRefreshHeader(this);
refreshLayout.setRefreshHeader(refreshHeader);
refreshLayout.setEnableRefresh(openRefreshEnable);
refreshLayout.setOnRefreshLoadMoreListener(this);
//默认不展示分享
functionBar.closeShare();
//设置背景为透明
mWebView.setBackgroundColor(0);
Drawable bgDrawable = mWebView.getBackground();
if(bgDrawable != null){
bgDrawable.mutate().setAlpha(0);
}
}
@Override
protected StatusBarStyleEnum getStatusBarStyle() {
return StatusBarStyleEnum.FULLSCREEN_DARK_ENUM;
}
@Override
protected void initData() {
Object actionBeanObject = getExtrasSerializableObject();
if (actionBeanObject == null) {
return;
}
pageJSONObject = JsonUtils.convertJsonToObject(((ActionBean) actionBeanObject).paramBean.params, JSONObject.class);
webUrl = pageJSONObject.getString(IntentConstants.WEB_URL);
String normalLinkUrl = pageJSONObject.getString(IntentConstants.NORMAL_LINK_URL);
topicId = pageJSONObject.getString(IntentConstants.TOPIC_ID);
pageId = pageJSONObject.getString(IntentConstants.PARAM_PAGE_ID);
if(StringUtils.isNotBlank(normalLinkUrl) && StringUtils.isNotBlank(topicId) &&
StringUtils.isNotBlank(pageId)){
webUrl = normalLinkUrl;
}
fromPage = pageJSONObject.getString(IntentConstants.JUMP_FROM_PAGE);
relId = pageJSONObject.getString(IntentConstants.REL_ID);
relType = pageJSONObject.getString(IntentConstants.REL_TYPE);
traceBean = new TraceBean();
String traceId = pageJSONObject.getString(IntentConstants.CNSTRACEID);
if (!TextUtils.isEmpty(traceId)) {
traceBean.traceId = traceId;
traceBean.sceneId = pageJSONObject.getString(IntentConstants.SCENEID);
traceBean.subSceneId = pageJSONObject.getString(IntentConstants.SUBSCENEID);
traceBean.itemId = pageJSONObject.getString(IntentConstants.ITEMID);
traceBean.expIds = pageJSONObject.getString(IntentConstants.EXPIDS);
} else {
traceBean.traceId = "selfHold";
traceBean.sceneId = "9999";
}
if (TextUtils.isEmpty(webUrl)) {
finish();
return;
}
initWeb();
//监听
receiveLiveDataMsg();
// 需要网络监听
setNetStateObserver();
}
/**
* 设置运营
*
* @param jsPageBean
*/
private void setOperDataJump(JsPageBean jsPageBean) {
if (jsPageBean == null) {
return;
}
String dataJson = jsPageBean.getDataJson();
try {
ContentBean contentBean = GsonUtils.fromJson(dataJson, ContentBean.class);
ProcessUtils.processPage(contentBean);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 设置专题pageinfo数据
*
* @param jsPageBean
*/
private void setPageInfoData(JsPageBean jsPageBean) {
if (jsPageBean == null) {
return;
}
String dataJson = jsPageBean.getDataJson();
try {
PageBean pageBean = GsonUtils.fromJson(dataJson, PageBean.class);
mPageBean = pageBean;
topicInfoBean = pageBean.getTopicInfo();
if (topicInfoBean != null) {
topicInfoBean.setTitleName(mPageBean.getName());
topicInfoBean.setLocalPageId(mPageBean.getId());
topicInfoBean.setLocalPageName(mPageBean.getName());
topicInfoBean.setBackgroundImgUrl(mPageBean.getBackgroundImgUrl());
topicInfoBean.setRelId(relId);
topicInfoBean.setRelType(relType);
setCommentLayout();
setGetDataLiveDataMsg();
//不是浏览历史进入,添加浏览历史
if (!StringUtils.isEqual(PageNameConstants.MY_HISTORY_PAGE,fromPage)){
HistoryDataHelper.getInstance().addHistoryForTopicInfo(topicInfoBean);
}
}
// 处理彩蛋
handlerPopUps();
// 挂角广告view
advLogic(false);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 创建评论布局
*/
private void setCommentLayout() {
if (null != topicInfoBean) {
//给底部view 设置相关数据
transparentBean = new TransparentBean();
transparentBean.setPageId(topicInfoBean.getLocalPageId());
transparentBean.setPageName(topicInfoBean.getLocalPageName());
transparentBean.summaryType = topicInfoBean.getTopicTypeWord();
transparentBean.summaryId = topicInfoBean.getTopicId();
transparentBean.setContentId(topicInfoBean.getTopicId());
transparentBean.setContentType(ContentTypeConstant.URL_TYPE_FIVE + "");
transparentBean.setPreCommentFlag(topicInfoBean.getCommentPreviewFlag());
transparentBean.setTargetRelId(topicInfoBean.getRelId());
transparentBean.setTargetRelType(topicInfoBean.getRelType());
//迭代二新增
transparentBean.setContentTitle(topicInfoBean.getTitle());
transparentBean.setTargetRelObjectId(topicInfoBean.getRelObjectId());
transparentBean.isBackIcon = true;
transparentBean.isLikeIcon = true;
//***********************评论权限控制start**********************
//设置游客评论开关
transparentBean.setVisitorComment(topicInfoBean.getVisitorComment());
transparentBean.setOpenComment(topicInfoBean.getCommentFlag());
transparentBean.setCommentDisplay(topicInfoBean.getCommentShowFlag() == 1 ? 1 : 2);
transparentBean.setPreCommentFlag(topicInfoBean.getCommentPreviewFlag());
/**
* 1、评论总开关:当开关为关时评论展示区、发布评论入口均隐藏
* 2、评论展示开关:当开关为关时发布评论入口隐藏、评论展示区正常展现(评论总开关 打开情况下)
* 3、人民号信息接口已处理
* 4、用户自己被禁言了,不隐藏评论输入框,点击时弹提示“暂时无法评论”;“回复”一样
*/
int openComment = topicInfoBean.getCommentFlag();
if (openComment == 0) {
//评论总开关:当开关为关,评论展示区、发布评论入口均隐藏
functionBar.closeComment();
} else {
if (topicInfoBean.getCommentShowFlag() != 1) {
//评论展示开关:当开关为关或者内容不可评论时发布评论入口隐藏、评论展示区正常展现(评论总开关 打开情况下)
functionBar.hideInputView();
} else {
functionBar.openInputView();
}
functionBar.openCommentBtn();
}
//**************************评论控制end**************************
if ("1".equals(topicInfoBean.getShareOpen())) {
functionBar.openShare();
} else {
//分享关闭换成...icon
functionBar.setShareMoreIcon();
}
transparentBean.isShareIcon = false;
//打开收藏
functionBar.openCollect();
ShareBean mShareBean = new ShareBean();
//设置分享框中,适老化入口可见
mShareBean.setShowFontSize(true);
mShareBean.setTitle(topicInfoBean.getShareTitle());
mShareBean.setDescription(topicInfoBean.getShareSummary());
mShareBean.setImageUrl(topicInfoBean.getShareCoverUrl());
//链接地址
mShareBean.setShareUrl(topicInfoBean.getShareUrl());
mShareBean.setContentType(ContentTypeConstant.URL_TYPE_FIVE + "");
mShareBean.setContentId(topicInfoBean.getTopicId());
mShareBean.setShareOpen(topicInfoBean.getShareOpen());
mShareBean.setTargetRelId(topicInfoBean.getRelId());
mShareBean.setTargetRelType(topicInfoBean.getRelType());
mShareBean.setShowReport(false);
mShareBean.setShowPosterType(PosterTypeEnum.CONTENT);
mShareBean.setShowPoster(topicInfoBean.getPosterFlag() > 0 ? 1 : -1);
transparentBean.setShareBean(mShareBean);
functionBar.setContentAndType(transparentBean);
functionBar.queryContentDyNumber();
}
}
/**
* 数据传递 测试接口查询点赞、收藏,用于修改图标
*/
private void setFunctionBarListener() {
functionBar.setCommentFunctionListener(new BottomCommentFunctionBar.CommentFunctionListener() {
@Override
public void backClick() {
goBack();
}
@Override
public void inputClick() {
openComment();
}
@Override
public void commentClick() {
//显示评论信息
showInputCommentDialog(-1);
}
@Override
public void likeClick(String status) {
}
@Override
public void collectClick(String status) {
// 埋点
if (topicInfoBean != null) {
boolean isCollect = "1".equals(status);
TrackContentBean trackContentBean = makeTrackContentBean();
if(trackContentBean != null){
trackContentBean.collectAction(isCollect);
// CommonTrack.getInstance().contentCollectionTrack(trackContentBean, isCollect);
}
}
}
@Override
public void shareClick() {
if(FastClickUtil.isFastClick()){
return;
}
goShare();
}
});
functionBar.setAddFavoriteLabelCallback(new AddFavoriteLabelCallback() {
@Override
public void onAddFavoriteLabel(String favoriteCategoryLabel) {
TrackContentBean trackContentBean = makeTrackContentBean();
if(trackContentBean != null){
// CommonTrack.getInstance().addFavoriteCategoryEventTrack(trackContentBean,
// favoriteCategoryLabel);
}
}
});
}
private TrackContentBean makeTrackContentBean(){
if (topicInfoBean != null) {
WebDataUtils.setTopFiveData(topicInfoBean, shareDataJson);
ShareBean shareBean = new ShareBean();
topicInfoBean.linkUrl = webUrl;
return WebDataUtils.shareTopicInfoBean(topicInfoBean, shareBean, traceBean);
}
return null;
}
/**
* 专题分享
*/
private void goShare(){
if (topicInfoBean != null) {
WebDataUtils.setTopFiveData(topicInfoBean, shareDataJson);
ShareBean shareBean = new ShareBean();
topicInfoBean.linkUrl = webUrl;
TrackContentBean trackContentBean = WebDataUtils.shareTopicInfoBean(topicInfoBean, shareBean, traceBean);
//推荐数据设置
if(traceBean != null) {
trackContentBean.setTraceBean(traceBean);
}
showShareMore(shareBean,trackContentBean);
}
}
private void showShareMore(ShareBean shareBean,TrackContentBean trackContentBean) {
// if (shareBean == null){
// return;
// }
// MoreDialogTools moreDialogTools = new MoreDialogTools(this, true);
// //图文分享 参数bean:实体类 参数2:回调,参数3:去掉指定分享平台
// moreDialogTools.showDialog(shareBean, new ShareResultCallBack() {
// @Override
// public void onComplete(String platform, String msg) {
// if (null != functionBar) {
// //点赞
// if (platform.equals(MoreEnum.LIKE + "")) {
// if (StringUtils.isEqual("1",msg)) {
// functionBar.setLikeStatusIcon(true, msg);
// long likeCount = functionBar.getLikeCount();
// functionBar.setLikeNum(likeCount+1);
// } else {
// functionBar.setLikeStatusIcon(false, msg);
// long likeCount = functionBar.getLikeCount();
// functionBar.setLikeNum(likeCount-1);
// }
// //评论弹窗的底部bar点赞
// sheetDialog.setLikeStatusIcon(msg);
// }
// //收藏
// if (platform.equals(MoreEnum.COLLECT + "")) {
// functionBar.setCollectStatusIcon(msg);
// //评论弹窗的底部bar收藏
// sheetDialog.setCollectStatusIcon(msg);
// }else if(StringUtils.isEqual(MoreEnum.ADDCOLLECTLABEL+"",platform)){
// // 埋点
// if (topicInfoBean != null) {
// TrackContentBean trackContentBean = new TrackContentBean();
// topicInfoBean.linkUrl = webUrl;
// trackContentBean.topicInfoBeanBeantoBean(topicInfoBean);
// CommonTrack.getInstance().addFavoriteCategoryEventTrack(trackContentBean,
// msg);
// }
// }
// }
// }
//
// @Override
// public void onError(String platform, String msg) {
//
// ToastNightUtil.showShort(msg);
// }
//
// @Override
// public void onCancel(String platform, String msg) {
//
// }
//
// @Override
// public void onShareClick(String platform, String status) {
// //收藏埋点
// if (platform.equals(ShareTypeConstants.COLLECT)) {
// //用户未登录,不做处理
//// if ("-1".equals(collectStatus)) {
//// return;
//// }
//// //collectStatus 0:收藏 1:取消
//// trackContentBean.setBhv_value("collect");
//// CommonTrack.getInstance().collectClickTrack(trackContentBean, collectStatus);
// }
// //分享埋点
// else {
// if (trackContentBean != null){
// trackContentBean.setShare_type(platform);
// CommonTrack.getInstance().shareTypeClickTrack(trackContentBean);
// }
//
// }
// }
//
// @Override
// public void onCommonClick(String platform, String status) {
//
// }
//
//
// });
// //设置字号大小回调
// setFontSizeSetCallBack(moreDialogTools);
}
// private void setFontSizeSetCallBack(MoreDialogTools moreDialogTools){
// if (moreDialogTools != null){
// moreDialogTools.setFontSizeSetCallBack(new IFontSizeSetCallBack() {
// @Override
// public void onFontSizeSet(String type) {
// // 1、小 2、标准 3、大 4、特大
// 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(mWebView,jsonObject);
}
/**
* 输入弹出框
*/
private void showInputCommentDialog(int position) {
//显示评论信息
sheetDialog.setInitData(transparentBean);
sheetDialog.setBottomCommentIcon(transparentBean);
if(functionBar != null){
sheetDialog.setCommentNum(functionBar.getCommentNum()+"");
}
sheetDialog.show();
}
/**
* 弹出评论弹出框
*/
private void openComment() {
if(transparentBean == null){
return;
}
int visitorComment = transparentBean.getVisitorComment();
if (visitorComment == 0 && !PDUtils.isLogin()) {
//游客评论开关未开且未登录
ProcessUtils.toOneKeyLoginActivity();
return;
}
CommentCommitDialog commitDialog = new CommentCommitDialog(mActivity);
// 2023/11/3 设置评论发布点击埋点数据
if (transparentBean != null) {
TrackContentBean trackContentBean = makeTrackContentBean();
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(ResUtils.getString(R.string.res_comment_no_input_tips));
return;
}
if (null != sheetDialog) {
sheetDialog.setInput(transparentBean);
if(functionBar != null){
sheetDialog.setCommentNum(functionBar.getCommentNum()+"");
}
//发布评论,3是带定制表情,或定制表情+文字,2是普通表情,或普通表情+文字
if(StringUtils.isEmpty(gifUrl)) {
sheetDialog.submitComment(text.trim(), "2", "", -1);
}else{
sheetDialog.submitComment(text.trim(), "3", gifUrl, -1);
}
}
}
@Override
public void getUnloadImg(ArrayList<String> images) {
}
});
commitDialog.showDefaultHint(transparentBean.getBestNoticer());
}
/**
* livedata监听
*/
private void receiveLiveDataMsg() {
//登录成功
LiveDataBus.getInstance().with(EventConstants.USER_ALREADY_LOGIN, Boolean.class).observe(this, aBoolean -> {
if (aBoolean) {
JSBridgeUtils.jsCall_appNotifyEvent(mWebView, AppNotifyEventConstant.EVENT_ONE);
// queryLikeAndCollectStatus();
if (functionBar != null) {
functionBar.setContentAndType(transparentBean);
}
}
});
//接收关注事件
LiveDataBus.getInstance().with(EventConstants.FRESH_FOLLOW_CREATOR_EVENT,
EventMessage.class).observe(this, mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != mWebView) {
// 同步关注信息
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(mWebView,jsonObject);
}
});
//接收点赞事件
LiveDataBus.getInstance().with(EventConstants.FRESH_ZAN_CREATOR_EVENT,
EventMessage.class).observe(this, mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != mWebView ) {
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(mWebView,jsonObject);
}
});
}
/**
* 设置获取数据后的livedata监听
*/
private void setGetDataLiveDataMsg() {
if (topicInfoBean == null) {
return;
}
//收藏
LiveDataBus.getInstance().with(EventConstants.COMMNET_FAV + topicInfoBean.getTopicId(),
String.class).observe(this, s -> {
functionBar.collectIcon("1".equals(s));
});
//评论个数
LiveDataBus.getInstance().with(EventConstants.COMMENT_NUM, EventMessage.class).
observe(this, mEventMessage -> {
if (functionBar == null) {
return;
}
if (topicInfoBean == null) {
return;
}
if (mEventMessage == null) {
return;
}
String contentId_new = mEventMessage.getStringExtra(IntentConstants.CONTENT_ID);
String contentType_new = mEventMessage.getStringExtra(IntentConstants.CONTENT_TYPE);
String num = mEventMessage.getStringExtra(IntentConstants.COMMENT_NUM);
if (StringUtils.isEmpty(num)) {
return;
}
if (StringUtils.isEqual(contentId_new, topicInfoBean.getTopicId()) &&
StringUtils.isEqual(contentType_new, ContentTypeConstant.URL_TYPE_FIVE + "")) {
functionBar.setCommentNum(num);
}
});
}
/**
* 监听网络
*/
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 (networkFirst) {
networkFirst = false;
return;
}
if (msg == null) {
return;
}
JSBridgeUtils.jsCall_appNetworkStatusChangedEvent(mWebView);
}
});
}
/**
* 初始化webview
*/
private void initWeb() {
mWebView.setGson(new Gson());
mWebView.setWebChromeClient(new WebChromeClient() {
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType, String capture) {
this.openFileChooser(uploadMsg);
}
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType) {
this.openFileChooser(uploadMsg);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
return true;
}
@Override
public void onProgressChanged(WebView view, int newProgress) {
// NBSWebChromeClient.initJSMonitor(view, newProgress);
super.onProgressChanged(view, newProgress);
}
});
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
webViewLoad = true;
// Log.d(TAG, "onPageStarted time=" + System.currentTimeMillis());
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if(view.getProgress() == 100) {
stopLoading();
stopLoadingTag = true;
}
// Log.d(TAG, "onPageFinished time=" + System.currentTimeMillis());
if (webViewLoad) {
if (mWebView != null && mWebView.getVisibility() == View.GONE) {
mWebView.setVisibility(View.VISIBLE);
}
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.startsWith("http")) {
try {
//处理唤端
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (request.getUrl().toString().endsWith(".apk")) {
return;
}
if (request.isForMainFrame()) {
/**
* webview加载异常时 webViewLoad设置为false,隐藏webview 避免显示x5系统默认网络错误页面,显示自定义断网/网络不给力页面
*/
webViewLoad = false;
stopLoading();
mWebView.setVisibility(View.GONE);
//展示缺省页
int type = DefaultViewConstant.TYPE_GET_CONTENT_ERROR;
if (!NetworkUtil.isNetAvailable()) {
type = DefaultViewConstant.TYPE_NO_NETWORK;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if(error != null && error.getErrorCode() == ERROR_TIMEOUT){
type = DefaultViewConstant.TYPE_NO_NETWORK;
}
}
showDefaultView(defaultView, type);
defaultView.setVisibility(View.VISIBLE);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return;
}
if (failingUrl.endsWith(".apk")) {
return;
}
/**
* webview加载异常时 webViewLoad设置为false,隐藏webview 避免显示系统默认网络错误页面,显示自定义断网/网络不给力页面
*/
webViewLoad = false;
stopLoading();
mWebView.setVisibility(View.GONE);
//展示缺省页
int type = DefaultViewConstant.TYPE_GET_CONTENT_ERROR;
if (!NetworkUtil.isNetAvailable()) {
type = DefaultViewConstant.TYPE_NO_NETWORK;
}
if(errorCode == ERROR_TIMEOUT){
type = DefaultViewConstant.TYPE_NO_NETWORK;
}
showDefaultView(defaultView, type);
defaultView.setVisibility(View.VISIBLE);
}
});
//设置下载监听
mWebView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
//进行下载处理,跳转浏览器或者调用系统下载方法
try {
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
});
//H5白名单控制JS交互
if (H5JsApiPermissionUtil.getInstance().isAppWhiteHostForJs(webUrl)){
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.addJavascriptInterface(new BridgeJavascriptInterface(mWebView.getCallbacks(), mWebView, callBackHandler), "WebViewJavascriptBridge");
}else {
mWebView.getSettings().setJavaScriptEnabled(false);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
}
mWebView.loadUrl(webUrl);
mWebView.postDelayed(new Runnable() {
@Override
public void run() {
//延迟200ms,且没有关闭,展示loading
if(!stopLoadingTag){
startLoading();
startLoading(false);
}
}
},200);
}
@Override
protected void initViewModel() {
articleDetailViewModel = new ArticleDetailViewModel();
articleDetailViewModel.observerDataListener(this, new IArticleDetailDataListener() {
@Override
public void onDetailDataSuccess(String dataList) {
}
@Override
public void onDetailDataError(String errorMsg) {
}
@Override
public void onPageDataSuccess(String url, String dataList, String callbackId) {
sendPageDataToH5("0", dataList, callbackId);
}
@Override
public void onPageDataError(String errorMsg, String callbackId) {
sendPageDataToH5("1", "", callbackId);
}
@Override
public void onGetNewsDetailSuccess(List<NewsDetailBean> newsDetailBeanList) {
}
@Override
public void onGetNewsDetailFailed(String error) {
}
@Override
public void onGetRecListSuccess(List<ContentBean> operDataList) {
}
@Override
public void onGetRecListFailed(String error) {
}
});
//初始化评论
initComment();
}
/**
* 初始化评论
*/
private void initComment() {
//评论相关
//默认不展示评论
functionBar.closeComment();
//默认不展示点赞
functionBar.closeLike();
//默认不展示收藏
functionBar.closeCollect();
//默认不展示分享
functionBar.closeShare();
commentViewModel = getViewModel(CommentViewModel.class);
sheetDialog = new CommentSheetDialog(this).builder(true);
sheetDialog.setViewModel(commentViewModel);
sheetDialog.setDialogHeight(UiUtils.dp2px(550));
sheetDialog.setShareBack(new CommentSheetDialog.ShareBack() {
@Override
public void doShare() {
goShare();
}
});
setCommentListener();
}
/**
* 接口回调
*/
private void setCommentListener() {
commentViewModel.observeCommentListener(this, new ICommentDataNewListener() {
/**
*获取数据成功
*/
@Override
public void onGetCommentListSuccess(CommentListBean commentList) {
sheetDialog.setCommentData(commentList);
}
/**
* 获取数据失败
*/
@Override
public void onGetCommentListFail(int code, String msg) {
sheetDialog.onGetCommentListFail(code, msg);
}
/**
*获取二级数据成功
*/
@Override
public void onGetSecondCommentListSuccess(int position, CommentListBean childCommentList) {
sheetDialog.onGetSecondCommentListSuccess(position, childCommentList);
}
/**
*获取二级数据失败
*/
@Override
public void onGetSecondCommentListFail() {
sheetDialog.onGetSecondCommentListFail();
}
/**
*发布数据成功
*/
@Override
public void onSubmitPushCommentSuccess(CommentItem pushListBean, int position, String msg) {
sheetDialog.submitCommentSuccess(pushListBean, position, msg);
}
/**
*发布数据失败
*/
@Override
public void onSubmitPushCommentFail(int code, String msg) {
sheetDialog.onSubmitPushCommentFail(code, msg);
}
/**
* 获取号主认证信息
*/
@Override
public void onGetMastersAuthenticationListSuccess(List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
sheetDialog.setMastersAuthenticationList(masterInfoList, originalListData, freshStartIndex, listLevel);
}
/**
* 获取号主信息失败
*/
@Override
public void onGetMastersAuthenticationListFailure(String errorInfo, int listLevel) {
sheetDialog.onGetMastersAuthenticationListFailure(errorInfo, listLevel);
}
/**
* 重组所有信息
*/
@Override
public void onGetAllDataSuccess(List<CommentStatusBean> statusList, List<PersonalInfoBean> masterInfoList, List<CommentItem> originalListData, int freshStartIndex, int listLevel) {
sheetDialog.setAllList(statusList, masterInfoList, originalListData, freshStartIndex, listLevel);
}
/**
*获取所有评论状态失败
*/
@Override
public void onGetCommentStatusListFailure(String errorInfo, int listLevel) {
sheetDialog.setErrorView(listLevel);
}
/**
*删除评论
*/
@Override
public void delCommentSuccess(int freshPosition) {
sheetDialog.delCommentSuccess(freshPosition);
}
/**
* 删除评论失败
*/
@Override
public void delCommentFail(String e) {
sheetDialog.delCommentFail(e);
}
/**
* 获取单个认证
*/
@Override
public void onGetSingleMastersAuthenticationDataSuccess(PersonalInfoBean mMasterInfoBean, int freshPosition) {
sheetDialog.setSingleMastersAuthentication(mMasterInfoBean, freshPosition);
}
@Override
public void onGetLevelInfoBeanListSuccess(List<CommentItem> data, int freshStartIndex, int listLevel) {
}
});
}
/**
* 透传接口数据给h5
*
* @param netError
* @param dataList
* @param callbackId
*/
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);
mWebView.sendResponse(data, callbackId);
}
/**
* 处理js传递给APP的数据
*
* @param jsCallAppBean
*/
private 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();
}
}
/**
* 设置状态栏颜色
*
* @param statusBarMode 1深色 (黑) 2、浅色 (白色)
*/
private void setStatusBarMode(String statusBarMode) {
setStatusBarStyle(StringUtils.isEqual("2", statusBarMode) ? StatusBarStyleEnum.FULLSCREEN_LIGHT_ENUM :
StatusBarStyleEnum.FULLSCREEN_DARK_ENUM);
}
/**
* 设置底部蒙层是否展示
*
* @param subjectBottomMaskBean
*/
private void setBottomMaskShow(SubjectBottomMaskBean subjectBottomMaskBean) {
if (subjectBottomMaskBean == null) {
return;
}
String isShow = subjectBottomMaskBean.getIsShow();
if (StringUtils.isEqual("1", isShow)) {
//展示
try {
String color = subjectBottomMaskBean.getColor();
bottomMaskView.setBackgroundColor(Color.parseColor(color));
bottomMaskView.setVisibility(View.VISIBLE);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
//隐藏
bottomMaskView.setVisibility(View.GONE);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// 判断是否可以返回操作
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
goBack();
}
return false;
}
/**
* 返回逻辑
*/
private void goBack() {
if (mWebView == null) {
return;
}
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
finish();
}
}
@Override
public void retryBtnClickListener() {
super.retryBtnClickListener();
refresh();
}
/**
* web view refresh
*/
public void refresh() {
//重新加载刷新时隐藏缺省页
hideDefaultView();
defaultView.setVisibility(View.GONE);
if (mWebView != null) {
mWebView.reload();
// startLoading();
}
}
@Override
protected void onPause() {
super.onPause();
isVisible = false;
JSBridgeUtils.jsCall_appNotifyEvent(mWebView, AppNotifyEventConstant.EVENT_TWO);
if (eggdialog != null && eggdialog.isShowing()) {
// 解决显示彩蛋时切换页面在其他页面显示问题
eggdialog.close();
easterEggsNeedHandler = true;
}
//处理挂角
clearAdView(false);
}
@Override
protected void onDestroy() {
if (callBackHandler != null) {
callBackHandler.removeCallbacksAndMessages(null);
callBackHandler = null;
}
if (mReceiver != null) {
unregisterReceiver(mReceiver);
}
if(mWebView != null){
mWebView.destroy();
mWebView = null;
}
super.onDestroy();
//页面浏览埋点
handlechannelExposureTrack();
// 根据时间顺序删除缓存文件
File cacheDir = new File (AppContext.getContext().getFilesDir().getAbsolutePath()+"/cache/web/");
long currentTimeMillis = System.currentTimeMillis();
if(cacheDir.exists()){
for (File file : cacheDir.listFiles()) {
long lastModified = file.lastModified();
if ((currentTimeMillis - lastModified) >= TimeUnit.DAYS.toMillis(3)) {
file.delete();
}
}
}
}
@Override
protected void onResume() {
super.onResume();
JSBridgeUtils.jsCall_appNotifyEvent(mWebView,AppNotifyEventConstant.EVENT_ONE);
isVisible = true;
//处理彩蛋
if (easterEggsNeedHandler) {
handlerPopUps();
}
//处理挂角
advLogic(true);
}
/**
* 彩蛋回调
*/
private void addEasterEggsCallBack() {
LiveDataBus.getInstance().with(EventConstants.EASTER_EGGS_DIALOG, PopUpsBean.class).observe(this, result -> {
if (easterEggsNeedHandler) {
handlerPopUps();
}
});
}
/**
* 处理彩蛋
*/
private void handlerPopUps() {
if (mPageBean == null) {
return;
}
PopUpsBean popUpsBean =
PopUpsUtils.handlerPopUps(mPageBean.isHasPopUp(), mPageBean.getPopUps(), SpUtils.POPUP_PAGE);
if (popUpsBean == null) {
return;
}
easterEggsNeedHandler = true;
if (isVisible && StringUtils.isEqual("0", Constants.easterEggsCanShow)) {
easterEggsNeedHandler = false;
// 展示彩蛋
showEasterEggsDialog(popUpsBean);
}
}
/**
* 显示彩蛋
*/
private void showEasterEggsDialog(PopUpsBean popUpsBean) {
if (showPopUpsBean != null && eggdialog != null && eggdialog.isShowing()) {
if (showPopUpsBean.getId().equals(popUpsBean.getId())) {
return;
}
}
//彩蛋曝光埋点
// AdvsTrack.easterEggsContentTrack(0, mPageBean, popUpsBean);
showPopUpsBean = popUpsBean;
Constants.isShowingEasterEggs = true;
eggdialog = PopUpsUtils.showEasterEggsDialog(mContext, popUpsBean, SpUtils.POPUP_PAGE,
new EasterEggsDialog.DialogClickListener() {
@Override
public void onJump() {
Constants.isShowingEasterEggs = false;
//彩蛋点击埋点
// AdvsTrack.easterEggsContentTrack(1, mPageBean, popUpsBean);
PopUpsUtils.easterEggsDialogJump(popUpsBean);
}
@Override
public void onClose() {
Constants.isShowingEasterEggs = false;
}
});
}
/**
* 调用挂角广告逻辑
*/
private void advLogic(boolean isResume) {
if (!isVisible) {
return;
}
if (cornerAdvLogic != null) {
if (getWindow() != null) {
Window window = getWindow();
cornerAdvLogic.setDragViewType(0);
cornerAdvLogic.handlerAdLogic(this, mPageBean, false, window,
isResume);
}
}
}
/**
* 清理挂角广告
*/
private void clearAdView(boolean clearLocalData) {
if (cornerAdvLogic != null) {
cornerAdvLogic.removeAllDragView(clearLocalData);
}
}
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
}
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
if(refreshLayout != null){
refreshLayout.finishRefresh();
}
}
/**
* 埋点页面浏览
*/
private void handlechannelExposureTrack(){
if(topicInfoBean == null){
return;
}
//埋点:页面浏览
TrackContentBean trackContentBean = new TrackContentBean();
topicInfoBean.linkUrl = webUrl;
trackContentBean.topicInfoBeanBeantoBean(topicInfoBean);
trackContentBean.setExposure(duration);
//推荐数据设置
if(traceBean != null) {
trackContentBean.setTraceBean(traceBean);
}
// CommonTrack.getInstance().channelExposureTrack(trackContentBean);
}
}