ColumnFragment.java
62.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
/*
* Copyright (c) People Technologies Co., Ltd. 2019-2022. All rights reserved.
*/
package com.wd.capability.layout.fragment;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;
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.layout.R;
import com.wd.foundation.wdkit.adv.CornerAdvLogic;
import com.wd.capability.layout.comp.layoutdata.AbsGroup;
import com.wd.capability.layout.comp.layoutdata.Group;
import com.wd.capability.layout.comp.layoutdata.Page;
import com.wd.capability.layout.comp.layoutmanager.BaseAdapter;
import com.wd.capability.layout.comp.layoutmanager.ILayoutRender;
import com.wd.capability.layout.comp.layoutmanager.ItemLayoutManager;
import com.wd.capability.layout.comp.layoutmanager.LayoutAdapter;
import com.wd.capability.layout.listener.ColumnFragmentCallback;
import com.wd.capability.layout.page.model.CompLogicDataBean;
import com.wd.capability.layout.page.vm.IPageDataStreamListener;
import com.wd.capability.layout.page.vm.PageViewModel;
import com.wd.capability.layout.ui.channel.listener.PageInforToLayoutManagerCallback;
import com.wd.capability.layout.ui.widget.ColumnRecyclerView;
import com.wd.capability.layout.ui.widget.VerticalLoadScrollListener;
import com.wd.capability.layout.ui.widget.itemhelp.ItemStateChangeListener;
import com.wd.capability.layout.ui.widget.progress.SkeletonLoadingView;
import com.wd.capability.layout.uitls.CompentLogicUtil;
import com.wd.foundation.wdkit.constant.Constants;
import com.wd.foundation.wdkit.constant.IntentConstants;
import com.wd.capability.network.utils.NetworkUtil;
import com.wd.foundation.wdkit.constant.DefaultViewConstant;
import com.wd.foundation.wdkit.constant.EventConstants;
import com.wd.foundation.wdkit.decoration.Decoration;
import com.wd.foundation.wdkit.dialog.EasterEggsDialog;
import com.wd.foundation.wdkit.base.fragment.BaseAutoLazyFragment;
import com.wd.foundation.wdkit.dialog.PopUpsUtils;
import com.wd.foundation.wdkit.utils.GrayManager;
import com.wd.foundation.wdkit.view.CommomLoadMoreFooter;
import com.wd.foundation.wdkit.view.CommonRefreshHeader;
import com.wd.foundation.wdkit.view.CustomSmartRefreshLayout;
import com.wd.foundation.wdkit.view.DefaultView;
import com.wd.foundation.bean.custom.comp.ChannelInfoBean;
import com.wd.foundation.bean.custom.comp.CompBean;
import com.wd.foundation.bean.custom.comp.PageBean;
import com.wd.foundation.bean.custom.comp.TopicInfoBean;
import com.wd.foundation.bean.custom.content.ContentBean;
import com.wd.foundation.bean.custom.content.ContentTypeConstant;
import com.wd.foundation.bean.livedate.EventMessage;
import com.wd.foundation.bean.pop.PopUpsBean;
import com.wd.foundation.bean.theme.ThemeMessage;
import com.wd.foundation.wdkit.system.DeviceUtil;
import com.wd.foundation.wdkit.utils.SafeBundleUtil;
import com.wd.foundation.wdkit.utils.SpUtils;
import com.wd.foundation.wdkit.utils.UiUtils;
import com.wd.foundation.wdkitcore.livedata.LiveDataBus;
import com.wd.foundation.wdkitcore.thread.ThreadPoolUtils;
import com.wd.foundation.wdkitcore.tools.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* 栏目、专题fragment<BR>
* 除了个别特殊样式,基本和channelFragment一致
*
* @author zhangbo
* @version [V1.0.0, 2022/5/28]
* @since V1.0.0
*/
public class ColumnFragment extends BaseAutoLazyFragment implements OnRefreshLoadMoreListener {
private static final String TAG = "ColumnFragment";
/**
* 父根布局
*/
private ViewGroup superRootLayout;
private CustomSmartRefreshLayout refreshLayout;
private CommonRefreshHeader refreshHeader;
private CommomLoadMoreFooter footView;
private ColumnRecyclerView mRecyclerView;
private VerticalLoadScrollListener aheadLoadScrollListener;
private ILayoutRender layoutRender;
private PageViewModel mViewModel;
private Page mPage;
/**
* 当前页数据
*/
private PageBean mPageBean;
/**
* 透传进来的页面数据
*/
private PageBean pageInforBean;
/**
* 页面请求接口次数,累积统计,下拉是从1开始
*/
private int requestTime = 1;
// 页面是否展示了底线
private boolean haveBottomLine = false;
/**
* 此页码调用相关接口需要的入参对象
*/
private CompLogicDataBean compLogicDataBean;
/**
* 页面所在的tab id
*/
private String oneTabChannelId = "";
/**
* 频道策略:1-推荐; 2-时间线
*/
public int channelStrategy;
/**
* 默认选中频道
*/
private boolean isDefaultShowChannel = false;
/**
* 信息流页面容器
*/
private FrameLayout contentFrameLayout;
/**
* 缺省页
*/
private DefaultView defaultView;
/**
* 挂角广告操作对象
*/
private CornerAdvLogic cornerAdvLogic;
private FrameLayout mFrameLayout;
private PageInforToLayoutManagerCallback mTabChangeListener;
private ColumnFragmentCallback columnFragmentCallback;
private SkeletonLoadingView skeletonLoadingView;
/**
* recyclerview背景
*/
protected View viewBg;
/**
* 背景是否隐藏了
*/
boolean isBgHide = true;
/**
* fragment 主题配置色
*/
private ThemeMessage themeMessage;
/**
* 页面是否已经有数据显示
*/
private boolean isHashLoadDataInPage = false;
/**
* fragment是否可见
*/
private boolean isFragmentVisible = false;
/**
* fragment 开启RefreshLayout 下拉
*/
private boolean openRefreshEnable = true;
/**
* 是否需要处理彩蛋数据
*/
private boolean easterEggsNeedHandler = false;
/**
* 已经展示过的bean
*/
private PopUpsBean showPopUpsBean;
/**
* 彩蛋弹窗
*/
private EasterEggsDialog eggdialog;
private boolean loginStatus = false;
/**
* 创建是否来自新闻页面
*/
private boolean isFromHome = false;
/**
* 首次处理挂角
*/
private boolean dragViewFirstTag = true;
/**
* 点击重试是否需求调onRefresh
*/
private boolean retryNeedRefresh = false;
/**
* 获取Fragment实例对象
*
* @return Fragment实例
*/
public static ColumnFragment newInstance() {
return new ColumnFragment();
}
/**
* 获取Fragment实例对象
*
* @param pageId 数据id
* @return Fragment实例
*/
public static ColumnFragment newInstance(String pageId) {
ColumnFragment fragment = new ColumnFragment();
Bundle bundle = new Bundle();
bundle.putString(IntentConstants.PARAM_PAGE_ID, pageId);
fragment.setArguments(bundle);
return fragment;
}
/**
* @param pageId 页面id
* @param enableRefreshFlag 页面下拉动画 :false:关闭使用RefreshLayout
* @return
*/
public static ColumnFragment newInstance(String pageId, boolean enableRefreshFlag, int objectType, PageBean pageBean) {
ColumnFragment fragment = new ColumnFragment();
Bundle bundle = new Bundle();
bundle.putString(IntentConstants.PARAM_PAGE_ID, pageId);
bundle.putBoolean(IntentConstants.PARAM_OPENREFRESHLAYOUT, enableRefreshFlag);
bundle.putInt(IntentConstants.PAGE_TYPE, objectType);
bundle.putSerializable(IntentConstants.PAGE_INFOR_DATA, pageBean);
fragment.setArguments(bundle);
return fragment;
}
/**
* @param pageId 页面id
* @return
*/
public static ColumnFragment newInstance(String pageId, int objectType, PageBean pageBean) {
ColumnFragment fragment = new ColumnFragment();
Bundle bundle = new Bundle();
bundle.putString(IntentConstants.PARAM_PAGE_ID, pageId);
bundle.putInt(IntentConstants.PAGE_TYPE, objectType);
bundle.putSerializable(IntentConstants.PAGE_INFOR_DATA, pageBean);
fragment.setArguments(bundle);
return fragment;
}
/**
* @param pageId 频道页面id
* @param channelId 所有频道页面所在id
* @param topMarginInt
* @param grayFlag 国殇开关
* @return
*/
public static ColumnFragment newInstance(String pageId, String channelId, int topMarginInt, boolean grayFlag) {
ColumnFragment fragment = new ColumnFragment();
Bundle bundle = new Bundle();
bundle.putString(IntentConstants.PARAM_PAGE_ID, pageId);
bundle.putString(IntentConstants.PARAM_CHANNEL_ID, channelId);
bundle.putInt(IntentConstants.PARAM_TOPMARGININT, topMarginInt);
bundle.putBoolean(IntentConstants.PARAM_COUNTRY_GRAY, grayFlag);
fragment.setArguments(bundle);
return fragment;
}
/**
* @param pageId 频道页面id
* @param channelId 所有频道页面所在id
* @param topMarginInt
* @param grayFlag 国殇开关
* @param dropDownAnimationColor 1白色,2灰色。
* @return
*/
public static ColumnFragment newInstance(String pageId, String channelId, int topMarginInt,
boolean grayFlag, boolean fromHome, int dropDownAnimationColor,
int channelStrategy) {
ColumnFragment fragment = new ColumnFragment();
Bundle bundle = new Bundle();
bundle.putString(IntentConstants.PARAM_PAGE_ID, pageId);
bundle.putString(IntentConstants.PARAM_CHANNEL_ID, channelId);
bundle.putInt(IntentConstants.PARAM_TOPMARGININT, topMarginInt);
bundle.putInt("dropDownAnimationColor", dropDownAnimationColor);
bundle.putBoolean(IntentConstants.PARAM_COUNTRY_GRAY, grayFlag);
bundle.putBoolean(IntentConstants.PARAM_FROM_HOME, fromHome);
bundle.putInt(IntentConstants.PARAM_CHANNEL_STRATEGY, channelStrategy);
fragment.setArguments(bundle);
return fragment;
}
@Override
protected String getLogTag() {
return TAG;
}
@Deprecated
@Override
protected int getLayout() {
return 0;
}
@Override
protected View getJavaLayout() {
mFrameLayout = new FrameLayout(activity);
mFrameLayout.setBackgroundColor(0x00FFFFFF);
FrameLayout.LayoutParams params = null;
//刷新框架
refreshLayout = (CustomSmartRefreshLayout) LayoutInflater.from(activity).inflate(R.layout.page_layout_smartrefreshlayout, null);
FrameLayout pFrameLayout = getSubLayout();
refreshLayout.addView(pFrameLayout);
mFrameLayout.addView(refreshLayout);
//ViewStub
// params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
// ViewStub view_stub_special_view = new ViewStub(activity);
// view_stub_special_view.setLayoutParams(params);
// mFrameLayout.addView(view_stub_special_view);
// view_stub_special_view.setLayoutResource(R.layout.custom_layout_special_view);
//PageLoadingView
params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
skeletonLoadingView = new SkeletonLoadingView(activity);
skeletonLoadingView.setLayoutParams(params);
skeletonLoadingView.setVisibility(View.VISIBLE);
mFrameLayout.addView(skeletonLoadingView);
return mFrameLayout;
}
private FrameLayout getSubLayout() {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
contentFrameLayout = new FrameLayout(activity);
contentFrameLayout.setLayoutParams(params);
viewBg = new View(activity);
viewBg.setAlpha(0);
viewBg.setBackgroundColor(ContextCompat.getColor(activity, R.color.res_color_common_C8));
contentFrameLayout.addView(viewBg);
mRecyclerView = (ColumnRecyclerView) LayoutInflater.from(activity).inflate(R.layout.page_layout_columnrecyclerview, null);
contentFrameLayout.addView(mRecyclerView);
if (getArguments().containsKey(IntentConstants.PARAM_OPENREFRESHLAYOUT)) {
openRefreshEnable = SafeBundleUtil.getBoolean(getArguments(), IntentConstants.PARAM_OPENREFRESHLAYOUT);
}
setRecyclerViewAttribute();
//DefaultView
FrameLayout.LayoutParams defaultViewLp = new FrameLayout.LayoutParams(DeviceUtil.getDeviceWidth(), DeviceUtil.getDeviceHeight());
defaultView = new DefaultView(activity, openRefreshEnable ? false : true);
defaultView.setTopViewWeight(120);
defaultView.setLayoutParams(defaultViewLp);
FrameLayout pContent = new FrameLayout(activity);
pContent.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
pContent.addView(defaultView);
pContent.addView(contentFrameLayout);
return pContent;
}
/**
* 自动刷
*/
@Override
public void clickTabAutoRefresh() {
if (mRecyclerView != null) {
// 滚动到顶部
if (mRecyclerView.canScrollVertically(-1)) {
//mRecyclerView.smoothScrollToPosition(0);
mRecyclerView.scrollToPosition(0);
}
}
// 隐藏缺省页
hideDefaultView();
// 下拉刷新
if (refreshLayout != null) {
if (!refreshLayout.isRefreshing()) {
refreshLayout.autoRefresh();
}
}
}
@Override
protected void initView(View rootView) {
cornerAdvLogic = new CornerAdvLogic(activity);
clearAdView(true);
// 添加彩蛋回调
addEasterEggsCallBack();
}
/**
* 接收处理登录登出后的逻辑
*
* @param isLogin
*/
public void handlerLoginLogic(Boolean isLogin) {
if (isHashLoadDataInPage) {
if (mRecyclerView.canScrollVertically(-1)) {
//mRecyclerView.smoothScrollToPosition(0);
mRecyclerView.scrollToPosition(0);
}
loginStatus = true;
}
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
oneTabChannelId = SafeBundleUtil.getString(getArguments(), IntentConstants.PARAM_CHANNEL_ID, "");
mPageId = SafeBundleUtil.getString(getArguments(), IntentConstants.PARAM_PAGE_ID, "");
if (getArguments().containsKey(IntentConstants.PAGE_INFOR_DATA)) {
pageInforBean = (PageBean) SafeBundleUtil.getSerializable(getArguments(), IntentConstants.PAGE_INFOR_DATA);
if(pageInforBean != null && pageInforBean.getTopicInfo() != null &&
ContentTypeConstant.SUBJECT_TOPICTYPE_25 == pageInforBean.getTopicInfo().
getTopicType()){
//早晚报
if(defaultView != null){
defaultView.setTopViewWeight(20);
}
retryNeedRefresh = true;
}
}
if (getArguments().containsKey(IntentConstants.PARAM_COUNTRY_GRAY)) {
contryGrayFlag = SafeBundleUtil.getBoolean(getArguments(), IntentConstants.PARAM_COUNTRY_GRAY);
}
if (getArguments().containsKey(IntentConstants.PARAM_FROM_HOME)) {
isFromHome = SafeBundleUtil.getBoolean(getArguments(), IntentConstants.PARAM_FROM_HOME);
}
if (getArguments().containsKey(IntentConstants.PAGE_TYPE)) {
objectType = SafeBundleUtil.getInt(getArguments(), IntentConstants.PAGE_TYPE, 0);
}
/**
* 时间线、推荐频道
*/
if (getArguments().containsKey(IntentConstants.PARAM_CHANNEL_STRATEGY)) {
channelStrategy = SafeBundleUtil.getInt(getArguments(), IntentConstants.PARAM_CHANNEL_STRATEGY,0);
}
addHeadFootViewRF();
initViewModel();
int topMarginInt = SafeBundleUtil.getInt(getArguments(), IntentConstants.PARAM_TOPMARGININT, 0);
if (topMarginInt != 0) {
mFrameLayout.setPadding(0, topMarginInt, 0, 0);
}
registerBus();
}
/**
* 注册LiveBus
*/
private void registerBus() {
// 接收删除稿件事件
LiveDataBus.getInstance().with(EventConstants.USER_COMP_MANUSCRIPT_DEL + mPageId, Integer.class).observe(getViewLifecycleOwner(), hashcode -> {
if (layoutRender != null) {
layoutRender.itemRemovedByLayoutManagerHashCode(hashcode);
}
});
//接受关注事件
LiveDataBus.getInstance().with(EventConstants.FRESH_FOLLOW_CREATOR_EVENT, EventMessage.class).observe(getViewLifecycleOwner(), mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
// 同步关注信息
List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
CompentLogicUtil.updateUserFollowInforLayout(mEventMessage, layoutManagers);
}
});
// 关注和取消关注接口返回失败事件
LiveDataBus.getInstance()
.with(EventConstants.FRESH_FOLLOW_CREATOR_ERROR_EVENT, EventMessage.class)
.observe(getViewLifecycleOwner(), new Observer<EventMessage>() {
@Override
public void onChanged(EventMessage mEventMessage) {
if (mEventMessage == null) {
return;
}
if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
// 同步关注信息
List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
CompentLogicUtil.updateUserFollowFail(mEventMessage, layoutManagers);
}
}
});
//接受点赞事件
LiveDataBus.getInstance().with(EventConstants.FRESH_ZAN_CREATOR_EVENT, EventMessage.class).observe(getViewLifecycleOwner(), mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
// 同步关注信息
List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
CompentLogicUtil.updateUserZanInforLayout(mEventMessage, layoutManagers);
}
});
//接受预约状态事件
LiveDataBus.getInstance().with(EventConstants.FRESH_APPONINTMENT_STATUS_EVENT, EventMessage.class).observe(getViewLifecycleOwner(), mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
// 同步关注信息
List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
CompentLogicUtil.updateCompLiveAppointStatus(mEventMessage, layoutManagers);
}
});
//刷新直播人数事件
LiveDataBus.getInstance().with(EventConstants.REFRESH_LIVE_PV, EventMessage.class).observe(getViewLifecycleOwner(), mEventMessage -> {
if (mEventMessage == null) {
return;
}
if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
// 同步关注信息
List<ItemLayoutManager> layoutManagers = layoutRender.getAllSectionLayoutManager();
CompentLogicUtil.updateCompLivePV(mEventMessage, layoutManagers);
}
});
//设置文字大小发消息通知刷新
LiveDataBus.getInstance().with(EventConstants.FONT_SIZE_SET_SUCCESS, Boolean.class).observe(getViewLifecycleOwner(), aBoolean -> {
if (aBoolean) {
if (null != mRecyclerView && null != mRecyclerView.getAdapter()) {
mRecyclerView.getAdapter().notifyDataSetChanged();
}
}
});
//启动页结束监听
LiveDataBus.getInstance().with(EventConstants.WELCOME_END, Boolean.class).observe(getViewLifecycleOwner(), isEnd -> {
if (isEnd) {
//处理挂角
advLogic(false);
}
});
}
boolean openTip = false;
/**
* 初始化 ViewModel
*/
private void initViewModel() {
mViewModel = getViewModelThis(PageViewModel.class);
mViewModel.observeChannelListener(this, iPageDataStreamListener);
mViewModel.release();
}
private IPageDataStreamListener iPageDataStreamListener = new IPageDataStreamListener() {
@Override
public void onPageInforSuccess(PageBean data) {
mPageBean = data;
postThemeMessage();
}
@Override
public void onPageDataSuccess(Page page, PageBean data) {
// Logger.t(TAG).w("onPageDataSuccess ");
mPage = page;
mPageBean = data;
if (mPageBean != null) {
mPageBean.setLevel1ChannelId(oneTabChannelId);
}
//隐藏loading
hidePageLoadingView();
hideLoading(openTip);
if(mPageBean.totalCompSize > 0){
hideDefaultView();
}
// pageinfor 访问成功,group无数值
if (page == null && !isHashLoadDataInPage) {
//显示过数据不替换成错误页面
showDefaultView(DefaultViewConstant.TYPE_NO_CONTENT);
// 背景主题
initBackground();
// 专题顶部配置信息
handlerTopicInfo();
// 处理频道信息
handlerChannelInfor();
return;
}
if (aheadLoadScrollListener != null) {
aheadLoadScrollListener.setDataSize(mPageBean.totalCompSize);
}
// Log.e("DDDDSSS", mPageBean.getName() + " requestTime=" + requestTime + " isLocalCache =" + mPageBean.isLocalCache +
// " needRefresh =" + data.needRefresh + " moreRefresh=" + data.moreRefresh+ " pageInforRefresh=" + data.pageInforRefresh);
// pageinfor 访问成功,group有业务 数据
if (mPageBean.isLocalCache || mPageBean.needRefresh) {
isHashLoadDataInPage = true;
compLogicDataBean.tipFlag = true;
// 绘制页面
doPageDataSuccess();
} else if (layoutRender != null && data.moreRefresh) {
// 加载更多组件
List<ItemLayoutManager> layoutManagerList = layoutRender.getAllSectionLayoutManager();
// 页面缓存数据量
int startIndex = layoutManagerList.size();
// 渲染页面
layoutRender.renderPage(page, false);
// 检测是否满足加载更多
boolean isLoadMore = checkOpenLoadMoreAction(false);
if (!isLoadMore) {
if (!haveBottomLine) {
layoutRender.addBaseLine(mPage);
haveBottomLine = true;
}
} else {
haveBottomLine = false;
}
List<ItemLayoutManager> newList = layoutRender.getAllSectionLayoutManager();
// 页面新数据量
int size = newList.size();
if (size > startIndex) {
int endIndex = size - startIndex;
BaseAdapter baseAdapter = (BaseAdapter) layoutRender;
baseAdapter.notifyItemRangeChanged(startIndex, endIndex);
} else {
layoutRender.notifyDataSetChanged();
}
} else if (!mPageBean.isLocalCache || !data.needRefresh) {
// 检测是否满足加载更多
checkOpenLoadMoreAction(requestTime == 1);
}
// 下拉刷新中,检查到无需要重新更新页面,请清理上次下拉更新后操作加载更多产生的数据
if (requestTime == 1 && !mPageBean.isLocalCache && !data.needRefresh && layoutRender != null) {
List<ItemLayoutManager> cacheLayoutManagerList = layoutRender.getAllSectionLayoutManager();
// 页面中layoutmanager的数据量
int chacheLayoutManangerSize = cacheLayoutManagerList.size();
// 下拉刷接口提供的数据量生成的comp组件集合的数据量
if (mPage.getGroups() != null && mPage.getGroups().size() > 0) {
int totalSectionsNum = 0;
for (AbsGroup absGroup : mPage.getGroups()) {
Group groupBean = (Group) absGroup;
totalSectionsNum = totalSectionsNum + groupBean.getSections().size();
}
if (chacheLayoutManangerSize > totalSectionsNum) {
// Log.e("DDDDSSS", " 页面缓存数据量 size =" + chacheLayoutManangerSize + " totalSectionsNum=" + totalSectionsNum);
int startIndex = totalSectionsNum;
int count = chacheLayoutManangerSize - totalSectionsNum;
layoutRender.itemRangeRemoved(startIndex, count);
haveBottomLine = false;
}
}
layoutRender.updateItemData();
}
// 页面详情接口有变化
if (mPageBean.isLocalCache || data.pageInforRefresh || data.needRefresh) {
// 背景主题
initBackground();
// 专题顶部配置信息
handlerTopicInfo();
// 处理频道信息
handlerChannelInfor();
}
if (mPageBean.isLocalCache || data.pageInforRefresh) {
// 挂角广告view
advLogic(false);
if(dragViewFirstTag && !mPageBean.isLocalCache){
//首次进入非缓存刷新了挂角,后面刷新需要刷新挂角
dragViewFirstTag = false;
}
}else {
if(!dragViewFirstTag && !data.moreRefresh){
//处理挂角广告
advLogic(false);
}else {
dragViewFirstTag = false;
}
}
//不是加载更多
if (!data.moreRefresh) {
// 彩蛋
handlerPopUps();
}
//检测是否需要开启预先加载
boolean openLoadMore = checkOpenLoadMoreAction(requestTime == 1);
// 检测到有分页数据,启用本地缓存无需要给pagenum加1
if (openLoadMore && !mPageBean.isLocalCache) {
// 添加页码
if(compLogicDataBean != null &&
StringUtils.isEqual(CompLogicDataBean.FIRST_LOAD,
compLogicDataBean.loadStrategy)){
requestTime = 2;
}else {
requestTime = requestTime + 1;
}
}
if (aheadLoadScrollListener != null) {
aheadLoadScrollListener.setOneAheadLoadMore(openLoadMore);
}
// 无业务数据并且是第一个楼层
if (mPageBean.totalCompSize == 0 && requestTime == 1) {
if (mTabChangeListener != null) {
mTabChangeListener.failedPage(DefaultViewConstant.TYPE_GET_CONTENT_ERROR);
}
showDefaultView(DefaultViewConstant.TYPE_GET_CONTENT_ERROR);
}
//缓存数据之后请求新数据
if (mPageBean.isLocalCache) {
refreshUI(false, CompLogicDataBean.FIRST_LOAD, false);
//使用缓存、并且请求了一次
requestTime = requestTime + 1;
} else {
if (aheadLoadScrollListener != null) {
aheadLoadScrollListener.setOneAheadLoadMore(true);
}
}
}
@Override
public void onPageDataFailed(int type,String error) {
Logger.t(TAG).w("onPageDataFailed, error: " + error);
clearAdView(true);
if(dragViewFirstTag){
//首次进入页面接口失败,后面刷新需要刷新挂角
dragViewFirstTag = false;
}
if (!isHashLoadDataInPage) {
//显示过数据不替换成错误页面
showDefaultView(type == 1 ? DefaultViewConstant.TYPE_NO_NETWORK :
DefaultViewConstant.TYPE_GET_CONTENT_ERROR);
if (mTabChangeListener != null) {
mTabChangeListener.failedPage(type == 1 ? DefaultViewConstant.TYPE_NO_NETWORK :
DefaultViewConstant.TYPE_GET_CONTENT_ERROR);
}
}
hidePageLoadingView();
hideLoading(false);
handlerErrorCallback();
}
@Override
public void onPageDataSetChanged() {
if (layoutRender != null) {
int startIndex = 0;
if (mPage != null) {
List<AbsGroup> list = mPage.getGroups();
for (AbsGroup group : list) {
startIndex = startIndex + group.getDisplayItemCount();
}
}
List<ItemLayoutManager> newList = layoutRender.getAllSectionLayoutManager();
// 页面中layoutmanager的数据量
int chacheLayoutManangerSize = newList.size();
// Log.e("DDDDSSS",requestTime+" startIndex="+startIndex+" chacheLayoutManangerSize="+chacheLayoutManangerSize);
for (int i = startIndex; i < chacheLayoutManangerSize; i++) {
ItemLayoutManager itemLayoutManager = newList.get(i);
itemLayoutManager.updateData(startIndex);
}
}
}
};
/**
* 调用挂角广告逻辑
*/
private void advLogic(boolean isResume) {
if (!isFragmentVisible) {
return;
}
if (!Constants.finishPageLoad) {
return;
}
if (cornerAdvLogic != null) {
/*if (superRootLayout != null) {
cornerAdvLogic.setDragViewType(1);
}
cornerAdvLogic.handlerAdLogic(mPageBean, contryGrayFlag,
superRootLayout != null ? superRootLayout : mFrameLayout);*/
if (getActivity() != null && getActivity().getWindow() != null) {
Window window = getActivity().getWindow();
cornerAdvLogic.setDragViewType(0);
cornerAdvLogic.handlerAdLogic(activity, mPageBean, contryGrayFlag, window, isResume);
}
}
}
/**
* 清理挂角广告
*/
private void clearAdView(boolean clearLocalData) {
if (cornerAdvLogic != null) {
cornerAdvLogic.removeAllDragView(clearLocalData);
}
}
/**
* 更新页面数据
*
* @param isCache 是否使用缓存
* @param loadStrategy 首次加载:loadStrategy= first_load;
* 上推刷新:loadStrategy= push_up;
* 下拉刷新:loadStrategy= pull_down
* @param loadMore
*/
private void refreshUI(boolean isCache, String loadStrategy, boolean loadMore) {
if (mViewModel == null) {
return;
}
// 接口参数对象
if (compLogicDataBean == null) {
compLogicDataBean = new CompLogicDataBean();
}
compLogicDataBean.pageInforBean = pageInforBean;
compLogicDataBean.loadStrategy = loadStrategy;
compLogicDataBean.pageId = mPageId;
compLogicDataBean.requestTime = requestTime;
compLogicDataBean.contryGrayFlag = contryGrayFlag;
compLogicDataBean.oneChannelId = oneTabChannelId;
compLogicDataBean.objectType = objectType;
compLogicDataBean.loadMore = loadMore;
compLogicDataBean.useV2 = requestUseV2(loadStrategy);
// 获取页面数据
mViewModel.getPageData(isCache, compLogicDataBean);
}
/**
* 改动 时间线频道,首次和下拉刷新都用V2接口
* @return
*/
private boolean requestUseV2(String loadStrategy){
// if (isDefaultShowChannel){
//时间线、FIRST_LOAD(首次) 或者 PULL_DOWN(下拉)使用V2
if (2 == channelStrategy){
if (CompLogicDataBean.FIRST_LOAD.equals(loadStrategy)
|| CompLogicDataBean.PULL_DOWN.equals(loadStrategy)){
return true;
}
}
// }
return false;
}
/**
* 隐藏关闭加载动效
*/
private void hidePageLoadingView() {
if (skeletonLoadingView != null) {
skeletonLoadingView.setVisibility(View.GONE);
}
}
/**
* 添加头部和底部view
*/
private void addHeadFootViewRF() {
if (refreshHeader == null) {
refreshHeader = new CommonRefreshHeader(getActivity());
refreshLayout.setRefreshHeader(refreshHeader);
int topMarginInt = SafeBundleUtil.getInt(getArguments(), "dropDownAnimationColor", 0);
if (topMarginInt == 1) {
refreshHeader.setWhiteEffectSource();
}
}
// 国殇模式
if (contryGrayFlag) {
GrayManager.getInstance().setLayerGrayType(refreshHeader);
GrayManager.getInstance().setLayerGrayType(defaultView);
}
refreshLayout.setEnableRefresh(openRefreshEnable);
refreshLayout.setOnRefreshLoadMoreListener(this);
if (footView == null) {
footView = new CommomLoadMoreFooter(getActivity());
footView.setDescTextColor(ContextCompat.getColor(getActivity(), R.color.color_93959D));
refreshLayout.setRefreshFooter(footView);
}
refreshLayout.setEnableLoadMore(false);
refreshLayout.setEnableOverScrollDrag(false);
}
/**
* 设置RecyclerView属性
*/
private void setRecyclerViewAttribute() {
mRecyclerView.setItemViewCacheSize(4);
mRecyclerView.setDrawingCacheEnabled(true);
mRecyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
// mRecyclerView.setHasFixedSize(true);
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 12, RecyclerView.VERTICAL, false);
// mRecyclerView.setOnAllowEnableLoadMoreListener(onAllowEnableLoadMoreListener);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (layoutRender.getAllSectionLayoutManager().size() == 0) {
return 0;
}
return 12 / layoutRender.getAllSectionLayoutManager().get(position).getItemSpan();
}
});
// mRecyclerView.setItemAnimator(new NoAlphaItemAnimator());
// 关闭动画,防止刷新闪烁
RecyclerView.ItemAnimator animator = mRecyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
RecyclerView.RecycledViewPool pool = new RecyclerView.RecycledViewPool();
pool.setMaxRecycledViews(0, 10);
mRecyclerView.setRecycledViewPool(pool);
mRecyclerView.getItemAnimator().setChangeDuration(0);
mRecyclerView.setLayoutManager(layoutManager);
// 设置分割线
mRecyclerView.addItemDecoration(new Decoration());
mRecyclerView.addOnScrollListener(mRvScrollListener);
// 预先加载更多
if (aheadLoadScrollListener == null) {
aheadLoadScrollListener = new VerticalLoadScrollListener(onAheadLoadListener);
mRecyclerView.addOnScrollListener(aheadLoadScrollListener);
}
aheadLoadScrollListener.setOneAheadLoadMore(false);
}
private void initCommonRecyclerView() {
// mRecyclerView.setNestedScrollingEnabled(true);
if (layoutRender != null) {
layoutRender.releaseLayoutManagers();
}
layoutRender = new LayoutAdapter();
mRecyclerView.setAdapter((BaseAdapter) layoutRender);
mRecyclerView.openGlobalLayout();
mRecyclerView.itemVisibilityHelper.attachToRecyclerView(mRecyclerView, R.id.player_container, true, RecyclerView.VERTICAL, false, new ItemStateChangeListener() {
@Override
public void onActivateItem(@NotNull View view, int position) {
super.onActivateItem(view, position);
//Log.e("DDDDSSS", "onActivateItem=" + position);
((LayoutAdapter) layoutRender).onItemVisible(position);
}
@Override
public void onDeactivateItem(@NotNull View view, int position) {
super.onDeactivateItem(view, position);
// Log.e("DDDDSSS", "onDeactivateItem=" + position);
((LayoutAdapter) layoutRender).onItemInVisible(position);
}
@Override
public void onPauseItem(@NotNull View view, int position) {
super.onPauseItem(view, position);
// Log.e("DDDDSSS", "onPauseItem=" + position);
((LayoutAdapter) layoutRender).onItemInVisible(position);
}
@Override
public void onResumeItem(@NotNull View view, int position) {
super.onResumeItem(view, position);
// Log.e("DDDDSSS", "onResumeItem=" + position);
((LayoutAdapter) layoutRender).onItemVisible(position);
}
});
}
/**
* rv滚动监听
*/
private RecyclerView.OnScrollListener mRvScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView r, int newState) {
super.onScrollStateChanged(r, newState);
// scrollCalculatorHelper.onScrollStateChanged(r, newState);
// setDragViewState(newState);
// 关闭提示
// ToastPopupUtils.closePop();
}
@Override
public void onScrolled(@NonNull RecyclerView r, int dx, int dy) {
super.onScrolled(r, dx, dy);
boolean dyBgAlpha = true;
if (mPageBean != null) {
// 早晚报专题不支持动态背景色变化
TopicInfoBean topicInfo = mPageBean.getTopicInfo();
if (topicInfo != null) {
int topicTemplate = topicInfo.getTopicType();
if (ContentTypeConstant.SUBJECT_TOPICTYPE_25 == topicTemplate) {
dyBgAlpha = false;
}
}
}
if (dyBgAlpha) {
handleBgAlpha(r);
}
}
};
@Override
public void onDestroyView() {
super.onDestroyView();
handlerPageCompLifeEvent(2);
refreshHeader = null;
footView = null;
}
/**
* 处理背景透明度变化
*/
private void handleBgAlpha(@NonNull RecyclerView r) {
if (r.computeVerticalScrollOffset() >= UiUtils.dp2px(100)) {
if (isBgHide) {
isBgHide = false;
viewBg.animate().cancel();
viewBg.animate().alpha(1).setDuration(300).start();
}
} else {
if (!isBgHide) {
isBgHide = true;
viewBg.animate().cancel();
viewBg.animate().alpha(0).setDuration(300).start();
}
}
}
/**
* 显示缺省页
*/
private void showDefaultView(int type) {
//显示错误页面都算未显示过数据
isHashLoadDataInPage = false;
if (defaultView == null) {
return;
}
contentFrameLayout.setVisibility(View.GONE);
if (!NetworkUtil.isNetAvailable()) {
type = DefaultViewConstant.TYPE_NO_NETWORK;
}
if (objectType == ContentTypeConstant.URL_TYPE_FIVE) {
} else {
defaultView.setColumnFragmentBackgroundColor();
}
defaultView.setRetryBtnClickListener(new DefaultView.RetryClickListener() {
@Override
public void onRetryClick() {
// 隐藏缺省页
hideDefaultView();
// 下拉刷新
if (refreshLayout != null) {
if (!refreshLayout.isRefreshing()) {
refreshLayout.autoRefresh();
}
}
if(retryNeedRefresh){
//早晚报没有执行onRefresh回调,再处理下
onRefresh();
}
}
});
defaultView.show(type);
if (contryGrayFlag) {
GrayManager.getInstance().setLayerGrayType(defaultView);
}
}
/**
* 隐藏缺省页
*/
private void hideDefaultView() {
if (defaultView != null) {
defaultView.hide();
}
contentFrameLayout.setVisibility(View.VISIBLE);
}
private boolean exposure = true;
/**
* 初始化页面背景
*/
protected void initBackground() {
Logger.t(TAG).d("initBackground");
if (mPageBean == null) {
return;
}
viewBg.setAlpha(0);
// 浏览埋点
// if (mPageBean != null && !TextUtils.isEmpty(oneTabChannelId) && exposure) {
// exposure = false;
// TrackContentBean bean = new TrackContentBean();
// bean.pageBeanToTrackContentBean(mPageBean);
// bean.setExposure(duration);
// CommonTrack.getInstance().channelExposureTrack(bean);
// }
}
/**
* 处理数据获取成功后续逻辑
*/
private void doPageDataSuccess() {
if (mPage == null) {
return;
}
mPage.setFragment(ColumnFragment.this);
initCommonRecyclerView();
if (layoutRender != null) {
layoutRender.renderPage(mPage, true);
//
if (mPageBean.getChannelInfo() != null) {
List<ItemLayoutManager> layoutManagerList = layoutRender.getAllSectionLayoutManager();
if (layoutManagerList.size() > 0) {
ItemLayoutManager itemLayoutManager = layoutManagerList.get(0);
itemLayoutManager.setInChannelFlag(true);
}
}
// 检测是否满足加载更多
boolean isLoadMore = checkOpenLoadMoreAction(true);
if (!isLoadMore) {
haveBottomLine = true;
layoutRender.addBaseLine(mPage);
} else {
haveBottomLine = false;
}
layoutRender.notifyDataSetChanged();
}
// 早晚报专题,添加个仿ios回弹效果
if (objectType == ContentTypeConstant.URL_TYPE_FIVE) {
if (pageInforBean != null && pageInforBean.getTopicInfo() != null) {
TopicInfoBean topicInfo = pageInforBean.getTopicInfo();
int topicTemplate = topicInfo.getTopicType();
if (ContentTypeConstant.SUBJECT_TOPICTYPE_25 == topicTemplate) {
// 早晚报专题
// OverScrollDecoratorHelper.setUpOverScroll(mRecyclerView, OverScrollDecoratorHelper.ORIENTATION_VERTICAL);
} else {
}
}
}
}
@Override
public void onPause() {
super.onPause();
Logger.t(TAG).d("onPause========>");
isFragmentVisible = false;
if (eggdialog != null && eggdialog.isShowing()) {
// 解决显示彩蛋时切换页面在其他页面显示问题
eggdialog.close();
easterEggsNeedHandler = true;
}
handlerPageCompLifeEvent(2);
//处理挂角
clearAdView(false);
}
@Override
public void onResume() {
super.onResume();
Logger.t(TAG).d("onResume========>");
isFragmentVisible = true;
handlerPageCompLifeEvent(1);
postThemeMessage();
//处理彩蛋
if (easterEggsNeedHandler) {
handlerPopUps();
}
//处理挂角
advLogic(true);
// 登录状态切换
if (loginStatus) {
loginStatus = false;
requestTime = 1;
refreshUI(true, CompLogicDataBean.FIRST_LOAD, false);
}
if(contentFrameLayout != null && contentFrameLayout.getVisibility() == View.GONE &&
NetworkUtil.isNetAvailable()){
//页面展示了缺省页,可见时需要刷新页面
clickTabAutoRefresh();
}
}
@Override
protected void lazyLoadData() {
requestTime = 1;
// 获取页面数据
requestData();
}
/**
* 发送请求数据
*/
public void requestData() {
// 获取页面数据
if (skeletonLoadingView != null) {
skeletonLoadingView.setVisibility(View.VISIBLE);
}
refreshUI(true, CompLogicDataBean.FIRST_LOAD, false);
}
@Override
public void onStop() {
Logger.t(TAG).i("onStop.");
if (getActivity() != null && getActivity().isFinishing()) {
// 释放播放器,后续如果有播放器释放慢的问题,可以考虑放在onPause里做
Logger.t(TAG).i("on onStop, release player before activity destroy.");
if (mViewModel != null) {
mViewModel.release();
}
if (refreshLayout != null) {
refreshLayout.setOnRefreshListener(null);
}
}
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
handlerPageCompLifeEvent(0);
// if (mPageBean != null) {
// TrackContentBean bean = new TrackContentBean();
// bean.pageBeanToTrackContentBean(mPageBean);
// bean.setExposure(duration);
// CommonTrack.getInstance().channelExposureTrack(bean);
// }
refreshHeader = null;
footView = null;
if (mRvScrollListener != null) {
mRecyclerView.removeOnScrollListener(mRvScrollListener);
}
if (aheadLoadScrollListener != null) {
mRecyclerView.removeOnScrollListener(aheadLoadScrollListener);
}
LiveDataBus.getInstance()
.with(EventConstants.USER_COMP_MANUSCRIPT_DEL + mPageId, Integer.class).removeObservers(this);
LiveDataBus.getInstance()
.with(EventConstants.FRESH_FOLLOW_CREATOR_EVENT, EventMessage.class).removeObservers(this);
LiveDataBus.getInstance()
.with(EventConstants.FRESH_ZAN_CREATOR_EVENT, EventMessage.class).removeObservers(this);
LiveDataBus.getInstance()
.with(EventConstants.FRESH_APPONINTMENT_STATUS_EVENT, EventMessage.class).removeObservers(this);
LiveDataBus.getInstance()
.with(EventConstants.WELCOME_END, Boolean.class).removeObservers(this);
// LiveDataBus.getInstance()
// .with(EventConstants.STOP_SCROLL, Boolean.class).removeObservers(this);
//适老化-设置文字大小
LiveDataBus.getInstance()
.with(EventConstants.FONT_SIZE_SET_SUCCESS, Boolean.class).removeObservers(this);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Logger.t(TAG).i("onKeyDown " + keyCode);
// 主要是播放器相关处理
if (mViewModel != null) {
return true;
}
if (keyCode == KeyEvent.KEYCODE_BACK && handleBackEvent(event)) {
Logger.t(TAG).i("keyCode back");
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* 处理返回按键
*
* @param event 按键
* @return 是否消费
*/
private boolean handleBackEvent(KeyEvent event) {
// 拦截返回键并退出全屏
return mViewModel != null && mViewModel.handleBackEvent(event);
}
/**
* 优先使用背景图,其次是通知切换主题颜色
*/
private void postThemeMessage() {
if (mPageBean == null) {
return;
}
if (themeMessage == null) {
themeMessage = new ThemeMessage();
}
if (mPageBean != null) {
themeMessage.setPageName(mPageBean.getName());
themeMessage.setPageId(mPageBean.getId());
themeMessage.channeId = compLogicDataBean.channelId;
// 默认使用backgroundImgUrl
themeMessage.setBackgroundImage(mPageBean.getBackgroundImgUrl());
themeMessage.setBackgroundColor(mPageBean.getBackgroundColor());
themeMessage.setLabelIsBlack(mPageBean.statusBarColorFlag());
themeMessage.setBackIconUrl(mPageBean.getBackIconUrl());
themeMessage.setShareIconUrl(mPageBean.getShareIconUrl());
// 修改顶部状态栏状态
// changePhoneStatusBarWhiteOrBlack(themeMessage.isLabelIsBlack());
}
if (mTabChangeListener != null) {
mTabChangeListener.onPageThemeChange(themeMessage);
}
}
/**
* 处理专题顶部信息
*/
private void handlerTopicInfo() {
if (mPageBean == null) {
return;
}
if (mPageBean.getTopicInfo() != null && mTabChangeListener != null) {
TopicInfoBean bean = mPageBean.getTopicInfo();
bean.setTitleName(mPageBean.getName());
bean.setLocalPageId(mPageBean.getId());
bean.setLocalPageName(mPageBean.getName());
//早晚报专题页
List<CompBean> requestLayerCompList = mPageBean.getRequestLayerCompList();
if (requestLayerCompList != null && objectType == ContentTypeConstant.URL_TYPE_FIVE) {
List<ContentBean> shareContentList = new ArrayList<>();
for (CompBean compBean : requestLayerCompList) {
if(compBean.getOperDataList() != null){
shareContentList.addAll(compBean.getOperDataList());
}
}
bean.setShareContentList(shareContentList);
}
mTabChangeListener.listenerTopicInfoBean(bean);
}
}
/**
* 处理频道信息
*/
private void handlerChannelInfor() {
if (mPageBean == null) {
return;
}
if (mTabChangeListener != null && mPageBean.getChannelInfo() != null) {
ChannelInfoBean channelInfo = mPageBean.getChannelInfo();
channelInfo.setLocalPageName(mPageBean.getName());
channelInfo.setLocalPageId(mPageBean.getId());
mTabChangeListener.listenerChannelInfoBean(channelInfo);
}
}
/**
* 设置页面布局管理监听器
*/
public void setPageLayoutManagerListener(PageInforToLayoutManagerCallback listener) {
this.mTabChangeListener = listener;
}
public void setColumnFragmentCallback(ColumnFragmentCallback columnFragmentCallback) {
this.columnFragmentCallback = columnFragmentCallback;
}
/**
* 刷新页面数据
*
* @param refreshLayout
*/
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
if (columnFragmentCallback != null) {
columnFragmentCallback.userRefreshAction();
}
if (defaultView != null) {
defaultView.hide();
}
onRefresh();
}
/**
* 请求刷新数据
*/
public void onRefresh() {
openTip = true;
requestTime = 1;
pageInforBean = null;
// 默认刷新更新页码
String strategy = CompLogicDataBean.PULL_DOWN;
//清理掉缓存的专题请求标识,可以重新请求
CompentLogicUtil.cleanTopicRequestIds();
refreshUI(false, strategy, false);
}
@Override
public void onLoadMore(@NonNull RefreshLayout layout) {
boolean loadMoreFlag = true;
if (aheadLoadScrollListener != null) {
loadMoreFlag = aheadLoadScrollListener.isOneAheadLoadMore();
}
if (loadMoreFlag) {
onLoadMore();
} else {
refreshLayout.finishLoadMore(1000);
aheadLoadScrollListener.setOneAheadLoadMore(true);
}
// ThreadPoolUtils.postToMainDelay(new Runnable() {
// @Override
// public void run() {
// //更新小组件数据,如果已经调用过不会再调用,随机延迟3-6秒,缓解接口并发
// ((IBindServiceProvider) WdRouterRule.getInstance()
// .getProvider(IBindServiceProvider.class))
// .bindMorningAndEveningPostService(getContext());
// }
// }, RandomUtil.getRandomMillisecondsBetween3And6Seconds());
}
/**
* 请求加载分页数据
*/
public void onLoadMore() {
ThreadPoolUtils.postToMainDelay(new Runnable() {
@Override
public void run() {
pageInforBean = null;
refreshUI(false, CompLogicDataBean.PUSH_UP, true);
}
},800);
}
/**
* 隐藏loading
*
* @param headToastFlag
*/
public void hideLoading(boolean headToastFlag) {
if (refreshLayout != null) {
if (compLogicDataBean.loadMore) {
refreshLayout.finishLoadMore();
} else {
if (headToastFlag && mPageBean.totalCompSize > 0) {
if (refreshHeader != null) {
refreshHeader.setTvDesc(getString(R.string.refresh_head_msg_zui_news));
}
refreshLayout.finishRefresh(1000);
openTip = false;
} else {
refreshLayout.finishRefresh();
}
}
}
if (aheadLoadScrollListener != null) {
aheadLoadScrollListener.setOneAheadLoadMore(false);
}
}
/**
* 处理页面组件的生命节点事件
*
* @param type 0:destory;1:resume;2:pause
*/
private void handlerPageCompLifeEvent(int type) {
if (mRecyclerView != null && layoutRender != null) {
RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
int firstVisiblePosition = linearLayoutManager.findFirstVisibleItemPosition();
int lastVisiblePosition = linearLayoutManager.findLastVisibleItemPosition();
for (int index = firstVisiblePosition; index < lastVisiblePosition + 1; index++) {
if (type == 0) {
((LayoutAdapter) layoutRender).destory(index);
} else if (type == 1) {
((LayoutAdapter) layoutRender).resume(index);
} else if (type == 2) {
((LayoutAdapter) layoutRender).pause(index);
}
}
}
}
}
/**
* 检查能否开启加载下一页数据
*
* @param isRefreshAction true :用户刷新动作
* @return true: 有分页;false:无分页
*/
private boolean checkOpenLoadMoreAction(boolean isRefreshAction) {
boolean openLoadMore = checkHaveMoreLoad();
refreshLayout.setEnableLoadMore(openLoadMore);
if (mPageBean != null) {
TopicInfoBean topicInfo = mPageBean.getTopicInfo();
if (topicInfo != null && ContentTypeConstant.SUBJECT_TOPICTYPE_25 == topicInfo.getTopicType()) {
// 专题页面无需要添加弹簧
} else {
if (openLoadMore) {
refreshLayout.setEnableOverScrollDrag(false);
} else {
refreshLayout.setEnableOverScrollDrag(true);
}
}
}
if (mTabChangeListener != null) {
mTabChangeListener.fragmentRequestCallback(isRefreshAction, openLoadMore);
}
return openLoadMore;
}
/**
* 检测是否有下一页
*
* @return
*/
private boolean checkHaveMoreLoad() {
// 组件数量
int requestDataCompSize = mPageBean.totalCompSize;
boolean openLoadMore = requestDataCompSize > 0;
return openLoadMore;
}
/**
* 接口访问错误回调处理
*/
private void handlerErrorCallback() {
if (mTabChangeListener != null) {
boolean isRefresh = requestTime == 1;
mTabChangeListener.fragmentRequestCallback(isRefresh, false);
}
}
/**
* 彩蛋回调
*/
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 (getActivity() != null && "com.peopledailychina.activity.activity.AppMainActivity".equals(getActivity().getClass().getName()) && Constants.agreepomentDialogIsShow()) {
return;
}
if (isFragmentVisible && 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(getContext(), 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;
// }
// });
// 国殇模式
if (contryGrayFlag && eggdialog != null) {
GrayManager.getInstance().setLayerGrayType(eggdialog.view);
}
}
/**
* 设置根布局
*
* @param superRootLayout
*/
public void setSuperRootLayout(ViewGroup superRootLayout) {
this.superRootLayout = superRootLayout;
}
/**
* 是否默认选中的频道
* @param defaultShowChannel
*/
public void setDefaultShowChannel(boolean defaultShowChannel) {
isDefaultShowChannel = defaultShowChannel;
}
/**
* 监听加载更多事件
*/
private VerticalLoadScrollListener.OnAheadLoadListener onAheadLoadListener =
new VerticalLoadScrollListener.OnAheadLoadListener() {
@Override
public void aheadLoadMoreData() {
// 翻页必须大于1
if (requestTime > 1) {
onLoadMore();
}
}
@Override
public void isTop() {
}
};
/**
* 开启国殇
*/
public void grayUiPage() {
if (!contryGrayFlag) {
contryGrayFlag = true;
GrayManager.getInstance().setLayerGrayType(refreshHeader);
GrayManager.getInstance().setLayerGrayType(defaultView);
if (compLogicDataBean != null) {
compLogicDataBean.contryGrayFlag = contryGrayFlag;
int size = compLogicDataBean.compGraySize;
List<ItemLayoutManager> layoutManagerList = layoutRender.getAllSectionLayoutManager();
int pageSize = layoutManagerList.size();
int endSize = pageSize > size ? size : pageSize;
for (int i = 0; i < endSize; i++) {
ItemLayoutManager layoutManager = layoutManagerList.get(i);
layoutManager.getSection().getCompBean().setPageGrayFlag(true);
layoutManager.checkOpenGrayModel(null, i);
}
}
}
}
@Override
protected void perCreate() {
super.perCreate();
//首页启动速度用户,使用java布局
setIsjava(true);
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (layoutRender != null){
layoutRender.notifyDataSetChanged();
}
}
}