VoiceViewController.m
50.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
//
// VoiceViewController.m
// SCIOLiveCN
//
// Created by huayu on 16/12/7.
// Copyright © 2016年 huayu. All rights reserved.
//
#import "VoiceViewController.h"
#import "SelectedTableViewCell.h"
#import "NewVoiceTableViewCell.h"
#import "NewsVoiceTableViewCell.h"
@interface VoiceViewController()<UITableViewDelegate,UITableViewDataSource,JGMusicManagerDelegate>{
UIButton *listenBtn; //收听
UIButton *sVoiceBtn; //国新之声 GXZS
UIButton *engVOSBtn; //VOICE OF SCIO
UIView *selectView;//线
NSInteger selectType;
NSDictionary *_dictionary;
JGMusicManager *music;//播放器
UILabel *titleLabel;//标题
UILabel *subTitleLabel;
UILabel *timeLabel;//时间
UILabel *sourceLabel;//来源
UIButton *shareBtn;//分享
UIButton *favoriteBtn;//收藏
UIImageView *reviewImage;//预览图片
UIButton *playBackBtn;//15s
UIButton *playBtn;//播放
UIButton *playNextBtn;//下一首
UILabel *playTimeLabel;//播放时间
UIView *playProgress;//进度条
}
@property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeGestureRecognizer;
@property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipeGestureRecognizer;
@property (nonatomic, strong) NSMutableArray *stingArray;//国新之声 专题数据源
@property (nonatomic, strong) NSMutableArray *dataArray;//国新之声 最新数据源
@property (nonatomic, strong) NSMutableArray *engStingArray;//VOS 专题数据源
@property (nonatomic, strong) NSMutableArray *engDataArray;//VOS 最新数据源
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITableView *enTableView;
@property (nonatomic, assign) NSInteger pageNumber;
@property (nonatomic, assign) NSInteger engPageNumber;
@property (nonatomic, strong) NSTimer *timer;
@end
@implementation VoiceViewController
static const NSInteger margin = 34;
#pragma mark - Data
- (void)getData{
if(IS_CHINESE){
self.pageNumber = 1;
[self loadVoiceData];
}else{
self.engPageNumber = 1;
[self loadVOSData];
}
}
#pragma mark - Data
- (void)loadVoiceData {
//中文
[self loadVoice];//最新
[self loadVoiceTopic];//推荐
}
- (void)loadVOSData {
//英文
[self loadVOS];//最新
[self loadVOSTopic];//推荐
}
//国新之声推荐
- (void)loadVoiceTopic {
NSString *strUrl = REQUESTURL(@"gxb/api/page");
NSLog(@"%@",strUrl);
NSDictionary *parameters = @{@"params":@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"pageUUID\":\"d6262244-b059-11e6-b220-c7d8a7a18cc4\",\"pageType\":\"index\"}"};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:strUrl parameters:parameters headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// 请求成功,解析数据
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
NSLog(@"%@", dic);
if ([dic[@"errorCode"] isEqualToString:@"0"]) {
NSDictionary *gxzstj = dic[@"gxzstj"];
NSArray *array = gxzstj[@"programs"];
if (array.count > 0) {
[self->_stingArray removeAllObjects];
[self.stingArray addObjectsFromArray:array];
}
} else {
[AlertViewTool showHUDViewText:dic[@"errorMessage"]];
}
[self.tableView reloadData];
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
NSLog(@"%@", [error localizedDescription]);
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
//国新之声最新
- (void)loadVoice {
self.pageNumber = 1;
[self.tableView.mj_footer setHidden:NO];
NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest");
NSString *categoryId = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"categoryId\":\"spzl/gxzs/\",\"page\":\"%ld\",\"pageSize\":\"10\"}",(long)self.pageNumber];
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
[self.tableView.mj_header endRefreshing];
[self.tableView.mj_footer endRefreshing];
return;
}
[AlertViewTool showHUDView];
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) {
// 请求成功,解析数据
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
NSLog(@"%@", dic);
if ([dic[@"errorCode"] isEqualToString:@"0"]) {
NSArray *array = dic[@"programs"];
if ([array count] > 0) {
[self.dataArray removeAllObjects];
[self->music.musicArray removeAllObjects];
NSMutableArray *newArray = [self arrayDateFromArray:array];
self.dataArray = [NSMutableArray arrayWithArray:newArray];
self->music.musicArray = [NSMutableArray arrayWithArray:newArray];
self->music.index = 0;
self->_dictionary = [self.dataArray firstObject];
if (self.tableView.hidden) {
[self setPlayModel:self->_dictionary];
}
}
} else {
[AlertViewTool showHUDViewText:dic[@"errorMessage"]];
}
[self.tableView.mj_header endRefreshing];
[self.tableView reloadData];
[AlertViewTool hideHUDView];
[self.tableView.mj_footer setState:MJRefreshStateIdle];
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self.tableView.mj_header endRefreshing];
[AlertViewTool hideHUDView];
[self.tableView.mj_footer setState:MJRefreshStateIdle];
}];
}
//VOS专题
- (void)loadVOSTopic {
NSString *strUrl = REQUESTURL(@"gxb/api/page");
NSLog(@"%@",strUrl);
NSDictionary *parameters = @{@"params":@"{\"plat\":\"a\",\"version\":\"5.0\",\"appid\":\"gxb\",\"pageUUID\":\"bca5bdd0-259a-11e8-908c-c7d8a7a18cc4\",\"pageType\":\"channelList\"}"};
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:strUrl
parameters:parameters headers:nil
progress:^(NSProgress * _Nonnull uploadProgress) {}
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// 请求成功,解析数据
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
NSLog(@"%@", dic);
if ([dic[@"errorCode"] isEqualToString:@"0"]) {
NSDictionary *gxzstj = dic[@"gxzsnews"];
NSArray *array = gxzstj[@"programs"];
if ([array count] > 0) {
[self.engStingArray removeAllObjects];
[self.engStingArray addObjectsFromArray:array];
}
} else {
[AlertViewTool showHUDViewText:dic[@"errorMessage"]];
}
[self.enTableView reloadData];
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
NSLog(@"%@", [error localizedDescription]);
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
//VOS最新
- (void)loadVOS{
self.engPageNumber = 1;
[self.enTableView.mj_footer setHidden:NO];
NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest");
NSString *categoryId = [NSString stringWithFormat:@"{\"plat\":\"a\",\"version\":\"5.0\",\"appid\":\"gxb\",\"categoryId\":\"spzl/news/\",\"page\":\"%ld\"}",(long)self.engPageNumber];
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
[self.enTableView.mj_header endRefreshing];
[self.enTableView.mj_footer endRefreshing];
return;
}
[AlertViewTool showHUDView];
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) {
// 请求成功,解析数据
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
NSLog(@"%@", dic);
if ([dic[@"errorCode"] isEqualToString:@"0"]) {
NSArray *array = dic[@"programs"];
if (array.count > 0) {
[self.engDataArray removeAllObjects];
[self->music.musicArray removeAllObjects];
NSMutableArray *newArray = [self arrayDateFromArray:array];
self.engDataArray = [NSMutableArray arrayWithArray:newArray];
self->music.musicArray = [NSMutableArray arrayWithArray:newArray];
self->music.index = 0;
self->_dictionary = [self.engDataArray firstObject];
//通知主线程刷新
dispatch_async(dispatch_get_main_queue(), ^{
if (self.enTableView.hidden) {
[self setPlayModel:self->_dictionary];
}
});
}
} else {
[AlertViewTool showHUDViewText:dic[@"errorMessage"]];
}
[self.enTableView reloadData];
[AlertViewTool hideHUDView];
[self.enTableView.mj_header endRefreshing];
[self.enTableView.mj_footer setState:MJRefreshStateIdle];
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
[self.enTableView.mj_header endRefreshing];
[self.enTableView.mj_footer endRefreshing];
NSLog(@"%@", [error localizedDescription]);
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
- (void)loadMoreOfGXZS {
self.pageNumber++;
NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest");
NSString *categoryId = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"categoryId\":\"spzl/gxzs/\",\"page\":\"%ld\",\"pageSize\":\"10\"}",(long)self.pageNumber];
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
[self.tableView.mj_footer endRefreshing];
[self.tableView.mj_header endRefreshing];
return;
}
[AlertViewTool showHUDView];
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) {
// 请求成功,解析数据
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
NSLog(@"%@", dic);
if ([dic[@"errorCode"] isEqualToString:@"0"]) {
NSArray *array = dic[@"programs"];
if ([array count] > 0) {
NSMutableArray *newsArray = [self arrayDateFromArray:array];
[self.dataArray addObjectsFromArray:newsArray];
[self->music.musicArray addObjectsFromArray:newsArray];
}
} else {
[AlertViewTool showHUDViewText:dic[@"errorMessage"]];
}
[self.tableView reloadData];
[self.tableView.mj_footer endRefreshing];
[self.tableView.mj_header endRefreshing];
if ([dic[@"nextCursor"] isEqualToString:@"0"]) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
[AlertViewTool hideHUDView];
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
[self.tableView.mj_header endRefreshing];
[self.tableView.mj_footer endRefreshing];
NSLog(@"%@", [error localizedDescription]);
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
- (void)loadMoreOfVOS {
self.engPageNumber++;
NSString *strUrl = REQUESTURL(@"gxb/api/cataloglatest");
NSString *categoryId = [NSString stringWithFormat:@"{\"plat\":\"a\",\"version\":\"5.0\",\"appid\":\"gxb\",\"categoryId\":\"spzl/news/\",\"page\":\"%ld\"}",(long)self.engPageNumber];
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
[self.enTableView.mj_footer endRefreshing];
[self.enTableView.mj_header endRefreshing];
return;
}
[AlertViewTool showHUDView];
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) {
// 请求成功,解析数据
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
NSLog(@"%@", dic);
if ([dic[@"errorCode"] isEqualToString:@"0"]) {
NSArray *array = dic[@"programs"];
if (array.count > 0) {
NSMutableArray *newsArray = [self arrayDateFromArray:array];
[self.engDataArray addObjectsFromArray:newsArray];
}
} else {
[AlertViewTool showHUDViewText:dic[@"errorMessage"]];
}
[self.enTableView reloadData];
[self.enTableView.mj_footer endRefreshing];
[self.enTableView.mj_header endRefreshing];
if ([dic[@"nextCursor"] isEqualToString:@"0"]) {
[self.enTableView.mj_footer endRefreshingWithNoMoreData];
}
[AlertViewTool hideHUDView];
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
[self.enTableView.mj_header endRefreshing];
[self.enTableView.mj_footer endRefreshing];
[AlertViewTool hideHUDView];
NSLog(@"%@", [error localizedDescription]);
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// UIImage *backGroundImage = [UIImage imageNamed:@"cnlive_headerBack"];
//
// backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
// [self.navigationController.navigationBar setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];
NSError *error = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &error];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
// 判断收藏按钮状态
TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary];
BOOL isIn = [[DBAction sharedDBAction] isInTable:[User_Defaults objectForKey:Language_Local] notice:notice];
if (isIn) {
[favoriteBtn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
} else {
[favoriteBtn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
if(![music isPlay]){
// [music playAndPause];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = HEXCOLOR(0xeaeded);
self.name = CustomStr(@"VOICEOFSCIO");
self.stingArray = [[NSMutableArray alloc] init];
self.dataArray = [[NSMutableArray alloc] init];
self.engStingArray = [[NSMutableArray alloc] init];
self.engDataArray = [[NSMutableArray alloc] init];
_dictionary = [[NSDictionary alloc] init];
music = [JGMusicManager shareMusicManager];
music.delegate = self;
//数据
[self getData];
//顶部切换菜单
[self setButtonView];
//播放器
[self setAVPlayerView];
//列表
[self createUI];
//滑动手势
[self createSwipeGestureRecognizer];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerAct) userInfo:nil repeats:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reSetPlayer) name:@"pauseVocieNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLanguageVersion:) name:@"changeLanguageVersion" object:nil];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[music playStop];
}
#pragma mark - Notification
- (void)changeLanguageVersion:(NSNotification *)notification {
[music playStop];
}
- (void)reSetPlayer {
[playBackBtn setEnabled:NO];
[playBtn setImage:[UIImage imageNamed:@"cnlive_voice_play"] forState:UIControlStateNormal];
}
#pragma mark - UI
//顶部按钮UI
- (void)setButtonView {
UIView *btnBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 45)];
// btnBackView.backgroundColor = [UIColor whiteColor];
btnBackView.backgroundColor = HEXCOLOR(0x1959C9);
listenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[listenBtn addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
// [listenBtn setTitleColor:HEXCOLOR(0x1959C9) forState:UIControlStateNormal];
[listenBtn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
[listenBtn setFrame:CGRectMake(0, 0, MainScreenWidth/2.0, 45)];
[listenBtn setTitle:CustomStr(@"Play") forState:UIControlStateNormal];
listenBtn.titleLabel.font = [UIFont systemFontOfSize:16];
[btnBackView addSubview:listenBtn];
listenBtn.tag = 1000;
selectType = 1000;
if(IS_CHINESE){
sVoiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[sVoiceBtn addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
[sVoiceBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
[sVoiceBtn setFrame:CGRectMake(MainScreenWidth/2.0, 0, MainScreenWidth/2.0, 45)];
[sVoiceBtn setTitle:@"国新之声" forState:UIControlStateNormal];
sVoiceBtn.titleLabel.font = [UIFont systemFontOfSize:16];
[btnBackView addSubview:sVoiceBtn];
sVoiceBtn.tag = 1001;
}else{
engVOSBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[engVOSBtn addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventTouchUpInside];
[engVOSBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
[engVOSBtn setFrame:CGRectMake(MainScreenWidth/2.0, 0, MainScreenWidth/2.0, 45)];
[engVOSBtn setTitle:@"VOICE OF SCIO" forState:UIControlStateNormal];
engVOSBtn.titleLabel.font = [UIFont systemFontOfSize:16];
[btnBackView addSubview:engVOSBtn];
engVOSBtn.tag = 1002;
}
CGFloat selectViewWidth = 90;
CGFloat margin = (MainScreenWidth/2.0-selectViewWidth)/2.0;
selectView = [[UIView alloc] initWithFrame:CGRectMake(margin, 42, selectViewWidth, 2)];
// selectView.backgroundColor = HEXCOLOR(0x1959C9);
selectView.backgroundColor = [UIColor whiteColor];
[btnBackView addSubview:selectView];
[self.view addSubview:btnBackView];
}
//收听界面UI
- (void)setAVPlayerView {
// subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(34, 56, screenWidth - 68, 20)];
// subTitleLabel.textColor = UIColorFromRGB(0x1959C9);
// subTitleLabel.font = [UIFont systemFontOfSize:15];
// [self.view addSubview:subTitleLabel];
titleLabel = [[UILabel alloc] init];
titleLabel.numberOfLines = 0;
titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
titleLabel.font = [UIFont systemFontOfSize:21];
titleLabel.textColor = HEXCOLOR(0x333333);
[self.view addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset(60);
make.left.equalTo(self.view.mas_left).with.offset(margin);
make.right.equalTo(self.view.mas_right).with.offset(-margin);
}];
timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth - 2*margin, 20)];
timeLabel.numberOfLines = 2;
timeLabel.font = [UIFont systemFontOfSize:13];
timeLabel.textColor = HEXCOLOR(0x666666);
[self.view addSubview:timeLabel];
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->titleLabel.mas_bottom).with.offset(10);
make.left.equalTo(self.view.mas_left).with.offset(margin);
}];
sourceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth - 2*margin, 20)];
sourceLabel.text = [NSString stringWithFormat:@"%@: ", CustomStr(@"Source")];
sourceLabel.numberOfLines = 2;
sourceLabel.font = [UIFont systemFontOfSize:13];
sourceLabel.textColor = HEXCOLOR(0x666666);
[self.view addSubview:sourceLabel];
[sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->timeLabel.mas_bottom).with.offset(10);
make.left.equalTo(self.view.mas_left).with.offset(margin);
}];
//分享
shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[shareBtn setFrame:CGRectMake(0, 0, 100, 20)];
[shareBtn setImage:[UIImage imageNamed:@"cnlive_share"] forState:UIControlStateNormal];
[shareBtn setTitleColor:HEXCOLOR(0x666666) forState:UIControlStateNormal];
shareBtn.titleLabel.font = [UIFont systemFontOfSize:13];
[shareBtn setTitle:[NSString stringWithFormat:@" %@", CustomStr(@"Share")] forState:UIControlStateNormal];
[shareBtn addTarget:self action:@selector(shareBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[shareBtn setTitleColor:HEXCOLOR(0x666666) forState:UIControlStateNormal];
[self.view addSubview:shareBtn];
[shareBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->sourceLabel.mas_bottom).with.offset(10);
make.left.equalTo(self.view.mas_left).with.offset(50);
}];
//收藏
favoriteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[favoriteBtn setFrame:CGRectMake(0, 0, 100, 20)];
[favoriteBtn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
[favoriteBtn setTitleColor:HEXCOLOR(0x666666) forState:UIControlStateNormal];
favoriteBtn.titleLabel.font = [UIFont systemFontOfSize:13];
[favoriteBtn setTitle:[NSString stringWithFormat:@" %@", CustomStr(@"Collection")] forState:UIControlStateNormal];
[favoriteBtn addTarget:self action:@selector(favoriteBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[favoriteBtn setTitleColor:HEXCOLOR(0x666666) forState:UIControlStateNormal];
[self.view addSubview:favoriteBtn];
[favoriteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->sourceLabel.mas_bottom).with.offset(10);
make.right.equalTo(self.view.mas_right).with.offset(-50);
}];
CGFloat playBackX = (MainScreenWidth - 80 - 64)/2 - 80*(MainScreenWidth/640);
CGFloat playBtnX = (MainScreenWidth - 80)/2;
CGFloat playNextX = (MainScreenWidth + 80)/2 + 80*(MainScreenWidth/640);
NSLog(@"%f",80*(MainScreenWidth/640));
playBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
if (iPhoneX) {
[playBackBtn setFrame:CGRectMake(playBackX, MainScreenHeight - 218 - 34 - 44, 32, 37)];
} else {
[playBackBtn setFrame:CGRectMake(playBackX, MainScreenHeight - 218, 32, 37)];
}
[playBackBtn setImage:[UIImage imageNamed:@"cnlive_voice_back"] forState:UIControlStateNormal];
[playBackBtn addTarget:self action:@selector(playBackBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:playBackBtn];
playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
if (iPhoneX) {
[playBtn setFrame:CGRectMake(playBtnX, MainScreenHeight - 240 - 34 - 44, 80, 80)];
} else {
[playBtn setFrame:CGRectMake(playBtnX, MainScreenHeight - 240, 80, 80)];
}
[playBtn setImage:[UIImage imageNamed:@"cnlive_voice_play"] forState:UIControlStateNormal];
[playBtn addTarget:self action:@selector(playBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:playBtn];
playNextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
if (iPhoneX) {
[playNextBtn setFrame:CGRectMake(playNextX, MainScreenHeight - 213 - 34 - 44, 27, 26)];
} else {
[playNextBtn setFrame:CGRectMake(playNextX, MainScreenHeight - 213, 27, 26)];
}
[playNextBtn setImage:[UIImage imageNamed:@"cnlive_voice_next"] forState:UIControlStateNormal];
[playNextBtn addTarget:self action:@selector(playNextBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:playNextBtn];
if (iPhoneX) {
playTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(MainScreenWidth - 125, MainScreenHeight - 160 - 34 - 44, 100, 20)];
} else {
playTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(MainScreenWidth - 125, MainScreenHeight - 160, 100, 20)];
}
playTimeLabel.numberOfLines = 2;
playTimeLabel.textAlignment = NSTextAlignmentRight;
playTimeLabel.font = [UIFont systemFontOfSize:13];
playTimeLabel.textColor = HEXCOLOR(0x666666);
[self.view addSubview:playTimeLabel];
UIView *progressView = [[UIView alloc] init];
if (iPhoneX) {
progressView.frame = CGRectMake(25, MainScreenHeight - 138 - 34 - 44, MainScreenWidth - 50, 13);
} else {
progressView.frame = CGRectMake(25, MainScreenHeight - 138, MainScreenWidth - 50, 13);
}
progressView.backgroundColor = HEXCOLOR(0xD9D9D9);
[self.view addSubview:progressView];
if (iPhoneX) {
playProgress = [[UIView alloc] initWithFrame:CGRectMake(25, MainScreenHeight - 138 - 34 - 44, 0, 13)];
} else {
playProgress = [[UIView alloc] initWithFrame:CGRectMake(25, MainScreenHeight - 138, 0, 13)];
}
playProgress.backgroundColor = HEXCOLOR(0x1959C9);
[self.view addSubview:playProgress];
reviewImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
reviewImage.backgroundColor = [UIColor whiteColor];
reviewImage.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:reviewImage];
[reviewImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self->titleLabel.mas_left);
make.right.equalTo(self->titleLabel.mas_right);
make.top.equalTo(self->favoriteBtn.mas_bottom).with.offset(5);
make.bottom.equalTo(self->playBtn.mas_top).with.offset(-5);
}];
}
//2个列表UI
- (void)createUI{
CGFloat viewHeight = MainScreenHeight - NavBarHeight - TabBarHeight - 45;//45 顶部按钮高度
NSMutableArray *refreshingImages = [NSMutableArray array];
for (NSUInteger i = 1; i < 4; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refresh_animation%lu", (unsigned long)i]];
[refreshingImages addObject:image];
}
if(IS_CHINESE){
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 45, MainScreenWidth, viewHeight) style:UITableViewStyleGrouped];
_tableView.backgroundColor = HEXCOLOR(0xeaeded);
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.tag = 10000;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
[self.view addSubview:self.tableView];
//设置下拉刷新
MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadVoiceData)];
[header setImages:refreshingImages forState:MJRefreshStateRefreshing];
header.lastUpdatedTimeLabel.hidden = YES;
header.stateLabel.hidden = YES;
//设置上拉加载
MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreOfGXZS)];
[footer setTitle:CustomStr(@"RefreshBackFooterIdleText") forState:MJRefreshStateIdle];
[footer setTitle:CustomStr(@"RefreshBackFooterPullingText") forState:MJRefreshStatePulling];
[footer setTitle:CustomStr(@"RefreshBackFooterRefreshingText") forState:MJRefreshStateRefreshing];
[footer setTitle:CustomStr(@"RefreshBackFooterNoMoreDataText") forState:MJRefreshStateNoMoreData];
_tableView.mj_header = header;
_tableView.mj_footer = footer;
_tableView.hidden = YES;
}else{
self.enTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 45, MainScreenWidth, viewHeight) style:UITableViewStyleGrouped];
_enTableView.backgroundColor = HEXCOLOR(0xeaeded);
_enTableView.dataSource = self;
_enTableView.delegate = self;
_enTableView.tag = 10001;
_enTableView.estimatedRowHeight = 0;
_enTableView.estimatedSectionHeaderHeight = 0;
_enTableView.estimatedSectionFooterHeight = 0;
_enTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.enTableView];
//设置下拉刷新
MJRefreshGifHeader *engHeader = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadVOSData)];
[engHeader setImages:refreshingImages forState:MJRefreshStateRefreshing];
engHeader.lastUpdatedTimeLabel.hidden = YES;
engHeader.stateLabel.hidden = YES;
//设置上拉加载
MJRefreshAutoNormalFooter *engFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreOfVOS)];
[engFooter setTitle:CustomStr(@"RefreshBackFooterIdleText") forState:MJRefreshStateIdle];
[engFooter setTitle:CustomStr(@"RefreshBackFooterPullingText") forState:MJRefreshStatePulling];
[engFooter setTitle:CustomStr(@"RefreshBackFooterRefreshingText") forState:MJRefreshStateRefreshing];
[engFooter setTitle:CustomStr(@"RefreshBackFooterNoMoreDataText") forState:MJRefreshStateNoMoreData];
_enTableView.mj_header = engHeader;
_enTableView.mj_footer = engFooter;
_enTableView.hidden = YES;
}
}
#pragma mark - 左右滑动手势
- (void)createSwipeGestureRecognizer{
self.leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
self.rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
self.leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
self.rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:self.leftSwipeGestureRecognizer];
[self.view addGestureRecognizer:self.rightSwipeGestureRecognizer];
}
- (void)timerAct {
if (music.player.currentTime.timescale == 0 || music.player.currentItem.duration.timescale == 0) {
return;
}
if (music.isPlay) {
//获取音乐总时长
long long int totalTime = music.player.currentItem.duration.value / music.player.currentItem.duration.timescale;
//获取当前时间
long long int currentTime = music.player.currentTime.value / music.player.currentTime.timescale;
if (currentTime > 15) {
[playBackBtn setEnabled:YES];
}
[playBtn setImage:[UIImage imageNamed:@"cnlive_voice_pause"] forState:UIControlStateNormal];
NSString *currentTimeText = [NSString stringWithFormat:@"%02lld:%02lld",currentTime / 60, currentTime % 60];
NSString *totalTimeText = [NSString stringWithFormat:@"%02lld:%02lld",totalTime / 60, totalTime % 60];
playTimeLabel.text = [NSString stringWithFormat:@"%@ / %@",currentTimeText,totalTimeText];
if (totalTime) {
double viewWidth = currentTime*(MainScreenWidth - 50)/totalTime;
CGRect frame = playProgress.frame;
frame.size.width = viewWidth;
playProgress.frame = frame;
}
if (currentTime == totalTime) {
[self playNextBtnClicked:nil];
}
}
}
#pragma mark - 滑动切换顶部按钮
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)handleSwipes:(UISwipeGestureRecognizer *)sender {
if (sender.direction == UISwipeGestureRecognizerDirectionRight) {
[self ToShouTing];
return;
} else if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
if(IS_CHINESE){
[self ToGXZSList];
return;
}else{
[self ToVOSList];
return;
}
}
}
- (void)changeType:(id)sender {
UIButton *btn = (UIButton *)sender;
if (selectType == btn.tag) return;
if (1000 == btn.tag) {
[self ToShouTing];
} else if (1001 == btn.tag) {
[self ToGXZSList];
} else {
[self ToVOSList];
}
}
#pragma mark - 点击切换顶部按钮
- (void)ToShouTing {
selectType = 1000;
// [listenBtn setTitleColor:HEXCOLOR(0x1959C9) forState:UIControlStateNormal];
[listenBtn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
[sVoiceBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
[engVOSBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
CGFloat margin = (MainScreenWidth/2.0-90)/2.0;
[selectView setFrame:CGRectMake(margin, 42, 90, 2)];
_tableView.hidden = YES;
_enTableView.hidden = YES;
}
- (void)ToGXZSList {
selectType = 1001;
[listenBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
// [sVoiceBtn setTitleColor:HEXCOLOR(0x1959C9) forState:UIControlStateNormal];
[sVoiceBtn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
[engVOSBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
CGFloat margin = (MainScreenWidth/2.0-90)/2.0;
[selectView setFrame:CGRectMake(MainScreenWidth/2.0+margin, 42, 90, 2)];
_tableView.hidden = NO;
_enTableView.hidden = YES;
}
- (void)ToVOSList {
selectType = 1002;
[listenBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
[sVoiceBtn setTitleColor:HEXCOLOR(0x979ba3) forState:UIControlStateNormal];
// [engVOSBtn setTitleColor:HEXCOLOR(0x1959C9) forState:UIControlStateNormal];
[engVOSBtn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
CGFloat margin = (MainScreenWidth/2.0-90)/2.0;
[selectView setFrame:CGRectMake(MainScreenWidth/2.0+margin, 42, 90, 2)];
_enTableView.hidden = NO;
_tableView.hidden = YES;
}
- (void)setPlayModel:(NSDictionary *)dic {
[AlertViewTool showHUDView];
[self reSetPlayer];
subTitleLabel.text = dic[@"cmsColumnName"];
titleLabel.text = dic[@"title"];
timeLabel.text = dic[@"createDate"];
if ([[sourceLabel.text substringWithRange:NSMakeRange(0, 2)] isEqualToString:@"来源"]) {
sourceLabel.text = [NSString stringWithFormat:@"%@: %@",CustomStr(@"Source"), dic[@"author"]];
} else {
sourceLabel.text = [NSString stringWithFormat:@"Source: %@",dic[@"author"]];
}
[reviewImage sd_setImageWithURL:dic[@"imgSmall"]];
// 判断收藏按钮状态
TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary];
BOOL isIn = [[DBAction sharedDBAction] isInTable:[User_Defaults objectForKey:Language_Local] notice:notice];
if (isIn) {
[favoriteBtn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
} else {
[favoriteBtn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
[music replaceItemWithDictionary:dic];
}
#pragma mark - JGMusicManagerDelegate
- (void)lastMusic {
[self reSetPlayer];
music.index--;
if (music.index == -1) {
music.index = music.musicArray.count - 1;
}
_dictionary = music.musicArray[music.index];
[self setPlayModel:_dictionary];
}
- (void)NextMusic {
[self playNextBtnClicked:nil];
}
#pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView.tag == 10000) {
NSInteger count = 0;
if (0 == section) {
count = self.stingArray.count;
} else if (1 == section) {
count = self.dataArray.count;
}
return count;
} else {
NSInteger count = 0;
if (0 == section) {
count = self.engStingArray.count;
} else if (1 == section) {
count = self.engDataArray.count;
}
return count;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 35.0;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 35)];
view.backgroundColor = HEXCOLOR(0xeaeded);
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(12, 0, MainScreenWidth - 24, 1)];
lineView.backgroundColor = HEXCOLOR(0x04558c);
[view addSubview:lineView];
UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 10, MainScreenWidth - 24, 20)];
topLabel.backgroundColor = [UIColor clearColor];
topLabel.textColor = HEXCOLOR(0x04558c);
topLabel.font = [UIFont systemFontOfSize:15];
[view addSubview:topLabel];
if (0 == section) {
if (tableView.tag == 10000) {
topLabel.text = @"国新之声推荐";
}
if (tableView.tag == 10001) {
topLabel.text = @"EDITOR'S PICK";
}
} else if (1 == section) {
if (tableView.tag == 10000) {
topLabel.text = @"最新";
}
if (tableView.tag == 10001) {
topLabel.text = @"LATEST";
}
}
return view;
}
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section {
return 5.0;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 5)];
view.backgroundColor = HEXCOLOR(0xeaeded);
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return 66.0;
} else if (indexPath.section == 1) {
return 86;
}
return 66;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (0 == indexPath.section) {
NSDictionary *_dic = [NSDictionary dictionary];
if (tableView.tag == 10000) {
_dic = self.stingArray[indexPath.row];
} else {
_dic = self.engStingArray[indexPath.row];
}
static NSString *identifier = @"SelectedTableViewCell";
SelectedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[SelectedTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
if (0 == indexPath.row%2) {
cell.bgView.backgroundColor = HEXCOLOR(0x9189CF);
} else {
cell.bgView.backgroundColor = HEXCOLOR(0x66AFD5);
}
cell.titleLabel.text = _dic[@"title"];
cell.playImage.image = [UIImage imageNamed:@"whitePlay"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} else if (1 == indexPath.section) {
NSDictionary *_dic = [NSDictionary dictionary];
if (tableView.tag == 10000) {
_dic = self.dataArray[indexPath.row];
} else {
_dic = self.engDataArray[indexPath.row];
}
static NSString *identifier = @"NewsVoiceTableViewCell";
NewsVoiceTableViewCell *cell = [[NewsVoiceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];;
cell.titleLabel.text = _dic[@"title"];
cell.timeLabel.text = _dic[@"createDate"];
cell.lengthLabel.text= [self computingTime:[_dic[@"totalTime"] integerValue]];
cell.soundImage.image= [UIImage imageNamed:@"voiceTime"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *text = [NSString stringWithFormat:@"%@",_dic[@"tags"]];
if ([text isEqualToString:@"<null>"]) {
text = @"";
}
if (text.length > 0) {
cell.tagLabel.text = text;
[cell reSetTagFrame];
}
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 {
if (tableView.tag == 10000) {
[music.musicArray removeAllObjects];
music.musicArray = [NSMutableArray arrayWithArray:self.dataArray];
if (0 == indexPath.section) {
_dictionary = self.stingArray[indexPath.row];
for (int i = 0; i < self.dataArray.count; i++) {
NSDictionary *d = self.dataArray[i];
if ([_dictionary[@"title"] isEqualToString:d[@"title"]]) {
music.index = i;
_dictionary = d;
}
}
} else if (1 == indexPath.section) {
_dictionary = self.dataArray[indexPath.row];
music.index = indexPath.row;
}
} else {
[music.musicArray removeAllObjects];
music.musicArray = [NSMutableArray arrayWithArray:self.engDataArray];
if (0 == indexPath.section) {
_dictionary = self.engStingArray[indexPath.row];
for (int i = 0; i < self.engDataArray.count; i++) {
NSDictionary *d = self.engDataArray[i];
if ([_dictionary[@"cid"] isEqualToString:d[@"cmsContentId"]]) {
music.index = i;
_dictionary = d;
}
}
} else if (1 == indexPath.section) {
_dictionary = self.engDataArray[indexPath.row];
music.index = indexPath.row;
}
}
[self setPlayModel:_dictionary];
if (tableView.tag == 10000) {
sourceLabel.text = [NSString stringWithFormat:@"来源: %@",_dictionary[@"author"]?_dictionary[@"author"]:@"国新APP"];
[shareBtn setTitle:[NSString stringWithFormat:@" %@",CustomStr(@"Share")] forState:UIControlStateNormal];
[favoriteBtn setTitle:[NSString stringWithFormat:@" %@",CustomStr(@"Collection")] forState:UIControlStateNormal];
} else {
sourceLabel.text = [NSString stringWithFormat:@"Source: %@",_dictionary[@"author"]?_dictionary[@"author"]:@"China SCIO"];
[shareBtn setTitle:@" Share" forState:UIControlStateNormal];
[favoriteBtn setTitle:@" Favorite" forState:UIControlStateNormal];
}
[self ToShouTing];
}
#pragma mark - Action
- (void)shareBtnClicked:(id)sender {
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];
}
- (void)favoriteBtnClicked:(id)sender {
TableData *notice = [[TableData alloc] initWithJSONDictionary:_dictionary];
if (!notice.pageUrl) {
return;
}
BOOL isIn = [[DBAction sharedDBAction] isInTable:[User_Defaults objectForKey:Language_Local] notice:notice];
NSMutableDictionary *author = [NSMutableDictionary dictionaryWithContentsOfFile:FavouriteAuthors_PATH];
if (!author) {
author = [NSMutableDictionary dictionary];
}
if (!isIn) {
BOOL isInsert = [[DBAction sharedDBAction] insertTable:[User_Defaults objectForKey:Language_Local] notice:notice];
[author setObject:_dictionary[@"author"] forKey:notice.pageUrl];
[author writeToFile:FavouriteAuthors_PATH atomically:YES];
if (isInsert) {
[AlertViewTool showHUDViewText:CustomStr(@"CollectSuccess")];
[favoriteBtn setImage:[UIImage imageNamed:@"cnlive_isfavorited"] forState:UIControlStateNormal];
}
} else {
BOOL isDelete = [[DBAction sharedDBAction] deleteTable:[User_Defaults objectForKey:Language_Local] notice:notice];
[author removeObjectForKey:notice.pageUrl];
[author writeToFile:FavouriteAuthors_PATH atomically:YES];
if (isDelete) {
[AlertViewTool showHUDViewText:CustomStr(@"CancelCollect")];
[favoriteBtn setImage:[UIImage imageNamed:@"cnlive_isfavorite"] forState:UIControlStateNormal];
}
}
}
- (void)playBackBtnClicked:(id)sender {
long long int currentTime = music.player.currentTime.value / music.player.currentTime.timescale;
[music playerProgressWithProgressFloat:(currentTime - 15)];
}
- (void)playBtnClicked:(id)sender {
[music playAndPause];
if (music.isPlay) {
[playBtn setImage:[UIImage imageNamed:@"cnlive_voice_pause"] forState:UIControlStateNormal];
} else {
[playBtn setImage:[UIImage imageNamed:@"cnlive_voice_play"] forState:UIControlStateNormal];
}
}
- (void)playNextBtnClicked:(id)sender {
[self reSetPlayer];
music.index++;
if (music.index == music.musicArray.count) {
music.index = 0;
}
_dictionary = music.musicArray[music.index];
[self setPlayModel:_dictionary];
}
#pragma mark - Tool
- (NSMutableArray *)arrayDateFromArray:(NSArray *)array {
if (!array || 0 == array.count) {
return [[NSMutableArray array] init];
}
NSMutableArray *muArray = [[NSMutableArray alloc] init];
for (int i = 0; i < array.count; i++) {
NSDictionary *dic = array[i];
NSString *urlString = dic[@"videoUrl"];
urlString = [urlString stringByReplacingOccurrencesOfString:@" " withString:@""];
NSDictionary *opts = [NSDictionary dictionaryWithObject:@(NO) forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:urlString] options:opts];
NSUInteger second = 0;
second = urlAsset.duration.value / urlAsset.duration.timescale;
NSMutableDictionary *muDic = [[NSMutableDictionary alloc] init];
[muDic setDictionary:dic];
[muDic setValue:[NSNumber numberWithInteger:second] forKey:@"totalTime"];
[muArray addObject:muDic];
}
return muArray;
}
- (NSString *)computingTime:(NSInteger)time {
if ( 0 == time) {
return @"";
}
double totalTime = time;
double hoursRemaining = floor(totalTime / 3600.0);
double minutesRemaining = floor(totalTime / 60.0);
double secondsRemaining = floor(fmod(totalTime, 60.0));
NSString *timeRmainingString = nil;
if (hoursRemaining > 0) {
if (hoursRemaining > 9) {
timeRmainingString = [NSString stringWithFormat:@"%02.0f:%02.0f:%02.0f", hoursRemaining, minutesRemaining, secondsRemaining];
} else {
timeRmainingString = [NSString stringWithFormat:@"%01.0f:%02.0f:%02.0f", hoursRemaining, minutesRemaining, secondsRemaining];
}
} else if (minutesRemaining > 0) {
if (minutesRemaining > 9) {
timeRmainingString = [NSString stringWithFormat:@"%02.0f:%02.0f", minutesRemaining, secondsRemaining];
} else {
timeRmainingString = [NSString stringWithFormat:@"%01.0f:%02.0f", minutesRemaining, secondsRemaining];
}
} else {
if (secondsRemaining > 9) {
timeRmainingString = [NSString stringWithFormat:@"%02.0f", secondsRemaining];
} else {
timeRmainingString = [NSString stringWithFormat:@"%01.0f", secondsRemaining];
}
}
return timeRmainingString;
}
@end