developer
2023-05-20 c1ffd99c4b60066774eb2c97b31e4aaa014e7f51
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
//
//  SubregionDetailViewController.m
//  BuWanVideo2.0
//
//  Created by weikou on 16/8/23.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "SubregionDetailViewController.h"
#import "searchTableViewCell.h"//本视图所使用的cell与搜索视图使用的cell相同
#import "XYRVideoInfoModel.h"
#import "searchViewController.h"
#import "SearchController.h"
#import "LookNoteController.h"
#import "XYRDetailViewController.h"
#import "XYRVideoInfoModel.h"
#import "recommentCollectionViewCell.h"
#import "shufflingCollectionReusableView.h"
#import "HeaderCollectionReusableView.h"
#import "GoogleAdTableViewCell.h"
 
 
@interface SubregionDetailViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
    NSInteger SpeciesNumber;//种类的位置
    NSInteger typeNumber;//细分类
    
    UICollectionView *recommendation;//推荐页面的collectionView
    
    BOOL googleNoAdToShow;//当这个变量为YES时,说明谷歌广告没有资源
    BOOL LoadGoogleAD;//是否选择加载谷歌广告
}
 
@property (weak, nonatomic) IBOutlet UISegmentedControl *segView;
@property (nonatomic , strong) HMSegmentedControl *segmentedControl;
@property (nonatomic , strong) NSMutableArray *SpeciesAry;//种类
@property (nonatomic , strong) NSMutableDictionary *dataDic;//种类下的数据源
@property (nonatomic, strong) UIScrollView *scrollView;//显示分类内容的视图
@property (nonatomic , strong) NSString *CategoryType;//内容类型
@property (nonatomic , strong) NSString *Species;//种类
 
@property (nonatomic , strong) NSMutableArray *CycleScrollData;//轮播图数据
@property (nonatomic , strong) NSMutableArray *hotListData;//榜首数据
 
@property (nonatomic , strong) NSMutableArray *addrssForshuffling;//装载推荐轮播图的地址
@property (nonatomic , strong) NSMutableArray *TitleForshuffling;//装载轮播图的标题
 
@property(nonatomic, strong) UIView *nativeAdView;//装载谷歌广告的视图
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *toplayout;
@property (nonatomic,assign)NSInteger kNavHeight;
 
@property (weak, nonatomic) IBOutlet UIButton *topButton;
 
@property (nonatomic, strong) UIView *viewTop;
 
@property (nonatomic, assign) BOOL isWhite;
@end
 
@implementation SubregionDetailViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    if (KIsiPhoneX) {
        self.kNavHeight = 84;
    }else{
        self.kNavHeight = 64;
    }
    //加载定制的导航栏视图
    [self loadNavigationView];
    //请求种类数据
    [self getDataFirstChildType];
    //添加分段显示器的属性
    
    [self addSegment];
    if (KIsiPhoneX) {
        _toplayout .constant = 130;
    }else{
        _toplayout.constant = 110;
    }
}
 
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    //NSString *str=[NSString stringWithFormat:@"分类的%@界面",self.titles];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    self.navigationController.navigationBar.translucent = YES;
    //[MobClick beginLogPageView:str];
}
 
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if (_isWhite) {
        self.isWhite = NO;
        
    } else {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    }
   
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    self.navigationController.navigationBar.translucent = NO;
    //NSString *str=[NSString stringWithFormat:@"分类的%@界面",self.titles];
    //[MobClick endLogPageView:str];
}
 
/**
 *  定制导航栏视图
 */
-(void)loadNavigationView {
    [self.view addSubview:self.viewTop];
    self.viewTop.sd_layout.leftSpaceToView(self.view, 0).topSpaceToView(self.view, 0).rightSpaceToView(self.view, 0).heightIs(self.kNavHeight);
    
    //去掉titlie
    UIView *tview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0.01, 0.01)];
    self.navigationItem.titleView = tview;
    
    //定制返回按钮
    UIButton *BackBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
    [BackBtn setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    BackBtn.layer.masksToBounds=YES;
    BackBtn.layer.cornerRadius=15.0;
    [BackBtn addTarget:self action:@selector(backToRoot:) forControlEvents:UIControlEventTouchUpInside];
    [self.viewTop addSubview:BackBtn];
    BackBtn.sd_layout.leftSpaceToView(_viewTop, 16).bottomSpaceToView(_viewTop, 7).widthIs(30).heightIs(30);
    
    //显示分类名
    UILabel *nameLabel=[[UILabel alloc] init];
    nameLabel.backgroundColor=[UIColor clearColor];
    nameLabel.font=[UIFont systemFontOfSize:15];
    nameLabel.textAlignment = NSTextAlignmentCenter;
    [nameLabel setText:self.titles];
    [nameLabel setTextColor:[UIColor whiteColor]];
 
    [self.viewTop addSubview:nameLabel];
    nameLabel.sd_layout.centerXEqualToView(_viewTop).bottomSpaceToView(_viewTop, 7).widthIs(100).heightIs(30);
 
    //搜索
    UIButton *SearchBtn = [[UIButton alloc] init];
    [SearchBtn setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
    [SearchBtn addTarget:self action:@selector(JumpToSearchView) forControlEvents:UIControlEventTouchUpInside];
    
    [self.viewTop addSubview:SearchBtn];
    SearchBtn.sd_layout.rightSpaceToView(_viewTop, 16).bottomSpaceToView(_viewTop, 7).widthIs(30).heightIs(30);
    
    //观看记录
    UIButton *recordBtn = [[UIButton alloc] init];
    [recordBtn setImage:[UIImage imageNamed:@"历史记录"] forState:UIControlStateNormal];
    [recordBtn addTarget:self action:@selector(JumpToRecordView) forControlEvents:UIControlEventTouchUpInside];
  
    [self.viewTop addSubview:recordBtn];
    recordBtn.sd_layout.rightSpaceToView(SearchBtn, 10).bottomSpaceToView(_viewTop, 7).widthIs(30).heightIs(30);
}
 
- (IBAction)topTaped:(UIButton *)sender {
    UITableView *tableview = [self.view viewWithTag:800 + SpeciesNumber ];
    NSIndexPath* indexPat = [NSIndexPath indexPathForRow:0 inSection:0];
    [tableview scrollToRowAtIndexPath:indexPat atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    
}
 
 
/**
 *  滑动视图
 */
-(void)addScrollerView{
    //配置滑动视图
    NSInteger index = KIsiPhoneX ? 84 :64 ;
 
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.kNavHeight+40, KScreenW, KScreenH-self.kNavHeight-40)];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator=NO;
    self.scrollView.bounces=NO;
    self.scrollView.contentSize = CGSizeMake(KScreenW * _SpeciesAry.count, KScreenH-self.kNavHeight-40);
    self.scrollView.delegate = self;
    [self.scrollView scrollRectToVisible:CGRectMake(0, 0, KScreenW, KScreenH-self.kNavHeight-40) animated:NO];
    [self.view addSubview:self.scrollView];
 
    //非推荐界面视图
    for (int i=0; i<_SpeciesAry.count; i++) {
        UITableView *scollerTableView=[[UITableView alloc] initWithFrame:CGRectMake(KScreenW*i, 40 , KScreenW, KScreenH-self.kNavHeight-80) style:UITableViewStylePlain];
        scollerTableView.tag=800+i;
        scollerTableView.delegate=self;
        scollerTableView.dataSource=self;
        scollerTableView.separatorStyle = NO;
        //注册Cell
        [scollerTableView registerNib:[UINib nibWithNibName:@"searchTableViewCell" bundle:nil] forCellReuseIdentifier:@"searchTableViewCellID"];
        [scollerTableView registerNib:[UINib nibWithNibName:@"GoogleAdTableViewCell" bundle:nil] forCellReuseIdentifier:@"GoogleAdTableViewCellID"];
        
        //添加下拉刷新
        scollerTableView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
            _CategoryType=[NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"CategoryType"]];
            [self getdataClassVideoWithPage:1];
        }];
        //添加下拉加载更多
        scollerTableView.mj_footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            //页数
            NSString *str=[NSString stringWithFormat:@"pagenumberX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
            NSString *pagenumber=[_dataDic objectForKey:str];
            if (pagenumber==nil) {
                pagenumber=@"1";
            }
            _CategoryType=[NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"CategoryType"]];
            [self getdataClassVideoWithPage:[pagenumber integerValue]];
        }];
        [self.scrollView addSubview:scollerTableView];
    }
    //首次加载视图时,需要加载首页的数据
//    [recommendation.mj_header beginRefreshing];
    SpeciesNumber = 0;
    UITableView *tableview = [self.view viewWithTag:800 + SpeciesNumber ];
    _Species = [NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"Id"]];
    typeNumber=1;
    [self.view bringSubviewToFront:_segView];
    [tableview.mj_header beginRefreshing];
}
 
/**
 *  定制轮播图
 */
-(void)addSliderView{
    if (_addrssForshuffling) {
        _addrssForshuffling=nil;
    }
    _addrssForshuffling = [[NSMutableArray alloc] initWithCapacity:0];
    _TitleForshuffling=[[NSMutableArray alloc] initWithCapacity:0];
    //判断
    for (int i = 0; i<_CycleScrollData.count; i++) {
        [_addrssForshuffling addObject:[[_CycleScrollData objectAtIndex:i] objectForKey:@"Picture"]];
        if ([[_CycleScrollData objectAtIndex:i] objectForKey:@"Ad"]!=nil) {
            [_TitleForshuffling addObject:[[[_CycleScrollData objectAtIndex:i] objectForKey:@"Ad"]objectForKey:@"Name"]];
        }else{
            [_TitleForshuffling addObject:[[[_CycleScrollData objectAtIndex:i] objectForKey:@"VideoInfo"]objectForKey:@"Name"]];
        }
    }
}
 
 
 
/**
 *  添加segment的属性
 */
-(void)addSegment{
    _segView.tintColor = kGlobalYellowColor;
    [_segView setTitleTextAttributes:@{NSForegroundColorAttributeName:KGlobalLightGreyColor_153} forState:UIControlStateNormal];
    [_segView setTitleTextAttributes:@{NSForegroundColorAttributeName:kGlobalMainColor} forState:UIControlStateSelected];
    [_segView addTarget:self action:@selector(segmentHasClick:) forControlEvents:UIControlEventValueChanged];
}
 
 
 
/**
 *  种类布局
 */
- (void)getaddView{
    //获取分类
    NSMutableArray *ar = [[NSMutableArray alloc] initWithCapacity:0];
    for (int i = 0; i<_SpeciesAry.count; i++) {
        if (i == 0) {
            _Species = [[_SpeciesAry objectAtIndex:i] objectForKey:@"Id"];
        }
        [ar addObject:[[_SpeciesAry objectAtIndex:i] objectForKey:@"Name"]];
        NSLog(@"%@",[[_SpeciesAry objectAtIndex:i] objectForKey:@"Name"]);
    }
    NSLog(@"%@",ar);
    
    _segmentedControl= [[HMSegmentedControl alloc] initWithSectionTitles:ar];
    _segmentedControl.backgroundColor=kGlobalMainColor;
    _segmentedControl.selectionIndicatorHeight = 2.0f;
    _segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
    _segmentedControl.frame = CGRectMake(0, self.kNavHeight, KScreenW, 40);
    _segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10);
    _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe;
    _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
    _segmentedControl.type=HMSegmentedControlTypeText;
    _segmentedControl.selectedSegmentIndex = 0;
    [_segmentedControl setSegmentWidthStyle:HMSegmentedControlSegmentWidthStyleDynamic];
    _segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName :[UIFont systemFontOfSize:15]};
    _segmentedControl.selectedTitleTextAttributes=@{NSForegroundColorAttributeName : kGlobalYellowColor,NSFontAttributeName :[UIFont systemFontOfSize:15]};
    _segmentedControl.selectionIndicatorColor = kGlobalYellowColor;
    
    __weak typeof(self) weakSelf = self;
    [_segmentedControl setIndexChangeBlock:^(NSInteger index) {
        SpeciesNumber = index;
        typeNumber=1;
        weakSelf.segView.selectedSegmentIndex=0;
        weakSelf.Species = [NSString stringWithFormat:@"%@",[[weakSelf.SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"Id"]];
        [weakSelf.scrollView scrollRectToVisible:CGRectMake(KScreenW * index, self.kNavHeight+40, KScreenW, KScreenH-self.kNavHeight-40) animated:YES];
//        if (index==0) {
//            [self.view sendSubviewToBack:_segView];
//            if (_CycleScrollData==nil&&_hotListData==nil) {
//                //数据不存在,请求数据
//                [recommendation.mj_header beginRefreshing];
//            }else{
//                //数据存在,直接加载,不需要处理
//            }
//        }else{
            [self.view bringSubviewToFront:_segView];
            UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
            NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",weakSelf.Species,(long)SpeciesNumber,(long)typeNumber];
            NSMutableArray *dataAry=[weakSelf.dataDic objectForKey:str];
            if(dataAry!=nil){
                //如果数据存在就加载数据
                [tableView reloadData];
            }else{
                //如果数据不存在就请求数据
                [tableView.mj_header beginRefreshing];
            }
        //        }
    }];
    [self.view addSubview:_segmentedControl];
    
    //添加滑动视图
    [self addScrollerView];
    [self.view bringSubviewToFront:self.topButton];
}
 
-(void)changeTheClassifyWith:(NSInteger)index{
    typeNumber = 1;//默认显示最新更新
    _segView.selectedSegmentIndex=typeNumber-1;
    _Species = [[[_SpeciesAry objectAtIndex:index] objectForKey:@"Id"] stringValue];
    //首先查看是否在字典里面有数据了,如果有数据,就直接使用字典里面的数据,否者刷新,获取数据
    NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
    NSMutableArray *dataAry=[_dataDic objectForKey:str];
    UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
    if(dataAry!=nil){
        [tableView reloadData];
    }else{
        [tableView.mj_header beginRefreshing];
    }
}
 
/**
 *  分段按钮的值变化事件
 *
 *  @param seg 当前segment
 */
- (void)segmentHasClick:(UISegmentedControl *)seg{
    switch (seg.selectedSegmentIndex) {
        case 0:{//最新更新
            typeNumber = 1;
            //刷新视图
            _segView.selectedSegmentIndex=typeNumber-1;
        }
            break;
        case 1:{//最热视频
            typeNumber = 2;
            //刷新视图
            _segView.selectedSegmentIndex=typeNumber-1;
        }
            break;
        case 2:{//评论最多
            typeNumber = 3;
            //刷新视图
            _segView.selectedSegmentIndex=typeNumber-1;
        }
            break;
        default:
            break;
    }
    NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
    NSMutableArray *dataAry=[_dataDic objectForKey:str];
    UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
    if(dataAry!=nil){
        [tableView reloadData];
    }else{
        [tableView.mj_header beginRefreshing];
    }
}
 
/**
 *  跳转到历史记录
 */
-(void)JumpToRecordView{
    self.isWhite = YES;
    LookNoteController *LookNoteLookNoteVC=[[LookNoteController alloc] init];
    [self.navigationController pushViewController:LookNoteLookNoteVC animated:YES];
}
 
/**
 *  跳转到搜索
 */
-(void)JumpToSearchView{
    SearchController *vc = [[SearchController alloc] init];
    vc.ptitle = [YTHsharedManger startManger].searchTitle;
    [self.navigationController pushViewController:vc animated:YES];
}
 
/**
 *  返回
 */
-(void)backToRoot:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
 
/// Gets an image representing the number of stars. Returns nil if rating is less than 3.5 stars.
- (UIImage *)imageForStars:(NSDecimalNumber *)numberOfStars {
    double starRating = [numberOfStars doubleValue];
    if (starRating >= 5) {
        return [UIImage imageNamed:@"stars_5"];
    } else if (starRating >= 4.5) {
        return [UIImage imageNamed:@"stars_4_5"];
    } else if (starRating >= 4) {
        return [UIImage imageNamed:@"stars_4"];
    } else if (starRating >= 3.5) {
        return [UIImage imageNamed:@"stars_3_5"];
    } else {
        return nil;
    }
}
 
/***********(以下)网络请求**************/
/**
 *  请求分类
 */
 
- (void)getDataFirstChildType{
    [[YTHNetInterface startInterface] getFirstChildTypeWithUid:[YTHsharedManger startManger].Uid withParentId:self.Id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSDictionary *dic = (NSDictionary *)result;
            if (!_SpeciesAry) {
                _SpeciesAry = [[NSMutableArray alloc] initWithCapacity:0];
            }
            _SpeciesAry = [[dic objectForKey:@"Data"] objectForKey:@"data"];
//            [_SpeciesAry removeObjectAtIndex:0];
            NSLog(@"%@",_SpeciesAry);
            _Species = [NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:0] objectForKey:@"Id"]];
            _CategoryType=[NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:0] objectForKey:@"CategoryType"]];
            //种类布局
 
            [self getaddView];
        }else{
            //报错
            if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
                [self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
            }
            NSLog(@"%@",error);
        }
    }];
}
 
/**
 *  请求分类下的数据
 *
 *  @param page 请求第几页
 */
- (void)getdataClassVideoWithPage:(NSInteger)page{
    [[YTHNetInterface startInterface] getVideoListWithUid:[YTHsharedManger startManger].Uid withPage:[NSString stringWithFormat:@"%ld",(long)page] withVideoType:_Species withOrder:[NSString stringWithFormat:@"%ld",(long)typeNumber] withSystem:@"1" withCategoryType:_CategoryType withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        NSLog(@"%@",result);
        if (isSuccessful) {
            NSDictionary *dic = (NSDictionary *)result;
            //数据
            NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
            NSMutableArray *_dataAry=[_dataDic objectForKey:str];
            
            if (!_dataAry) {
                _dataAry = [[NSMutableArray alloc] initWithCapacity:0];
            }
            if (page == 1) {
                [_dataAry removeAllObjects];
            }
            NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
            for (int i =0; i<ar.count; i++) {
                [_dataAry addObject:[ar objectAtIndex:i]];
            }
  
            NSString *str2=[NSString stringWithFormat:@"pagenumberX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
            NSString *pagenumber=[NSString stringWithFormat:@"%d",(int)(page+1)];
            //将获取到的数据存入字典中
            if (!_dataDic) {
                _dataDic=[NSMutableDictionary dictionary];
            }
            [_dataDic setObject:_dataAry forKey:str];
            [_dataDic setObject:pagenumber forKey:str2];
       
            //刷新视图
            UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
            [tableView.mj_header endRefreshing];
            [tableView.mj_footer endRefreshing];
            if (ar.count == 0) {
                [tableView.mj_footer endRefreshingWithNoMoreData];
            }
            [tableView reloadData];
        }else{
            UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
            [tableView.mj_header endRefreshing];
            [tableView.mj_footer endRefreshing];
            //网络连接失败
        }
    }];
}
/**
 *  获取大分类推荐Banner
 **/
-(void)getVideoBanner{
    [[YTHNetInterface startInterface] getRecommendCategoryVideoBannerWithUid:[YTHsharedManger startManger].Uid withVideoType:self.Id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSDictionary *dic = (NSDictionary *)result;
            if(!_CycleScrollData){
                _CycleScrollData=[[NSMutableArray alloc] initWithCapacity:0];
            }else{
                [_CycleScrollData removeAllObjects];
            }
            NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
            for (int i =0; i<ar.count; i++) {
                [_CycleScrollData addObject:[ar objectAtIndex:i]];
            }
            //加载轮播图
            [self addSliderView];
            //刷新collectionView
            [recommendation reloadData];
        }else{
            
        }
    }];
    
}
 
/**
 *  获取大分类推荐热榜
 */
 
-(void)VideoList{
    [[YTHNetInterface startInterface] getRecommendCategoryVideoListWithUid:[YTHsharedManger startManger].Uid withVideoType:self.Id withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            NSDictionary *dic = (NSDictionary *)result;
            if(!_hotListData){
                _hotListData=[[NSMutableArray alloc] initWithCapacity:0];
            }else{
                [_hotListData removeAllObjects];
            }
            NSArray *ar = [[dic objectForKey:@"Data"] objectForKey:@"data"];
            for (int i =0; i<ar.count; i++) {
                [_hotListData addObject:[ar objectAtIndex:i]];
            }
            [recommendation.mj_header endRefreshing];
            //刷新collectionView
            [recommendation reloadData];
        }else{
            
        }
    }];
    
}
 
 
/***********(以下)协议**************/
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    //因为tableView也是继承自UIScrollView,也会执行这个方法,所以必须做一个判断
    if(scrollView==self.scrollView){
        SpeciesNumber = scrollView.contentOffset.x / KScreenW;
        typeNumber=1;
        _segView.selectedSegmentIndex=typeNumber-1;
        _Species = [NSString stringWithFormat:@"%@",[[_SpeciesAry objectAtIndex:SpeciesNumber] objectForKey:@"Id"]];
        [self.segmentedControl setSelectedSegmentIndex:SpeciesNumber animated:YES];
        
        if (SpeciesNumber==0) {
            if (_CycleScrollData==nil&&_hotListData==nil) {
                //数据不存在,请求数据
                [recommendation.mj_header beginRefreshing];
            }else{
                //数据存在,直接加载,不需要处理
            }
        }else{
            //把选择器移到视图的最顶层
            [self.view bringSubviewToFront:_segView];
            
            NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
            NSMutableArray *dataAry=[_dataDic objectForKey:str];
            
            UITableView *tableView=[self.view viewWithTag:800+SpeciesNumber];
            if(dataAry!=nil){
                //如果数据存在就加载数据
                [tableView reloadData];
            }else{
                //如果数据不存在就请求数据
                [tableView.mj_header beginRefreshing];
            }
        }
    }
}
 
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    //因为tableView也是继承自UIScrollView,也会执行这个方法,所以必须做一个判断
    if(scrollView==self.scrollView){
        [self.view sendSubviewToBack:_segView];
    }
}
 
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 95;
}
 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(LoadGoogleAD){//加载广告
        if (indexPath.row/20>0&&indexPath.row%20!=0) {//这是广告的cell
            
        }
    }
    //这是处理内容的cell
    NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
    NSMutableArray *dataAry=[_dataDic objectForKey:str];
    XYRDetailViewController *detailVC=[[XYRDetailViewController alloc] init];
    [YTHsharedManger startManger].preController = self;
    detailVC.modalPresentationStyle = 0;
    if(LoadGoogleAD){//加载广告
        detailVC.Model=[XYRVideoInfoModel yy_modelWithDictionary:dataAry[indexPath.row-indexPath.row/20]];
    }else{
        detailVC.Model=[XYRVideoInfoModel yy_modelWithDictionary:dataAry[indexPath.row]];
    }
    [self presentViewController:detailVC animated:YES completion:^{
        
    }];
    
}
 
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
    NSArray *_dataAry=[_dataDic objectForKey:str];
    if (_dataAry.count>0) {
        tableView.separatorStyle = YES;
    }
    if (googleNoAdToShow) {//没有请求到广告
        LoadGoogleAD=NO;
        return _dataAry.count;
    }else{//谷歌广告可能还在请求中,或者有广告
        if(_dataAry.count>20&&self.nativeAdView!=nil){//确认请求到广告
            LoadGoogleAD=YES;
            return _dataAry.count+_dataAry.count/20;
        }else{//广告还在请求中,目前暂不考虑加载
            LoadGoogleAD=NO;
            return _dataAry.count;
        }
    }
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(LoadGoogleAD){//加载广告
        if ((indexPath.row/20>0)&&(indexPath.row%20==0)&&self.nativeAdView!=nil) {
            //显示谷歌广告
            GoogleAdTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"GoogleAdTableViewCellID"];
            [cell addSubview:self.nativeAdView];
            return cell;
        }
    }
    NSString *str=[NSString stringWithFormat:@"ValueX%@Y%ldZ%ld",_Species,(long)SpeciesNumber,(long)typeNumber];
    NSArray *_dataAry;
    searchTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"searchTableViewCellID"];
 
    if ([str isEqual:[NSNull null]]) {
        str = @"";
        return cell;
    }else{
        _dataAry=[_dataDic objectForKey:str];
        if (indexPath.row >=  _dataAry.count) {
            return cell;
        }
    }
    //获取到该cell的数据
    XYRVideoInfoModel *model;
    if(LoadGoogleAD){//加载了谷歌广告的
        model = [XYRVideoInfoModel yy_modelWithDictionary:[_dataAry objectAtIndex:(indexPath.row-indexPath.row/20)]];
    }else{
        model = [XYRVideoInfoModel yy_modelWithDictionary:[_dataAry objectAtIndex:(indexPath.row)]];
    }
    //加载图片
    [cell.searchTableViewCellImage setYthImageWithURL:model.Hpicture placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    //显示Tag值
    cell.SearchTabelViewTag.text=model.Tag;
    cell.SearchTabelViewTag.textColor=[UIColor grayColor];
    //加载名称
    cell.searchTableViewCellTitle.text=model.Name;
    if([model.Name rangeOfString:@"一家两口"].location !=NSNotFound){
        NSLog(@"%@\n",model.Hpicture);
        NSLog(@"%@",[_dataAry objectAtIndex:(indexPath.row)]);
 
    }
 
    //观看数量
    cell.searchTableViewCellWatchNUB.textColor=kGlobalLightGreyColor_210;
    NSString *recommentStr;
    if ([model.WatchCount intValue]<10000) {
        recommentStr=model.WatchCount;
    }else{
        recommentStr=[NSString stringWithFormat:@"%0.1f万",[model.WatchCount floatValue]/10000.0];
    }
    cell.searchTableViewCellWatchNUB.text=recommentStr;
    //评论数量CommentCount
    cell.searchTableViewCellCommentNUB.textColor=kGlobalLightGreyColor_210;
    NSString *commentCountStr;
    commentCountStr=[NSString stringWithFormat:@"%ld",(long)model.CommentCount];
    if (model.CommentCount<10000) {
        
    }else{
        commentCountStr=[NSString stringWithFormat:@"%0.1f万",[commentCountStr floatValue]/10000.0];
    }
    cell.searchTableViewCellCommentNUB.text=[NSString stringWithFormat:@"%@",commentCountStr];
    return cell;
}
 
 
#pragma mark -UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section==0) {
        return 0;
    }else{
        return _hotListData.count;
    }
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    recommentCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"recommentCollectionViewCell" forIndexPath:indexPath];
    //设置cell的背景色(白色)
    cell.backgroundColor=[UIColor whiteColor];
    //在这里对cell进行设置
    NSDictionary *VideoInformation=_hotListData[indexPath.row];
    NSString *picStr=[VideoInformation objectForKey:@"Picture"];
    //设置图片
    cell.recommentImageView.contentMode=UIViewContentModeScaleAspectFill;
    [cell.recommentImageView setYthImageWithURL:picStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    
    //设置短评(如果有Tag就设置Tag,没有Tag就设置Score)
    NSString *TagStr1=[VideoInformation objectForKey:@"Tag"];
    NSString *Score=[VideoInformation objectForKey:@"Score"];
    if(TagStr1.length>1){
        cell.recommentReplyLabel.text=TagStr1;
    }else if([Score intValue]>0){
        cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:%@",Score];
    }else{
        cell.recommentReplyLabel.text=[NSString stringWithFormat:@"评分:无"];
    }
    cell.recommentReplyLabel.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
    //标题
    cell.recommentTitleLabel.text=[NSString stringWithFormat:@"%@",[VideoInformation objectForKey:@"Name"]];
    //观看数量
    cell.recommentrecommentVV.textColor=kGlobalLightGreyColor_210;
    NSString *recommentStr;
    if ([[VideoInformation objectForKey:@"WatchCount"] intValue]<10000) {
        recommentStr=[VideoInformation objectForKey:@"WatchCount"];
    }else{
        recommentStr=[NSString stringWithFormat:@"%0.1f万",[[VideoInformation objectForKey:@"WatchCount"] floatValue]/10000.0];
    }
    cell.recommentrecommentVV.text=recommentStr;
    //评论数量CommentCount
    cell.recommentCommentNub.textColor=kGlobalLightGreyColor_210;
    NSString *commentCountStr;
    if ([[VideoInformation objectForKey:@"CommentCount"] intValue]<10000) {
        commentCountStr=[VideoInformation objectForKey:@"CommentCount"];
    }else{
        commentCountStr=[NSString stringWithFormat:@"%0.1f万",[[VideoInformation objectForKey:@"CommentCount"] floatValue]/10000.0];
    }
    cell.recommentCommentNub.text=[NSString stringWithFormat:@"%@",commentCountStr];
    return cell;
}
 
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}
 
//定制collectionView的head和foot
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader){
        if(indexPath.section==0){
            //如果是轮播图
            shufflingCollectionReusableView *shuffling=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"shufflingCollectionReusableView" forIndexPath:indexPath];
            //定制轮播图
//            [shuffling addSubview:_cycleScrollView];
            return shuffling;
            
        }else{
            //分类标头
            HeaderCollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderCollectionReusableView" forIndexPath:indexPath];
            header.headerImage.image=[UIImage imageNamed:@"今日热点"];
            header.HeaderTitle.text=@"全区榜首";
            [header.headerMore setHidden:YES];
            return header;
        }
    }
    return nil;
}
 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    //宽度随便定,系统会自动取collectionView的宽度
    //高度为分组头的高度
    if(section==0){
        //设置轮播图的高度
        return CGSizeMake(0, KScreenW*7/16);
    }else{
        return CGSizeMake(0, 50);
    }
}
 
#pragma mark -UICollectionViewDelegate
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
 
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
 
//cell被点击的处理方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.hotListData == nil || self.hotListData.count<1) {
        return;
    }
    XYRDetailViewController *play=[[XYRDetailViewController alloc]init];
    [YTHsharedManger startManger].preController = self;
    play.modalPresentationStyle = 0;
    play.Model = [XYRVideoInfoModel yy_modelWithDictionary:_hotListData[indexPath.row]];
    [self presentViewController:play animated:YES completion:^{
        
    }];
}
 
#pragma mark -UICollectionViewDelegateFlowLayout
//协议中的方法,用于返回单元格的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((KScreenW-30)/2, (KScreenW-30)*10/16/2+55);
}
 
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    //上、左、下、右的边距
    return UIEdgeInsetsMake(0, 10, 10, 10);
}
 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView.contentOffset.y<KScreenH/2) {
        [self.topButton setHidden:YES];
    }else{
        [self.topButton setHidden:NO];
    }
}
 
- (void)dealloc{
    
}
 
- (UIView *)viewTop {
    if (!_viewTop) {
        _viewTop = [[UIView alloc] init];
        _viewTop.backgroundColor = [UIColor blackColor];
    }
    return _viewTop;
}
@end