HmV2.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. //
  2. // HmV2.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/13.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "HmV2.h"
  9. #import "AdvertisingColumn.h"
  10. #import "STButton.h"
  11. #import "TRDetailVC.h"
  12. #import "TRListVC.h"
  13. #import "CLCell.h"
  14. #import "VowBar.h"
  15. #import "TopicesVC.h"
  16. @interface HmV2 ()<UITableViewDataSource,UITableViewDelegate>
  17. {
  18. NSArray *arr;
  19. NSArray *titles;
  20. NSArray *videoArray;
  21. NSMutableArray *array;
  22. NSMutableArray *dataArray;
  23. UITableView *_tableView;
  24. VowBar *vowItem;
  25. UIView *videoView;
  26. AdvertisingColumn *adView;
  27. }
  28. @end
  29. @implementation HmV2
  30. - (void)viewDidLoad
  31. {
  32. [super viewDidLoad];
  33. [self myInit];
  34. if (myDelegate.isLogin) {
  35. //更新登录信息 如果是登录状态的时候
  36. [LoginViewController reLoginFromViewController:self finishBlock:^{
  37. [LoginViewController getCurrentStateWithCompleteBlock:nil];
  38. }];
  39. }
  40. [self getVideos];
  41. }
  42. - (void)didReceiveMemoryWarning {
  43. [super didReceiveMemoryWarning];
  44. // Dispose of any resources that can be recreated.
  45. }
  46. -(void)myInit
  47. {
  48. self.view.height = self.viewH;
  49. [self.view setBackgroundColor:backGroundColor];
  50. [self configNavigationBar];
  51. arr = @[@"科目二小错误千万别大意",
  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. @"考驾照14条关键经验,学员含泪总结",
  77. @"科目二考前准备",
  78. @"科目二合格标准",
  79. @"科目二必过考试经验分享",
  80. @"坡道起步怎么预防倒溜和熄火?",
  81. @"科目二全程“难点”独家解析!",
  82. @"科二最难的:倒车入口+坡道起步独家秘笈",
  83. @"你必须注意的科目二考试须知!"];
  84. array = [NSMutableArray arrayWithArray:arr];
  85. dataArray = [NSMutableArray array];
  86. for (int i = 0; i < 6; i ++)
  87. {
  88. int index = arc4random()%(array.count - 1);
  89. [dataArray addObject:array[index]];
  90. [array removeObjectAtIndex:index];
  91. }
  92. scroll = self.zzScrollV;
  93. [scroll setScrollEnabled:YES];
  94. [self.view addSubview:scroll];
  95. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAD:) name:@"updateAD" object:nil];
  96. adView = [[AdvertisingColumn alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.width*9/32.0)];
  97. //广告
  98. NSMutableArray *newAD = [NSMutableArray array];
  99. for (NSDictionary *dic in myDelegate.adArray) {
  100. if ([dic[@"LOCATION"] isEqualToString:@"4"]) {
  101. [newAD addObject:dic];
  102. }
  103. }
  104. [adView setImgArray:newAD];
  105. adView.supVC = self;
  106. [scroll addSubview:adView];
  107. CGFloat btnW = kSize.width/4;
  108. CGFloat btnH = 90;
  109. UIView* btnBg = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.width*9/32.0, kSize.width, btnH)];
  110. [btnBg setBackgroundColor:[UIColor whiteColor]];
  111. [scroll addSubview:btnBg];
  112. NSInteger tag = 0;
  113. // titles = @[@"考前准备",@"合格标准",@"考试经验",@"秘籍指导"];
  114. titles = @[@"考前准备",@"合格标准",@"考试经验"];
  115. // NSArray* images = @[@"subject3_secret_guide_icon.png",@"subject2_standart_icon.png",@"subject2_exam_experance_icon.png",@"subject1_newbie_onroad_icon.png"];
  116. NSArray* images = @[@"subject3_secret_guide_icon.png",@"subject2_standart_icon.png",@"subject2_exam_experance_icon.png"];
  117. NSMutableArray *btns = [NSMutableArray array];
  118. for (int i =0; i<titles.count; i++) {
  119. STButton* btn = [[STButton alloc] initWithFrame:CGRectMake(btnW*i, 0, btnW, btnH)];
  120. btn.style = 1;
  121. [btnBg addSubview:btn];
  122. [btn setImage:[UIImage imageNamed:images[i]] withTitle:titles[i] Font:NormalFont forState:UIControlStateNormal];
  123. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  124. [btn setTag:tag++];
  125. [btns addObject:btn];
  126. }
  127. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, btnBg.y + btnBg.height + 10, kFrame.size.width, 265)];
  128. [_tableView setScrollEnabled:NO];
  129. _tableView.dataSource = self;
  130. _tableView.delegate = self;
  131. [scroll addSubview:_tableView];
  132. //加一项许愿
  133. vowItem = [[VowBar alloc] initWithFrame:CGRectMake(0, [[scroll subviews] lastObject].bottom + 10, kFrame.size.width, VAWBAR_H) title:@"科目二"];
  134. vowItem.countLabel.text = @"点击参与讨论>>";
  135. [vowItem.topicBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside];
  136. vowItem.topicBtn.tag = 11;
  137. [vowItem.vomBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside];
  138. vowItem.vomBtn.tag = 12;
  139. // [scroll addSubview:vowItem];
  140. [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame) + SCRV_BottomH)];
  141. }
  142. - (void)updateAD:(NSNotification *)notifica
  143. {
  144. NSMutableArray *newAD = [NSMutableArray array];
  145. for (NSDictionary *dic in myDelegate.adArray) {
  146. if ([dic[@"LOCATION"] isEqualToString:@"4"]) {
  147. [newAD addObject:dic];
  148. }
  149. }
  150. [adView setImgArray:newAD];
  151. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil];
  152. }
  153. -(void)vowClick:(UIButton *)btn
  154. {
  155. TopicesVC* vc = [[TopicesVC alloc] init];
  156. vc.type = @"1";
  157. if (btn.tag == 11)
  158. {
  159. vc.groupId = @"5";
  160. }
  161. else
  162. {
  163. vc.groupId = @"9";
  164. }
  165. [self navPushHideTabbarToVC:vc];
  166. }
  167. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  168. {
  169. return dataArray.count;
  170. }
  171. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  172. {
  173. CLCell *cell= [CLCell cellForTableView:tableView Style:UITableViewCellStyleDefault];
  174. [cell.textLabel setText:dataArray[indexPath.row]];
  175. [cell.imageView setImage:defaultImg];
  176. return cell;
  177. }
  178. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  179. {
  180. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  181. TRDetailVC *vc=[[TRDetailVC alloc]init];
  182. [vc setFile:dataArray[indexPath.row]];
  183. [self navPushHideTabbarToVC:vc];
  184. }
  185. -(void)btnClick:(STButton*)sender
  186. {
  187. if (0 == sender.tag)
  188. {
  189. TRDetailVC* vc = [[TRDetailVC alloc] init];
  190. [vc setFile:@"科目二考前准备"];
  191. [self navPushHideTabbarToVC:vc];
  192. return;
  193. }
  194. if (1 == sender.tag)
  195. {
  196. TRDetailVC* vc = [[TRDetailVC alloc] init];
  197. [vc setFile:@"科目二合格标准"];
  198. [self navPushHideTabbarToVC:vc];
  199. return;
  200. }
  201. if (2 == sender.tag)
  202. {
  203. TRDetailVC* vc = [[TRDetailVC alloc] init];
  204. [vc setFile:@"科目二考试经验"];
  205. [self navPushHideTabbarToVC:vc];
  206. return;
  207. }
  208. if (3 == sender.tag)
  209. {
  210. TRListVC* vc = [[TRListVC alloc] init];
  211. [vc setModels:arr];
  212. [vc setTitle:@"秘籍指导"];
  213. [self navPushHideTabbarToVC:vc];
  214. return;
  215. }
  216. if (5 == sender.tag) {
  217. //
  218. // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init];
  219. // downLoadVC.subject = 2;
  220. // [self navPushHideTabbarToVC:downLoadVC];
  221. // VideoDownLoadListVC *downLoadVC = [[VideoDownLoadListVC alloc] init];
  222. // downLoadVC.videoListSegControlIndex = VideoListSegControlIndex_ObjectTwo;
  223. // [self navPushHideTabbarToVC:downLoadVC];
  224. }
  225. if (sender.tag > 5 && sender.tag < 12) {
  226. // VideoPlayVC *vc = [[VideoPlayVC alloc] init];
  227. // if (videoArray.count > 5) {
  228. // vc.dataDic = videoArray[sender.tag - 6];
  229. // }
  230. // vc.subject = 2;
  231. // [self navPushHideTabbarToVC:vc];
  232. // LeeVideoVC *vc = [[LeeVideoVC alloc]init];
  233. // if (videoArray.count > 5) {
  234. // vc.dataDic = videoArray[sender.tag - 6];
  235. // }
  236. // vc.subject = 2;
  237. // vc.goDownLoadBlock = ^{
  238. // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init];
  239. // downLoadVC.subject = 2;
  240. // [self navPushHideTabbarToVC:downLoadVC];
  241. // };
  242. // vc.modalPresentationStyle = UIModalPresentationFullScreen;
  243. // [self presentViewController:vc animated:YES completion:nil];
  244. // VideoPlayViewController *vc = [[VideoPlayViewController alloc] init];
  245. // if (videoArray.count > 5) {
  246. // NSDictionary *dic = videoArray[sender.tag - 6];
  247. // RQDownloadModel *downloadModel = [[RQDownloadModel alloc] init];
  248. // downloadModel.videoId = dic[@"id"];
  249. // downloadModel.subject = dic[@"subject"];
  250. // downloadModel.title = dic[@"title"];
  251. // downloadModel.urlString = dic[@"videoPath"];
  252. // downloadModel.imageUrl = dic[@"image"];
  253. // downloadModel.content = dic[@"content"];
  254. // vc.currentModel = downloadModel;
  255. // }
  256. // [self navPushHideTabbarToVC:vc];
  257. }
  258. }
  259. #pragma mark 获取视频资源
  260. - (void)getVideos {
  261. if (![Util connectedToNetWork]) {
  262. showMsgUnconnect();
  263. return;
  264. }
  265. NSMutableArray *aArray=[NSMutableArray array];
  266. [aArray addPro:@"chapterId" Value:@"2"];
  267. [aArray addPro:@"subject" Value:@"2"];
  268. [aArray addPro:@"isPage" Value:@"0"];
  269. [aArray addPro:@"pageSize" Value:@"0"];
  270. [aArray addPro:@"currentPage" Value:@"0"];
  271. NSString* method = @"getVideos";
  272. [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) {
  273. //NSLog(@"获取视频aArray-->%@------------------root-->%@",aArray,root);
  274. if (!root) {
  275. // ShowMsg(@"操作失败!请重试");
  276. return ;
  277. }
  278. if ([root[@"code"] isEqualToString:@"1"]) {
  279. return;
  280. }
  281. if ([root[@"body"] count] > 5) {
  282. videoArray = root[@"body"];
  283. [self initVideoView];
  284. //NSLog(@"-%d---%@",(int)videoArray.count,videoArray);
  285. }else{
  286. //其实这个是多余的 因为这个页面每次进来只会加载一次 就是说这个方法只会调用一次
  287. if ([videoView isKindOfClass:[UIView class]]) {
  288. [_tableView setHidden:NO];
  289. [videoView removeFromSuperview];
  290. vowItem.y = [[scroll subviews] lastObject].bottom + 10;
  291. [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame) + SCRV_BottomH)];
  292. }
  293. }
  294. }];
  295. }
  296. -(void)initVideoView
  297. {
  298. [_tableView setHidden:YES];
  299. //290*260 290*180 290*70 h = 265
  300. videoView = [[UIView alloc] initWithFrame:_tableView.frame];
  301. videoView.backgroundColor = [UIColor whiteColor];
  302. //重置页面展示形式
  303. CGFloat w = (kSize.width - 30)/2.0;
  304. videoView.height = w*78/29.0 + 40;
  305. [scroll addSubview:videoView];
  306. [scroll setContentSize:CGSizeMake(0, videoView.bottom + (10+VAWBAR_H) + SCRV_BottomH)];
  307. vowItem.y = videoView.bottom + 10;
  308. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, kSize.width/2.0 - 10, 40)];
  309. [label setText:@"教学视频" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  310. [videoView addSubview:label];
  311. label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0 - 10, 40)];
  312. [label setText:[NSString stringWithFormat:@"共%d个视频>",(int)videoArray.count] Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentRight];
  313. [videoView addSubview:label];
  314. UIButton *moreVideoBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  315. [moreVideoBtn target:self tag:5];//tag 5开始
  316. [videoView addSubview:moreVideoBtn];
  317. CGFloat bdH = w*26/29.0;
  318. CGFloat photoH = w*18/29.0;
  319. CGFloat labelH = w*7/29.0;
  320. NSInteger videoNum = videoArray.count;
  321. if (videoNum > 6) {
  322. videoNum = 6;
  323. }
  324. for (int i = 0; i < videoNum; i ++) {
  325. int row = i/2;
  326. int clumn = i%2;
  327. NSDictionary *dic = videoArray[i];
  328. //照片
  329. UIImageView *videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, photoH)];
  330. NSString *str = dic[@"image"];
  331. if (str && ![str hasPrefix:@"http"]){
  332. str = [imgPreFix stringByAppendingString:str];
  333. }
  334. if (!str) {
  335. str = @"";
  336. }
  337. [videoImageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]];
  338. [videoView addSubview:videoImageView];
  339. //时长
  340. label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), row*bdH + photoH + 15, w - 10, 25)];
  341. label.backgroundColor = windowBlockColor;
  342. int seconds = [dic[@"times"] intValue];
  343. NSString *min = [NSString stringWithFormat:@"%d",seconds/60];
  344. NSString *sec = [NSString stringWithFormat:@"%d",seconds%60];
  345. if (seconds/60 < 10) {
  346. min = [NSString stringWithFormat:@"0%@",min];
  347. }
  348. if (seconds%60 < 10) {
  349. sec = [NSString stringWithFormat:@"0%@",sec];
  350. }
  351. [label setText:[NSString stringWithFormat:@"%@:%@",min,sec] Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentRight];
  352. [videoView addSubview:label];
  353. //title
  354. label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH + photoH, w, labelH)];
  355. [label setText:dic[@"title"] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft];
  356. [videoView addSubview:label];
  357. //btn
  358. UIButton *playBtn = [[UIButton alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, bdH)];
  359. playBtn.backgroundColor = [UIColor clearColor];
  360. [playBtn target:self tag:6 + i];//6开始
  361. [videoView addSubview:playBtn];
  362. }
  363. }
  364. -(void)dealloc
  365. {
  366. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil];
  367. //下边这个其实不用写的 我们的项目应该不会被用在arc环境下
  368. #if ! __has_feature(objc_arc)
  369. [super dealloc];
  370. #endif
  371. }
  372. @end