// // HomeViewController.m // KulexiuForTeacher // // Created by Kyle on 2022/3/17. // #import "HomeViewController.h" #import "KSBaseWKWebViewController.h" #import "InstrumentChooseViewController.h" #import "NotiferMessageViewController.h" #import "HomeNavSearchView.h" #import "KSScanViewController.h" #import "HomeBannerView.h" #import #import "TYCyclePagerView.h" #import "TYPageControl.h" #import "HomeBannerCell.h" #import "HomeBannerCell.h" #import "HomeButtonView.h" #import "KSHomeButton.h" #import "PublicNoticeView.h" #import "SDCycleScrollView.h" #import "NoticeSourceModel.h" #import "AppDelegate.h" #import "KSNewsAlert.h" #import "StudentInfoModel.h" #import "UserInfoManager.h" #import "HomeRecentCourseView.h" #import "AccompanyDetailViewController.h" #import "MusicRoomDetailViewController.h" #import "HomeHotAlbumView.h" #import "HomeAlbumModel.h" #import "HomeHotAlbumCell.h" #import "HomeHotMusicView.h" #import "HomeHotMusicCollectionCell.h" #import "KSPremissionAlert.h" #import "RecordCheckManager.h" #import "KSAccompanyWebViewController.h" #import "HomeHotTalentView.h" #import "HomeHotTalentCell.h" #import "TalentTeacherModel.h" #import "HomeHotVideoCourseView.h" #import "HomeHotVideoCell.h" #import "HomeVideoGroupModel.h" #import "HomeHotLiveCourseView.h" #import "HomeHotLiveCell.h" #import "HomeLiveGroupModel.h" #import "JXCategoryView.h" #import "JXPagerListRefreshView.h" #import "HomePageBodyView.h" #import "HomeInformationBodyView.h" #import "TeacherStyleModel.h" #import "HomeTeacherLiveModel.h" #define BUTTONWIDTH (65) #define BUTTONHEIGHT (80) @interface HomeViewController () @property (nonatomic, strong) StudentInfoModel *mineInfo; @property (nonatomic, strong) HomeNavSearchView *navView; @property (nonatomic, strong) HomeMessageModel *flashModel; @property (nonatomic, assign) BOOL isFirstLoad; // banner @property (nonatomic, strong) TYPageControl *pageControl; @property (nonatomic, strong) HomeBannerView *bannerView; // banner container @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动 @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据 @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度 // 按钮 @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container @property (nonatomic, strong) UIScrollView *buttonScrollView; @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容 @property (nonatomic, assign) NSInteger buttonDotWidth; @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度 // 公告 @property (nonatomic, strong) PublicNoticeView *noticeView; @property (nonatomic, strong) SDCycleScrollView *noticeScrollView; @property (nonatomic, strong) NSMutableArray *noticeArray; // notice数据 @property (nonatomic, strong) NSMutableArray *noticeTitleArray; // 标题数组 @property (nonatomic, assign) CGFloat noticeViewHeight; // 最近课程 @property (nonatomic, strong) HomeRecentCourseView *courseView; @property (nonatomic, assign) CGFloat courseViewHeight; @property (nonatomic, strong) RecentCourseModel *recentCourseModel; // 热门专辑 @property (nonatomic, strong) HomeHotAlbumView *albumView; @property (nonatomic, strong) NSMutableArray *albumArray; @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器 @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度 // 热门曲谱 @property (nonatomic, strong) HomeHotMusicView *hotMusicView; @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器 @property (nonatomic, strong) NSMutableArray *musicArray; // 曲谱数据 @property (nonatomic, assign) CGFloat musicViewHeight; // music 高度 // 推荐达人 @property (nonatomic, strong) HomeHotTalentView *talentView; @property (nonatomic, strong) UICollectionView *talentCollectionView; // 推荐达人容器 @property (nonatomic, strong) NSMutableArray *talentArray; // 推荐达人数据 @property (nonatomic, assign) CGFloat talentViewHeight; // talent 高度 // 视频课 @property (nonatomic, strong) HomeHotVideoCourseView *videoCourseView; @property (nonatomic, strong) UICollectionView *videoCollectionView; // 视频课容器 @property (nonatomic, strong) NSMutableArray *videoCourseArray; // 视频课数据 @property (nonatomic, assign) CGFloat videoViewHeight; // video 高度 // 直播课 @property (nonatomic, strong) HomeHotLiveCourseView *liveCourseView; @property (nonatomic, strong) UICollectionView *liveCollectionView; // 直播课容器 @property (nonatomic, strong) NSMutableArray *liveCourseArray; // 直播课数据 @property (nonatomic, assign) CGFloat liveViewHeight; // live 高度 @property (nonatomic, strong) dispatch_group_t requestGroup; // 顶部数据容器 @property (nonatomic, strong) UIView *headView; @property (nonatomic, strong) JXCategoryTitleView *myCategoryView; @property (nonatomic, assign) NSInteger currentIndex; @property (nonatomic, strong) NSMutableArray *listViewArray; @property (nonatomic, assign) NSInteger headViewHeight; @property (nonatomic, strong) NSMutableArray *teacherArray; @property (nonatomic, strong) NSMutableArray *liveListArray; @property (nonatomic, strong) NSMutableArray *informationArray; @property (nonatomic, strong) UIView *headBgView; @end @implementation HomeViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.ks_prefersNavigationBarHidden = YES; _titles = @[@"达人风采",@"热门资讯"]; self.isFirstLoad = YES; [self configNavView]; [self configUI]; } - (void)requestTrackAuth { AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate appTrackActionAuth]; } - (void)configNavView { [self.scrollView removeFromSuperview]; [self.view addSubview:self.navView]; [self.navView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(self.view); make.height.mas_equalTo(kNaviBarHeight); }]; [self.view bringSubviewToFront:self.navView]; } - (void)configHeadView { [self.headView addSubview:self.headBgView]; // banner [self.headView addSubview:self.bannerView]; self.bannerViewHeight = [HomeBannerView getViewHeight]; [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(self.headView); make.height.mas_equalTo(self.bannerViewHeight); }]; // 按钮 [self.headView addSubview:self.buttonContainer]; self.buttonViewHeight = CGFLOAT_MIN; [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.bannerView.mas_bottom); make.height.mas_equalTo(CGFLOAT_MIN); }]; self.buttonContainer.hidden = YES; // 公告 [self.headView addSubview:self.noticeView]; self.noticeViewHeight = CGFLOAT_MIN; [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.buttonContainer.mas_bottom); make.height.mas_equalTo(CGFLOAT_MIN); }]; [self.noticeView.adView addSubview:self.noticeScrollView]; [self.noticeScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.bottom.mas_equalTo(self.noticeView.adView); }]; self.noticeView.hidden = YES; // 最近课程 [self.headView addSubview:self.courseView]; self.courseViewHeight = CGFLOAT_MIN; [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.noticeView.mas_bottom); make.height.mas_equalTo(CGFLOAT_MIN); }]; self.courseView.hidden = YES; // 热门专辑 [self.headView addSubview:self.albumView]; self.albumViewHeight = [HomeHotAlbumView getViewHeight]; [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.courseView.mas_bottom); make.height.mas_equalTo(self.albumViewHeight); }]; // 热门曲目 [self.headView addSubview:self.hotMusicView]; self.musicViewHeight = [HomeHotMusicView getViewHeight]; [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.albumView.mas_bottom); make.height.mas_equalTo(self.musicViewHeight); }]; // 推荐达人 [self.headView addSubview:self.talentView]; self.talentViewHeight = CGFLOAT_MIN; [self.talentView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.hotMusicView.mas_bottom); make.height.mas_equalTo(self.talentViewHeight); }]; self.talentView.hidden = YES; // 视频课 [self.headView addSubview:self.videoCourseView]; self.videoViewHeight = CGFLOAT_MIN; [self.videoCourseView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.talentView.mas_bottom); make.height.mas_equalTo(self.videoViewHeight); }]; self.videoCourseView.hidden = YES; // 直播 [self.headView addSubview:self.liveCourseView]; self.liveViewHeight = CGFLOAT_MIN; [self.liveCourseView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.videoCourseView.mas_bottom); make.height.mas_equalTo(self.liveViewHeight); }]; self.liveCourseView.hidden = YES; [self.headBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.bannerView.mas_top); make.bottom.mas_equalTo(self.buttonContainer.mas_bottom); }]; self.headBgView.layer.masksToBounds = YES; self.headBgView.layer.cornerRadius = 18.0f; self.headBgView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner; [self refreshHeadHeight]; } - (void)refreshHeadHeight { CGFloat bottomSpace = 20.0f; self.headViewHeight = self.bannerViewHeight + self.buttonViewHeight + self.noticeViewHeight + self.courseViewHeight + self.albumViewHeight + self.musicViewHeight + self.talentViewHeight + self.liveViewHeight + self.videoViewHeight + bottomSpace; [self.pagerView reloadData]; } - (void)configUI { [self configHeadView]; _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, kNaviBarHeight, kScreenWidth, 44)]; self.categoryView.backgroundColor = [UIColor clearColor]; self.categoryView.titles = self.titles; self.categoryView.delegate = self; self.categoryView.titleFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium]; self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:18.0f weight:UIFontWeightMedium]; self.categoryView.titleSelectedColor = HexRGB(0x333333); self.categoryView.titleColor = HexRGB(0x999999); self.categoryView.titleColorGradientEnabled = YES; self.categoryView.cellWidth = 90.0f; self.categoryView.cellSpacing = 16.0f; self.categoryView.averageCellSpacingEnabled = NO; JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init]; lineView.verticalMargin = 10; lineView.indicatorColor = THEMECOLOR; lineView.indicatorWidth = 63.0f; lineView.indicatorHeight = 12.0f; self.categoryView.indicators = @[lineView]; _pagerView = [self preferredPagingView]; self.pagerView.frame = CGRectMake(0, kNaviBarHeight, kScreenWidth, kScreenHeight - kNaviBarHeight - kTabBarHeight); self.pagerView.mainTableView.gestureDelegate = self; [self.view addSubview:self.pagerView]; self.pagerView.backgroundColor = [UIColor clearColor]; self.pagerView.mainTableView.backgroundColor = [UIColor clearColor]; self.categoryView.listContainer = (id)self.pagerView.listContainerView; // 头部刷新 MJWeakSelf; self.pagerView.mainTableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{ [weakSelf requestData]; }]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0); } - (JXPagerView *)preferredPagingView { return [[JXPagerView alloc] initWithDelegate:self]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (self.isFirstLoad == YES) { [self requestUserInfo:YES]; // 获取声部 [self requestTrackAuth]; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate handleNotiferSource]; } else { [self requestUserInfo:YES]; } [self requestUnreadCount]; } - (void)requestUnreadCount { [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) { if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *countArray = [dic arrayValueForKey:@"data"]; NSInteger courseCount = 0; NSInteger sysCount = 0; for (NSDictionary *parm in countArray) { if ([[parm stringValueForKey:@"key"] isEqualToString:@"COURSE"]) { courseCount = [parm integerValueForKey:@"value"]; } if ([[parm stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) { sysCount = [parm integerValueForKey:@"value"]; } } if (courseCount != 0 || sysCount != 0) { self.navView.dotView.hidden = NO; } else { self.navView.dotView.hidden = YES; } } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { }]; } - (void)requestUserInfo:(BOOL)checkSubject { self.isFirstLoad = NO; [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) { if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]]; NSString *rongToken = UserDefault(RongTokenKey); if ([NSString isEmptyString:rongToken]) { [USER_MANAGER queryUserInfoConnectRongCloud:YES]; } [self refreshSource:checkSubject]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { }]; } - (void)refreshSource:(BOOL)checkSubject { if (checkSubject) { if ([NSString isEmptyString:self.mineInfo.subjectName]) { [self showInstrumentView:YES]; } else { [self requestData]; } } } - (void)showInstrumentView:(BOOL)hideBackButton { InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init]; MJWeakSelf; [ctrl chooseCallback:^{ [weakSelf requestUserInfo:NO]; [weakSelf requestData]; }]; if (hideBackButton) { ctrl.isModalPresent = YES; CustomNavViewController *navCrtl = [[CustomNavViewController alloc] initWithRootViewController:ctrl]; navCrtl.modalPresentationStyle = UIModalPresentationFullScreen; [self.navigationController presentViewController:navCrtl animated:YES completion:nil]; } else { [self.navigationController pushViewController:ctrl animated:YES]; } } - (void)requestNewsList { dispatch_group_enter(self.requestGroup); [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSDictionary *result = [dic dictionaryValueForKey:@"data"]; // banner NSArray *bannerArray = [result arrayValueForKey:@"banner"]; NSMutableArray *bannerInfoArray = [NSMutableArray array]; for (NSDictionary *parm in bannerArray) { HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm]; [bannerInfoArray addObject:model]; } self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray]; // button NSArray *buttonArray = [result arrayValueForKey:@"appMenu"]; NSMutableArray *buttonInfoArray = [NSMutableArray array]; for (NSDictionary *parm in buttonArray) { HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm]; [buttonInfoArray addObject:model]; } self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray]; // news NSArray *flashArray = [result arrayValueForKey:@"flashPage"]; if (flashArray.count) { self.flashModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]]; } // // information // NSArray *information = [result arrayValueForKey:@"information"]; // NSMutableArray *informationInfoArray = [NSMutableArray array]; // for (NSDictionary *parm in information) { // HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm]; // [informationInfoArray addObject:model]; // } // self.informationArray = [NSMutableArray arrayWithArray:informationInfoArray]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestHotAlbum { dispatch_group_enter(self.requestGroup); [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"]; NSMutableArray *albumArray = [NSMutableArray array]; for (NSDictionary *parm in sourceArray) { HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm]; [albumArray addObject:model]; } self.albumArray = [NSMutableArray arrayWithArray:albumArray]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestCourseInfo { dispatch_group_enter(self.requestGroup); [KSNetworkingManager homeQueryLiveAndVideo:KS_GET version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSDictionary *sourceDic = [dic dictionaryValueForKey:@"data"]; NSArray *liveList = [sourceDic arrayValueForKey:@"liveList"]; NSMutableArray *liveCourse = [NSMutableArray array]; for (NSDictionary *parm in liveList) { HomeLiveGroupModel *model = [[HomeLiveGroupModel alloc] initWithDictionary:parm]; [liveCourse addObject:model]; } self.liveCourseArray = [NSMutableArray arrayWithArray:liveCourse]; NSArray *videoList = [sourceDic arrayValueForKey:@"videoList"]; NSMutableArray *videoCourse = [NSMutableArray array]; for (NSDictionary *parm in videoList) { HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm]; [videoCourse addObject:model]; } self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse]; // 最近课程 NSDictionary *parm = [sourceDic dictionaryValueForKey:@"recentCourses"]; if (parm == nil) { self.recentCourseModel = nil; } else { self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm]; } } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestNotice { dispatch_group_enter(self.requestGroup); [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"]; if (sourceArray.count) { NSDictionary *parm = [sourceArray firstObject]; NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm]; [self.noticeArray addObject:bannerModel]; [self.noticeTitleArray addObject:bannerModel.title]; } else { self.noticeArray = [NSMutableArray array]; self.noticeTitleArray = [NSMutableArray array]; } } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestHotMusic { dispatch_group_enter(self.requestGroup); [KSNetworkingManager homeMusicListRequest:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"]; NSMutableArray *musicArray = [NSMutableArray array]; for (NSDictionary *parm in sourceArray) { HomeHotMusicModel *model = [[HomeHotMusicModel alloc] initWithDictionary:parm]; [musicArray addObject:model]; } self.musicArray = [NSMutableArray arrayWithArray:musicArray]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestTalentSource { dispatch_group_enter(self.requestGroup); [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *sourceArray = [dic arrayValueForKey:@"data"]; NSMutableArray *talentArray = [NSMutableArray array]; for (NSDictionary *parm in sourceArray) { TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm]; [talentArray addObject:model]; } self.talentArray = [NSMutableArray arrayWithArray:talentArray]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestTeacherStyle { dispatch_group_enter(self.requestGroup); [KSNetworkingManager homeQueryTeacherStyle:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"]; NSMutableArray *styleArray = [NSMutableArray array]; for (NSDictionary *parm in sourceArray) { TeacherStyleModel *model = [[TeacherStyleModel alloc] initWithDictionary:parm]; [styleArray addObject:model]; } self.teacherArray = [NSMutableArray arrayWithArray:styleArray]; } else { [self MBPShow:MESSAGEKEY]; } // 回调 } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestLiveList { dispatch_group_enter(self.requestGroup); [KSNetworkingManager queryTeacherLivingListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *sourceArray = [dic arrayValueForKey:@"data"]; NSMutableArray *liveListArray = [NSMutableArray array]; for (NSDictionary *parm in sourceArray) { HomeTeacherLiveModel *model = [[HomeTeacherLiveModel alloc] initWithDictionary:parm]; [liveListArray addObject:model]; } self.liveListArray = [NSMutableArray arrayWithArray:liveListArray]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestInformationList { dispatch_group_enter(self.requestGroup); [KSNetworkingManager informationListRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) { dispatch_group_leave(self.requestGroup); if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) { NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"]; NSMutableArray *informationInfoArray = [NSMutableArray array]; for (NSDictionary *parm in sourceArray) { HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm]; [informationInfoArray addObject:model]; } self.informationArray = [NSMutableArray arrayWithArray:informationInfoArray]; } else { [self MBPShow:MESSAGEKEY]; } } faliure:^(NSError * _Nonnull error) { dispatch_group_leave(self.requestGroup); }]; } - (void)requestData { [self showhud]; [self requestNewsList]; [self requestNotice]; [self requestCourseInfo]; // 达人 [self requestTalentSource]; [self requestHotAlbum]; [self requestHotMusic]; [self requestTeacherStyle]; [self requestLiveList]; [self requestInformationList]; dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{ [self removehub]; [self.pagerView.mainTableView.mj_header endRefreshing]; [self refreshView]; }); } - (void)refreshView { [self refreshBannaerView]; [self showButtonMessage]; [self refreshNotice]; [self refreshCourseView:self.recentCourseModel]; [self refreshAlbumView]; [self refreshMusicView]; // 达人 [self refreshTalentView]; // 课程 [self refreshCourseView]; // 刷新排序 [self refreshViewLocation]; [self refreshHeadHeight]; [self refreshPageView]; if (self.flashModel) { [self showNewsWithSource:self.flashModel]; } } - (void)showNewsWithSource:(HomeMessageModel *)sourceModel { // 登录之后才弹窗 if ([self checkIsLoginToLoginView:NO]) { NSString *useId = UserDefault(UIDKey); NSMutableArray *newArray = UserDefault(useId); if (newArray.count) { if ([newArray containsObject:sourceModel.coverImage]) { return; } else { [self displayAlert:sourceModel]; } } else { [self displayAlert:sourceModel]; } } } - (void)displayAlert:(HomeMessageModel *)sourceModel { AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; if (appDelegate.isShowMemoAlert) { return; } NSString *useId = UserDefault(UIDKey); UserDefaultRemoveObjectForKey(useId); NSMutableArray *sourceArray = [NSMutableArray arrayWithArray:UserDefault(useId)]; [sourceArray addObject:sourceModel.coverImage]; UserDefaultSetObjectForKey(sourceArray, useId); KSNewsAlert *newAlert = [KSNewsAlert shareInstance]; MJWeakSelf; [newAlert evaluateWithMessage:sourceModel.coverImage linkUrl:sourceModel.linkUrl callbackAction:^(BOOL isSure, NSString * _Nonnull linkUrl) { appDelegate.isShowFlashAlert = NO; if (isSure) { if (![NSString isEmptyString:linkUrl]) { KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = linkUrl; [weakSelf.navigationController pushViewController:webCtrl animated:YES]; } } [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新 }]; [newAlert showAlert]; appDelegate.isShowFlashAlert = YES; } - (void)refreshPageView { for (NSInteger i = 0; i < self.listViewArray.count; i++) { id view = self.listViewArray[i]; if ([view isKindOfClass:[HomePageBodyView class]]) { HomePageBodyView *styleView = (HomePageBodyView *)view; styleView.styleArray = [self.teacherArray mutableCopy]; styleView.liveArray = [self.liveListArray mutableCopy]; [styleView resetAndRefresh]; } else if ([view isKindOfClass:[HomeInformationBodyView class]]) { HomeInformationBodyView *informationView = (HomeInformationBodyView *)view; informationView.informationArray = [self.informationArray mutableCopy]; [informationView beginFirstRefresh]; } } } - (void)refreshTalentView { if (self.talentArray.count) { self.talentViewHeight = [HomeHotTalentView getViewHeight]; self.talentView.hidden = NO; } else { self.talentViewHeight = CGFLOAT_MIN; self.talentView.hidden = YES; } [self.talentView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.talentViewHeight); }]; [self.talentCollectionView reloadData]; } - (void)refreshViewLocation { // 如果有课程和公告 且有按钮 CGFloat buttonViewDefaultHeight = self.buttonArray.count > 5 ? [HomeButtonView getViewHeight] : [HomeButtonView getViewHeight] - 20; if (self.noticeTitleArray.count && self.recentCourseModel && self.buttonArray.count) { self.noticeViewHeight = [PublicNoticeView getViewHeight]; [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.bannerView.mas_bottom); make.height.mas_equalTo(self.noticeViewHeight); }]; self.buttonViewHeight = buttonViewDefaultHeight; [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.noticeView.mas_bottom); make.height.mas_equalTo(self.buttonViewHeight); }]; self.courseViewHeight = 91.0f; [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.buttonContainer.mas_bottom); make.height.mas_equalTo(self.courseViewHeight); }]; [self.headBgView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.bannerView.mas_top); make.bottom.mas_equalTo(self.buttonContainer.mas_bottom); }]; } else { self.buttonViewHeight = self.buttonArray.count ? buttonViewDefaultHeight : CGFLOAT_MIN; [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.bannerView.mas_bottom); make.height.mas_equalTo(self.buttonViewHeight); }]; self.noticeViewHeight = self.noticeTitleArray.count ? [PublicNoticeView getViewHeight] : CGFLOAT_MIN; [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.buttonContainer.mas_bottom); make.height.mas_equalTo(self.noticeViewHeight); }]; [self.headBgView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.bannerView.mas_top); make.bottom.mas_equalTo(self.noticeView.mas_bottom); }]; CGFloat courseViewHeight = self.recentCourseModel ? 90.0f : CGFLOAT_MIN; self.courseViewHeight = courseViewHeight; [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.headView); make.top.mas_equalTo(self.noticeView.mas_bottom); make.height.mas_equalTo(self.courseViewHeight); }]; } } - (void)refreshBannaerView { if (self.bannerArray.count > 1) { self.bannerScroll.autoScrollInterval = 3.0f; [self.bannerScroll addSubview:self.pageControl]; } else { self.bannerScroll.autoScrollInterval = 0; [self.pageControl removeFromSuperview]; } _pageControl.numberOfPages = self.bannerArray.count; [self.bannerScroll reloadData]; } - (void)showButtonMessage { // 添加按钮 if (self.buttonArray.count) { self.buttonContainer.hidden = NO; if (self.buttonArray.count > 5) { // 大于4个显示底部滚动视图 self.buttonContainer.buttonPageCtrl.hidden = NO; self.buttonContainer.buttonDotLeft.constant = 0; NSInteger addPage = (self.buttonArray.count % 5) > 0 ? 1 : 0; NSInteger pageCount = self.buttonArray.count / 5 + addPage; self.buttonDotWidth = 36 / pageCount; self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth; self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth * pageCount, BUTTONHEIGHT); } else { self.buttonContainer.buttonPageCtrl.hidden = YES; self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, BUTTONHEIGHT); } } else { self.buttonContainer.hidden = YES; self.buttonContainer.buttonPageCtrl.hidden = YES; self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, CGFLOAT_MIN); } self.buttonScrollView.contentOffset = CGPointMake(0, 0); [self.buttonScrollView removeAllSubViews]; CGFloat buttonSpace = (kScreenWidth - 5 * BUTTONWIDTH) / 6; for (NSInteger i = 0; i < self.buttonArray.count; i++) { HomeMessageModel *model = self.buttonArray[i]; KSHomeButton *buttonView = [KSHomeButton shareInstance]; [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]]; buttonView.buttonTitle.text = model.title; buttonView.frame = CGRectMake(buttonSpace + (i % 5) * (BUTTONWIDTH + buttonSpace) + (i / 5) * KPortraitWidth, 0, BUTTONWIDTH, BUTTONHEIGHT); buttonView.actionButton.tag = 3000 + i; [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.buttonScrollView addSubview:buttonView]; } } - (void)HomeTopButtonAction:(UIButton *)sender { NSInteger index = sender.tag - 3000; if ([self checkIsLoginToLoginView:YES]) { HomeMessageModel *model = self.buttonArray[index]; if (![NSString isEmptyString:model.linkUrl]) { KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = model.linkUrl; [self.navigationController pushViewController:webCtrl animated:YES]; } } } - (void)refreshNotice { if (self.noticeTitleArray.count) { self.noticeView.hidden = NO; } else { self.noticeView.hidden = YES; } self.noticeScrollView.titlesGroup = self.noticeTitleArray; } - (void)refreshCourseView:(RecentCourseModel *)model { if (model) { [self.courseView configCourseMessage:model]; self.courseView.hidden = NO; } else { self.courseView.hidden = YES; } } - (void)refreshAlbumView { if (self.albumArray.count) { self.albumViewHeight = [HomeHotAlbumView getViewHeight]; self.albumView.hidden = NO; } else { self.albumViewHeight = CGFLOAT_MIN; self.albumView.hidden = YES; } [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.albumViewHeight); }]; [self.albumCollectionView reloadData]; } - (void)refreshMusicView { [self.musicCollectionView reloadData]; } - (void)refreshCourseView { // 课程 if (self.liveCourseArray.count) { self.liveViewHeight = [HomeHotLiveCourseView getViewHeight]; self.liveCourseView.hidden = NO; } else { self.liveViewHeight = CGFLOAT_MIN; self.liveCourseView.hidden = YES; } [self.liveCourseView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.liveViewHeight); }]; if (self.videoCourseArray.count) { self.videoViewHeight = [HomeHotVideoCourseView getViewHeight]; self.videoCourseView.hidden = NO; } else { self.videoViewHeight = CGFLOAT_MIN; self.videoCourseView.hidden = YES; } [self.videoCourseView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.videoViewHeight); }]; [self.videoCollectionView reloadData]; [self.liveCollectionView reloadData]; } #pragma mark - JXPagerViewDelegate - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView { return self.headView; } - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView { return self.headViewHeight; } - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return self.categoryView; } - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView { return 44; } - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView { //和categoryView的item数量一致 return self.titles.count; } - (id)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index { if (index == 0) { HomePageBodyView *listView = [[HomePageBodyView alloc] init]; listView.naviController = self.navigationController; [self.listViewArray replaceObjectAtIndex:index withObject:listView]; self.listViewArray[index] = listView; listView.selectIndex = index; listView.styleArray = [self.teacherArray mutableCopy]; listView.liveArray = [self.liveListArray mutableCopy]; [listView beginFirstRefresh]; return listView; } else { HomeInformationBodyView *listView = [[HomeInformationBodyView alloc] init]; listView.naviController = self.navigationController; [self.listViewArray replaceObjectAtIndex:index withObject:listView]; self.listViewArray[index] = listView; listView.selectIndex = index; listView.informationArray = [self.informationArray mutableCopy]; [listView beginFirstRefresh]; return listView; } } #pragma mark - JXCategoryViewDelegate - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0); if (self.listViewArray.count > index) { id value = self.listViewArray[index]; if ([value isKindOfClass:[KSJXBodyView class]]) { KSJXBodyView *listView = (KSJXBodyView *)value; [listView beginFirstRefresh]; } else if ([value isKindOfClass:[kSJXCollectionView class]]) { kSJXCollectionView *listView = (kSJXCollectionView *)value; [listView beginFirstRefresh]; } } } #pragma mark - JXPagerMainTableViewGestureDelegate - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { //禁止categoryView左右滑动的时候,上下和左右都可以滚动 if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) { return NO; } return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]; } - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView { NSLog(@"sscroll content offset y %f", scrollView.contentOffset.y); NSInteger height = self.headViewHeight; CGFloat space = scrollView.contentOffset.y; if (space > 0) { self.navView.lineView.hidden = NO; } else { self.navView.lineView.hidden = YES; } if (space >= height) { self.categoryView.backgroundColor = [UIColor whiteColor]; } else { self.categoryView.backgroundColor = [UIColor clearColor]; } } #pragma mark - TYCyclePagerViewDataSource代理 - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView { return self.bannerArray.count; } - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index { HomeMessageModel *model = self.bannerArray[index]; HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index]; [cell configCellWithModel:model]; return cell; } - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView { TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init]; layout.itemSize = CGSizeMake(kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132); layout.itemSpacing = 0; return layout; } - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex { if (pageView == self.bannerScroll) { [self.pageControl setCurrentPage:toIndex animate:YES]; } } - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index { HomeMessageModel *model = self.bannerArray[index]; if (![NSString isEmptyString:model.linkUrl]) { KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = model.linkUrl; [self.navigationController pushViewController:webCtrl animated:YES]; } } #pragma mark ---- collection data source - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { if (collectionView == self.albumCollectionView) { // 专辑 return self.albumArray.count; } else if (collectionView == self.musicCollectionView) { // 乐谱 NSInteger lastRowCount = (self.musicArray.count % 3) > 0 ? 1 : 0; NSInteger count = self.musicArray.count / 3 + lastRowCount; return count; } else if (collectionView == self.talentCollectionView) { // 推荐达人 return self.talentArray.count; } else if (collectionView == self.videoCollectionView) { // 视频课 return self.videoCourseArray.count; } else { // 直播课 return self.liveCourseArray.count; } } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (collectionView == self.albumCollectionView) { HomeAlbumModel *model = self.albumArray[indexPath.item]; HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath]; [cell configWithAlbumModel:model]; return cell; } else if (collectionView == self.musicCollectionView) { NSMutableArray *songArray = [NSMutableArray array]; NSInteger length = indexPath.item * 3 + 3 > self.musicArray.count ? self.musicArray.count - indexPath.item * 3: 3; NSRange range = NSMakeRange(indexPath.item * 3, length); songArray = [NSMutableArray arrayWithArray:[self.musicArray subarrayWithRange:range]]; HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath]; MJWeakSelf; [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) { [weakSelf displaySongDetail:songId]; }]; return cell; } else if (collectionView == self.talentCollectionView) { TalentTeacherModel *talentModel = self.talentArray[indexPath.item]; HomeHotTalentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotTalentCell" forIndexPath:indexPath]; [cell configWithSource:talentModel]; return cell; } else if (collectionView == self.videoCollectionView) { HomeVideoGroupModel *model = self.videoCourseArray[indexPath.item]; HomeHotVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotVideoCell" forIndexPath:indexPath]; [cell configWithSource:model]; return cell; } else { HomeLiveGroupModel *model = self.liveCourseArray[indexPath.item]; HomeHotLiveCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotLiveCell" forIndexPath:indexPath]; [cell configWithSource:model]; return cell; } } - (void)displaySongDetail:(NSString *)songId { // 检测权限 PREMISSIONTYPE micEnable = [RecordCheckManager checkPermissionShowAlert:NO showInView:nil]; PREMISSIONTYPE cameraEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil]; if (micEnable == PREMISSIONTYPE_YES && cameraEnable == PREMISSIONTYPE_YES) { // 如果麦克风和摄像头权限都有 // 跳转到播放页面 KSAccompanyWebViewController *detailCtrl = [[KSAccompanyWebViewController alloc] init]; detailCtrl.url = [NSString stringWithFormat:@"%@/accompany?id=%@",hostURL, songId]; detailCtrl.hiddenNavBar = YES; detailCtrl.parmDic = @{@"isOpenLight" : @(YES), @"orientation" : @(0),@"isHideTitle" : @(YES)}; [self.navigationController pushViewController:detailCtrl animated:YES]; } else { if (micEnable == PREMISSIONTYPE_NO && cameraEnable == PREMISSIONTYPE_NO) { // 如果麦克风权限和摄像头权限都没有 [self showAlertWithMessage:@"请开启相机和麦克风访问权限" type:CHECKDEVICETYPE_BOTH]; } else if (micEnable == PREMISSIONTYPE_NO) { // 如果没有麦克风权限 [self showAlertWithMessage:@"请开启麦克风访问权限" type:CHECKDEVICETYPE_MIC]; } else if (cameraEnable == PREMISSIONTYPE_NO) { // 如果没有摄像头权限 [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA]; } } } - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType { [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{ } confirm:^{ [self openSettingView]; }]; } - (void)openSettingView { if (@available(iOS 10, *)) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil]; } else { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (collectionView == self.albumCollectionView) { // 专辑详情 HomeAlbumModel *model = self.albumArray[indexPath.item]; KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier]; [self.navigationController pushViewController:ctrl animated:YES]; } else if (collectionView == self.talentCollectionView) { // 达人风采 TalentTeacherModel *model = self.talentArray[indexPath.item]; [self displayTeacherDetail:[NSString stringWithFormat:@"%.0f",model.userId]]; } else if (collectionView == self.videoCollectionView) { // 视频课 HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row]; NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId]; KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = url; [self.navigationController pushViewController:ctrl animated:YES]; } else if (collectionView == self.liveCollectionView) { // 直播课详情 HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row]; KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId]; ctrl.url = url; [self.navigationController pushViewController:ctrl animated:YES]; } } // 老师风采 - (void)displayTeacherDetail:(NSString *)teacherId { KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId]; [self.navigationController pushViewController:ctrl animated:YES]; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (collectionView == self.albumCollectionView) { return CGSizeMake(100, 134); } else if (collectionView == self.musicCollectionView) { return CGSizeMake(KPortraitWidth * 0.83, 240); } else if (collectionView == self.talentCollectionView) { return CGSizeMake(110, 150); } else if (collectionView == self.videoCollectionView) { return CGSizeMake(168, 157); } else { return CGSizeMake(168, 157); } } #pragma mark ----- SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { NoticeSourceModel *noticeModel = self.noticeArray[index]; KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, noticeModel.internalBaseClassIdentifier]; [self.navigationController pushViewController:webCtrl animated:YES]; } #pragma mark ------- lazying - (HomeNavSearchView *)navView { if (!_navView) { _navView = [HomeNavSearchView shareInstance]; MJWeakSelf; [_navView homeNavSearchAction:^(HOMENAV_TAG action) { [weakSelf homeNavAction:action]; }]; } return _navView; } - (void)homeNavAction:(HOMENAV_TAG)action { switch (action) { case HOMENAV_TAG_SCAN: // 扫一扫 { [self showScanView]; } break; case HOMENAV_TAG_MESSAGE: // 消息 { NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init]; [self.navigationController pushViewController:ctrl animated:YES]; } break; case HOMENAV_TAG_SEARCH: // 搜索 { KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = [NSString stringWithFormat:@"%@/#/music-songbook/search", WEBHOST]; [self.navigationController pushViewController:webCtrl animated:YES]; } break; default: break; } } - (void)showScanView { // 判断是否有权限 PREMISSIONTYPE albumEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil]; if (albumEnable == PREMISSIONTYPE_YES) { // 如果有权限 KSScanViewController *ctrl = [[KSScanViewController alloc] init]; [self.navigationController pushViewController:ctrl animated:YES]; } else { if (albumEnable == PREMISSIONTYPE_NO) { [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA]; } } } - (dispatch_group_t)requestGroup { if (!_requestGroup) { _requestGroup = dispatch_group_create(); } return _requestGroup; } - (UIView *)headView { if (!_headView) { _headView = [[UIView alloc] init]; _headView.backgroundColor = [UIColor clearColor]; } return _headView; } - (NSMutableArray *)listViewArray { if (!_listViewArray) { _listViewArray = [NSMutableArray arrayWithArray:@[@"",@""]]; } return _listViewArray; } - (HomeBannerView *)bannerView { if (!_bannerView) { _bannerView = [HomeBannerView shareInstance]; [_bannerView.bannerContentView addSubview:self.bannerScroll]; } return _bannerView; } #pragma mark --- banner - (TYCyclePagerView *)bannerScroll { if (!_bannerScroll) { _bannerScroll = [[TYCyclePagerView alloc] init]; _bannerScroll.backgroundColor = [UIColor clearColor]; _bannerScroll.frame = CGRectMake(0, 0, kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132); _bannerScroll.isInfiniteLoop = YES; _bannerScroll.autoScrollInterval = 3.0f; _bannerScroll.reloadDataNeedResetIndex = YES; _bannerScroll.dataSource = self; _bannerScroll.delegate = self; [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"]; if (@available(iOS 11.0, *)) { _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions if (@available(iOS 13.0, *)) { _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO; } else { // Fallback on earlier versions } } } return _bannerScroll; } - (TYPageControl *)pageControl { if (!_pageControl) { _pageControl = [[TYPageControl alloc] init]; _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; _pageControl.pageIndicatorSpaing = 4.0f; _pageControl.frame = CGRectMake(0, (kScreenWidth - 28) * 132 / 347 - 20, kScreenWidth-28 - 12, 12); _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff); _pageControl.pageIndicatorTintColor = HexRGB(0xffffff); _pageControl.pageIndicatorSize = CGSizeMake(5, 5); _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5); } return _pageControl; } - (NSMutableArray *)bannerArray { if (!_bannerArray) { _bannerArray = [NSMutableArray array]; } return _bannerArray; } #pragma mark ---- scroll view delegate - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == self.buttonScrollView) { NSInteger index = (NSInteger)(scrollView.contentOffset.x / (KPortraitWidth - 28)); [UIView animateWithDuration:0.3f animations:^{ self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth; }]; } } #pragma mark ---- button container - (HomeButtonView *)buttonContainer { if (!_buttonContainer) { _buttonContainer = [HomeButtonView shareInstance]; [_buttonContainer.buttonContentView addSubview:self.buttonScrollView]; } return _buttonContainer; } - (UIScrollView *)buttonScrollView { if (!_buttonScrollView) { _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, BUTTONHEIGHT)]; _buttonScrollView.backgroundColor = [UIColor clearColor]; _buttonScrollView.pagingEnabled = YES; _buttonScrollView.showsHorizontalScrollIndicator = NO; _buttonScrollView.showsVerticalScrollIndicator = NO; _buttonScrollView.delegate = self; } return _buttonScrollView; } #pragma mark ---- notice view - (UIView *)headBgView { if (!_headBgView) { _headBgView = [[UIView alloc] init]; _headBgView.backgroundColor = [UIColor whiteColor]; } return _headBgView; } - (PublicNoticeView *)noticeView { if (!_noticeView) { _noticeView = [PublicNoticeView shareInstance]; MJWeakSelf; [_noticeView moreCallback:^{ [weakSelf moreNotice]; }]; } return _noticeView; } - (NSMutableArray *)noticeArray { if (!_noticeArray) { _noticeArray = [NSMutableArray array]; } return _noticeArray; } - (NSMutableArray *)noticeTitleArray { if (!_noticeTitleArray) { _noticeTitleArray = [NSMutableArray array]; } return _noticeTitleArray; } - (void)moreNotice { if (self.noticeArray.count) { NoticeSourceModel *bannerModel = self.noticeArray[0]; KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init]; webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier]; [self.navigationController pushViewController:webCtrl animated:YES]; } } - (SDCycleScrollView *)noticeScrollView { if (!_noticeScrollView) { _noticeScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage new]]; _noticeScrollView.onlyDisplayText = YES; _noticeScrollView.autoScroll = NO; _noticeScrollView.scrollEnabled = NO; _noticeScrollView.scrollDirection = UICollectionViewScrollDirectionVertical; _noticeScrollView.titleLabelTextColor = HexRGB(0x1a1a1a); _noticeScrollView.titleLabelBackgroundColor = [UIColor clearColor]; _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14]; _noticeScrollView.titlesGroup = self.noticeTitleArray; } return _noticeScrollView; } - (HomeRecentCourseView *)courseView { if (!_courseView) { _courseView = [HomeRecentCourseView shareInstance]; MJWeakSelf; [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) { [weakSelf joinRoomAction:type courseMessage:courseModel]; }]; } return _courseView; } - (void)joinRoomAction:(RECENTCOURSE_TYPE)type courseMessage:(RecentCourseModel *)courseModel { if (type == RECENTCOURSE_TYPE_ACCOMPANY) { AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init]; detailVC.courseId = courseModel.courseId; detailVC.courseGroupId = courseModel.courseGroupId; detailVC.teacherId = courseModel.teacherId; [self.navigationController pushViewController:detailVC animated:YES]; } else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课 MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init]; detailVC.courseId = courseModel.courseId; detailVC.courseGroupId = courseModel.courseGroupId; detailVC.teacherId = courseModel.teacherId; [self.navigationController pushViewController:detailVC animated:YES]; } else { KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST,courseModel.courseGroupId,courseModel.courseId]; ctrl.url = url; [self.navigationController pushViewController:ctrl animated:YES]; } } #pragma mark ----- 专辑 - (HomeHotAlbumView *)albumView { if (!_albumView) { _albumView = [HomeHotAlbumView shareInstance]; MJWeakSelf; [_albumView homeAlbumMore:^{ [weakSelf moreAlbumDetail]; }]; [_albumView.albumContentView addSubview:self.albumCollectionView]; [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView); }]; } return _albumView; } - (UICollectionView *)albumCollectionView { if (!_albumCollectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _albumCollectionView.backgroundColor = [UIColor clearColor]; _albumCollectionView.delegate = self; _albumCollectionView.dataSource = self; _albumCollectionView.showsVerticalScrollIndicator = NO; _albumCollectionView.showsHorizontalScrollIndicator = NO; if (@available(iOS 11.0, *)) { _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions if (@available(iOS 13.0, *)) { _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO; } else { // Fallback on earlier versions } } [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"]; } return _albumCollectionView; } - (void)moreAlbumDetail { KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"]; [self.navigationController pushViewController:ctrl animated:YES]; } #pragma mark ---- 热门曲目 - (HomeHotMusicView *)hotMusicView { if (!_hotMusicView) { _hotMusicView = [HomeHotMusicView shareInstance]; MJWeakSelf; [_hotMusicView homeMusicMore:^{ [weakSelf moreHotMusic]; }]; [_hotMusicView.musicContentView addSubview:self.musicCollectionView]; [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView); }]; } return _hotMusicView; } - (void)moreHotMusic { KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"]; [self.navigationController pushViewController:ctrl animated:YES]; } - (UICollectionView *)musicCollectionView { if (!_musicCollectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _musicCollectionView.backgroundColor = [UIColor clearColor]; _musicCollectionView.delegate = self; _musicCollectionView.dataSource = self; _musicCollectionView.showsVerticalScrollIndicator = NO; _musicCollectionView.showsHorizontalScrollIndicator = NO; if (@available(iOS 11.0, *)) { _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions if (@available(iOS 13.0, *)) { _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO; } else { // Fallback on earlier versions } } [_musicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"]; } return _musicCollectionView; } #pragma mark ---- talent view - (HomeHotTalentView *)talentView { if (!_talentView) { _talentView = [HomeHotTalentView shareInstance]; [_talentView.talentContentView addSubview:self.talentCollectionView]; MJWeakSelf; [_talentView homeTalentMore:^{ [weakSelf teacherMoreIntorduce]; }]; [self.talentCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.top.mas_equalTo(_talentView.talentContentView); }]; } return _talentView; } - (void)teacherMoreIntorduce { KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherElegant"]; [self.navigationController pushViewController:ctrl animated:YES]; } - (UICollectionView *)talentCollectionView { if (!_talentCollectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _talentCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _talentCollectionView.backgroundColor = [UIColor clearColor]; _talentCollectionView.delegate = self; _talentCollectionView.dataSource = self; _talentCollectionView.showsVerticalScrollIndicator = NO; _talentCollectionView.showsHorizontalScrollIndicator = NO; if (@available(iOS 11.0, *)) { _talentCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions if (@available(iOS 13.0, *)) { _talentCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO; } else { // Fallback on earlier versions } } [_talentCollectionView registerNib:[UINib nibWithNibName:@"HomeHotTalentCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotTalentCell"]; } return _talentCollectionView; } #pragma mark ----- video course - (HomeHotVideoCourseView *)videoCourseView { if (!_videoCourseView) { _videoCourseView = [HomeHotVideoCourseView shareInstance]; MJWeakSelf; [_videoCourseView homeVideoMore:^{ [weakSelf toVideoMorePage]; }]; [_videoCourseView.videoContentView addSubview:self.videoCollectionView]; [self.videoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.top.mas_equalTo(_videoCourseView.videoContentView); }]; } return _videoCourseView; } - (UICollectionView *)videoCollectionView { if (!_videoCollectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _videoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _videoCollectionView.backgroundColor = [UIColor clearColor]; _videoCollectionView.delegate = self; _videoCollectionView.dataSource = self; _videoCollectionView.showsVerticalScrollIndicator = NO; _videoCollectionView.showsHorizontalScrollIndicator = NO; if (@available(iOS 11.0, *)) { _videoCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions if (@available(iOS 13.0, *)) { _videoCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO; } else { // Fallback on earlier versions } } [_videoCollectionView registerNib:[UINib nibWithNibName:@"HomeHotVideoCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotVideoCell"]; } return _videoCollectionView; } - (void)toVideoMorePage { KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"]; [self.navigationController pushViewController:ctrl animated:YES]; } #pragma mark ----- live course - (HomeHotLiveCourseView *)liveCourseView { if (!_liveCourseView) { _liveCourseView = [HomeHotLiveCourseView shareInstance]; MJWeakSelf; [_liveCourseView homeLiveMore:^{ [weakSelf toLiveMorePage]; }]; [_liveCourseView.liveContentView addSubview:self.liveCollectionView]; [self.liveCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.top.mas_equalTo(_liveCourseView.liveContentView); }]; } return _liveCourseView; } - (UICollectionView *)liveCollectionView { if (!_liveCollectionView) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14); layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _liveCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; _liveCollectionView.backgroundColor = [UIColor clearColor]; _liveCollectionView.delegate = self; _liveCollectionView.dataSource = self; _liveCollectionView.showsVerticalScrollIndicator = NO; _liveCollectionView.showsHorizontalScrollIndicator = NO; if (@available(iOS 11.0, *)) { _liveCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } else { // Fallback on earlier versions if (@available(iOS 13.0, *)) { _liveCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO; } else { // Fallback on earlier versions } } [_liveCollectionView registerNib:[UINib nibWithNibName:@"HomeHotLiveCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotLiveCell"]; } return _liveCollectionView; } // 更多直播课 - (void)toLiveMorePage { KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init]; ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"]; [self.navigationController pushViewController:ctrl animated:YES]; } - (NSMutableArray *)informationArray { if (!_informationArray) { _informationArray = [NSMutableArray array]; } return _informationArray; } - (NSMutableArray *)teacherArray { if (!_teacherArray) { _teacherArray = [NSMutableArray array]; } return _teacherArray; } - (NSMutableArray *)liveListArray { if (!_liveListArray) { _liveListArray = [NSMutableArray array]; } return _liveListArray; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end