admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
//
//  XYRDetailViewController.m
//  BuWanVideo2.0
//
//  Created by weikou on 16/8/5.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "AppDelegate.h"
 
#import "XYRDetailViewController.h"
#import "PPTVController.h"
#import "XYRVideoDetailModel.h"
#import "UIImageView+WebCache.h"
 
#import "CMuneBar.h"//视频源
#import "HMSegmentedControl.h"//详情与评论
 
//3种collectionViewCell的样式
#import "GroupCollectionViewCell.h"//选集
#import "IntroductionCollectionViewCell.h"//简介
#import "GuessYouLikeCollectionViewCell.h"//猜你喜欢
 
#import "titleCollectionReusableView.h"
#import "GroupSection.h"
#import "GroupSmallSection.h"
#import "GroupfootSection.h"
#import "ADCollectionReusableView.h"
#import "AttentionCollectionReusableView.h"
#import "newADCollectionViewCell.h"
 
//登录
#import "LoggingViewController.h"
 
#import "commentHeaderView.h"
#import "CommentTableViewCell.h"
 
//加载网页视图的框架,WK需要使用到的头文件
#import <WebKit/WebKit.h>
 
#import "Share.h"
#import "WEBViewController.h"
 
//广点通原生广告
//#import "GDTNativeAd.h"
//广点通banner广告
//#import "GDTMobBannerView.h"
 
//优酷播放器
//#import "YTEngineOpenViewManager.h"
//#import "YYMediaPlayerEvents.h"
 
//PPTV播放器导入
//#import "PPTVview.h"
//#import <PPTVSdk/PPTVSdk.h>
 
#import "LGLAlertView.h"
 
#import "GDTNativeExpressAd.h"
#import "GDTNativeExpressAdView.h"
 
#import <BUAdSDK/BUAdSDK.h>
 
#define MARGIN 5
#define BACK_WIDTH (DEVICE_TYPE_IPAD ? 30 : 20)
#define ui_round_size(x) (DEVICE_TYPE_IPAD ? ((x) < 50 ? 50 : (x)) : ((x) < 44 ? 44 : (x)))
#define TEXTVIEW_FONT (DEVICE_TYPE_IPAD ? 15 : 12)
#define TEXTVIEW_WIDTH (DEVICE_TYPE_IPAD ? 400 : 250)
#define TEXTVIEW_HEIGHT 30
#define BETWEEN_BOUND_FULL 100
#define BETWEEN_BOUND_NORMAL 20
 
@interface XYRDetailViewController ()<CMuneBarDelegate,UIScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,YTHNetDelegateRecommend,UIGestureRecognizerDelegate,YTHBacktoApplicationsDelegate,GDTNativeExpressAdDelegete,HXEasyCustomShareViewDelegate,BUNativeExpressFullscreenVideoAdDelegate>{
    int _gather;//集数加载更多的控制变量,默认为1
    int isCollectNum;//当前选中的集
    
    UIView *_replyMessageView;//回复的输入视图
    UIButton *sendButton;//回复按钮
    UITextField *_textField;//回复的输入框
    NSString *_clickedStr;//点击的哪一个回复评论,用于记录位置信息
    
    NSDictionary *_commentDataDic;//当前用户的评论信息
    NSMutableArray *_commentDataArr;//当前视频的用户评论的回复信息
    
    int abc;
    int commentPage;//评论请求第几页,一页30条评论
    
    BOOL displayInsIntroduction;//用于判断是否显示简介,通过改变简介大高度达到隐藏简介的效果
    
    CGSize CELLSize;//选择集cell的大小
    
    //广点通原生广告
    //    GDTNativeAd *_nativeAd;     //原生广告实例
    //    NSMutableArray  *nativeArray;//存储请求下来的原生广告信息
}
 
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageH;//顶部图片的高
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *MarkToTop;//返回键离顶部的距离
@property (weak, nonatomic) IBOutlet UIView *ADBannerView;//芒果banner广告视图
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *ADBannerViewH;//广告视图banner的高
 
@property (strong, nonatomic) CMuneBar *MuneBar;//视频源选择器
@property (weak, nonatomic) IBOutlet UIButton *playBtn;//播放按钮
 
@property (weak, nonatomic) IBOutlet UIButton *backBtn;//详情页面的返回按钮
@property (weak, nonatomic) IBOutlet YYAnimatedImageView *image;//顶部视频图片
@property (weak, nonatomic) IBOutlet UILabel *detailTitle;//顶部的标题
@property (weak, nonatomic) IBOutlet UILabel *detailTitleBackgroundColor;//顶部标题背景
@property (weak, nonatomic) IBOutlet UIButton *backgroundButton;//覆盖在头图片的Button,响应播放事件
 
@property (weak, nonatomic) IBOutlet UILabel *SegmentView;
 
@property (nonatomic , strong) UICollectionView *collectionView;
@property (nonatomic , strong) UITableView *commenttableview;
 
@property (nonatomic , strong) XYRVideoDetailModel *DetailModel;//详细界面的数据模型
@property (nonatomic , strong) NSArray *VideoDetailList;//获取到得集数
@property (nonatomic , strong) NSMutableArray *ResourceList;//视频源列表
@property (nonatomic , strong) NSString *NewResource;//当前的视频源
 
@property (nonatomic, strong) HMSegmentedControl *segmentedControl;//评论与详情的segment
@property (nonatomic, strong) UIScrollView *scrollView;//评论与详情的视图
 
@property (nonatomic,strong) NSArray *RelativeVideos;//获取到的相关视频的数据
@property (nonatomic,strong) NSArray *GuessYoulike;//获取到的猜你喜欢的数据
@property (nonatomic,strong) NSArray *PeopleSeeVideo;//获取到的大家都在看的数据
 
//优酷的三个属性:
//@property (nonatomic, retain) YTEngineOpenViewManager *viewManager;
//@property (nonatomic, strong) YYMediaPlayer *cloudPlayer;
@property (nonatomic, retain) UIButton *backButton;
@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, assign) BOOL YKloadSuccess;    //优酷创建成功
 
//PPTV
//@property (nonatomic, strong) PPTVview *pptvview;
@property (nonatomic, assign) BOOL isPPTVSuccess;     //PPTV创建成功
@property (nonatomic, strong) UIButton *collectionbt; //外部收藏按钮
@property (nonatomic, strong) NSString *showurl;      //PPTV来源
@property (nonatomic, assign) CGRect playerFrame;
@property (nonatomic, assign) CGRect cloudPlayerFrame;
@property (nonatomic, strong) NSDate *startTime;
@property (nonatomic, strong) NSArray *expressAdViews;
@property (nonatomic, strong) GDTNativeExpressAd *nativeExpressAd;
 
@property (nonatomic, strong) BUNativeExpressFullscreenVideoAd *fullscreenVideoAd;
 
@end
 
@implementation XYRDetailViewController
//@synthesize player = _player;
@synthesize islocal;
@synthesize videoItem;
 
 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.startTime = [NSDate date];
    //实现网络监控的代理
    ApplicationDelegate.YNetdelegateRecommend = self;
    //实现出去应用或者回到应用的处理
    ApplicationDelegate.YBackAppDelegate = self;
    if (KIsiPhoneX) {
        //        self.topLayout.constant = 20;
        self.backLayout.constant = 39;
    }else{
        //        self.topLayout.constant = 0;
        self.backLayout.constant = 19;
        
    }
    //加载基础数据
    [self loadData];
    //视频名称背景色
    [self addTitleBackView];
    //加载视频详情页面的数据
    [self getVideoDetailViewWithMovieId:self.Model.Id WithThirdType:self.Model.ThirdType WithResourceId:nil];
}
 
- (void)loadFullscreenVideoAd {
    
    NSDictionary *dictionary = [[NSUserDefaults standardUserDefaults] objectForKey:@"buUserInfo"];
    NSDate *datenow = [NSDate date]; // 现在时间
    NSInteger timeSp = [datenow timeIntervalSince1970]*1000;
    if(dictionary)
    {
        if ([dictionary[@"vipExpireTime"] integerValue] > timeSp) {
                return;
         }
    }
    
    self.fullscreenVideoAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:@"945472378"];
    self.fullscreenVideoAd.delegate = self;
    [self.fullscreenVideoAd loadAdData];
}
 
//此方法在视频广告素材加载成功时调用。
- (void)nativeExpressFullscreenVideoAdDidLoad:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    
}
 
//当视频广告素材加载失败时调用此方法。
- (void)nativeExpressFullscreenVideoAd:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
    
}
 
//此方法在成功呈现nativeExpressAdView时调用。
- (void)nativeExpressFullscreenVideoAdViewRenderSuccess:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd {
    
}
 
//当nativeExpressAdView无法呈现时,将调用此方法
- (void)nativeExpressFullscreenVideoAdViewRenderFail:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
    
}
//当视频缓存成功时调用此方法
- (void)nativeExpressFullscreenVideoAdDidDownLoadVideo:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    [fullscreenVideoAd showAdFromRootViewController:self];
}
 
//此方法在用户单击“跳过”按钮时调用
- (void)nativeExpressFullscreenVideoAdDidClickSkip:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    
}
 
//此方法在视频广告即将关闭时调用。
- (void)nativeExpressFullscreenVideoAdWillClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    
}
 
//关闭视频广告时调用此方法
- (void)nativeExpressFullscreenVideoAdDidClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    
}
 
//此方法在视频广告播放完成或发生错误时调用。
- (void)nativeExpressFullscreenVideoAdDidPlayFinish:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
    
    
}
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //让页面保持常亮
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    //增加通知中心监听,当键盘出现或消失时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    //增加通知中心监听,
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(replyMessage:) name:@"reply" object:nil];
    //友盟页面统计
    //[MobClick beginLogPageView:@"视频播放页面"];
    //显示状态栏
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    //网络状态
    [self NetWorkStuas];
}
 
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    //删除通知中心的监听
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    //让页面关闭常亮
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
    //友盟页面统计
   // [MobClick endLogPageView:@"视频播放页面"];
    
    //强制竖屏
    NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
    [[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];
    
    NSNumber *PortraitorientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:PortraitorientationUnknown forKey:@"orientation"];
    //显示状态栏
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}
 
/**
 *  退出视频播放详细界面
 */
- (IBAction)backToMainViewController:(id)sender {
    [self backToRootView];
    
}
 
 
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    [self.collectionView.collectionViewLayout invalidateLayout];
}
 
/**
 *  点击收藏视频
 *
 *  @param sender 收藏按钮
 */
- (void)ClickCollection:(UIButton *)sender {
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
        if (sender.isSelected) {
            [sender setSelected:NO];
            [[YTHNetInterface startInterface] getScoreCollectWithUid:[YTHsharedManger startManger].Uid withId:self.Model.Id withThirdType:self.Model.ThirdType WithType:@"0" withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
                if (isSuccessful) {
                    if([self.NewResource intValue]==16){
                        //                    [_pptvview SuccessCollection:NO]; //通知PPTV播放器收藏
                    }
                }else{//取消收藏失败
                    [sender setSelected:YES];
                }
            }];
        }else{
            [sender setSelected:YES];
            [[YTHNetInterface startInterface] getScoreCollectWithUid:[YTHsharedManger startManger].Uid withId:self.Model.Id withThirdType:self.Model.ThirdType WithType:@"1" withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
                if (isSuccessful) {
                    if([self.NewResource intValue]==16){
                        //                    [_pptvview SuccessCollection:YES];  //通知PPTV播放器收藏
                    }
                }else{//收藏失败
                    [sender setSelected:NO];
                }
            }];
        }
    }else{
        //未登录,引导用户登录
        LoggingViewController *loginVC=[[LoggingViewController alloc] init];
        loginVC.modalPresentationStyle = 0;
        loginVC.ispresent=YES;
        [self presentViewController:loginVC animated:YES completion:^{
            
        }];
        
    }
    
}
 
 
 
/**
 *  加载已经获取到的数据
 */
-(void)loadData{
    commentPage=1;
    abc=1;
    //集数的控制显示,默认为1
    _gather=1;
    //视频名称
    self.detailTitle.text=self.Model.Name;
    //设置图片的高
    self.imageH.constant=KScreenW/16*9;
    //设置banner广告视图的高
    self.ADBannerViewH.constant=50;
    //视频的图片
    self.image.clipsToBounds=YES;
    self.image.contentMode=UIViewContentModeScaleAspectFill;
    [self.image setYthImageWithURL:self.Model.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
}
 
 
/**
 * 视频名称背景色
 */
-(void)addTitleBackView{
    CAGradientLayer *gradientLayer= [CAGradientLayer layer];  //设置渐变效果
    gradientLayer.bounds = _detailTitleBackgroundColor.bounds;
    gradientLayer.borderWidth = 0;
    gradientLayer.frame =CGRectMake(_detailTitleBackgroundColor.bounds.origin.x, _detailTitleBackgroundColor.bounds.origin.y, KScreenW, 55);
    gradientLayer.colors = [NSArray arrayWithObjects:
                            (id)[kGlobalMainColor CGColor],
                            (id)[[UIColor clearColor] CGColor], nil];
    gradientLayer.startPoint = CGPointMake(0.0, 0.0);
    gradientLayer.endPoint = CGPointMake(0.0, 1.0);
    [_detailTitleBackgroundColor.layer insertSublayer:gradientLayer atIndex:0];
}
 
 
/**
 *  评论与详情的切换视图
 */
-(void)segmentView{
    if(_segmentedControl==nil){
        self.segmentedControl = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 80, 35)];
        self.segmentedControl.selectedSegmentIndex = 0;
        self.segmentedControl.selectionIndicatorHeight = 3.0f;
        self.segmentedControl.backgroundColor = [UIColor whiteColor];
        self.segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};
        self.segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:15]};
        self.segmentedControl.selectionIndicatorColor = kGlobalYellowColor;
        self.segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
        self.segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
        self.segmentedControl.type=HMSegmentedControlTypeText;
        self.SegmentView.userInteractionEnabled=YES;
        [self.SegmentView addSubview:self.segmentedControl];
        
        __weak typeof(self) weakSelf = self;
        [self.segmentedControl setIndexChangeBlock:^(NSInteger index) {
            [weakSelf.scrollView scrollRectToVisible:CGRectMake(KScreenW * index, KScreenW/48*27+35, KScreenW, KScreenH-(KScreenW/48*27)-35) animated:YES];
            //考虑到用户在输入的时候突然切换到详情,这个时候就需要取消评论框的第一响应
            if(index==0){
                [_textField resignFirstResponder];
            }
        }];
        
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, KScreenW/48*27+35, KScreenW, KScreenH-(KScreenW/48*27)-35)];
        self.scrollView.backgroundColor =[UIColor whiteColor];
        self.scrollView.pagingEnabled = YES;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.contentSize = CGSizeMake(KScreenW , KScreenH-(KScreenW/48*27)-35);
        self.scrollView.delegate = self;
        [self.scrollView scrollRectToVisible:CGRectMake(0, 0, KScreenW, KScreenH-(KScreenW/48*27)-35) animated:NO];
        [self.view addSubview:weakSelf.scrollView];
        //初始化详情视图
        [self detailedInformationView];
        //初始化评论视图
        [self commentView];
    }
    
    //评论数
    //    NSString *commentNub=[NSString stringWithFormat:@"评 论(%ld)",(long)_DetailModel.Data.CommentCount];
    self.segmentedControl.sectionTitles = @[@"详 情"];
}
 
/**
 *  初始化详情视图
 */
 
-(void)detailedInformationView{
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
    //指定布局方式为垂直
    flow.scrollDirection = UICollectionViewScrollDirectionVertical;
    flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
    flow.minimumInteritemSpacing = 10;//两个单元格之间的最小间距
    
    //创建CollectionView并指定布局对象
    if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
        self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, _scrollView.frame.size.height ) collectionViewLayout:flow];
    }else{
        self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, _scrollView.frame.size.height-50) collectionViewLayout:flow];
    }
    self.collectionView.backgroundColor = kGlobalBackgroundColor;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.scrollView addSubview:self.collectionView];
    
    //注册cell
    //集数的cell
    [self.collectionView registerNib:[UINib nibWithNibName:@"GroupCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"GroupCellID"];
    //简介 IntroductionCollectionViewCell
    [self.collectionView registerNib:[UINib nibWithNibName:@"IntroductionCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"IntroductionCollectionViewCell"];
    //猜你喜欢、相关视频、大家都在看
    [self.collectionView registerNib:[UINib nibWithNibName:@"GuessYouLikeCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"GuessYouLikeCollectionViewCell"];
    //5月18号,新增加的广告位
    [self.collectionView registerNib:[UINib nibWithNibName:@"newADCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"newADCollectionViewCell"];
    //collectiom的headView和footView
    [self.collectionView registerNib:[UINib nibWithNibName:@"titleCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleCollectionReusableViewID"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"GroupSection" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSectionID"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"GroupSmallSection" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSmallSection"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"GroupfootSection" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"GroupfootSectionID"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"ADCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"AttentionCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"AttentionCollectionReusableViewID"];
}
 
/**
 *  初始化评论视图
 */
-(void)commentView{
    //显示评论的视图
    _commenttableview= [[UITableView alloc] initWithFrame:CGRectMake(KScreenW, 0, KScreenW, _scrollView.frame.size.height-50) style:UITableViewStyleGrouped];
    _commenttableview.backgroundColor=kGlobalBackgroundColor;
    _commenttableview.delegate=self;
    _commenttableview.dataSource=self;
    _commenttableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _commenttableview.backgroundColor=kGlobalBackgroundColor;
    [_commenttableview registerNib:[UINib nibWithNibName:@"CommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"CommentCellId"];
    _commenttableview.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self reloadCommentView];
    }];
    
    //创建手势事件
    UITapGestureRecognizer *Tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignResponder)];
    [_commenttableview addGestureRecognizer:Tap];
    Tap.delegate=self;
    
    UIImageView *backimage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, KScreenW-80 , 30)];
    backimage.image=[[UIImage imageNamed:@"输入框"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 40, 20, backimage.frame.size.width-40)];
    
    //回复的输入视图
    if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
        _replyMessageView=[[UIView alloc] initWithFrame:CGRectMake(KScreenW, _scrollView.frame.size.height-50, KScreenW, 50)];
    }else{
        _replyMessageView=[[UIView alloc] initWithFrame:CGRectMake(0, KScreenH-50, KScreenW, 50)];
    }
    _replyMessageView.backgroundColor=[UIColor whiteColor];
    
    //回复的输入框
    _textField=[[UITextField alloc] initWithFrame:CGRectMake(20, 10, KScreenW-90, 30)];
    _textField.delegate=self;
    _textField.backgroundColor=kGlobalBackgroundColor;
    _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _textField.placeholder=@"  我也来说两句...";
    
    //回复发送按钮
    sendButton=[[UIButton alloc] initWithFrame:CGRectMake(KScreenW-60, 10, 50, 30)];
    sendButton.tag=888;
    [sendButton setBackgroundImage:[[UIImage imageNamed:@"发表"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
    
    [sendButton setTitleColor:kGlobalMainColor forState:UIControlStateNormal];
    [sendButton setTitle:@"发送" forState:UIControlStateNormal];
    [sendButton addTarget:self action:@selector(ClickSendComment) forControlEvents:UIControlEventTouchUpInside ];
    
    [_replyMessageView addSubview:backimage];
    [_replyMessageView addSubview:_textField];
    [_replyMessageView addSubview:sendButton];
    
    [self.scrollView addSubview:_commenttableview];
    if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
        [self.scrollView addSubview:_replyMessageView];
    }else{
        [self.view addSubview:_replyMessageView];
    }
}
 
/**
 *  加载视频源
 */
-(void)loadResourceItem{
    self.ResourceList=[[NSMutableArray alloc] initWithArray:_DetailModel.Data.ResourceList];
    NSMutableArray *arr=[[NSMutableArray alloc] initWithCapacity:(_DetailModel.Data.ResourceList.count+5)];
    NSArray *ResourceList=[[NSMutableArray alloc] initWithArray:_DetailModel.Data.ResourceList];
    for (int i=0; i<_DetailModel.Data.ResourceList.count; i++) {
        arr[i]=[ResourceList[i] objectForKey:@"Picture"];
        if ([[ResourceList[i] objectForKey:@"Checked"] intValue]==1) {
            self.NewResource=[ResourceList[i] objectForKey:@"Id"];
            //交换数组元素,让默认的播放源放在第一个
            NSString *str=arr[i];
            arr[i]=arr[0];
            arr[0]=str;
            
            Resourcelist *res=ResourceList[i];
            _ResourceList[i]=ResourceList[0];
            _ResourceList[0]=res;
        }
    }
    
    if(arr.count>0){
        if (_MuneBar!=nil) {
            _MuneBar=nil;
        }
        _MuneBar= [[CMuneBar alloc] initWithItems:arr size:CGSizeMake(40, 40) type:kMuneBarTypeLineRight];
        [_MuneBar setUserInteractionEnabled:YES];
        _MuneBar.delegate = self;
        _MuneBar.center = CGPointMake(((KScreenW/3)-80)/2, 22);
        [self.collectionView bringSubviewToFront:_MuneBar];
        //        [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
        [self.collectionView reloadData];
        
    }
}
//默认网络情况
- (void)NetWorkStuas{
    
    switch ([YTHsharedManger startManger].NetworkStatus) {
        case 0:{//当前网络不可用
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"message:@"当前网络不可用,是否使用连接网络?"preferredStyle:UIAlertControllerStyleAlert];
            //取消
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [self backToRootView];
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            //去连接网络
            [alert addAction:[UIAlertAction actionWithTitle:@"连接网络" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] ];
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
        }
            break;
        case 1:{//移动网络
            static BOOL isFirst = YES;
            if (!isFirst) {
                return;
            }else{
                isFirst = NO;
            }
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"您目前没有连接WIFi,是否使用流量继续观看" preferredStyle:UIAlertControllerStyleAlert];
            //继续观看
            [alert addAction:[UIAlertAction actionWithTitle:@"继续" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            //去连接网络
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }]];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
        }
            break;
        case 2://WIFI
            
            break;
        case 3:{//当前网络无法检测,需要用户自行判断网络
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"message:@"无法监测当前网络,请自行判断网络!"preferredStyle:UIAlertControllerStyleAlert];
            //继续观看
            [alert addAction:[UIAlertAction actionWithTitle:@"继续观看" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            //取消观看
            [alert addAction:[UIAlertAction actionWithTitle:@"不看了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [self backToRootView];
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
        }
            break;
    }
}
 
-(void)resignResponder{
    [_textField resignFirstResponder];
}
 
#pragma mark 重写方法,允许这个界面可以横屏
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
    //    if(_isPPTVSuccess){   //如果是PPTV 播放  返回可旋转
    //        if(_pptvview.playoptions.isHalfScreen){
    //            return UIInterfaceOrientationMaskLandscape;
    //        }else{
    //            return UIInterfaceOrientationMaskPortrait;
    //        }
    //    }
    if (self.YKloadSuccess==YES) {  //如果加载了优酷播放器
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    return UIInterfaceOrientationMaskPortrait;
}
 
/**
 *  把当前播放记录写入文件
 *
 *  @param currentURLString 播放链接
 */
-(void)recordHistoryToFile:(NSString *)currentURLString{
    NSMutableDictionary *historyDict = [NSMutableDictionary dictionary];
    [historyDict setObject:[NSNumber numberWithInteger:self.DetailModel.Data.VideoDetailList.count] forKey:@"TotalNum"];//总共的集数
    if(self.DetailModel.Data.Name){//存储视频的名称
        [historyDict setObject:self.DetailModel.Data.Name forKey:@"Name"];
    }else{
        return;
    }
    if (self.DetailModel.Data.CanSave) {//存储视频是否可下载
        [historyDict setObject:[NSNumber numberWithBool:self.DetailModel.Data.CanSave] forKey:@"CanSave"];
    }
    if(self.DetailModel.Data.Id){//存储当前视频的分集id
        [historyDict setObject:self.DetailModel.Data.Id forKey:@"movieId"];
    }
    if(self.Model.Id){//存储当前视频的视频id
        [historyDict setObject:self.Model.Id forKey:@"Id"];
    }
    if(self.Model.ThirdType){
        [historyDict setObject:self.Model.ThirdType forKey:@"ThirdType"];
    }
    NSData *imagedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:self.DetailModel.Data.Hpicture]];//存储当前的图片
    if (imagedata){
        [historyDict setObject:imagedata forKey:@"Hpicturedata"];
    }else{
        return;
    }
    if (self.DetailModel.Data.Hpicture) {
        [historyDict setObject:self.DetailModel.Data.Hpicture forKey:@"Hpicture"];
    }
    if(currentURLString){//当前播放链接
        [historyDict setObject:currentURLString forKey:@"URLString"];
    }else{
        return;
    }
    Videodetaillist *videodetailList=self.DetailModel.Data.VideoDetailList[isCollectNum-1];
    NSString *str=[videodetailList valueForKey:@"Tag"];
    if(str!=nil){
        [historyDict setObject:str forKey:@"Tag"];
    }
    NSMutableArray *movieInfoArray = [NSMutableArray arrayWithCapacity:0];
    NSMutableArray *movieInfoArrayResult = [NSMutableArray arrayWithCapacity:0];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:HISTORYFILE]){
        [fileManager createFileAtPath:HISTORYFILE contents:nil attributes:nil];
        [movieInfoArrayResult addObject:historyDict];
        [movieInfoArrayResult writeToFile:HISTORYFILE atomically:YES];
    }else{
        movieInfoArray = [NSMutableArray arrayWithContentsOfFile:HISTORYFILE];
        if (movieInfoArray.count>=10) {
            [movieInfoArray removeLastObject];
        }
        for (int i=0; i<movieInfoArray.count; i++){
            if ([[[movieInfoArray objectAtIndex:i] valueForKey:@"Id"] isEqual:[historyDict objectForKey:@"Id"]]){
                [movieInfoArray removeObjectAtIndex:i];
                [movieInfoArrayResult addObject:historyDict];
                [movieInfoArrayResult addObjectsFromArray:movieInfoArray];
                [movieInfoArrayResult writeToFile:HISTORYFILE atomically:YES];
                return;
            }
        }
        [movieInfoArrayResult addObject:historyDict];
        [movieInfoArrayResult addObjectsFromArray:movieInfoArray];
        [movieInfoArrayResult writeToFile:HISTORYFILE atomically:YES];
    }
}
 
/**
 *  播放详情页面的分享按钮被触发
 */
- (void)clickShareButton:(UIButton *)sender{
//    [Share shareAPP:self];
}
 
/**
 *  点击关注或取消关注
 */
-(void)ClickAttentionButton:(UIButton *)sender{
    if ([sender isSelected]) {//如果当前是选择中状态,用户将进行取消关注的操作
        [sender setSelected:NO];//在用户取关请求之前将按钮设为取关状态,是为了提高界面的响应,避免用户觉得界面反应迟钝
        //用户进行关注操作,说明用户已经登录,所以不需进行判断是否登录
        [[YTHNetInterface startInterface] cancelAttentionWithUid:[YTHsharedManger startManger].Uid WithVideoId:self.Model.Id WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                [sender setSelected:NO];
            }else{
                //取关失败
                [sender setSelected:YES];
                [SVProgressHUD showErrorWithStatus:@"取关失败!"];
            }
        }];
        
    }else{//用户进行关注操作
        //首先需要判断用户是否登录
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
            [sender setSelected:YES];
            //已登录
            [[YTHNetInterface startInterface] addAttentionWithUid:[YTHsharedManger startManger].Uid WithVideoId:self.Model.Id WithLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
                if (isSuccessful) {
                    [sender setSelected:YES];
                }else{
                    //提示用户关注失败
                    [sender setSelected:NO];
                    [SVProgressHUD showErrorWithStatus:@"关注失败!\n请你检查网络是否流畅!"];
                }
            }];
        }else{
            //未登录,引导用户登录
            LoggingViewController *loginVC=[[LoggingViewController alloc] init];
            loginVC.modalPresentationStyle = 0;
            loginVC.ispresent=YES;
            [self presentViewController:loginVC animated:YES completion:^{
                
            }];
        }
    }
}
 
/**
 *  点击查看广告或更多的方法
 */
-(void)getMoreInformation:(UIButton *)sender{
    if (sender.tag==521) {
        NSLog(@"选集更多");
        _gather++;
        //刷新视图
        //        [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
        [self.collectionView reloadData];
        
    }else {//广点通广告
        //        GDTNativeAdData * info =nativeArray[sender.tag-523];
        //        [_nativeAd clickAd:info];
    }
}
 
/**
 *  视频的播放页面被触发,跳转到全屏,通过网页观看影片
 */
-(void)loadWebView:(UIButton *)sender{//这里还需要判断是否已经获取到播放页面的详细数据
    NSDate *date = [NSDate date];
    NSTimeInterval seconds = [date timeIntervalSinceDate:self.startTime];
    NSLog(@"%f",seconds);
    static BOOL bor = NO;
    if (seconds < 1.5 && bor) {
        bor = YES;
        return;
    }
    self.startTime = date;
    //取消textfield的第一响应
    [_textField resignFirstResponder];
    if(isCollectNum == 0){
        isCollectNum = 1;
    }
    _gather = 1;
    //先判断是否获取到视频的详情信息,否者会崩溃
    if(self.VideoDetailList.count!=0){
        //判断是否加载[优酷播放器
        if([self.NewResource intValue]==15){
            //使用优酷播放器
            [self YKPlay:@"0"];
        }else if([self.NewResource intValue]==16){
            //PPTV播放器
            [self PPTVplay:@"0" WithBoolInit:NO];
        }else if([self.NewResource intValue]==18){
            //乐视播放器
            [self YKPlay:@"0"];
        }else{
            //其他 爱奇艺 和 搜狐 网页播放类型
            [self startToPlay:[NSString stringWithFormat:@"0"]];
        }
        NSArray *arr = [_collectionView indexPathsForVisibleItems];
        NSIndexPath * targetIndex=[NSIndexPath new];
        for( int i = 0 ; i < arr.count ; ++i){
            NSIndexPath * temp = arr[i];
            if(isCollectNum-1 == temp.row ){
                targetIndex = temp;
            }
        }
        //        [_collectionView reloadItemsAtIndexPaths:@[targetIndex]];
        [_collectionView reloadData];
    }
}
 
-(void)selfchose:(NSNotification*)notification{
    NSDictionary* num = [notification userInfo];
    isCollectNum = ((NSNumber*)[num objectForKey:@"index"]).intValue +1;
    
    if([self.NewResource intValue]==16){ //PPTV播放器
        [self PPTVplay:[NSString stringWithFormat:@"%d",isCollectNum-1] WithBoolInit:_isPPTVSuccess];
    }else if([self.NewResource intValue]==18){ //乐视播放器
        [self YKPlay:[NSString stringWithFormat:@"%d",isCollectNum-1]];
        //        [_collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
        [self.collectionView reloadData];
        
    }else{
        [self startToPlay:[NSString stringWithFormat:@"%d",isCollectNum-1]];
    }
    
}
 
//在已有的PPTV播放器进行播放
//-(void)playPPTVSecend:(NSString*)urlstring{
//    [SVProgressHUD show];
//    [_pptvview playvedio:urlstring];
//    [_pptvview.playoptions.collection OtherChose:isCollectNum-1];   //播放器内部显示同步
//}
 
 
////PPTV退出亲清除
//-(void)PPTVclear{
//    if(!_pptvview){
//        return ;
//    }
//    [_pptvview clear];
//}
 
 
//PPTV获取数据
-(void)PPTVplay:(NSString *)IDS WithBoolInit:(BOOL)BL{
    Videodetaillist *lst=self.VideoDetailList[[IDS intValue]];
    NSString *eId=[_NewResource intValue]==16?[(NSDictionary *)lst objectForKey:@"Id"]:nil;
    [[YTHNetInterface startInterface] getparseVideoUrlWithUid:[YTHsharedManger startManger].Uid WithId:[(NSDictionary *)lst objectForKey:@"Id"] WithVideoId:self.DetailModel.Data.Id WithSystem:@"1" WithType:[(NSDictionary *)lst objectForKey:@"Type"] WithResourceId:_NewResource WithEID:eId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSLog(@"获取视频播放链接成功");
            NSDictionary *dictionaryDta = (NSDictionary *)result;
            
            //视频播放地址
            NSString *urlstring=[[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Params"] objectForKey:@"playlink"];
            _showurl = [[dictionaryDta objectForKey:@"Data"] objectForKey:@"Url"];
            
            //存储当前播放记录
            [self recordHistoryToFile:urlstring];
            //隐藏playBtn
            [_playBtn setHidden:YES];
            [_backgroundButton setEnabled:YES];
            
            //加载PPTV播放器
            if(!BL){  //没有被初始化过
                //                [self playPPTV:urlstring];
            }else{
                //                [self playPPTVSecend:urlstring];
            }
        }else{
            NSLog(@"获取视频播放链接失败%@",error);
        }
    }];
}
 
/********************优酷**************************/
 
 
/**
 *  获取播放地址,并添加网页播放视图
 *
 *  @param IDS 播放的集
 */
-(void)startToPlay:(NSString *)IDS{
    [SVProgressHUD showWithStatus:@"精彩,马上就来!"];
    [_playBtn setEnabled:NO];
    [_backgroundButton setEnabled:NO];
    Videodetaillist *lst;
    if ([IDS intValue] <= self.VideoDetailList.count) {
        lst=self.VideoDetailList[[IDS intValue]];
    }
    [[YTHNetInterface startInterface] getparseVideoUrlWithUid:[YTHsharedManger startManger].Uid WithId:[(NSDictionary *)lst objectForKey:@"Id"] WithVideoId:self.DetailModel.Data.Id WithSystem:@"1" WithType:[(NSDictionary *)lst objectForKey:@"Type"] WithResourceId:_NewResource WithEID:nil withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSLog(@"获取视频播放链接成功");
            [SVProgressHUD show];
            NSDictionary *dictionaryDta = (NSDictionary *)result;
            //视频播放地址
            NSString *urlstring=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Url"];
            //判断是站内播放还是站外播放
            NSNumber *playtype=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"PlayType"];
            //存储当前播放记录
            [self recordHistoryToFile:urlstring];
            //加载网页视图
            [self addWebViewWithType:playtype WithUrl:urlstring];
        }else{
            [SVProgressHUD showErrorWithStatus:@"网络不稳定\n请稍后再试!"];
            [_playBtn setEnabled:YES];
            [_backgroundButton setEnabled:YES];
        }
    }];
}
 
/**
 *  优酷/乐视获取播放地址
 *
 *  @param IDS 播放第几集
 */
-(void)YKPlay:(NSString *)IDS{
    Videodetaillist *lst=self.VideoDetailList[[IDS intValue]];
    NSString *eId;
    if ([_NewResource intValue]==15||[_NewResource intValue]==18) {
        eId=[(NSDictionary *)lst objectForKey:@"Id"];
    }else{
        eId=nil;
    }
    
    [[YTHNetInterface startInterface] getparseVideoUrlWithUid:[YTHsharedManger startManger].Uid WithId:[(NSDictionary *)lst objectForKey:@"Id"] WithVideoId:self.DetailModel.Data.Id WithSystem:@"1" WithType:[(NSDictionary *)lst objectForKey:@"Type"] WithResourceId:_NewResource WithEID:eId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSLog(@"获取视频播放链接成功");
            NSDictionary *dictionaryDta = (NSDictionary *)result;
            //判断是站内播放还是站外播放
            NSNumber *playtype=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"PlayType"];
            //判断是站外播放还是站内播放,如果是站外播放还是通过调用网页播放的方式,如果是站内播放就调用优酷播放器
            if([playtype intValue]==2){//站内播放,乐视播放器已经被移除,所以,站内播放只有优酷
                //视频播放地址
                NSDictionary *tempDic=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Params"];
                NSString *urlstring=[tempDic objectForKey:@"vid"];
                //存储当前播放记录
                [self recordHistoryToFile:urlstring];
                //隐藏playBtn
                [_playBtn setHidden:YES];
                [_backgroundButton setEnabled:YES];
                if([_NewResource intValue]==15){
                    //加载优酷播放器
                    //                    [self loadYKPlayer:urlstring];
                }
            }else{//站外播放
                NSString *urlstring=[[dictionaryDta objectForKey:@"Data"] objectForKey:@"Url"];
                //存储当前播放记录
                [self recordHistoryToFile:urlstring];
                [self addWebViewWithType:playtype WithUrl:urlstring];
            }
        }else{
            NSLog(@"获取视频播放链接失败%@",error);
        }
    }];
}
 
 
/**
 *  加载优酷播放
 *
 *  @param urlstring 播放地址
 */
//-(void)loadYKPlayer:(NSString *)urlstring{
//    if(_cloudPlayer==nil){
//        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
//
//        _cloudPlayer = [[YYMediaPlayer alloc] init];
//        _cloudPlayer.controller = self;
//        _cloudPlayer.view.clipsToBounds = YES;
//        _cloudPlayer.fullscreen = NO;
//        _cloudPlayer.platform = @"youku";
//
//        CGSize size = self.view.bounds.size;
//
//        CGFloat width = 0.f;
//        if (DEVICE_TYPE_IPAD) {
//            width = 681.f;
//        } else {
//            width = KScreenWp;
//        }
//
//        CGFloat height = width * 9.0f / 16.0f;
//        _cloudPlayer.view.frame = CGRectMake(0, 0, width, height);
//
//        _playerFrame = CGRectMake(0, 20, size.width, size.height - 20);
//        _cloudPlayerFrame = _cloudPlayer.view.frame;
//
//        //竖屏时露出状态栏
//        if ([[UIDevice currentDevice].systemVersion floatValue] >= 7){
//            CGRect bounds = self.view.frame;
//            self.view.bounds = bounds;
//        }
//
//        self.MarkToTop.constant=8.0f;
//        [self.view addSubview:_cloudPlayer.view];
//
//        [self initViews];
//
//        [_cloudPlayer addEventsObserver:self];
//
//        _cloudPlayer.clientId = YKCLIENTId;
//        _cloudPlayer.clientSecret = YKCLIENTSECRET;
//
//        // 初始化播放器界面管理器
//        _viewManager = [[YTEngineOpenViewManager alloc] initWithPlayer:_cloudPlayer];
//        [_cloudPlayer addEventsObserver:_viewManager];
//        [self.view bringSubviewToFront:self.backBtn];
//        self.YKloadSuccess=YES;
//    }
//    if (!islocal) {
//        [_cloudPlayer playVid:urlstring quality:kYYVideoQualityFLV password:nil from:0];
//    } else {
//        if (self.videoItem) {
//            [_cloudPlayer playVideo:(id<YYMediaPlayerItem>)self.videoItem quality:kYYVideoQualityFLV from:0 oldEncrypt:NO];
//        }
//    }
//}
 
- (void)layout:(BOOL)fullscreen{
    CGFloat backHeight = _backButton.bounds.size.height;
    CGFloat y = 0;
    
    if (!fullscreen) {
        //        _cloudPlayer.view.frame = _cloudPlayerFrame;
        y = (44 - backHeight) / 2;
        _backButton.frame = CGRectMake(MARGIN, y , BACK_WIDTH, backHeight);
    } else {
        //        _cloudPlayer.view.frame = self.view.frame;
        y = (30 - backHeight) / 2 + 20;
        _backButton.frame = CGRectMake(MARGIN, y, BACK_WIDTH, _backButton.bounds.size.height);
    }
    //    _textView.frame = CGRectMake(_cloudPlayer.view.center.x - TEXTVIEW_WIDTH/2, _cloudPlayer.view.center.y - TEXTVIEW_HEIGHT/2, TEXTVIEW_WIDTH, TEXTVIEW_HEIGHT);
}
 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orien{
    if (DEVICE_TYPE_IPAD) {
        if (orien == UIInterfaceOrientationPortrait || orien == UIInterfaceOrientationPortraitUpsideDown) {
            return NO;
        } else {
            return [self rotatePlayer:orien];
        }
    } else {
        if (orien == UIInterfaceOrientationPortraitUpsideDown) {
            return NO;
        } else {
            return [self rotatePlayer:orien];
        }
    }
}
 
/**
 *  优酷播放器方法
 */
- (void)initViews{
    // 返回错误码
    _textView = [[UITextView alloc] init];
    _textView.backgroundColor = [UIColor clearColor];
    _textView.textColor = [UIColor whiteColor];
    _textView.font = [UIFont systemFontOfSize:TEXTVIEW_FONT];
    _textView.editable = NO;
    _textView.userInteractionEnabled = NO;
    //    _textView.frame = CGRectMake(_cloudPlayer.view.center.x - TEXTVIEW_WIDTH/2,_cloudPlayer.view.center.y - TEXTVIEW_HEIGHT/2, TEXTVIEW_WIDTH, TEXTVIEW_HEIGHT);
    [_textView setTextAlignment:NSTextAlignmentCenter];
    //    [_cloudPlayer.view addSubview:_textView];
}
 
/**
 *  优酷播放器方法
 */
- (BOOL)shouldAutorotate{
    if(_isPPTVSuccess){   //如果是PPTV 播放  返回可旋转
        return YES;
    }
    if([self.NewResource intValue]==15){//优酷的处理方法
        if (abc==1) {
            abc++;
        }else{
            UIInterfaceOrientation orien = [self interfaceOrientation:[UIDevice currentDevice].orientation];
            return [self rotatePlayer:orien];
        }
    }
    return YES;
}
 
/**
 优酷
 
 @param orien 方向
 
 @return 是否旋转
 */
- (BOOL)rotatePlayer:(UIInterfaceOrientation)orien
{
    if (!DEVICE_TYPE_IPAD) {
        if (orien == UIInterfaceOrientationPortrait &&
            self.interfaceOrientation != orien) {
            //            [_cloudPlayer setFullscreen:NO];
        } else if (UIInterfaceOrientationIsLandscape(orien)) {
            UIInterfaceOrientation corien = self.interfaceOrientation;
            if (!UIInterfaceOrientationIsLandscape(corien)) {
                //                [_cloudPlayer setFullscreen:YES];
            }
        }
    }
    return YES;
}
 
/**
 优酷
 
 @param orien 设备方向
 */
- (NSInteger)interfaceOrientation:(UIDeviceOrientation)orien
{
    if (DEVICE_TYPE_IPAD) {
        switch (orien) {
            case UIDeviceOrientationLandscapeLeft:
                return UIInterfaceOrientationLandscapeRight;
            case UIDeviceOrientationLandscapeRight:
                return UIInterfaceOrientationLandscapeLeft;
            default:
                return -1;
        }
    } else {
        switch (orien) {
            case UIDeviceOrientationPortrait:
                return UIInterfaceOrientationPortrait;
            case UIDeviceOrientationLandscapeLeft:
                return UIInterfaceOrientationLandscapeRight;
            case UIDeviceOrientationLandscapeRight:
                return UIInterfaceOrientationLandscapeLeft;
            default:
                return -1;
        }
    }
}
 
/**
 *  优酷播放器方法
 */
//- (void)endPlayCode:(YYErrorCode)err{
//    NSString *tip;
//    switch (err) {
//        case YYPlayCompleted:
//            tip = @"该视频已播放完成,点击重新播放";
//            _textView.text = tip;
//            break;
//        case YYPlayCanceled:
//            break;
//        case YYErrorClientFormat:
//            tip = [NSString stringWithFormat:@"client参数格式错误,错误码:%ld", (long)err];
//            _textView.text = tip;
//            break;
//        case YYErrorInvalidClient:
//            tip = [NSString stringWithFormat:@"client无效或sdk版本过低,错误码:%ld", (long)err];
//            _textView.text = tip;
//            break;
//        case YYErrorPermissionDeny:
//            tip = [NSString stringWithFormat:@"视频无权限播放,错误码:%ld", (long)err];
//            _textView.text = tip;
//            break;
//        case YYErrorInitOpenView:
//            tip = [NSString stringWithFormat:@"初始化界面无效,错误码:%ld", (long)err];
//            _textView.text = tip;
//            break;
//        case YYDataSourceError:
//            tip = [NSString stringWithFormat:@"媒体文件错误,错误码:%ld", (long)err];
//            _textView.text = tip;
//            break;
//        case YYNetworkError:
//            tip = [NSString stringWithFormat:@"网络连接超时,错误码:%ld, 点击重试", (long)err];
//            _textView.text = tip;
//            break;
//        default:
//            tip = [NSString stringWithFormat:@"播放发生错误,错误码:%ld, 点击重试", (long)err];
//            _textView.text = tip;
//            break;
//    }
//}
/**
 *  优酷播放器方法
 */
//- (void)startPlay {
//    if (_viewManager) {
//        _textView.hidden = YES;
//    }
//}
 
- (void)setNewOrientation:(BOOL)fullscreen
{
    UIDeviceOrientation lastDeviceOrien = [UIDevice currentDevice].orientation;
    UIDeviceOrientation deviceOiren = fullscreen ?
    UIDeviceOrientationLandscapeLeft : UIDeviceOrientationPortrait;
    
    if([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        NSNumber *oiren = [NSNumber numberWithInt:deviceOiren];
        [[UIDevice currentDevice] setValue:oiren forKey:@"orientation"];
        [[UIDevice currentDevice] performSelector:@selector(setOrientation:)
                                       withObject:oiren];
    }
    if (lastDeviceOrien == deviceOiren) {
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 5.0) {
            [UIViewController attemptRotationToDeviceOrientation];
        }
    }
}
 
/********************网页(包括爱奇艺。搜狐。腾讯,部分优酷)**************************/
 
/**
 *  加载网页播放视频
 *
 *  @param playtype  站内还是站外播放
 *  @param urlstring 播放地址
 */
-(void)addWebViewWithType:(NSNumber *)playtype WithUrl:(NSString *)urlstring{
    WEBViewController *webVC=[[WEBViewController alloc] init];
    webVC.url=urlstring;
    if([_NewResource intValue]==18){
        webVC.orMake=UIInterfaceOrientationMaskAll;
    }else{
        webVC.orMake=UIInterfaceOrientationMaskPortrait;
    }
    webVC.modalPresentationStyle = 0;
    [self presentViewController:webVC animated:YES completion:^{
        [_playBtn setEnabled:YES];
        [_backgroundButton setEnabled:YES];
        [SVProgressHUD dismiss];
    }];
}
 
/**
 *  退出详情页面的方法
 */
-(void)backToRootView{
    //    if(_isPPTVSuccess){
    //        if(_pptvview.playoptions.isHalfScreen){
    //            [_pptvview FullScreen];
    //            return;
    //        }
    //        [self PPTVclear];
    //    }
    //
    [SVProgressHUD dismiss];
    self.collectionView.delegate = nil;
    self.collectionView.dataSource = nil;
    [self.collectionView removeFromSuperview];
    self.collectionView = nil;
    //    _nativeAd.controller = nil;
    //    _nativeAd.delegate = nil;
    //    [self.player removeEventsObserver:_viewManager];
    [self dismissViewControllerAnimated:YES completion:nil];
    //显示状态栏
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
}
 
/**
 *  加载新的基础数据,当用户点击推荐的内容时
 */
-(void)flashAllView{
    //重新加载基础数据
    [self loadData];
    //加载新的,详细页面数据
    [self getVideoDetailViewWithMovieId:self.Model.Id WithThirdType:self.Model.ThirdType WithResourceId:nil];
}
 
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}
 
- (UIViewController *)fetchCurrentViewController {
    UIViewController* currentViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    BOOL runLoopFind = YES;
    while (runLoopFind) {
        if (currentViewController.presentedViewController) {
            currentViewController = currentViewController.presentedViewController;
        } else if ([currentViewController isKindOfClass:[UINavigationController class]]) {
            UINavigationController* navigationController = (UINavigationController* )currentViewController;
            currentViewController = [navigationController.childViewControllers lastObject];
        } else if ([currentViewController isKindOfClass:[UITabBarController class]]) {
            UITabBarController* tabBarController = (UITabBarController* )currentViewController;
            currentViewController = tabBarController.selectedViewController;
        } else {
            NSUInteger childViewControllerCount = currentViewController.childViewControllers.count;
            if (childViewControllerCount > 0) {
                currentViewController = currentViewController.childViewControllers.lastObject;
                return currentViewController;
            } else {
                return currentViewController;
            }
        }
    }
    return currentViewController;
}
 
/***********(以下)数据网路加载**************/
/**
 *  获取视频的详细信息并加载
 *
 *  @param movieid    视频的id
 *  @param thirdtype  视频的来源
 *  @param resourceId 第几集
 */
-(void)getVideoDetailViewWithMovieId:(NSString *)movieid WithThirdType:(NSString *)thirdtype WithResourceId:(NSString *)resourceId{
    NSLog(@"%@",self.Model);
    //提示数据加载
    [SVProgressHUD showWithStatus:@"加载中"];
    [[YTHNetInterface startInterface] getVoideoDetailWithUid:[YTHsharedManger startManger].Uid  withLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withId:movieid withThirdType:thirdtype withSystem:@"1" WithResourceId:resourceId withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        NSLog(@"%@",result);
        if (isSuccessful) {
            //瀑布流滑动到顶部
            [self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES];
            NSDictionary *dictionaryDta = (NSDictionary *)result;
            
            if ([dictionaryDta[@"Data"][@"pptv"] boolValue]) {
                [SVProgressHUD dismiss];
                // 拦截跳转界面
                PPTVController *vc = [[PPTVController alloc] init];
                vc.parms = dictionaryDta[@"Data"];
                vc.hidesBottomBarWhenPushed = YES;
                [[YTHsharedManger startManger].preController.navigationController pushViewController:vc animated:YES];
          
                [self dismissViewControllerAnimated:NO completion:^{}];
                return;
            }
            if ([YTHsharedManger startManger].ad[@"videoDetailFullVideo"] && [YTHsharedManger startManger].ad[@"videoDetailFullVideo"]!=[NSNull null] && [[YTHsharedManger startManger].ad[@"videoDetailFullVideo"][@"type"] isEqualToString:@"csj"]) {
                [self loadFullscreenVideoAd];
            }
            
            _DetailModel = [XYRVideoDetailModel yy_modelWithDictionary:dictionaryDta];
            //更新详情页的视频图片
            [self.image setYthImageWithURL:_DetailModel.Data.PlayPicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
            //在这里判断主演和主要内容是否为空,如果同时为空,就隐藏简介
            if((_DetailModel.Data.MainActor.length>0)||(_DetailModel.Data.Introduction.length>0)){
                displayInsIntroduction=YES;
            }else{
                displayInsIntroduction=NO;
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.collectionView reloadData];
                
            });
            //判断Model是否已经加载了最上面图片
            if(self.Model.Hpicture==nil){
                [self.image setYthImageWithURL:self.DetailModel.Data.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
            }
            if (self.Model.Name==nil) {
                //视频名称
                self.detailTitle.text=self.DetailModel.Data.Name;
            }
            //给播放按钮添加点击事件
            [self.playBtn addTarget:self action:@selector(loadWebView:) forControlEvents:UIControlEventTouchUpInside];
            [self.backgroundButton addTarget:self action:@selector(loadWebView:) forControlEvents:UIControlEventTouchUpInside];
            
            //评论与详情的切换视图
            [self segmentView];
            //获取视频详情信息
            _VideoDetailList=self.DetailModel.Data.VideoDetailList;
            //计算cell的大小
            [self CalculateHeightWithArray:_VideoDetailList];
            
            //加载广告
            [self loadAd];
            //加载相关视频
            [self getRelativeVideosWithVideoId:movieid];
            //加载猜你喜欢
            [self getGuessLikeWithVideoId:movieid];
            //加载大家都在看
            [self getPeopleSeeVideowithVideoId:movieid];
            //加载评论视图
            [self reloadCommentView];
            //加载视频源
            [self loadResourceItem];
            //数据加载成功
            [SVProgressHUD dismiss];
        }else{
            NSLog(@"%@",error);
            //提示用户错误
            [SVProgressHUD dismiss];
            
            //            [SVProgressHUD showErrorWithStatus:@"加载失败!"];
            
        }
    }];
}
 
/**
 *  视频源切换
 */
-(void)SourcesSwitching:(NSInteger)index{
    [SVProgressHUD showWithStatus:@"视频源切换中"];
    if(_isPPTVSuccess){
        //        [self PPTVclear];
    }
    [[YTHNetInterface startInterface] getVoideoDetailWithUid:[YTHsharedManger startManger].Uid withLoginUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] withId:self.Model.Id withThirdType:self.Model.ThirdType withSystem:@"1" WithResourceId:_NewResource withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSDictionary *dictionaryDta = (NSDictionary *)result;
            self.DetailModel=[XYRVideoDetailModel yy_modelWithDictionary:dictionaryDta];
            _VideoDetailList=self.DetailModel.Data.VideoDetailList;
            //计算cell的大小
            [self CalculateHeightWithArray:_VideoDetailList];
            
            _gather=1;
            
            //需要考虑到正在播放优酷视屏时,如果切换爱奇艺的情况
            if([_NewResource intValue]!=15){
                //                [self.player.view removeFromSuperview];
                //                [self.player removeEventsObserver:_viewManager];
                //                [self.player stop];
                //                [self.player deinit];
                
                //取消隐藏playBtn
                [_playBtn setHidden:NO];
                [_backgroundButton setEnabled:NO];
                //取消隐藏返回按钮
                [self.backBtn setHidden:NO];
                //取消隐藏标题
                _textView.hidden = NO;
                //优酷加载为no;
                self.YKloadSuccess=NO;
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [_collectionView reloadData];
                
            });
            
            //提示视频源切换成功
            [SVProgressHUD dismiss];
        }else{
            //提示用户资源切换失败,并把显示的资源显示为之前的
            [SVProgressHUD showErrorWithStatus:@"切换失败!"];
        }
    }];
}
 
/**
 *  联网检查是否收藏
 */
-(void)checkWhetherCollection{
    //    if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
    [[YTHNetInterface startInterface] getIsCollectedWithUid:[YTHsharedManger startManger].Uid withId:self.Model.Id withThirdType:self.Model.ThirdType withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        UIButton *B1=[self.view viewWithTag:321];
        if (isSuccessful) {
            [B1 setSelected:YES];
        }else{
            [B1 setSelected:NO];
        }
    }];
    //    }
}
 
//用于计算选集cell的大小
-(void)CalculateHeightWithArray:(NSArray *)arr {
    if (_VideoDetailList.count == 0) return;
    
    NSString *MAXStr=_VideoDetailList[0][@"Tag"];
    for (int i=1; i<arr.count; i++) {
        NSString *tempStr = _VideoDetailList[i][@"Tag"];
        if (MAXStr.length<tempStr.length) {
            MAXStr=tempStr;
        }
    }
    CGSize CellSize = [MAXStr boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    
    float tempCellW;
    if (CellSize.width+10<KScreenW/7) {
        tempCellW=KScreenW/7;
    }else{
        tempCellW=KScreenW-70;
    }
    
    CELLSize=CGSizeMake(tempCellW, CellSize.height+12);
}
 
/**
 *  加载广点通原生广告
 */
-(void)loadAd{
    //    _nativeAd = [[GDTNativeAd alloc] initWithAppkey:GDTADkey placementId:GDTYSADkey4];
    //    _nativeAd.controller = self;
    //    _nativeAd.delegate = self;
    //    [_nativeAd loadAd:4];
    self.nativeExpressAd = [[GDTNativeExpressAd alloc] initWithPlacementId:GDTYSADkey4 adSize:CGSizeMake(KScreenW, (KScreenW-20)/16*9 + 10)];
    
    self.nativeExpressAd.delegate = self;
    // 配置视频播放属性
    self.nativeExpressAd.videoAutoPlayOnWWAN = YES;
    self.nativeExpressAd.videoMuted = NO;
    [self.nativeExpressAd loadAd:4];
}
- (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd
                                      *)nativeExpressAd views:(NSArray<__kindof
                                                               GDTNativeExpressAdView *> *)views
{
    if(views&&views.count>=3)
    {
        self.expressAdViews = [NSArray arrayWithArray:views];
    }
    if (self.expressAdViews.count) {
        [self.expressAdViews enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
            expressView.controller = self;
            [expressView render];
        }];
    }
    // 广告位 render 后刷新 tableView
    [self.collectionView reloadData];
}
- (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{
    NSLog(@"%@",error);
}
/**
 *  获取视频的相关视频信息
 *
 *  @param MovieId 视频的id
 */
-(void)getRelativeVideosWithVideoId:(NSString *)MovieId{
    [[YTHNetInterface startInterface] getRelativeVideosWithUid:[YTHsharedManger startManger].Uid withVideoId:MovieId withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            _RelativeVideos=[[(NSDictionary*)result objectForKey:@"Data"] objectForKey:@"data"];
            //刷新瀑布流
            //            dispatch_sync(dispatch_get_main_queue(), ^{
            //                [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:3]];
            [self.collectionView reloadData];
            //            });
        }else{
            
        }
    }];
}
/**
 *  获取视频的猜你会喜欢的视频信息
 *
 *  @param MovieId 视频的id
 */
-(void)getGuessLikeWithVideoId:(NSString *)MovieId{
    [[YTHNetInterface startInterface] getGuessLikeWithUid:[YTHsharedManger startManger].Uid withVideoId:MovieId withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            _GuessYoulike=[[(NSDictionary*)result objectForKey:@"Data"] objectForKey:@"data"];
            //刷新瀑布流
            //            dispatch_sync(dispatch_get_main_queue(), ^{
            //                [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:4]];
            [self.collectionView reloadData];
            
            //            });
        }else{
            
        }
    }];
}
/**
 *  获取大家都在看的视频信息
 *
 *  @param MovieId 视频的id
 */
-(void)getPeopleSeeVideowithVideoId:(NSString *)MovieId{
    [[YTHNetInterface startInterface] getPeopleSeeVideoWithUid:[YTHsharedManger startManger].Uid withVideoId:MovieId withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            _PeopleSeeVideo=[[(NSDictionary*)result objectForKey:@"Data"] objectForKey:@"data"];
            //刷新瀑布流
            //            dispatch_sync(dispatch_get_main_queue(), ^{
            //                [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:5]];
            [self.collectionView reloadData];
            
            
            //            });
        }else{
        }
    }];
}
 
#pragma mark 点击发送评论
-(void)ClickSendComment{
    if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
        //如果用户登录
        if(sendButton.tag==888){
            if(![_textField.text isEqualToString:@""]){
                //评论视频
                [[YTHNetInterface startInterface] getreplayCommentWithUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithVideoId:_Model.Id withThirdType:[NSString stringWithFormat:@"%ld",(long)_DetailModel.Data.ThirdType] WithContent:_textField.text WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
                    if (isSuccessful) {
                        [_textField setText:@""];
                        [_textField resignFirstResponder];
                        [_commenttableview setContentOffset:CGPointMake(0, 0) animated:YES];
                        [self reloadCommentView];
                        
                        [SVProgressHUD showSuccessWithStatus:@"评论成功"];
                        
                    }else{
                        [SVProgressHUD showErrorWithStatus:@"发送失败!"];
                    }
                }];
            }else{
                [SVProgressHUD showErrorWithStatus:@"评论不能为空!"];
            }
        }else{
            //回复评论
            if(![_textField.text isEqualToString:@""]){
                [[YTHNetInterface startInterface] getreplayCommentWithUid:[[NSUserDefaults standardUserDefaults] objectForKey:@"LoginUid"] WithcommentReplayId:nil WithCommentId:[_commentDataArr[[_clickedStr intValue]] objectForKey:@"Id"] WithContent:_textField.text WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
                    if (isSuccessful) {
                        [_textField setText:@""];
                        _textField.placeholder=@"我也来说两句...";
                        sendButton.tag=888;
                        [_textField resignFirstResponder];
                        [self reloadCommentView];
                        [_commenttableview setContentOffset:CGPointMake(0, 0) animated:YES];
                    }else{
                        [SVProgressHUD showErrorWithStatus:@"回复失败!"];
                    }
                }];
            }else{
                //提示用户输入
                [SVProgressHUD showErrorWithStatus:@"评论不能为空!"];
            }
        }
    }else{
        //如果用户未登录
        LoggingViewController *loginVC=[[LoggingViewController alloc] init];
        loginVC.modalPresentationStyle = 0;
        loginVC.ispresent=YES;
        [self presentViewController:loginVC animated:YES completion:nil];
    }
}
 
#pragma mark 刷新评论视图
-(void)reloadCommentView{
    //首先重新从服务器获取数据
    [[YTHNetInterface startInterface] getVideoCommentListWithUid:[YTHsharedManger startManger].Uid WithVideoId:_Model.Id WithThirdType:_Model.ThirdType WithPage:[NSString stringWithFormat:@"%d",commentPage] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSDictionary *commentDic=(NSDictionary *)result;
            if(commentPage==1){
                //更新数据
                _commentDataDic=[commentDic objectForKey:@"Data"];
                _commentDataArr=[_commentDataDic objectForKey:@"data"];
                if([[_commentDataDic objectForKey:@"count"] intValue]<9){
                    
                }else{
                    //只有数据大于9条时才出现下拉刷新,不然没有出现的意义
                    _commenttableview.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                        ++commentPage;
                        [self reloadCommentView];
                    }];
                }
            }else{
                _commentDataDic=[commentDic objectForKey:@"Data"];
                NSArray *tempArr=[_commentDataDic objectForKey:@"data"];
                
                for (int a=0; a<tempArr.count; a++) {
                    [_commentDataArr addObject:[tempArr objectAtIndex:a]];
                }
                commentPage=commentPage+(tempArr.count)%30;
            }
            //刷新评论
            dispatch_async(dispatch_get_main_queue(), ^{
                [_commenttableview reloadData];
            });
            //刷新评论按钮上的评论数
            //            NSString *commentNub=[NSString stringWithFormat:@"评 论(%ld)",(long)_DetailModel.Data.CommentCount];
            self.segmentedControl.sectionTitles = @[@"详 情"];
            [_commenttableview.mj_header endRefreshing];
            [_commenttableview.mj_footer endRefreshing];
        }else{
            [_commenttableview.mj_header endRefreshing];
            [_commenttableview.mj_footer endRefreshing];
        }
    }];
}
#pragma mark 回复评论
-(void)replyMessage:(NSNotification *)notification{
    //被点击的评论的位置
    _clickedStr=notification.userInfo[@"replyMessage"];
    //用户点击的是回复还是举报
    NSString *type=notification.userInfo[@"replyType"];
    
    if([type isEqualToString:@"回复"]){
        [_textField becomeFirstResponder];
        //评论者的网名
        NSString *replyName=[[_commentDataArr[[_clickedStr intValue]] objectForKey:@"User"] objectForKey:@"Nickname"];
        _textField.placeholder=[NSString stringWithFormat:@"回复 :%@",replyName];
        sendButton.tag=889;
    }
    if ([type isEqualToString:@"举报"]) {
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"userOnLine"]){
            [LGLAlertView showAlertViewWith:self title:@"举报" message:@"请选择举报理由" CallBackBlock:^(NSInteger btnIndex) {
                NSLog(@"%ld————%ld", (long)btnIndex,(long)[_clickedStr intValue]);
                if(btnIndex!=0){
                    [SVProgressHUD showSuccessWithStatus:@"感谢您的反馈!"];
                }
            } cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"营销诈骗", @"淫秽色情", @"地域攻击",@"其他理由",nil];
        }else{
            //如果用户未登录
            LoggingViewController *loginVC=[[LoggingViewController alloc] init];
            loginVC.modalPresentationStyle = 0;
            loginVC.ispresent=YES;
            [self presentViewController:loginVC animated:YES completion:nil];
        }
    }
}
 
/*************(以下)协议***************/
#pragma mark -CMuneBarDelegate
-(void)muneBarselected:(NSInteger)index{
    NSLog(@"%@_____%@",self.NewResource,[_ResourceList[index] objectForKey:@"Id"]);
    if(self.NewResource!=[_ResourceList[index] objectForKey:@"Id"]){
        self.NewResource=[_ResourceList[index] objectForKey:@"Id"];
        [self.MuneBar.mainButton setImage:[UIImage imageNamed:[_ResourceList[index] objectForKey:@"Name"]] forState:UIControlStateNormal];
        //仅仅更新选集列表
        [self SourcesSwitching:index];
    }
    [self.MuneBar hideItems];
}
 
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    NSLog(@"%f",scrollView.contentOffset.x);
    if (scrollView==self.scrollView) {
        //        NSInteger page = scrollView.contentOffset.x / KScreenW;
        
        //        [self.scrollView scrollRectToVisible:CGRectMake(KScreenW * page, KScreenW/48*27+35, KScreenW, KScreenH-(KScreenW/48*27)-35) animated:YES];
        //        [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
        //考虑到用户在输入的时候突然切换到详情,这个时候就需要取消评论框的第一响应
        //        if(page==0){
        //            [_textField resignFirstResponder];
        //        }
    }
}
 
#pragma mark -UICollectionViewDelegate
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==2) {
        return NO;
    }
    return YES;
}
 
- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
 
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {//点击了广告
        //        GDTNativeAdData * info=nativeArray[3];
        //        [_nativeAd clickAd:info];
    }else if (indexPath.section==1) {
        //查找刷新视图
        NSMutableArray * indexPatharr = [[NSMutableArray alloc]init];
        [indexPatharr addObject:indexPath];
        NSIndexPath * lastIndex;
        if(_playBtn.hidden){
            if(indexPath.row == isCollectNum -1){
                return ;
            }
            
            NSArray *arr = [_collectionView indexPathsForVisibleItems];
            
            for( int i = 0 ; i < arr.count ; ++i){
                NSIndexPath * temp = arr[i];
                if(isCollectNum -1 == temp.row){
                    lastIndex = temp;
                    break;
                }
            }
            if(lastIndex){
                [indexPatharr addObject:lastIndex];
            }
        }
        isCollectNum=(int)indexPath.row +1;
        if(lastIndex.row == 0 || indexPath.row == 0 || !lastIndex){ //在iphone6以上刷新row==0时无效的特殊处理
            [_collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
            //            [self.collectionView reloadData];
            
        }else{
            [_collectionView reloadItemsAtIndexPaths:indexPatharr];
            //            [_collectionView reloadData];
            
        }
        
        //刷新播放器
        if([self.NewResource intValue]==15){ //使用优酷播放器
            [self YKPlay:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
        }else if([self.NewResource intValue]==16){ //PPTV播放器
            [self PPTVplay:[NSString stringWithFormat:@"%d",isCollectNum-1] WithBoolInit:_isPPTVSuccess];
        }else if([self.NewResource intValue]==18){ //乐视播放器
            [self YKPlay:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
        }else{
            [self startToPlay:[NSString stringWithFormat:@"%ld",(long)indexPath.row]];
        }
        
    }else{
        if(_isPPTVSuccess){   //清空pptv进行转换
            //            [self PPTVclear];
            _isPPTVSuccess = NO;
        }
        
        //考虑到正在播放优酷视频,切换到爱奇艺资源,所以要做一次移除优酷播放器的操作
        //        [self.player.view removeFromSuperview];
        //        [self.player removeEventsObserver:_viewManager];
        //        [self.player stop];
        //        [self.player deinit];
        //取消隐藏playBtn
        [_playBtn setHidden:NO];
        [_backgroundButton setEnabled:NO];
        //取消隐藏标题
        _textView.hidden = NO;
        
        if (indexPath.section==3) {
            _Model=[XYRVideoInfoModel yy_modelWithDictionary:_RelativeVideos[indexPath.row]];
        }else if(indexPath.section==4){
            _Model=[XYRVideoInfoModel yy_modelWithDictionary:_GuessYoulike[indexPath.row]];
        }else if(indexPath.section==5){
            _Model=[XYRVideoInfoModel yy_modelWithDictionary:_PeopleSeeVideo[indexPath.row]];
        }
        //刷新视图
        [self flashAllView];
    }
}
 
#pragma mark -UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section==0) {
        if(self.expressAdViews.count>3){
            return 1;
        }else{
            return 0;
        }
    }else if(section==1){
        if(_VideoDetailList!=nil){
            if (self.DetailModel.Data.ShowType==1) {//是综艺
                if (_VideoDetailList.count>6*_gather) {
                    return 6*_gather;
                }else{
                    return _VideoDetailList.count;
                }
            }else{//不是综艺
                if (_VideoDetailList.count>10*_gather) {
                    return 10*_gather;
                }else{
                    return _VideoDetailList.count;
                }
            }
        }else{
            return 0;
        }
    }else if(section==2){
        return 1;
    }else if(section==3){
        if (_RelativeVideos.count>0) {
            return _RelativeVideos.count;
        }else{
            return 0;
        }
    }else if(section==4){
        if (_GuessYoulike.count>0) {
            return _GuessYoulike.count;
        }else{
            return 0;
        }
    }else if(section==5){
        if (_PeopleSeeVideo.count>0) {
            return _PeopleSeeVideo.count;
        }else{
            return 0;
        }
    }else{
        return 0;
    }
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 6;
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    XYRVideoInfoModel *VideosDataModel;
    switch (indexPath.section) {
        case 0:{
            newADCollectionViewCell *cell;
            cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newADCollectionViewCell" forIndexPath:indexPath];
            if (self.expressAdViews.count <= 3) {
                return cell;
            }
            GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[3];
            [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            [cell.contentView addSubview:adView];
            //            GDTNativeAdData *info=nativeArray[3];
            //            cell.ADtitle.text=[info.properties objectForKey:GDTNativeAdDataKeyTitle];
            //            cell.ADtitle.backgroundColor=[UIColor clearColor];
            //            [cell.ADimage setYthImageWithURL:[info.properties objectForKey:GDTNativeAdDataKeyImgUrl] placeholderImage:nil];
            //            [_nativeAd attachAd:info toView:cell];
            return cell;
        }
            break;
        case 1:{
            GroupCollectionViewCell *cell;
            if (_VideoDetailList.count <= indexPath.row) {
                return cell;
            }
            cell.tag=indexPath.row+2000;
            cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GroupCellID" forIndexPath:indexPath];
            cell.selectCollect.titleLabel.lineBreakMode=NSLineBreakByTruncatingTail;
            [cell.selectCollect setTitle:[_VideoDetailList[indexPath.row] objectForKey:@"Tag"] forState:UIControlStateNormal];
            cell.selectCollect.titleLabel.numberOfLines=0;
            //设置集数的字体颜色
            [cell.selectCollect setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [cell.selectCollect setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
            //对cell的背景图片进行处理,让其从中间拉伸,反正图片变形
            UIImage *deselectImage=[UIImage imageNamed:@"集数框-未选择"];
            deselectImage=[deselectImage stretchableImageWithLeftCapWidth:floorf(deselectImage.size.width/2) topCapHeight:floorf(deselectImage.size.height/2)];
            UIImage *selectImage=[UIImage imageNamed:@"集数框-选择"];
            selectImage=[selectImage stretchableImageWithLeftCapWidth:floorf(selectImage.size.width/2) topCapHeight:floorf(selectImage.size.height/2)];
            //设置cell选中和未选中的背景图片
            [cell.selectCollect setBackgroundImage:deselectImage  forState:UIControlStateNormal];
            [cell.selectCollect setBackgroundImage:selectImage forState: UIControlStateSelected];
            //关闭button的交互,否则collectionView的交互无法使用
            cell.selectCollect.userInteractionEnabled=NO;
            //默认设置第一集为选中状态
            if(indexPath.row==isCollectNum-1){
                [cell.selectCollect setSelected:YES];
            }else{
                [cell.selectCollect setSelected:NO];
            }
            return cell;
        }
            break;
        case 2:{
            IntroductionCollectionViewCell *cell;
            cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"IntroductionCollectionViewCell" forIndexPath:indexPath];
            cell.backgroundColor = kGlobalBackgroundColor;
            cell.area.text=[NSString stringWithFormat:@"%@",_DetailModel.Data.Area.length?_DetailModel.Data.Area:@"内地"];
            cell.year.text=[NSString stringWithFormat:@"%@",_DetailModel.Data.Year!=nil?_DetailModel.Data.Year:@"2016"];
            cell.type.text=[NSString stringWithFormat:@"%@",_DetailModel.Data.VideoType.Name!=nil?_DetailModel.Data.VideoType.Name:@" "];
            NSString *actString=[NSString stringWithUTF8String:[_DetailModel.Data.MainActor?_DetailModel.Data.MainActor :@" " UTF8String]];
            cell.act.text=[NSString stringWithFormat:@"%@",actString.length?actString:@" "];
            NSString *mainContentString=[NSString stringWithUTF8String:[self.DetailModel.Data.Introduction?self.DetailModel.Data.Introduction:@"" UTF8String]];
            cell.mainContent.text=[NSString stringWithFormat:@"%@",mainContentString.length?mainContentString:@" "];
            return cell;
        }
            break;
        default:{
            
            GuessYouLikeCollectionViewCell *cell;
            if (indexPath.section==3) {
                //相关视频
                if (indexPath.row >= _RelativeVideos.count) {
                    return cell;
                }
                VideosDataModel=[XYRVideoInfoModel yy_modelWithDictionary:_RelativeVideos[indexPath.row]];
            }else if (indexPath.section==4){
                if (indexPath.row >= _GuessYoulike.count) {
                    return cell;
                }
                //猜你喜欢
                VideosDataModel=[XYRVideoInfoModel yy_modelWithDictionary:_GuessYoulike[indexPath.row]];
            }else{
                if (indexPath.row >= _PeopleSeeVideo.count) {
                    return cell;
                }
                //大家都在看
                VideosDataModel=[XYRVideoInfoModel yy_modelWithDictionary:_PeopleSeeVideo[indexPath.row]];
            }
            cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"GuessYouLikeCollectionViewCell" forIndexPath:indexPath];
            cell.backgroundColor=[UIColor whiteColor];
            cell.MovieImage.clipsToBounds=YES;
            cell.MovieImage.contentMode=UIViewContentModeScaleAspectFill;
            [cell.MovieImage setYthImageWithURL:VideosDataModel.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
            cell.name.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            cell.name.text=[NSString stringWithFormat:@"%@",VideosDataModel.Tag];
            cell.Score.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            cell.Score.text=[NSString stringWithFormat:@"%@",VideosDataModel.Score];
            cell.Title.text=[NSString stringWithFormat:@"%@",VideosDataModel.Name];
            cell.commentVV.text=[NSString stringWithFormat:@"%@",VideosDataModel.WatchCount];
            cell.CommentNub.text=[NSString stringWithFormat:@"%ld",(long)VideosDataModel.CommentCount];
            
            cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
            return cell;
        }
            break;
    }
}
 
//定制collectionView的head和foot
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:{
            if (kind == UICollectionElementKindSectionHeader) {
                
                titleCollectionReusableView *titleCollectionReusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"titleCollectionReusableViewID" forIndexPath:indexPath];
                
                //添加收藏的点击事件
                [titleCollectionReusableView.collectionBtn addTarget:self action:@selector(ClickCollection:) forControlEvents:UIControlEventTouchUpInside];
                _collectionbt = titleCollectionReusableView.collectionBtn;
                //添加分享的点击事件
                titleCollectionReusableView.shareBtn.hidden = YES;
                titleCollectionReusableView.share.hidden = YES;
                [titleCollectionReusableView.shareBtn addTarget:self action:@selector(clickShareButton:) forControlEvents:UIControlEventTouchUpInside];
                //联网检查是否收藏
                [self checkWhetherCollection];
                //加载视频源视图
                if (_MuneBar!=nil) {
                    [titleCollectionReusableView.resourceSelectionView addSubview:self.MuneBar];
                }
                
                return titleCollectionReusableView;
            }else if(kind == UICollectionElementKindSectionFooter){
                if(_DetailModel.Extra1.Attention.Name!=nil){
                    AttentionCollectionReusableView *attentionCollectionReusableView=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"AttentionCollectionReusableViewID" forIndexPath:indexPath];
                    
                    Attention *attentionModel=_DetailModel.Extra1.Attention;
                    [attentionCollectionReusableView.AttentionImage setYthImageWithURL:attentionModel.Picture placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
                    attentionCollectionReusableView.AttentionName.text=attentionModel.Name;
                    attentionCollectionReusableView.AttentionData.text=[NSString stringWithFormat:@"%@",attentionModel.UpdateInfo];
                    [attentionCollectionReusableView.AttentionButton setSelected:attentionModel.IsAttention];
                    [attentionCollectionReusableView.AttentionButton addTarget:self action:@selector(ClickAttentionButton:) forControlEvents:UIControlEventTouchUpInside];
                    
                    return attentionCollectionReusableView;
                }else{
                    return nil;
                }
            }
        }
            break;
        case 1:{
            if(kind == UICollectionElementKindSectionFooter){
                GroupfootSection *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"GroupfootSectionID" forIndexPath:indexPath];
                groupfootSection.backgroundColor=kGlobalBackgroundColor;
                [groupfootSection.getMore setTag:521];
                if(self.DetailModel.Data.ShowType==1){
                    //是综艺
                    [groupfootSection.getMore setTitle:_VideoDetailList.count>6*_gather?@"查看更多":@"全部加载完成" forState:UIControlStateNormal];
                    if(_VideoDetailList.count>6){
                        [groupfootSection.getMore addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
                    }
                }else{
                    //不是综艺
                    [groupfootSection.getMore setTitle:_VideoDetailList.count>10*_gather?@"查看更多":@"全部加载完成" forState:UIControlStateNormal];
                    if(_VideoDetailList.count>10){
                        [groupfootSection.getMore addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
                    }
                }
                return groupfootSection;
            }else{
                return nil;
            }
        }
            break;
        case 2:
            if (kind == UICollectionElementKindSectionHeader){
                GroupSection *groupSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSectionID" forIndexPath:indexPath];
                groupSection.sectionTitle.text =@"简介";
                groupSection.backgroundColor=kGlobalBackgroundColor;
                groupSection.scoreTitle.text=[NSString stringWithFormat:@"评分:%@",self.DetailModel.Data.Score!=nil?self.DetailModel.Data.Score:@"无"];
                //暂时隐藏掉评分
                [groupSection.scoreTitle setHidden:YES];
                return groupSection;
            }else if(kind == UICollectionElementKindSectionFooter){
                GroupfootSection *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"GroupfootSectionID" forIndexPath:indexPath];
                groupfootSection.backgroundColor=[UIColor whiteColor];
                [groupfootSection.getMore setTag:522];
                [groupfootSection.getMore setTitle:@"" forState:UIControlStateNormal];
                [groupfootSection.getMore addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
                return groupfootSection;
            }
            break;
        default:{
            NSArray *headStr=@[@"相关视频",@"猜你喜欢",@"大家都爱看"];
            if (kind == UICollectionElementKindSectionHeader){
                GroupSmallSection *groupSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"GroupSmallSection" forIndexPath:indexPath];
                groupSection.title.text=headStr[indexPath.section-3];
                return groupSection;
            }else if(kind == UICollectionElementKindSectionFooter){
                //返回广告视图
                if (indexPath.section>3) {
                    
                    
                    if(self.expressAdViews.count>0){
                        ADCollectionReusableView *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView" forIndexPath:indexPath];
                        
                        //把button设为透明
                        groupfootSection.ADClickButton.backgroundColor=[UIColor clearColor];
                        [groupfootSection.ADClickButton setTag:520+indexPath.section];
                        [groupfootSection.ADClickButton addTarget:self action:@selector(getMoreInformation:) forControlEvents:UIControlEventTouchUpInside];
                        GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[indexPath.section-3];
                        [groupfootSection addSubview:adView];
                        return groupfootSection;
                    }else{
                        return nil;
                    }
                }else{
                    return nil;
                }
            }
        }
            break;
    }
    return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    //宽度随便定,系统会自动取collectionView的宽度
    //高度为分组头的高度
    if(section==0){
        return CGSizeMake(0, 90);
    }else if(section==1){
        return CGSizeMake(0, 0);
    }else if(section==2){
        if(displayInsIntroduction){
            return CGSizeMake(0, 50);
        }else{
            return CGSizeMake(0, 0);
        }
    }else{
        return CGSizeMake(0, 40);
    }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    if (section==0) {
        //这里需要做个判断
        if(_DetailModel.Extra1.Attention.Name!=nil){
            return CGSizeMake(0, 75);
        }else{
            return CGSizeMake(0, 0);
        }
    }else if(section==1){
        return CGSizeMake(0, 42);
    }else if(section==2){
        return CGSizeMake(0, 0);
    }else{
        if (section>3) {
            if(self.expressAdViews.count>0){
                GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[section-3];
                return CGSizeMake(0, adView.bounds.size.height);
            }else{
                return CGSizeMake(0, 0);
            }
        }else{
            return CGSizeMake(0, 0);
        }
    }
}
 
 
#pragma mark -UICollectionViewDelegateFlowLayout
//协议中的方法,用于返回单元格的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        //        return CGSizeMake(KScreenW-20, (KScreenW-20)/16*9);
        GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[indexPath.section];
        return CGSizeMake(KScreenW, adView.bounds.size.height);
    }else if (indexPath.section==1) {
        return CELLSize;
    }else if(indexPath.section==2){
        if (displayInsIntroduction) {
            NSString *mainContentString=[NSString stringWithUTF8String:[self.DetailModel.Data.Introduction?self.DetailModel.Data.Introduction:@" " UTF8String]];
            NSString *IntroductionStr=[NSString stringWithFormat:@"%@",mainContentString.length?mainContentString:@" !"];
            CGSize IntroSize = [IntroductionStr boundingRectWithSize:CGSizeMake(KScreenW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]} context:nil].size;
            CGSize titleSize=CGSizeMake(KScreenW, IntroSize.height+115);
            return titleSize;
        }else{
            return CGSizeMake(0, 0);
        }
        
    }else{
        return CGSizeMake((KScreenW-30)/2, (KScreenW-30)*9/32+65);
    }
}
 
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    if(section==0){//上、左、下、右的边距
        return UIEdgeInsetsMake(0, 10, 0, 10);
    }else if(section==1){
        return UIEdgeInsetsMake(5, 10, 10, 10);
    }else{
        return UIEdgeInsetsMake(0, 10, 10, 10);
    }
}
 
#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *replylist=[_commentDataArr[indexPath.section] objectForKey:@"ReplyList"];
    //回复者的网名
    NSString *replyName=[[replylist[indexPath.row] objectForKey:@"User"] objectForKey:@"Nickname"];
    //回复者回复内容
    NSString *replyContent=[replylist[indexPath.row] objectForKey:@"Content"];
    //合成网名和内容
    NSString *reply=[NSString stringWithFormat:@"%@  回复:%@",replyName,replyContent];
    
    CGSize replySize = [reply boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    
    return replySize.height+30;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    NSDictionary *dic=_commentDataArr[section];
    NSString *commentStr=[dic objectForKey:@"Content"];
    
    CGSize commentSize = [commentStr boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    
    return commentSize.height+60;
}
 
//取消高亮
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
    return NO;
}
 
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    commentHeaderView *commentHeaderCell=[commentHeaderView headerViewWithTableView:tableView];
    //该评论用户的信息
    NSDictionary *dic=_commentDataArr[section];
    NSDictionary *userInfo=[dic objectForKey:@"User"];
    NSString *iconUrl;
    if (![[userInfo objectForKey:@"Portrait"] isEqualToString:@""]&&[userInfo objectForKey:@"Portrait"]!=nil) {
        if ([[[userInfo objectForKey:@"Portrait"] substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {
            iconUrl=[userInfo objectForKey:@"Portrait"];
        }else{
            iconUrl=[NSString stringWithFormat:@"%@%@",iconImageUrl,[userInfo objectForKey:@"Portrait"]];
        }
        [commentHeaderCell.headerImageView setYthImageWithURL:iconUrl placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
    }else{
        [commentHeaderCell.headerImageView setImage:[UIImage imageNamed:@"关注默认头像"]];
    }
    commentHeaderCell.userNameLabel.text=[NSString stringWithFormat:@"%@",[userInfo objectForKey:@"Nickname"]];
    //评论内容的高度和宽度
    CGSize commentSize = [[dic objectForKey:@"Content"] boundingRectWithSize:CGSizeMake(KScreenW-70, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    //设置评论内容的高度
    commentHeaderCell.commentContentLabel.frame=CGRectMake(50, 55, KScreenW-70, commentSize.height);
    //设置评论的内容
    commentHeaderCell.commentContentLabel.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"Content"]];
    //设置评论日期的内容
    commentHeaderCell.commentTimeLabel.text=[[YTHNetInterface startInterface] getDate:[dic objectForKey:@"Createtime"]];
    //设置评论Button的位置
    commentHeaderCell.replyButton.frame=CGRectMake(KScreenW-60, 20, 45, 20);
    //传递cell的位置
    commentHeaderCell.section=[NSString stringWithFormat:@"%d",(int)section];
    //隐藏第一个section的分割线
    if (section==0) {
        [commentHeaderCell.Splitline setHidden:YES];
    }else{
        [commentHeaderCell.Splitline setHidden:NO];
    }
    return commentHeaderCell;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    [_textView resignFirstResponder];
}
 
#pragma mark -UITableViewDataSource
//回复的数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //获取该视频的评论
    NSArray *replylist=[_commentDataArr[section] objectForKey:@"ReplyList"];
    return replylist.count;
}
 
//评论的数量
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [_commentDataArr count];
}
 
//回复的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CommentTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"CommentCellId"];
    NSArray *replylist=[_commentDataArr[indexPath.section] objectForKey:@"ReplyList"];
    //回复者的网名
    NSString *replyName=[[replylist[indexPath.row] objectForKey:@"User"] objectForKey:@"Nickname"];
    //回复者回复内容
    NSString *replyContent=[replylist[indexPath.row] objectForKey:@"Content"];
    //合成网名和内容
    NSString *reply=[NSString stringWithFormat:@"%@ 回复:%@",replyName,replyContent];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:reply];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0,replyName.length)];
    cell.replyView.attributedText=str;
    //回复评论者的时间
    cell.replyTime.text=[[YTHNetInterface startInterface] getDate:[replylist[indexPath.row] objectForKey:@"Createtime"]];
    return cell;
}
 
#pragma mark -UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [_scrollView setScrollEnabled:NO];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    [_scrollView setScrollEnabled:YES];
    sendButton.tag=888;
    _textField.placeholder=@"我也来说两句...";
}
 
#pragma mark 键盘隐藏
-(void)keyboardWillHide:(NSNotification *)notification{
    if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
        _replyMessageView.frame=CGRectMake(KScreenW, _scrollView.frame.size.height-50, KScreenW, 50);
        
    }else{
        _replyMessageView.frame=CGRectMake(0, KScreenH-50, KScreenW, 50);
        
    }
}
#pragma mark 键盘出现
-(void)keyboardWasShown:(NSNotification *)notification{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到键盘的高度
    if ([UIScreen mainScreen].bounds.size.height>480.0f) {//iphone4s以上
        _replyMessageView.frame=CGRectMake(KScreenW, _scrollView.frame.size.height-50-kbSize.height, KScreenW, 50);
        
    }else{
        _replyMessageView.frame=CGRectMake(0, KScreenH-50-kbSize.height, KScreenW, 50);
        [self.view bringSubviewToFront:_replyMessageView];
    }
}
 
#pragma mark -YTHNetDelegateRecommend
/**
 *  0 . 不可用   1. 移动网络   2.wifi   3.当前网络未知
 */
- (void)updateNet:(NSInteger )status{
    
    switch (status) {
            
        case 0:{//当前网络不可用
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"当前网络不可用,是否连接网络?"preferredStyle:UIAlertControllerStyleAlert];
            //取消
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:^{
                    [self backToRootView];
                }];
            }]];
            //去连接网络
            [alert addAction:[UIAlertAction actionWithTitle:@"连接网络" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                if (IOS_VERSION <  8.0) {
                    
                }else{
                    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                }
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
        }
            break;
        case 1:{//移动网络
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"您目前没有连接WIFi,是否使用流量继续观看"preferredStyle:UIAlertControllerStyleAlert];
            //继续观看
            [alert addAction:[UIAlertAction actionWithTitle:@"继续" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            //去连接网络
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }]];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
        }
            break;
        case 2://WIFI
            
            break;
        case 3:{//当前网络无法检测,需要用户自行判断网络
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示"message:@"无法监测当前网络,请自行判断网络!"preferredStyle:UIAlertControllerStyleAlert];
            //继续观看
            [alert addAction:[UIAlertAction actionWithTitle:@"继续观看" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            //取消观看
            [alert addAction:[UIAlertAction actionWithTitle:@"不看了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [self backToRootView];
                [alert dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }]];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
        }
            break;
    }
}
 
#pragma mark -YTHBacktoApplicationsDelegate
 
//- (void)OutApplication{
//    if (self.cloudPlayer) {
//        [self.cloudPlayer pause];
//    }
//}
//
//- (void)backApplication{
//    if (self.cloudPlayer) {
//        [self.cloudPlayer play];
//    }
//}
 
- (UIViewController *)viewControllerForPresentingModalView{
    return self;
}
 
#pragma mark -GDTNativeAdDelegate
/**
 *  原生广告加载广告数据成功回调,返回为GDTNativeAdData对象的数组
 */
//-(void)nativeAdSuccessToLoad:(NSArray *)nativeAdDataArray{
//    if (!nativeArray) {
//        nativeArray =[[NSMutableArray alloc]initWithArray:nativeAdDataArray];
//    }else{
//        [nativeArray addObjectsFromArray:nativeAdDataArray];
//    }
//    dispatch_async(dispatch_get_main_queue(), ^{
//        [self.collectionView reloadData];
//    });
//}
 
/**
 *  原生广告加载广告数据失败回调
 */
-(void)nativeAdFailToLoad:(NSError *)error{
    NSLog(@"XYR_%@",error);
}
 
#pragma mark -HXEasyCustomShareViewDelegate
//- (void)easyCustomShareViewButtonAction:(HXEasyCustomShareView *)shareView title:(NSString *)title {
//    if ([title isEqualToString:@"微信"]) {
//        [self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession];
//    }else if ([title isEqualToString:@"朋友圈"]) {
//        [self shareWebPageToPlatformType:UMSocialPlatformType_WechatTimeLine];
//    }else if ([title isEqualToString:@"QQ"]) {
//        [self shareWebPageToPlatformType:UMSocialPlatformType_QQ];
//    }else if ([title isEqualToString:@"新浪微博"]) {
//        [self shareWebPageToPlatformType:UMSocialPlatformType_Sina];
//    }else if ([title isEqualToString:@"QQ空间"]) {
//        [self shareWebPageToPlatformType:UMSocialPlatformType_Qzone];
//    }else{
//        //到这里就错了
//    }
//    [shareView tappedCancel];
//}
 
/**
 分享
 */
//- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType{
//    NSURL *imageurl;
//    //判断分享的图片地址是否存在
//    NSString *picUrl=_DetailModel.Data.Picture;
//    if (picUrl .length>4) {
//        //判断图片地址是否为http开头,是则为第三方图片
//        if ([[picUrl substringWithRange:NSMakeRange(0, 4)] isEqualToString:@"http"]) {
//            imageurl = [NSURL URLWithString:picUrl];
//        }else{
//            //否者为公司的图片,需要添加地址
//            imageurl =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ImageUrl,picUrl]];
//        }
//    }
//
//    //创建分享消息对象
//    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
//
//    //创建网页内容对象
//    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"布丸影视大全" descr:[NSString stringWithFormat:@"我在布丸影视大全看了《%@》影片,非常不错,大家一起看看吧!%@",_DetailModel.Data.Name,[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"]] thumImage:[NSData dataWithContentsOfURL:imageurl]];
//
//    //设置网页地址
//    shareObject.webpageUrl =[[NSUserDefaults standardUserDefaults] objectForKey:@"ShareUrl"];
//
//    //分享消息对象设置分享内容对象
//    messageObject.shareObject = shareObject;
//
//    //调用分享接口
//    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
//        if (error) {
//            [SVProgressHUD showErrorWithStatus:@"分享失败!"];
//            NSLog(@"************Share fail with error %@*********",error);
//        }else{
//            NSLog(@"response data is %@",data);
//        }
//    }];
//}
 
 
 
- (void)dealloc {
    
    
}
 
@end