// // HmV2.m // jiaPei // // Created by apple on 15/11/13. // Copyright (c) 2015年 JCZ. All rights reserved. // #import "HmV2.h" #import "AdvertisingColumn.h" #import "STButton.h" #import "TRDetailVC.h" #import "TRListVC.h" #import "CLCell.h" #import "VowBar.h" #import "TopicesVC.h" @interface HmV2 () { NSArray *arr; NSArray *titles; NSArray *videoArray; NSMutableArray *array; NSMutableArray *dataArray; UITableView *_tableView; VowBar *vowItem; UIView *videoView; AdvertisingColumn *adView; } @end @implementation HmV2 - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; if (myDelegate.isLogin) { //更新登录信息 如果是登录状态的时候 [LoginViewController reLoginFromViewController:self finishBlock:^{ [LoginViewController getCurrentStateWithCompleteBlock:nil]; }]; } [self getVideos]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)myInit { self.view.height = self.viewH; [self.view setBackgroundColor:backGroundColor]; [self configNavigationBar]; arr = @[@"科目二小错误千万别大意", @"科目二到底考什么?全部都在这", @"科目二考试不过的原因大解析", @"侧方停车只是倒车速度慢一点,为什么判不过?", @"考官说扣分:“驾考科目二场考五项讲解全攻略”", @"科目二考试技巧口诀,小伙伴要记牢哦", @"科目二考试详细流程", @"科目二之直角拐弯", @"科目二考场温馨提示要点图", @"侧方停车技巧,超详细!", @"四张图让你秒变倒车界的独孤求败!", @"倒车入库再也不发愁,蜀黍教你各种倒车技巧!", @"科目二五项过关神技巧,超级详细!", @"因为这些挂掉,冤枉死!", @"科目二坡道,这些不良动作是你考试不过关的根源!", @"倒车入位用这三招,想怎么钻就怎么钻!", @"科目二失分点都在这,想过来看!", @"倒车入库究竟有多难?", @"学车入门级知识问题", @"科二全程解剖,让“菜鸟级”的你轻松通过考试", @"直角转弯操作技巧,一看秒懂", @"六张图,教会你“侧方停车”神技能", @"全程考试技巧汇总", @"坡道定点停车技巧(图解)", @"坡道定点找三十公分线的技巧方法", @"考驾照14条关键经验,学员含泪总结", @"科目二考前准备", @"科目二合格标准", @"科目二必过考试经验分享", @"坡道起步怎么预防倒溜和熄火?", @"科目二全程“难点”独家解析!", @"科二最难的:倒车入口+坡道起步独家秘笈", @"你必须注意的科目二考试须知!"]; array = [NSMutableArray arrayWithArray:arr]; dataArray = [NSMutableArray array]; for (int i = 0; i < 6; i ++) { int index = arc4random()%(array.count - 1); [dataArray addObject:array[index]]; [array removeObjectAtIndex:index]; } scroll = self.zzScrollV; [scroll setScrollEnabled:YES]; [self.view addSubview:scroll]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateAD:) name:@"updateAD" object:nil]; adView = [[AdvertisingColumn alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.width*9/32.0)]; //广告 NSMutableArray *newAD = [NSMutableArray array]; for (NSDictionary *dic in myDelegate.adArray) { if ([dic[@"LOCATION"] isEqualToString:@"4"]) { [newAD addObject:dic]; } } [adView setImgArray:newAD]; adView.supVC = self; [scroll addSubview:adView]; CGFloat btnW = kSize.width/4; CGFloat btnH = 90; UIView* btnBg = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.width*9/32.0, kSize.width, btnH)]; [btnBg setBackgroundColor:[UIColor whiteColor]]; [scroll addSubview:btnBg]; NSInteger tag = 0; // titles = @[@"考前准备",@"合格标准",@"考试经验",@"秘籍指导"]; titles = @[@"考前准备",@"合格标准",@"考试经验"]; // NSArray* images = @[@"subject3_secret_guide_icon.png",@"subject2_standart_icon.png",@"subject2_exam_experance_icon.png",@"subject1_newbie_onroad_icon.png"]; NSArray* images = @[@"subject3_secret_guide_icon.png",@"subject2_standart_icon.png",@"subject2_exam_experance_icon.png"]; NSMutableArray *btns = [NSMutableArray array]; for (int i =0; i>"; [vowItem.topicBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside]; vowItem.topicBtn.tag = 11; [vowItem.vomBtn addTarget:self action:@selector(vowClick:) forControlEvents:UIControlEventTouchUpInside]; vowItem.vomBtn.tag = 12; // [scroll addSubview:vowItem]; [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame) + SCRV_BottomH)]; } - (void)updateAD:(NSNotification *)notifica { NSMutableArray *newAD = [NSMutableArray array]; for (NSDictionary *dic in myDelegate.adArray) { if ([dic[@"LOCATION"] isEqualToString:@"4"]) { [newAD addObject:dic]; } } [adView setImgArray:newAD]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil]; } -(void)vowClick:(UIButton *)btn { TopicesVC* vc = [[TopicesVC alloc] init]; vc.type = @"1"; if (btn.tag == 11) { vc.groupId = @"5"; } else { vc.groupId = @"9"; } [self navPushHideTabbarToVC:vc]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CLCell *cell= [CLCell cellForTableView:tableView Style:UITableViewCellStyleDefault]; [cell.textLabel setText:dataArray[indexPath.row]]; [cell.imageView setImage:defaultImg]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; TRDetailVC *vc=[[TRDetailVC alloc]init]; [vc setFile:dataArray[indexPath.row]]; [self navPushHideTabbarToVC:vc]; } -(void)btnClick:(STButton*)sender { if (0 == sender.tag) { TRDetailVC* vc = [[TRDetailVC alloc] init]; [vc setFile:@"科目二考前准备"]; [self navPushHideTabbarToVC:vc]; return; } if (1 == sender.tag) { TRDetailVC* vc = [[TRDetailVC alloc] init]; [vc setFile:@"科目二合格标准"]; [self navPushHideTabbarToVC:vc]; return; } if (2 == sender.tag) { TRDetailVC* vc = [[TRDetailVC alloc] init]; [vc setFile:@"科目二考试经验"]; [self navPushHideTabbarToVC:vc]; return; } if (3 == sender.tag) { TRListVC* vc = [[TRListVC alloc] init]; [vc setModels:arr]; [vc setTitle:@"秘籍指导"]; [self navPushHideTabbarToVC:vc]; return; } if (5 == sender.tag) { // // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init]; // downLoadVC.subject = 2; // [self navPushHideTabbarToVC:downLoadVC]; // VideoDownLoadListVC *downLoadVC = [[VideoDownLoadListVC alloc] init]; // downLoadVC.videoListSegControlIndex = VideoListSegControlIndex_ObjectTwo; // [self navPushHideTabbarToVC:downLoadVC]; } if (sender.tag > 5 && sender.tag < 12) { // VideoPlayVC *vc = [[VideoPlayVC alloc] init]; // if (videoArray.count > 5) { // vc.dataDic = videoArray[sender.tag - 6]; // } // vc.subject = 2; // [self navPushHideTabbarToVC:vc]; // LeeVideoVC *vc = [[LeeVideoVC alloc]init]; // if (videoArray.count > 5) { // vc.dataDic = videoArray[sender.tag - 6]; // } // vc.subject = 2; // vc.goDownLoadBlock = ^{ // DownLoadVC *downLoadVC = [[DownLoadVC alloc] init]; // downLoadVC.subject = 2; // [self navPushHideTabbarToVC:downLoadVC]; // }; // vc.modalPresentationStyle = UIModalPresentationFullScreen; // [self presentViewController:vc animated:YES completion:nil]; // VideoPlayViewController *vc = [[VideoPlayViewController alloc] init]; // if (videoArray.count > 5) { // NSDictionary *dic = videoArray[sender.tag - 6]; // RQDownloadModel *downloadModel = [[RQDownloadModel alloc] init]; // downloadModel.videoId = dic[@"id"]; // downloadModel.subject = dic[@"subject"]; // downloadModel.title = dic[@"title"]; // downloadModel.urlString = dic[@"videoPath"]; // downloadModel.imageUrl = dic[@"image"]; // downloadModel.content = dic[@"content"]; // vc.currentModel = downloadModel; // } // [self navPushHideTabbarToVC:vc]; } } #pragma mark 获取视频资源 - (void)getVideos { if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *aArray=[NSMutableArray array]; [aArray addPro:@"chapterId" Value:@"2"]; [aArray addPro:@"subject" Value:@"2"]; [aArray addPro:@"isPage" Value:@"0"]; [aArray addPro:@"pageSize" Value:@"0"]; [aArray addPro:@"currentPage" Value:@"0"]; NSString* method = @"getVideos"; [jiaPeiManager requestAnythingWithURL:method array:aArray data:nil completion:^(NSDictionary *root) { //NSLog(@"获取视频aArray-->%@------------------root-->%@",aArray,root); if (!root) { // ShowMsg(@"操作失败!请重试"); return ; } if ([root[@"code"] isEqualToString:@"1"]) { return; } if ([root[@"body"] count] > 5) { videoArray = root[@"body"]; [self initVideoView]; //NSLog(@"-%d---%@",(int)videoArray.count,videoArray); }else{ //其实这个是多余的 因为这个页面每次进来只会加载一次 就是说这个方法只会调用一次 if ([videoView isKindOfClass:[UIView class]]) { [_tableView setHidden:NO]; [videoView removeFromSuperview]; vowItem.y = [[scroll subviews] lastObject].bottom + 10; [scroll setContentSize:CGSizeMake(0, CGRectGetMaxY(vowItem.frame) + SCRV_BottomH)]; } } }]; } -(void)initVideoView { [_tableView setHidden:YES]; //290*260 290*180 290*70 h = 265 videoView = [[UIView alloc] initWithFrame:_tableView.frame]; videoView.backgroundColor = [UIColor whiteColor]; //重置页面展示形式 CGFloat w = (kSize.width - 30)/2.0; videoView.height = w*78/29.0 + 40; [scroll addSubview:videoView]; [scroll setContentSize:CGSizeMake(0, videoView.bottom + (10+VAWBAR_H) + SCRV_BottomH)]; vowItem.y = videoView.bottom + 10; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, kSize.width/2.0 - 10, 40)]; [label setText:@"教学视频" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; [videoView addSubview:label]; label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width/2.0, 0, kSize.width/2.0 - 10, 40)]; [label setText:[NSString stringWithFormat:@"共%d个视频>",(int)videoArray.count] Font:Font17 TextColor:contentTextColor Alignment:NSTextAlignmentRight]; [videoView addSubview:label]; UIButton *moreVideoBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)]; [moreVideoBtn target:self tag:5];//tag 5开始 [videoView addSubview:moreVideoBtn]; CGFloat bdH = w*26/29.0; CGFloat photoH = w*18/29.0; CGFloat labelH = w*7/29.0; NSInteger videoNum = videoArray.count; if (videoNum > 6) { videoNum = 6; } for (int i = 0; i < videoNum; i ++) { int row = i/2; int clumn = i%2; NSDictionary *dic = videoArray[i]; //照片 UIImageView *videoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, photoH)]; NSString *str = dic[@"image"]; if (str && ![str hasPrefix:@"http"]){ str = [imgPreFix stringByAppendingString:str]; } if (!str) { str = @""; } [videoImageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"NOIMG.png"]]; [videoView addSubview:videoImageView]; //时长 label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), row*bdH + photoH + 15, w - 10, 25)]; label.backgroundColor = windowBlockColor; int seconds = [dic[@"times"] intValue]; NSString *min = [NSString stringWithFormat:@"%d",seconds/60]; NSString *sec = [NSString stringWithFormat:@"%d",seconds%60]; if (seconds/60 < 10) { min = [NSString stringWithFormat:@"0%@",min]; } if (seconds%60 < 10) { sec = [NSString stringWithFormat:@"0%@",sec]; } [label setText:[NSString stringWithFormat:@"%@:%@",min,sec] Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentRight]; [videoView addSubview:label]; //title label = [[UILabel alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH + photoH, w, labelH)]; [label setText:dic[@"title"] Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; [videoView addSubview:label]; //btn UIButton *playBtn = [[UIButton alloc] initWithFrame:CGRectMake(10 + clumn*(w + 10), 40 + row*bdH, w, bdH)]; playBtn.backgroundColor = [UIColor clearColor]; [playBtn target:self tag:6 + i];//6开始 [videoView addSubview:playBtn]; } } -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateAD" object:nil]; //下边这个其实不用写的 我们的项目应该不会被用在arc环境下 #if ! __has_feature(objc_arc) [super dealloc]; #endif } @end