HmV3.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. #import "HmV3.h"
  2. #import "STButton.h"
  3. #import "AdvertisingColumn.h"
  4. #import "TRListVC.h"
  5. #import "TRDetailVC.h"
  6. #import "TopicesVC.h"
  7. #import "VowBar.h"
  8. #import "CLCell.h"
  9. #import "LightingAndSoundVC.h"
  10. @interface HmV3 ()<UITableViewDataSource,UITableViewDelegate>
  11. {
  12. NSArray *arr;
  13. NSArray *videoArray;
  14. NSMutableArray *array;
  15. NSMutableArray *dataArray;
  16. UITableView *_tableView;
  17. VowBar *vowItem;
  18. UIView *videoView;
  19. AdvertisingColumn *adView;
  20. }
  21. @end
  22. @implementation HmV3
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self myInit];
  26. [self getVideos];
  27. }
  28. - (void)didReceiveMemoryWarning {
  29. [super didReceiveMemoryWarning];
  30. // Dispose of any resources that can be recreated.
  31. }
  32. -(void)myInit
  33. {
  34. self.view.height = self.viewH;
  35. [self.view setBackgroundColor:backGroundColor];
  36. [self configNavigationBar];
  37. arr = @[@"科目三考试评判标准,提前了解不失分",
  38. @"科目三原来是这样丢分的",
  39. @"三招提高科目三考试成功率",
  40. @"科目三考试详细流程",
  41. @"科三再升级“人考”改“机考”车内多名安全员",
  42. @"科目三--加减档位操作",
  43. @"夜考,用这几招轻轻松松过",
  44. @"科目三大路考之靠边停车小技巧",
  45. @"科目三:模拟夜间行驶场景灯光使用技巧",
  46. @"超详细科目三考试口令速记口诀!",
  47. @"控制科目三方向的几个生死关键点",
  48. @"2015年科目三考试新规则和扣分标准",
  49. @"科目三:路考超车须知",
  50. @"科目三:电子路考需要注意什么",
  51. @"科目三:老手教你靠边停车技术",
  52. @"科目三:路考变更车道须知",
  53. @"科目三:路考通过人行横道线须知",
  54. @"科目三:路考中14项细节必需注意",
  55. @"考试指南 - 科目三路考评判标准",
  56. @"考试指南 - 科目三路考秘诀",
  57. @"考试指南 - 科目三必过的考场经验分享",
  58. @"考试指南 - 科目三抽到夜间考试怎么办?",
  59. @"考试指南 - 夜考灯光使用攻略,看完就过了!",
  60. @"考试指南 - 科目三路考会车攻略"];
  61. array = [NSMutableArray arrayWithArray:arr];
  62. dataArray = [NSMutableArray array];
  63. for (int i = 0; i < 5; i ++)
  64. {
  65. int index = arc4random()%(array.count - 1);
  66. [dataArray addObject:array[index]];
  67. [array removeObjectAtIndex:index];
  68. }
  69. scroll = self.zzScrollV;
  70. [scroll setScrollEnabled:YES];
  71. [self.view addSubview:scroll];
  72. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAD:) name:@"updateAD" object:nil];
  73. adView = [[AdvertisingColumn alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.width*9/32.0)];
  74. //广告
  75. NSMutableArray *newAD = [NSMutableArray array];
  76. for (NSDictionary *dic in myDelegate.adArray) {
  77. if ([dic[@"LOCATION"] isEqualToString:@"5"]) {
  78. [newAD addObject:dic];
  79. }
  80. }
  81. [adView setImgArray:newAD];
  82. adView.supVC = self;
  83. [scroll addSubview:adView];
  84. CGFloat btnW = kSize.width/4;
  85. CGFloat btnH = 90;
  86. UIView* btnBg = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(adView.frame), kSize.width, btnH)];
  87. [btnBg setBackgroundColor:[UIColor whiteColor]];
  88. [scroll addSubview:btnBg];
  89. NSInteger tag =0;
  90. NSArray* titles = @[@"评判标准",@"路考秘诀",@"考场经验",@"秘籍指导"];
  91. NSArray* images = @[@"subject3_secret_guide_icon.png",@"subject2_standart_icon.png",
  92. @"subject1_apply_know_icon.png",@"subject1_newbie_onroad_icon.png"];
  93. for (int i =0; i<titles.count; i++) {
  94. STButton* btn = [[STButton alloc] initWithFrame:CGRectMake(btnW*i, 0, btnW, btnH)];
  95. btn.style = 1;
  96. //这里y为0是因为添加到btnBg里面了、
  97. [btnBg addSubview:btn];
  98. [btn setTag:tag++];
  99. [btn setImage:[UIImage imageNamed:images[i]] withTitle:titles[i] Font:NormalFont forState:UIControlStateNormal];
  100. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  101. }
  102. UIButton* btn;
  103. btn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(adView.frame)+btnH, kSize.width/2, 40)];
  104. [scroll addSubview:btn];
  105. [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
  106. [btn setImage:[UIImage imageNamed:@"subject3_light_ico.png"] forState:UIControlStateNormal];
  107. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  108. [btn setTitle:@"灯光操作" forState:UIControlStateNormal];
  109. [btn setBackgroundColor:[UIColor whiteColor]];
  110. [btn setTag:tag++];
  111. btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2, CGRectGetMaxY(adView.frame)+btnH, kSize.width/2, 40)];
  112. [scroll addSubview:btn];
  113. [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
  114. [btn setImage:[UIImage imageNamed:@"subject3_voice_icon.png"] forState:UIControlStateNormal];
  115. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  116. [btn setTitle:@"语音模拟" forState:UIControlStateNormal];
  117. [btn setBackgroundColor:[UIColor whiteColor]];
  118. [btn setTag:tag++];
  119. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, btn.y + btn.height + 10, kFrame.size.width, 220)];
  120. [_tableView setScrollEnabled:NO];
  121. _tableView.dataSource = self;
  122. _tableView.delegate = self;
  123. [scroll addSubview:_tableView];
  124. //加一项许愿
  125. vowItem = [[VowBar alloc] initWithFrame:CGRectMake(0, [[scroll subviews] lastObject].bottom + 10, kFrame.size.width, VAWBAR_H) title:@"科目三"];
  126. vowItem.countLabel.text = @"点击参与讨论>>";
  127. [vowItem.topicBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside];
  128. vowItem.topicBtn.tag = 11;
  129. [vowItem.vomBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside];
  130. vowItem.vomBtn.tag = 12;
  131. // [scroll addSubview:vowItem];
  132. [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame)+SCRV_BottomH)];
  133. }
  134. - (void)updateAD:(NSNotification *)notifica
  135. {
  136. NSMutableArray *newAD = [NSMutableArray array];
  137. for (NSDictionary *dic in myDelegate.adArray) {
  138. if ([dic[@"LOCATION"] isEqualToString:@"5"]) {
  139. [newAD addObject:dic];
  140. }
  141. }
  142. [adView setImgArray:newAD];
  143. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil];
  144. }
  145. -(void)vowClick:(UIButton *)btn
  146. {
  147. TopicesVC* vc = [[TopicesVC alloc] init];
  148. vc.type = @"1";
  149. if (btn.tag == 11)
  150. {
  151. vc.groupId = @"6";
  152. }
  153. else
  154. {
  155. vc.groupId = @"9";
  156. }
  157. [self navPushHideTabbarToVC:vc];
  158. }
  159. #pragma mark tableView delegate
  160. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  161. {
  162. return dataArray.count;
  163. }
  164. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  165. {
  166. CLCell *cell= [CLCell cellForTableView:tableView Style:UITableViewCellStyleDefault];
  167. [cell.textLabel setText:dataArray[indexPath.row]];
  168. [cell.imageView setImage:defaultImg];
  169. return cell;
  170. }
  171. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  172. {
  173. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  174. TRDetailVC *vc=[[TRDetailVC alloc]init];
  175. [vc setFile:dataArray[indexPath.row]];
  176. [self navPushHideTabbarToVC:vc];
  177. }
  178. -(void)btnClick:(STButton*)sender
  179. {
  180. if (0 == sender.tag)
  181. {
  182. TRDetailVC* vc = [[TRDetailVC alloc] init];
  183. [vc setFile:@"科目三评判标准"];
  184. [self navPushHideTabbarToVC:vc];
  185. return;
  186. }
  187. if (1 == sender.tag)
  188. {
  189. TRDetailVC* vc = [[TRDetailVC alloc] init];
  190. [vc setFile:@"科目三路考秘诀"];
  191. [self navPushHideTabbarToVC:vc];
  192. return;
  193. }
  194. if (2 == sender.tag)
  195. {
  196. TRDetailVC* vc = [[TRDetailVC alloc] init];
  197. [vc setFile:@"科目三考场经验"];
  198. [self navPushHideTabbarToVC:vc];
  199. return;
  200. }
  201. if (3 == sender.tag)
  202. {
  203. TRListVC* vc = [[TRListVC alloc] init];
  204. arr = @[@"科目三考试评判标准,提前了解不失分",
  205. @"科目三原来是这样丢分的",
  206. @"三招提高科目三考试成功率",
  207. @"科目三考试详细流程",
  208. @"科三再升级“人考”改“机考”车内多名安全员",
  209. @"科目三--加减档位操作",
  210. @"夜考,用这几招轻轻松松过",
  211. @"科目三大路考之靠边停车小技巧",
  212. @"科目三:模拟夜间行驶场景灯光使用技巧",
  213. @"超详细科目三考试口令速记口诀!",
  214. @"控制科目三方向的几个生死关键点",
  215. @"2015年科目三考试新规则和扣分标准",
  216. @"科目三:路考超车须知",
  217. @"科目三:电子路考需要注意什么",
  218. @"科目三:老手教你靠边停车技术",
  219. @"科目三:路考变更车道须知",
  220. @"科目三:路考通过人行横道线须知",
  221. @"科目三:路考中14项细节必需注意",
  222. @"考试指南 - 科目三路考评判标准",
  223. @"考试指南 - 科目三路考秘诀",
  224. @"考试指南 - 科目三必过的考场经验分享",
  225. @"考试指南 - 科目三抽到夜间考试怎么办?",
  226. @"考试指南 - 夜考灯光使用攻略,看完就过了!",
  227. @"考试指南 - 科目三路考会车攻略"];
  228. [vc setModels:arr];
  229. [vc setTitle:@"秘籍指导"];
  230. [self navPushHideTabbarToVC:vc];
  231. return;
  232. }
  233. if (sender.tag == 4 || sender.tag == 5)
  234. {
  235. LightingAndSoundVC *VC = [[LightingAndSoundVC alloc] init];
  236. VC.styleTag = sender.tag;
  237. [self navPushHideTabbarToVC:VC];
  238. }
  239. if (6 == sender.tag) {
  240. // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init];
  241. // downLoadVC.subject = 3;
  242. //
  243. // [self navPushHideTabbarToVC:downLoadVC];
  244. // VideoDownLoadListVC *downLoadVC = [[VideoDownLoadListVC alloc] init];
  245. // downLoadVC.videoListSegControlIndex = VideoListSegControlIndex_ObjectThree;
  246. // [self navPushHideTabbarToVC:downLoadVC];
  247. }
  248. if (sender.tag > 6 && sender.tag < 13) {
  249. // VideoPlayVC *vc = [[VideoPlayVC alloc] init];
  250. // if (videoArray.count > 5) {
  251. // vc.dataDic = videoArray[sender.tag - 7];
  252. // }
  253. // vc.subject = 3;
  254. // [self navPushHideTabbarToVC:vc];
  255. // LeeVideoVC *vc = [[LeeVideoVC alloc]init];
  256. // if (videoArray.count > 5) {
  257. // vc.dataDic = videoArray[sender.tag - 7];
  258. // }
  259. // vc.subject = 3;
  260. // vc.goDownLoadBlock = ^{
  261. // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init];
  262. // downLoadVC.subject = 3;
  263. // [self navPushHideTabbarToVC:downLoadVC];
  264. // };
  265. // vc.modalPresentationStyle = UIModalPresentationFullScreen;
  266. // [self presentViewController:vc animated:YES completion:nil];
  267. // VideoPlayViewController *vc = [[VideoPlayViewController alloc] init];
  268. // if (videoArray.count > 5) {
  269. // NSDictionary *dic = videoArray[sender.tag - 7];
  270. // RQDownloadModel *downloadModel = [[RQDownloadModel alloc] init];
  271. // downloadModel.videoId = dic[@"id"];
  272. // downloadModel.subject = dic[@"subject"];
  273. // downloadModel.title = dic[@"title"];
  274. // downloadModel.urlString = dic[@"videoPath"];
  275. // downloadModel.imageUrl = dic[@"image"];
  276. // downloadModel.content = dic[@"content"];
  277. // vc.currentModel = downloadModel;
  278. // }
  279. // [self navPushHideTabbarToVC:vc];
  280. }
  281. }
  282. #pragma mark 获取视频资源
  283. -(void)getVideos
  284. {
  285. if (![Util connectedToNetWork]) {
  286. showMsgUnconnect();
  287. return;
  288. }
  289. NSMutableArray *aArray=[NSMutableArray array];
  290. [aArray addPro:@"chapterId" Value:@"3"];
  291. [aArray addPro:@"subject" Value:@"3"];
  292. [aArray addPro:@"isPage" Value:@"0"];
  293. [aArray addPro:@"pageSize" Value:@"0"];
  294. [aArray addPro:@"currentPage" Value:@"0"];
  295. NSString* method = @"getVideos";
  296. [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) {
  297. //NSLog(@"获取视频aArray-->%@------------------root-->%@",aArray,root);
  298. if (!root) {
  299. // ShowMsg(@"操作失败!请重试");
  300. return ;
  301. }
  302. if ([root[@"code"] isEqualToString:@"1"]) {
  303. return;
  304. }
  305. if ([root[@"body"] count] > 5) {
  306. videoArray = root[@"body"];
  307. [self initVideoView];
  308. //NSLog(@"-%d---%@",(int)videoArray.count,videoArray);
  309. }else{
  310. //其实这个是多余的 因为这个页面每次进来只会加载一次 就是说这个方法只会调用一次
  311. if ([videoView isKindOfClass:[UIView class]]) {
  312. [_tableView setHidden:NO];
  313. [videoView removeFromSuperview];
  314. vowItem.y = [[scroll subviews] lastObject].bottom + 10;
  315. [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame)+SCRV_BottomH)];
  316. }
  317. }
  318. }];
  319. }
  320. -(void)initVideoView
  321. {
  322. [_tableView setHidden:YES];
  323. //290*260 290*180 290*70
  324. videoView = [[UIView alloc] initWithFrame:_tableView.frame];
  325. videoView.backgroundColor = [UIColor whiteColor];
  326. //重置页面展示形式
  327. CGFloat w = (kSize.width - 30)/2.0;
  328. videoView.height = w*78/29.0 + 40;
  329. [scroll addSubview:videoView];
  330. vowItem.y = videoView.bottom + 10;
  331. [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame)+SCRV_BottomH)];
  332. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, kSize.width/2.0 - 10, 40)];
  333. [label setText:@"教学视频" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  334. [videoView addSubview:label];
  335. label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0 - 10, 40)];
  336. [label setText:[NSString stringWithFormat:@"共%d个视频>",(int)videoArray.count] Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentRight];
  337. [videoView addSubview:label];
  338. UIButton *moreVideoBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  339. [moreVideoBtn target:self tag:6];//tag 6开始
  340. [videoView addSubview:moreVideoBtn];
  341. CGFloat bdH = w*26/29.0;
  342. CGFloat photoH = w*18/29.0;
  343. CGFloat labelH = w*7/29.0;
  344. NSInteger videoNum = videoArray.count;
  345. if (videoNum > 6) {
  346. videoNum = 6;
  347. }
  348. for (int i = 0; i < videoNum; i ++) {
  349. int row = i/2;
  350. int clumn = i%2;
  351. NSDictionary *dic = videoArray[i];
  352. //照片
  353. UIImageView *videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, photoH)];
  354. NSString *str = dic[@"image"];
  355. if (str && ![str hasPrefix:@"http"]){
  356. str = [imgPreFix stringByAppendingString:str];
  357. }
  358. if (!str) {
  359. str = @"";
  360. }
  361. [videoImageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]];
  362. [videoView addSubview:videoImageView];
  363. //时长
  364. label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), row*bdH + photoH + 15, w - 10, 25)];
  365. label.backgroundColor = windowBlockColor;
  366. int seconds = [dic[@"times"] intValue];
  367. NSString *min = [NSString stringWithFormat:@"%d",seconds/60];
  368. NSString *sec = [NSString stringWithFormat:@"%d",seconds%60];
  369. if (seconds/60 < 10) {
  370. min = [NSString stringWithFormat:@"0%@",min];
  371. }
  372. if (seconds%60 < 10) {
  373. sec = [NSString stringWithFormat:@"0%@",sec];
  374. }
  375. [label setText:[NSString stringWithFormat:@"%@:%@",min,sec] Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentRight];
  376. [videoView addSubview:label];
  377. //title
  378. label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH + photoH, w, labelH)];
  379. [label setText:dic[@"title"] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  380. [videoView addSubview:label];
  381. //btn
  382. UIButton *playBtn = [[UIButton alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, bdH)];
  383. playBtn.backgroundColor = [UIColor clearColor];
  384. [playBtn target:self tag:7 + i];//7开始
  385. [videoView addSubview:playBtn];
  386. }
  387. }
  388. -(void)dealloc
  389. {
  390. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil];
  391. //下边这个其实不用写的 我们的项目应该不会被用在arc环境下
  392. #if ! __has_feature(objc_arc)
  393. [super dealloc];
  394. #endif
  395. }
  396. @end