OldVideoDetailViewController.m
27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
//
// OldVideoDetailViewController.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/9/27.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "OldVideoDetailViewController.h"
#import "OldArticleDetailViewController.h"
#import "VideoTableViewCell.h"
#import "ArticleTableViewCell.h"
#import "SearchResultViewController.h"
@interface OldVideoDetailViewController ()<CNLivePlayerControllerDelegate>{
UIButton *_shareBtn;
}
@end
@implementation OldVideoDetailViewController
- (void)Pop:(id)sender{
// [self.videoController stop];
for(UIViewController *controller in self.navigationController.viewControllers) {
if([controller isKindOfClass:[CNLiveMyCollectionViewController class]]) {
[self.navigationController popViewControllerAnimated:YES];
return;
}
if ([controller isKindOfClass:[SearchResultViewController class]]) {
[self.navigationController popViewControllerAnimated:YES];
return;
}
}
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (id)initWithDictionary:(NSDictionary *)dictionary{
if (self = [super init]) {
_dictionary = [NSDictionary dictionaryWithDictionary:dictionary];
url = _dictionary[@"videoUrl"];
if (0 == [url length]) {
url = _dictionary[@"uploadVideoUrl"];
}
url = [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
movieUrl = [NSURL URLWithString:url];
videoHeight = MainScreenWidth * (9.0 / 16.0);
if(!(0 == [_dictionary[@"img"] length])){
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_dictionary[@"img"]]];
bgImg = [UIImage imageWithData:data];
}
}
return self;
}
- (NSString *)setHTMLString {
NSString* htmlHeader = [[NSString alloc] initWithFormat:@"<html><p><font style=\"font-size:20px;\"><strong>%@</strong></font></p><body>",[_dictionary objectForKey:@"title"]];
NSString* htmldate = @"";
NSString* htmlForm = @"";
if ([_dictionary objectForKey:@"publishDate"] && [_dictionary objectForKey:@"author"]) {
htmldate = [[NSString alloc] initWithFormat:@"<html><p>%@</p><body>",[NSString stringWithFormat:@"%@",[_dictionary objectForKey:@"publishDate"]]];
htmlForm = [[NSString alloc] initWithFormat:@"<html><p>%@:%@</p><body>", CustomStr(@"Source"), _dictionary[@"author"]];
self.authorName = _dictionary[@"author"];
} else {
htmldate = [[NSString alloc] initWithFormat:@"<html><p>%@</p><body>",[NSString stringWithFormat:@"%@",[_dictionary objectForKey:@"publishDate"]]];
NSDictionary *author = [NSDictionary dictionaryWithContentsOfFile:FavouriteAuthors_PATH];
self.authorName = author[_dictionary[@"pageUrl"]];
htmlForm = [[NSString alloc] initWithFormat:@"<html><p>%@:%@</p><body>",CustomStr(@"Source"), self.authorName];
}
NSString* htmlBody = [[NSString alloc] initWithFormat:@"<div class=\"logo\" style=\"text-indent:2em\"><font style=\"font-size:%@px;\">%@</font></div>",fontArray[fontIndex],[_dictionary objectForKey:@"desc"]];
NSString* htmlFooter = @"</body></html>";
NSString* strHtml = [[NSString alloc] initWithFormat:@"%@%@%@%@%@",htmlHeader,htmldate,htmlForm,htmlBody,htmlFooter];
return strHtml;
}
#pragma mark - UI
-(void)dealloc
{
[self.liveController stop];
self.liveController = nil;
self.videoController = nil;
NSLog(@"delloc");
}
- (void)loadShareView {
UIImageView *lineImage = [[UIImageView alloc] init];
if (iPhoneX) {
lineImage.frame = CGRectMake(0, MainScreenHeight - 44 - 34, MainScreenWidth, 1);
} else {
lineImage.frame = CGRectMake(0, MainScreenHeight - 44, MainScreenWidth, 1);
}
lineImage.backgroundColor = Color_Line;
[self.view addSubview:lineImage];
UIButton *fontSizeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[fontSizeButton setImage:[UIImage imageNamed:@"cnlive_fontsize"] forState:UIControlStateNormal];
if (iPhoneX) {
[fontSizeButton setFrame:CGRectMake((MainScreenWidth/2 - 33)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34, 33, 22)];
} else {
[fontSizeButton setFrame:CGRectMake((MainScreenWidth/2 - 33)/2, MainScreenHeight - 44 + (44 - 22)/2, 33, 22)];
}
[fontSizeButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:fontSizeButton];
[fontSizeButton setTag:10000];
UIButton *isFavoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary];
BOOL isIn = [[DBAction sharedDBAction] isInTable:notice];
if (isIn) {
[isFavoriteButton setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
} else {
[isFavoriteButton setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
if (iPhoneX) {
[isFavoriteButton setFrame:CGRectMake((MainScreenWidth - 23)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34, 33, 22)];
} else {
[isFavoriteButton setFrame:CGRectMake((MainScreenWidth - 23)/2, MainScreenHeight - 44 + (44 - 22)/2, 33, 22)];
}
[isFavoriteButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:isFavoriteButton];
[isFavoriteButton setTag:20000];
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
[shareButton setImage:[UIImage imageNamed:@"cnlive_share"] forState:UIControlStateNormal];
if (iPhoneX) {
[shareButton setFrame:CGRectMake((MainScreenWidth*3/2 - 22)/2, MainScreenHeight - 44 + (44 - 22)/2 - 34, 33, 22)];
} else {
[shareButton setFrame:CGRectMake((MainScreenWidth*3/2 - 22)/2, MainScreenHeight - 44 + (44 - 22)/2, 33, 22)];
}
[shareButton addTarget:self action:@selector(shareButtonTaped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:shareButton];
[shareButton setTag:30000];
_shareBtn = shareButton;
}
- (void)shareButtonTaped:(id)sender {
UIButton *btn = (UIButton *)sender;
if (10000 == btn.tag) {
if ([fontArray count] - 1 == fontIndex) {
fontIndex = 0;
} else {
fontIndex++;
}
[_webView loadHTMLString:[self setHTMLString] baseURL:nil];
} else if (20000 == btn.tag) {
TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary];
BOOL isIn = [[DBAction sharedDBAction] isInTable:notice];
NSMutableDictionary *author = [NSMutableDictionary dictionaryWithContentsOfFile:FavouriteAuthors_PATH];
if (!author) {
author = [NSMutableDictionary dictionary];
}
if (!isIn) {
BOOL isInsert = [[DBAction sharedDBAction] insertTable:notice];
[author setObject:self.authorName forKey:notice.pageUrl];
[author writeToFile:FavouriteAuthors_PATH atomically:YES];
if (isInsert) {
[AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"CollectSuccess")];
[btn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
}
} else {
BOOL isDelete = [[DBAction sharedDBAction] deleteTable:notice];
[author removeObjectForKey:notice.pageUrl];
[author writeToFile:FavouriteAuthors_PATH atomically:YES];
if (isDelete) {
[AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"CancelCollect")];
[btn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
}
} else if (30000 == btn.tag) {
NSString *img = [NSString stringWithFormat:@"%@",_dictionary[@"img"]];
NSString *title = [NSString stringWithFormat:@"%@",_dictionary[@"title"]];
NSString *text = [NSString stringWithFormat:@"%@",!_dictionary[@"desc"]||[_dictionary[@"desc"] isEqualToString:@""]?title:_dictionary[@"desc"]];
NSString *url = [NSString stringWithFormat:@"%@",_dictionary[@"pageUrl"]];
[[TemplateShareManager manager] shareImage:img title:title text:text url:url controller:self];
return;
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[JGMusicManager shareMusicManager] playStop];
[self.navigationController setNavigationBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.videoController stop];
[self.liveController stopShow];
// self.liveController = nil;
[self.navigationController setNavigationBarHidden:NO];
NSError *error = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &error];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadShareView];
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
self.view.backgroundColor = [UIColor whiteColor];
if (iPhoneX) {
backgroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, videoHeight + 44, MainScreenWidth, MainScreenHeight - videoHeight - 44 - 44 - 34)];
} else {
backgroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, videoHeight, MainScreenWidth, MainScreenHeight - videoHeight - 44)];
}
[self.view addSubview:backgroundView];
fontIndex = (int)[[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
heightArr = [NSMutableArray arrayWithArray:@[@"0",@"0",@"0"]];
fontArray = @[@"16",@"20",@"24"];
NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width, user-scalable=no'); document.getElementsByTagName('head')[0].appendChild(meta);";
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
[wkUController addUserScript:wkUScript];
WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
wkWebConfig.userContentController = wkUController;
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 0) configuration:wkWebConfig];
_webView.scrollView.backgroundColor = [UIColor clearColor];
// _webView.dataDetectorTypes = UIDataDetectorTypeNone;
_webView.backgroundColor = [UIColor clearColor];
_webView.scrollView.bounces = NO;
// _webView.delegate = self;
_webView.navigationDelegate = self;
_webView.UIDelegate = self;
_webView.opaque = NO;
[backgroundView addSubview:_webView];
[_webView loadHTMLString:[self setHTMLString] baseURL:nil];
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.backgroundView = nil;
self.tableView.scrollEnabled = NO;
self.tableView.dataSource = self;
self.tableView.delegate = self;
[backgroundView addSubview:self.tableView];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsVerticalScrollIndicator = NO;
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
self.errorLabe = [[UILabel alloc] initWithFrame:CGRectZero];
self.errorLabe.backgroundColor = [UIColor clearColor];
self.errorLabe.textColor = HEXCOLOR(0x333333);
self.errorLabe.font = [UIFont systemFontOfSize:15];
[backgroundView addSubview:self.errorLabe];
self.errorLabe.text = @"没有数据";
self.errorLabe.hidden = YES;
if ([_dictionary[@"playType"] isEqualToString:@"1"]) {
[self addCNLivePlayer];
} else {
[self addZXVideo:movieUrl];
}
}
// CNLivePlayer
- (void)addCNLivePlayer {
if (!self.liveController) {
CGRect frame = CGRectMake(0, iPhoneX ? 44 : 0, MainScreenWidth, videoHeight);
UIView *bgView = [[UIView alloc] initWithFrame:frame];
bgView.backgroundColor = [UIColor blackColor];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(20, 20, 25, 41);
[backButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[bgView addSubview:backButton];
[self.view addSubview:bgView];
// 点播
self.liveController = [[CNLivePlayerController alloc] initVodPlayWithVId:_dictionary[@"uuid"] authSuccess:^{
NSError *error = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error: &error];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[bgView removeFromSuperview];
[self.liveController configPlayerWithFrame:frame isLiving:NO];
[self.liveController showInView:self.view];
} authFailed:^(NSDictionary *errorInfo) {
NSLog(@"初始化点播播放器失败%@", errorInfo);
}];
self.liveController.delegate = self;
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:@"ZXVideoPlayer_DidLockScreen"];
__weak typeof(self) weakSelf = self;
self.liveController.videoPlayerGoBackBlock = ^{
__strong typeof(self) strongSelf = weakSelf;
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:@"ZXVideoPlayer_DidLockScreen"];
[strongSelf.liveController destroyPlayer];
// strongSelf.liveController = nil;
[strongSelf Pop:nil];
};
}
ZXVideo *video = [[ZXVideo alloc] init];
video.title = _dictionary[@"title"];
video.playUrl = url;
self.liveController.video = video;
}
- (void)viewDidDisappear:(BOOL)animated{
[(AppDelegate *)[UIApplication sharedApplication].delegate initializeSDKConfiguration];
}
- (void)backButtonAction:(UIButton *)sender {
[(AppDelegate *)[UIApplication sharedApplication].delegate initializeSDKConfiguration];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)addZXVideo:(NSURL *)videoUrl {
if (!self.videoController) {
CGRect frame = CGRectMake(0, iPhoneX ? 44 : 0, MainScreenWidth, videoHeight);
self.videoController = [[ZXVideoPlayerController alloc] initWithFrame:frame];
//增加播放器背景图片
if (!(nil==bgImg)) {
self.videoController.view.contentMode=UIViewContentModeScaleAspectFit;
self.videoController.view.layer.contents=(__bridge id _Nullable)(bgImg.CGImage);
}
self.liveController.delegate = self;
[self.videoController showInView:self.view];
__weak typeof(self) weakSelf = self;
self.videoController.videoPlayerGoBackBlock = ^{
__strong typeof(self) strongSelf = weakSelf;
[[NSUserDefaults standardUserDefaults] setObject:@0 forKey:@"ZXVideoPlayer_DidLockScreen"];
// strongSelf.videoController = nil;
[strongSelf Pop:nil];
//时长统计结束
if ([strongSelf->_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/djzw/"]) {
//记者问答
[CNLiveStat endEvent:@"djzwsc"];
}else if ([strongSelf->_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/zgsfz/"]){
//视界
[CNLiveStat endEvent:@"sjsc"];
}else if ([strongSelf->_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/gxzf/"]){
//国新联播
[CNLiveStat endEvent:@"gxlbsc"];
}else if ([strongSelf->_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/jlzg/"]){
//记录中国
[CNLiveStat endEvent:@"jlzgsc"];
}else if ([strongSelf->_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/fbhhf/"]){
//发布会回放
[CNLiveStat endEvent:@"fbhhfsc"];
}else if ([strongSelf->_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/icons/"]){
//CHINA ICONS
[CNLiveStat endEvent:@"iconssc"];
}else if ([strongSelf->_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/gxzs/"]){
//CHINA ICONS
[CNLiveStat endEvent:@"gxzssc"];
}
};
}
//时长统计开始
if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/djzw/"]) {
//记者问答
[CNLiveStat beginEvent:@"djzwsc"];
}else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/zgsfz/"]){
//视界
[CNLiveStat beginEvent:@"sjsc"];
}else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/gxzf/"]){
//国新联播
[CNLiveStat beginEvent:@"gxlbsc"];
}else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/jlzg/"]){
//记录中国
[CNLiveStat beginEvent:@"jlzgsc"];
}else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/fbhhf/"]){
//发布会回放
[CNLiveStat beginEvent:@"fbhhfsc"];
}else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/icons/"]){
//CHINA ICONS
[CNLiveStat beginEvent:@"iconssc"];
}else if ([_dictionary[@"cmsColumnId"] isEqualToString:@"spzl/gxzs/"]){
//CHINA ICONS
[CNLiveStat beginEvent:@"gxzssc"];
}
ZXVideo *video = [[ZXVideo alloc] init];
video.playUrl = url;
video.title = _dictionary[@"title"];
self.videoController.video = video;
}
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSURL *requestURL = webView.URL;
if (([[requestURL scheme] isEqualToString: @"http"] || [[requestURL scheme] isEqualToString:@"https"] || [[requestURL scheme] isEqualToString: @"mailto" ]) && (navigationAction.navigationType == WKNavigationTypeLinkActivated)) {
[[UIApplication sharedApplication] openURL:requestURL];
decisionHandler(WKNavigationActionPolicyCancel);
}
decisionHandler(WKNavigationActionPolicyAllow);
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation {
CGFloat width = MainScreenWidth - 20;
NSString *string = [NSString stringWithFormat:
@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function ResizeImages() { "
"var myimg,oldwidth;"
"var maxwidth=%f;" //缩放系数
"for(i=0;i <document.images.length;i++){"
"myimg = document.images[i];"
"if(myimg.width > maxwidth){"
"oldwidth = myimg.width;"
"myimg.width = maxwidth;"
"myimg.height = myimg.height * (maxwidth/oldwidth);"
"}"
"}"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);",width];
[webView evaluateJavaScript:@"ResizeImages();" completionHandler:nil];
[webView evaluateJavaScript:string completionHandler:^(id _Nullable response, NSError * _Nullable error) {
NSLog(@"value: %@ error: %@", response, error);
dispatch_async(dispatch_get_main_queue(), ^{
CGRect frame = self->_webView.frame;
frame.size.width = MainScreenWidth;
frame.size.height = 1;
self->_webView.frame = frame;
CGFloat graphicLiveHeight = self->_webView.scrollView.contentSize.height;
frame.size.height = self->_webView.scrollView.contentSize.height;
self->_webView.frame = frame;
if (0 == [self->heightArr[self->fontIndex] floatValue]) {
[self->heightArr replaceObjectAtIndex:self->fontIndex withObject:[NSString stringWithFormat:@"%f",graphicLiveHeight]];
}
});
}];
[self loadRelatedInformation];
}
- (void)loadRelatedInformation {
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
return;
}
NSString *strUrl = @"http://app.phonemovie.cnlive.com/gxb/api/programRelative";
NSLog(@"%@",strUrl);
NSString *categoryId = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"cmsContentId\":\"%@\"}",_dictionary[@"cmsContentId"]];
NSLog(@"%@",categoryId);
NSDictionary *parameters = @{@"params":categoryId};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:strUrl
parameters:parameters headers:nil
progress:^(NSProgress * _Nonnull uploadProgress) {}
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// 请求成功,解析数据
NSLog(@"%@", responseObject);
NSDictionary *_dic = [NSDictionary dictionaryWithDictionary:responseObject];
if ([_dic[@"errorCode"] isEqualToString:@"0"]) {
NSArray *array = _dic[@"programs"];
if (0 != [array count]) {
self->_newsArray = [NSArray arrayWithArray:array];
[self.tableView setFrame:CGRectMake(0, [self->heightArr[self->fontIndex] floatValue], MainScreenWidth, 36 + 86*self->_newsArray.count)];
} else {
// [self.errorLabe setFrame:CGRectMake(12, [heightArr[fontIndex] floatValue], MainScreenWidth - 24, 20)];
// self.errorLabe.hidden = NO;
}
NSLog(@"%@",NSStringFromCGRect(self.tableView.frame));
[self->backgroundView setContentSize:CGSizeMake(MainScreenWidth, [heightArr[self->fontIndex] floatValue] + self.tableView.frame.size.height)];
[self.tableView reloadData];
} else {
[AlertViewTool showHUDViewText:_dic[@"errorMessage"]];
}
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
NSLog(@"%@", [error localizedDescription]);
[SVProgressHUD dismiss];
[AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")];
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_newsArray count];
}
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
return 86.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30.0;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 30)];
view.backgroundColor = [UIColor whiteColor];
UIImageView *lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 1)];
lineImage1.backgroundColor = Color_Line;
[view addSubview:lineImage1];
UILabel *relatedInformation = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, MainScreenWidth - 24, 30)];
relatedInformation.backgroundColor = [UIColor clearColor];
relatedInformation.textColor = HEXCOLOR(0x333333);
relatedInformation.font = [UIFont systemFontOfSize:15];
[view addSubview:relatedInformation];
relatedInformation.text = CustomStr(@"RelevantInformation");
return view;
}
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section {
return 6.0;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 6)];
view.backgroundColor = [UIColor whiteColor];
return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *_dic = _newsArray[indexPath.row];
if ([@"program" isEqualToString:_dic[@"type"]]) {
static NSString *identifier = @"videoCell";
VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[VideoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
[cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
cell.playImage.image = [UIImage imageNamed:@"playButton"];
cell.titleLabel.text = _dic[@"title"];
cell.timeLabel.text = _dic[@"createDate"];
return cell;
} else if ([@"article" isEqualToString:_dic[@"type"]]) {
static NSString *identifier = @"articleCell";
ArticleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[ArticleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
[cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
cell.titleLabel.text = _dic[@"title"];
cell.timeLabel.text = _dic[@"createDate"];
return cell;
}
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"%@",_newsArray[indexPath.row]);
NSDictionary *_dic = _newsArray[indexPath.row];
[self pushViewTo:_dic];
}
- (void)pushViewTo:(NSDictionary *)_dic {
if ([@"program" isEqualToString:_dic[@"type"]]) {
OldVideoDetailViewController *vc = [[OldVideoDetailViewController alloc] initWithDictionary:_dic];
vc.title = _dic[@"cmsColumnName"];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
} else if ([@"article" isEqualToString:_dic[@"type"]]) {
OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:_dic];
vc.title = _dic[@"cmsColumnName"];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
}
-(void)viewDidLayoutSubviews{
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
[self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([cell respondsToSelector:@selector(setSeparatorInset:)])
[cell setSeparatorInset:UIEdgeInsetsZero];
if ([cell respondsToSelector:@selector(setLayoutMargins:)])
[cell setLayoutMargins:UIEdgeInsetsZero];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (BOOL)shouldAutorotate {
return ![[[NSUserDefaults standardUserDefaults] objectForKey:@"ZXVideoPlayer_DidLockScreen"] boolValue];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (void)shareButtonCNLivePlayerController:(CNLivePlayerController *)view{
[self shareButtonTaped:_shareBtn];
}
@end