| | |
| | | // |
| | | |
| | | #import "RecommendController.h" |
| | | #import "OnlySpecialController.h"//专辑视图 |
| | | #import "XYRDetailViewController.h" |
| | | |
| | | #import "RecommendHeaderViewCell.h" |
| | | #import "ToDayHotCell.h" |
| | | #import "RecommendTwoColumnCell.h" |
| | |
| | | } |
| | | |
| | | -(void)getHomeAd{ |
| | | [SVProgressHUD show]; |
| | | dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
| | | // 创建全局并行 |
| | | dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); |
| | |
| | | dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
| | | |
| | | dispatch_async(dispatch_get_main_queue(), ^{ |
| | | [SVProgressHUD dismiss]; |
| | | [self.arrayContent addObjectsFromArray:self.arrayTemp]; |
| | | [self.collectionView reloadData]; |
| | | }); |
| | |
| | | [self changeData:vid page:page index:index]; |
| | | } |
| | | |
| | | - (void)onEventHeaderSection:(NSIndexPath *)indexpath { |
| | | if (indexpath.section == 1) { |
| | | return; |
| | | } |
| | | [self cellClick:indexpath]; |
| | | } |
| | | |
| | | - (void)onEventHotSection:(NSDictionary *)parms { |
| | | XYRDetailViewController *play = [[XYRDetailViewController alloc]init]; |
| | | [YTHsharedManger startManger].preController = [self fetchCurrentViewController]; |
| | | play.modalPresentationStyle = 0; |
| | | play.Model = [XYRVideoInfoModel yy_modelWithDictionary:parms]; |
| | | [[self fetchCurrentViewController] presentViewController:play animated:YES completion:^{}]; |
| | | } |
| | | |
| | | - (void)onEventBaner:(NSDictionary *)parms { |
| | | NSInteger LinkType = [parms[@"LinkType"] integerValue]; |
| | | |
| | | if (LinkType == 1) {//普通视频跳转 |
| | | XYRDetailViewController *play = [[XYRDetailViewController alloc]init]; |
| | | [YTHsharedManger startManger].preController = [self fetchCurrentViewController]; |
| | | NSString *video = @""; |
| | | video = @"VideoInfo"; |
| | | play.modalPresentationStyle = 0; |
| | | play.Model = [XYRVideoInfoModel yy_modelWithDictionary:parms[@"Video"]]; |
| | | [[self fetchCurrentViewController] presentViewController:play animated:YES completion:^{}]; |
| | | |
| | | } else if (LinkType == 2){//网页(网页) |
| | | NSString *s = [parms[@"Params"] stringByReplacingOccurrencesOfString:@"\\"withString:@""]; |
| | | NSDictionary *Params = [self dictionaryWithJsonString:s]; |
| | | [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[Params objectForKey:@"url"]]]; |
| | | |
| | | } else if (LinkType == 3){//专辑 |
| | | OnlySpecialController *OnlySpecial =[OnlySpecialController new]; |
| | | OnlySpecial.Id = [parms[@"Id"] intValue]; |
| | | [[self fetchCurrentViewController].navigationController pushViewController:OnlySpecial animated:YES]; |
| | | } |
| | | } |
| | | |
| | | #pragma mark 把json格式的字符串转换为字典格式 |
| | | - (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { |
| | | if (jsonString == nil) { |
| | | return nil; |
| | | } |
| | | NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; |
| | | NSError *err; |
| | | NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData |
| | | options:NSJSONReadingMutableContainers |
| | | error:&err]; |
| | | if(err) { |
| | | NSLog(@"json解析失败:%@",err); |
| | | return nil; |
| | | } |
| | | return dic; |
| | | } |
| | | |
| | | - (void)hideFooger { |
| | | self.collectionView.mj_footer = nil; |
| | | } |
| | |
| | | }]; |
| | | } |
| | | |
| | | - (void)setHeaderRefresh { |
| | | self.collectionView.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{ |
| | | self.page = 1; |
| | | [self loadFooter:^{ |
| | | |
| | | }]; |
| | | }]; |
| | | } |
| | | |
| | | - (void)cellClick:(NSIndexPath *)indexPath { |
| | | NSDictionary *parms = [NSDictionary new]; |
| | | parms = self.arrayContent[indexPath.section-1][@"HomeVideoList"][indexPath.row][@"Video"]; |
| | | XYRDetailViewController *play = [[XYRDetailViewController alloc]init]; |
| | | [YTHsharedManger startManger].preController = [self fetchCurrentViewController]; |
| | | play.modalPresentationStyle = 0; |
| | | play.Model = [XYRVideoInfoModel yy_modelWithDictionary:parms]; |
| | | [[self fetchCurrentViewController] presentViewController:play animated:YES completion:^{}]; |
| | | } |
| | | |
| | | - (UIViewController *)fetchCurrentViewController { |
| | | UIViewController* currentViewController = [UIApplication sharedApplication].keyWindow.rootViewController; |
| | | BOOL runLoopFind = YES; |
| | | while (runLoopFind) { |
| | | if (currentViewController.presentedViewController) { |
| | | currentViewController = currentViewController.presentedViewController; |
| | | } else if ([currentViewController isKindOfClass:[UINavigationController class]]) { |
| | | UINavigationController* navigationController = (UINavigationController* )currentViewController; |
| | | currentViewController = [navigationController.childViewControllers lastObject]; |
| | | } else if ([currentViewController isKindOfClass:[UITabBarController class]]) { |
| | | UITabBarController* tabBarController = (UITabBarController* )currentViewController; |
| | | currentViewController = tabBarController.selectedViewController; |
| | | } else { |
| | | NSUInteger childViewControllerCount = currentViewController.childViewControllers.count; |
| | | if (childViewControllerCount > 0) { |
| | | currentViewController = currentViewController.childViewControllers.lastObject; |
| | | return currentViewController; |
| | | } else { |
| | | return currentViewController; |
| | | } |
| | | } |
| | | } |
| | | return currentViewController; |
| | | } |
| | | |
| | | #pragma mark UICollectionViewDelegate, UICollectionViewDataSource |
| | | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { |
| | | //[self cellClick:indexPath]; |
| | | [self cellClick:indexPath]; |
| | | } |
| | | |
| | | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { |
| | |
| | | if (!self.cellRecommendHeader) { |
| | | self.cellRecommendHeader = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendHeaderViewCell" forIndexPath:indexPath]; |
| | | } |
| | | self.cellRecommendHeader.delegate = self; |
| | | self.cellRecommendHeader.arrayImageData = self.dictionaryBanaer; |
| | | return self.cellRecommendHeader; |
| | | } else { |
| | | NSUInteger Columns = [self.arrayContent[indexPath.section-1][@"Columns"] integerValue]; |
| | | if (Columns > 3) { |
| | | ToDayHotCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ToDayHotCell" forIndexPath:indexPath]; |
| | | cell.delegate = self; |
| | | cell.data = self.arrayContent[indexPath.section-1]; |
| | | return cell; |
| | | |
| | |
| | | view.isBanaer = BigPicture; |
| | | view.data = self.arrayContent[indexPath.section-1]; |
| | | view.index = indexPath.section; |
| | | view.indexPath = indexPath; |
| | | return view; |
| | | } |
| | | |
| | |
| | | [_collectionView registerClass:[RecommendChangeFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"RecommendChangeFooterView"]; |
| | | |
| | | [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView"]; |
| | | |
| | | [self setHeaderRefresh]; |
| | | } |
| | | return _collectionView; |
| | | } |