al
Aeline
2021-03-08 ce4eaddf9eb835f01e6bf5845a063d306f322b24
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
//
//  FuLiSheViewController.m
//  BuWanVideo2.0
//
//  Created by apple on 16/12/1.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "FuLiSheViewController.h"
#import "searchViewController.h"
#import "LookNoteController.h"
#import "recommentCollectionViewCell.h"
#import "XYRDetailViewController.h"
 
@interface FuLiSheViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
    UICollectionView *_CollectionView;//福利社的瀑布流
    int page;
}
@property (nonatomic , strong) NSMutableArray *arrDate;//福利社数据
@end
 
@implementation FuLiSheViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //初始化数据
    page=1;
    //加载定制的导航栏视图
    [self loadNavigationView];
    //请求数据
    [self loadData];
    //创建界面
    [self CreatUI];
}
 
/**
 *  定制导航栏视图
 */
-(void)loadNavigationView{
    //去掉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];
    UIBarButtonItem *backBarItem=[[UIBarButtonItem alloc] initWithCustomView:BackBtn];
    
    //显示分类名
    UILabel *nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 65, 20)];
    nameLabel.backgroundColor=[UIColor clearColor];
    nameLabel.font=[UIFont systemFontOfSize:15];
    [nameLabel setText:self.titles];
    [nameLabel setTextColor:[UIColor whiteColor]];
    UIBarButtonItem *nameBarItem=[[UIBarButtonItem alloc] initWithCustomView:nameLabel];
    
    //添加分类名和返回按钮到导航栏
    self.navigationItem.leftBarButtonItems=[[NSArray alloc] initWithObjects:backBarItem,nameBarItem,nil];
    
    //观看记录
    UIButton *recordBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
    [recordBtn setImage:[UIImage imageNamed:@"历史记录"] forState:UIControlStateNormal];
    [recordBtn addTarget:self action:@selector(JumpToRecordView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *recordBarItem=[[UIBarButtonItem alloc] initWithCustomView:recordBtn];
    
    //搜索
    UIButton *SearchBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
    [SearchBtn setImage:[UIImage imageNamed:@"搜索"] forState:UIControlStateNormal];
    [SearchBtn addTarget:self action:@selector(JumpToSearchView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *SearchBarItem=[[UIBarButtonItem alloc] initWithCustomView:SearchBtn];
    
    //空白间距
    UILabel *WhiteLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 8, 10)];
    WhiteLabel.backgroundColor=[UIColor clearColor];
    UIBarButtonItem *WhiteBarItem=[[UIBarButtonItem alloc] initWithCustomView:WhiteLabel];
    
    //添加 观看记录/下载/搜索 到导航栏
    self.navigationItem.rightBarButtonItems=[[NSArray alloc] initWithObjects:SearchBarItem,WhiteBarItem,recordBarItem,nil];
}
 
-(void)loadData{
    [SVProgressHUD showWithStatus:@"疯狂加载中..."];
    [[YTHNetInterface startInterface] getMoreVideoWithUid:[YTHsharedManger startManger].Uid withType:self.Id withSystem:@"1" withPage:[NSString stringWithFormat:@"%d",page] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if (isSuccessful) {
            if (!_arrDate) {
                _arrDate=[NSMutableArray arrayWithCapacity:0];
            }
            if (page == 1) {
                [_arrDate removeAllObjects];
            }
            NSArray *ar = [[result objectForKey:@"Data"] objectForKey:@"data"];
            for (int i =0; i<ar.count; i++) {
                [_arrDate addObject:[ar objectAtIndex:i]];
            }
            [_CollectionView reloadData];
            [SVProgressHUD dismiss];
        }else{
            //请求失败
            [SVProgressHUD dismiss];
            if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
                [self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
            }
        }
    }];
}
 
-(void)CreatUI{
    if (!_CollectionView) {
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
        //指定布局方式为垂直
        flow.scrollDirection = UICollectionViewScrollDirectionVertical;
        flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
        flow.minimumInteritemSpacing = 10;//两个单元格之间的最小间距
        
        _CollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH) collectionViewLayout:flow];
    }
    _CollectionView.delegate=self;
    _CollectionView.dataSource=self;
    _CollectionView.backgroundColor=kGlobalBackgroundColor;
    [_CollectionView registerNib:[UINib nibWithNibName:@"recommentCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"recommentCollectionViewCell"];
    [self.view addSubview:_CollectionView];
}
 
 
/**
 *  跳转到历史记录
 */
-(void)JumpToRecordView{
    LookNoteController *LookNoteLookNoteVC=[[LookNoteController alloc] init];
    [self.navigationController pushViewController:LookNoteLookNoteVC animated:YES];
}
 
/**
 *  跳转到搜索
 */
-(void)JumpToSearchView{
    searchViewController *searchVC=[[searchViewController alloc] init];
    [self.navigationController pushViewController:searchVC animated:YES];
}
 
/**
 *  返回
 */
-(void)backToRoot:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
    
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
#pragma mark -UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
        return _arrDate.count;
   
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    recommentCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"recommentCollectionViewCell" forIndexPath:indexPath];
    //设置cell的背景色(白色)
    cell.backgroundColor=[UIColor whiteColor];
    //在这里对cell进行设置
    NSDictionary *VideoInformation=_arrDate[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"];
 
    if(TagStr1.length>1){
        cell.recommentReplyLabel.text=TagStr1;
    }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"]==nil||[[VideoInformation objectForKey:@"WatchCount"] isEqualToString:@"(null)"]){
        recommentStr=[NSString stringWithFormat:@"0"];
    }else 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"]==nil) {
        commentCountStr=[NSString stringWithFormat:@"0"];
    }else 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];
    
    //添加阴影
    cell.layer.masksToBounds = NO;
    cell.layer.contentsScale = [UIScreen mainScreen].scale;
    cell.layer.shadowOpacity = 0.7f;
    cell.layer.shadowRadius = 1.0f;
    cell.layer.shadowOffset = CGSizeMake(0,2);
    cell.layer.shadowPath = [UIBezierPath bezierPathWithRect:cell.bounds].CGPath;
    cell.layer.shadowColor = kGlobalLightGreyColor_223.CGColor;
    //设置缓存
    cell.layer.shouldRasterize = YES;
    //设置抗锯齿边缘
    cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
    return cell;
}
 
#pragma mark -UICollectionViewDataSource
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    XYRDetailViewController *play=[[XYRDetailViewController alloc] init];
    [YTHsharedManger startManger].preController = self;
    play.modalPresentationStyle = 0;
    play.Model = [XYRVideoInfoModel yy_modelWithDictionary:_arrDate[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/32+55);
}
 
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    //上、左、下、右的边距
    return UIEdgeInsetsMake(10, 10, 10, 10);
}
 
 
 
 
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
 
@end