1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390 |
- //
- // HomeViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "HomeViewController.h"
- #import "HomeBodyView.h"
- #import "HomeNavView.h"
- #import "KSBaseWKWebViewController.h"
- #import "MyMusicViewController.h"
- #import "MyCourseViewController.h"
- #import "HomeworkListViewController.h"
- #import "EvaluateCourseListViewController.h"
- #import "NotiferMessageViewController.h"
- #import "UserInfoManager.h"
- #import "TeacherInfo.h"
- #import "MyIncomeViewController.h"
- #import "ReceiveEvaluateListController.h"
- #import "PublicNoticeView.h"
- #import "SDCycleScrollView.h"
- #import "NoticeSourceModel.h"
- #import "HomeRecentCourseView.h"
- #import "AccompanyDetailViewController.h"
- #import "RecentCourseModel.h"
- #import "AppDelegate.h"
- #import "MusicRoomViewController.h"
- #import "KSScanViewController.h"
- #import "KSPremissionAlert.h"
- #import "RecordCheckManager.h"
- #import "UserSettingViewController.h"
- #import "HomeMessageModel.h"
- #import "HomeButtonView.h"
- #import "KSHomeButton.h"
- #import "HomeNewHeadView.h"
- #import "HomeAlbumView.h"
- #import "HomeAlbumModel.h"
- #import "HomeHotAlbumCell.h"
- #import "HomeHotMusicModel.h"
- #import "HomeQualityMusic.h"
- #import "HomeQualityMusicCollectionCell.h"
- #import "KSPremissionAlert.h"
- #import "RecordCheckManager.h"
- #import "KSAccompanyWebViewController.h"
- #import "HomeHotMusicView.h"
- #import "HomeHotMusicCollectionCell.h"
- #import "HomeBannerView.h"
- #import <UIButton+WebCache.h>
- #import "TYCyclePagerView.h"
- #import "TYPageControl.h"
- #import "HomeBannerCell.h"
- #import "BadgeIntroduceView.h"
- #import "HomeAuthAlertView.h"
- #define BUTTONWIDTH (65)
- #define BUTTONHEIGHT (70)
- @interface HomeViewController ()<SDCycleScrollViewDelegate,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
- @property (nonatomic, strong) HomeNavView *navView;
- @property (nonatomic, strong) HomeNewHeadView *headView;
- @property (nonatomic, strong) HomeBodyView *bodyView;
- @property (nonatomic, strong) TeacherInfo *mineInfo;
- @property (nonatomic, strong) PublicNoticeView *noticeView;
- @property (nonatomic, strong) SDCycleScrollView *noticeScrollView;
- @property (nonatomic, strong) NSMutableArray *noticeArray; // 公告数据
- @property (nonatomic, strong) NSMutableArray *titleArray; // 标题数组
- @property (nonatomic, strong) HomeBannerView *bannerView; // banner
- @property (nonatomic, strong) NSMutableArray *bannerArray; //
- @property (nonatomic, strong) TYPageControl *pageControl;
- @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
- @property (nonatomic, strong) HomeRecentCourseView *courseView;
- @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, assign) BOOL isFirstLoad;
- @property (nonatomic, strong) HomeAlbumView *albumView;
- @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
- @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
- @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
- // 精品曲谱
- @property (nonatomic, strong) HomeQualityMusic *qualityMusicView;
- @property (nonatomic, strong) UICollectionView *qualityMusicCollectionView; // 精品曲谱容器
- @property (nonatomic, strong) NSMutableArray *qualityMusicArray; // 精品曲谱数据
- @property (nonatomic, assign) CGFloat qualityMusicViewHeight; // 精品music高度
- @property (nonatomic, strong) dispatch_group_t requestGroup;
- @property (nonatomic, strong) RecentCourseModel *recentCourseModel;
- // 热门曲目
- @property (nonatomic, strong) HomeHotMusicView *hotMusicView;
- @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
- @property (nonatomic, assign) CGFloat hotMusicHeight; // music 高度
- @property (nonatomic, strong) BadgeIntroduceView *intruduceAlert;
- @property (nonatomic, strong) HomeAuthAlertView *authAlertView;
- @end
- @implementation HomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- self.isFirstLoad = YES;
- [self configUI];
- }
- - (void)requestUserInfo {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager queryTeacherInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- self.mineInfo = [[TeacherInfo alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
- NSString *rongToken = UserDefault(RongTokenKey);
- if ([NSString isEmptyString:rongToken]) {
- [USER_MANAGER queryUserInfoConnectRongCloud:YES];
- }
- }
- 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.titleArray addObject:bannerModel.title];
- }
- else {
- self.noticeArray = [NSMutableArray array];
- self.titleArray = [NSMutableArray array];
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestRecentCourse {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager queryRecentLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSDictionary *parm = [[dic dictionaryValueForKey:@"data"] 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)refreshCourseView:(RecentCourseModel *)model {
- if (model) {
- [self.courseView configCourseMessage:model];
- self.courseView.hidden = NO;
- }
- else {
- self.courseView.hidden = YES;
- }
- }
- - (void)refreshNotice {
- if (self.titleArray.count) {
- self.noticeView.hidden = NO;
- }
- else {
- self.noticeView.hidden = YES;
- }
- self.noticeScrollView.titlesGroup = self.titleArray;
- }
- - (void)refreshView {
- [self.navView configMessage:self.mineInfo];
- [self.headView configMessage:self.mineInfo];
- [self refreshBannerView];
- [self refreshButtonView];
- [self refreshNotice];
- [self refreshCourseView:self.recentCourseModel];
- [self refreshAlbumView];
- [self refreshQualityView];
- [self refreshMusicView];
- // 刷新排序
- [self refreshViewLocation];
- }
- - (void)refreshBannerView {
- if (self.bannerArray.count) {
- self.bannerView.hidden = NO;
- CGFloat bannerViewHeight = [HomeBannerView getViewHeight];
- [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(bannerViewHeight);
- }];
- }
- else {
- self.bannerView.hidden = YES;
- [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- }
- if (self.bannerArray.count > 1) {
- self.bannerScroll.autoScrollInterval = 3.0f;
- [self.bannerScroll addSubview:self.pageControl];
- }
- else {
- self.bannerScroll.autoScrollInterval = 0;
- [self.pageControl removeFromSuperview];
- }
- self.pageControl.numberOfPages = self.bannerArray.count;
- [self.bannerScroll reloadData];
- }
- - (void)refreshViewLocation {
- // 如果有课程和公告 且有按钮
-
- CGFloat buttonViewDefaultHeight = self.buttonArray.count > 4 ? [HomeButtonView getViewHeight] : [HomeButtonView getViewHeight] - 20;
-
- if (self.titleArray.count && self.recentCourseModel && self.buttonArray.count) {
- [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.bannerView.mas_bottom);
- make.height.mas_equalTo(56.0f);
- }];
-
- [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.noticeView.mas_bottom);
- make.height.mas_equalTo(buttonViewDefaultHeight);
- }];
- [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.buttonContainer.mas_bottom);
- make.height.mas_equalTo(91.0f);
- }];
- }
- else {
- CGFloat buttonViewHeight = self.buttonArray.count ? buttonViewDefaultHeight : CGFLOAT_MIN;
- [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.bannerView.mas_bottom);
- make.height.mas_equalTo(buttonViewHeight);
- }];
- CGFloat noticeHeight = self.titleArray.count ? [self.noticeView getViewHeight] : CGFLOAT_MIN;
- [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.buttonContainer.mas_bottom);
- make.height.mas_equalTo(noticeHeight);
- }];
- CGFloat courseViewHeight = self.recentCourseModel ? 90.0f : CGFLOAT_MIN;
- [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.noticeView.mas_bottom);
- make.height.mas_equalTo(courseViewHeight);
- }];
-
- }
- }
- - (void)requestHomeButton {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeButtonList: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];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshButtonView {
- CGFloat containerWidth = (KPortraitWidth - 28);
-
- if (self.buttonArray.count) {
-
- self.buttonContainer.hidden = NO;
- // 添加按钮
- if (self.buttonArray.count > 4) { // 大于4个显示底部滚动视图
- self.buttonContainer.buttonPageCtrl.hidden = NO;
- self.buttonContainer.buttonDotLeft.constant = 0;
- NSInteger addPage = (self.buttonArray.count % 4) > 0 ? 1 : 0;
- NSInteger pageCount = self.buttonArray.count / 4 + addPage;
- self.buttonDotWidth = 36 / pageCount;
- self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
- self.buttonScrollView.contentSize = CGSizeMake(containerWidth * pageCount, BUTTONHEIGHT);
- }
- else {
- self.buttonContainer.buttonPageCtrl.hidden = YES;
- self.buttonScrollView.contentSize = CGSizeMake(containerWidth, BUTTONHEIGHT);
- }
- }
- else {
- self.buttonContainer.hidden = YES;
- self.buttonContainer.buttonPageCtrl.hidden = YES;
- self.buttonScrollView.contentSize = CGSizeMake(containerWidth, CGFLOAT_MIN);
- }
-
-
- self.buttonScrollView.contentOffset = CGPointMake(0, 0);
- [self.buttonScrollView removeAllSubViews];
- CGFloat leftSpace = 10.0f;
- CGFloat buttonSpace = (containerWidth - 4 * BUTTONWIDTH - leftSpace * 2) / 3;
-
- 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(leftSpace + (i % 4) * (BUTTONWIDTH + buttonSpace) + (i / 4) * containerWidth, 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)requestAlbumSource {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager HomeHotAlbumRequest: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 *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)refreshAlbumView {
- if (self.albumArray.count) {
- self.albumViewHeight = [HomeAlbumView 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)requestQualityMusic {
- [KSNetworkingManager homeQualityMusicListRequest: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.qualityMusicArray = [NSMutableArray arrayWithArray:musicArray];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestHotMusicList {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeMusicListRequest:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
-
- 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.dataArray = [NSMutableArray arrayWithArray:musicArray];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self requestQualityMusic];
- } faliure:^(NSError * _Nonnull error) {
- [self requestQualityMusic];
- }];
- }
- - (void)refreshQualityView {
- if (self.qualityMusicArray.count) {
- self.qualityMusicViewHeight = [HomeQualityMusic getViewHeight];
- self.qualityMusicView.hidden = NO;
- }
- else {
- self.qualityMusicViewHeight = CGFLOAT_MIN;
- self.qualityMusicView.hidden = YES;
- }
- [self.qualityMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.qualityMusicViewHeight);
- }];
- [self.qualityMusicCollectionView reloadData];
- }
- - (void)refreshMusicView {
- if (self.dataArray.count) {
- self.hotMusicHeight = [HomeHotMusicView getViewHeight];
- self.hotMusicView.hidden = NO;
- }
- else {
- self.hotMusicHeight = CGFLOAT_MIN;
- self.hotMusicView.hidden = YES;
- }
- [self.hotMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.hotMusicHeight);
- }];
- [self.musicCollectionView reloadData];
- }
- - (void)configUI {
- CGFloat navHeight = IS_iPhoneX ? 100 : 70;
- [self.view addSubview:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(kScreenWidth);
- make.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(navHeight);
- }];
- [self.view bringSubviewToFront:self.navView];
-
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.navView.mas_bottom);
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }];
- self.scrollView.backgroundColor = [UIColor clearColor];
- MJWeakSelf;
- self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- }];
-
- // header
- [self.scrollView addSubview:self.headView];
- CGFloat headHeight = [self.headView getViewHeight];
- [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.height.mas_equalTo(headHeight);
- }];
-
- [self.scrollView addSubview:self.bannerView];
-
- [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.headView.mas_bottom);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
-
- // 按钮
- [self.scrollView addSubview:self.buttonContainer];
- [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.bannerView.mas_bottom);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- self.buttonContainer.hidden = YES;
-
- // 公告
- [self.scrollView addSubview:self.noticeView];
- [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- 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.scrollView addSubview:self.courseView];
- [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.noticeView.mas_bottom);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- self.courseView.hidden = YES;
-
- [self.scrollView addSubview:self.albumView];
- self.albumViewHeight = [HomeAlbumView getViewHeight];
- [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.courseView.mas_bottom);
- make.height.mas_equalTo(self.albumViewHeight);
- }];
-
- [self.scrollView addSubview:self.qualityMusicView];
- self.qualityMusicViewHeight = [HomeQualityMusic getViewHeight];
- [self.qualityMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.albumView.mas_bottom);
- make.height.mas_equalTo(self.qualityMusicViewHeight);
- }];
-
- [self.scrollView addSubview:self.hotMusicView];
- CGFloat musicHeadHeight = [HomeHotMusicView getViewHeight];
- [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.qualityMusicView.mas_bottom);
- make.height.mas_equalTo(musicHeadHeight);
- make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
- }];
- }
- - (void)requestData {
- [self showhud];
- [self requestUserInfo];
- [self requestUserMemo];
- [self requestUnreadCount];
- [self requestHomeButton];
- [self requestRecentCourse];
- [self requestNotice];
- [self requestAlbumSource];
- [self requestHotMusicList];
-
- dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
- [self removehub];
- [self.scrollView.mj_header endRefreshing];
- [self refreshView];
- });
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (self.isFirstLoad == YES) {
- self.isFirstLoad = NO;
- [self requestTrackAuth];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate handleNotiferSource];
- }
-
- [self requestData];
- }
- // track
- - (void)requestTrackAuth {
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate appTrackActionAuth];
- }
- - (void)requestUserMemo {
- [[UserInfoManager shareInstance] requsetconfigCallback:^(BOOL success) {
- [self refreshBodyView:success];
- }];
- }
- - (void)refreshBodyView:(BOOL)isMemo {
- self.bodyView.isMemo = isMemo;
- CGFloat contentMinHeight = [_bodyView getViewHeight];
- [self.bodyView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(contentMinHeight);
- }];
- }
- - (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) {
-
- }];
- }
- #pragma mark ----- SDCycleScrollViewDelegate
- - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
- NoticeSourceModel *bannerModel = self.noticeArray[index];
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
-
- }
- #pragma mark ----- lazying
- - (HomeNavView *)navView {
- if (!_navView) {
- _navView = [HomeNavView shareInstance];
- MJWeakSelf;
- [_navView displayMessageCenter:^(HOMENAV_ACTION action) {
- if (action == HOMENAV_ACTION_MESSAGE) {
- [weakSelf toMessageCenter];
- }
- else {
- [weakSelf scanAction];
- }
- }];
- }
- return _navView;
- }
- - (void)scanAction {
- // 判断是否有权限
- 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];
- }
- }
- }
- - (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)toMessageCenter {
- NotiferMessageViewController *messageCenter = [[NotiferMessageViewController alloc] init];
- [self.navigationController pushViewController:messageCenter animated:YES];
- }
- - (HomeNewHeadView *)headView {
- if (!_headView) {
- _headView = [HomeNewHeadView shareInstance];
- MJWeakSelf;
- [_headView authDetailAction:^(HOMEHEADACTION action) {
- [weakSelf headAction:action];
- }];
- }
- return _headView;
- }
- - (void)headAction:(HOMEHEADACTION)type {
- switch (type) {
- case HOMEHEADACTION_DESC:
- {
- [self showDescAlert];
- }
- break;
- case HOMEHEADACTION_AUTH:
- {
- [self toAuthDetail];
- }
- break;
- case HOMEHEADACTION_EDUCATION:
- case HOMEHEADACTION_EDUCATIONFINISH:
- {
- [self showAuthEducationAlert];
- }
- break;
- default:
- break;
- }
- }
- - (void)toAuthEducation {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCertUpdate"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- - (void)showAuthEducationAlert {
- BOOL hasDegreeAuth = self.mineInfo.degreeFlag;
- BOOL hasTeacherAuth = self.mineInfo.teacherFlag;
-
- self.authAlertView = [HomeAuthAlertView shareIntance];
- if (hasDegreeAuth) {
- [self.authAlertView.educationImage setImage:[UIImage imageNamed:@"choose_instrument"]];
- [self.authAlertView.educationStatus setText:@"已认证"];
- [self.authAlertView.educationStatus setTextColor:HexRGB(0x999999)];
- }
- else {
- [self.authAlertView.educationImage setImage:[UIImage imageNamed:@""]];
- [self.authAlertView.educationStatus setText:@"未认证"];
- [self.authAlertView.educationStatus setTextColor:HexRGB(0xff0000)];
- }
-
- if (hasTeacherAuth) {
- [self.authAlertView.qualificationImage setImage:[UIImage imageNamed:@"choose_instrument"]];
- [self.authAlertView.qualificationStatus setText:@"已认证"];
- [self.authAlertView.qualificationStatus setTextColor:HexRGB(0x999999)];
- }
- else {
- [self.authAlertView.qualificationImage setImage:[UIImage imageNamed:@""]];
- [self.authAlertView.qualificationStatus setText:@"未认证"];
- [self.authAlertView.qualificationStatus setTextColor:HexRGB(0xff0000)];
- }
- if (hasDegreeAuth && hasTeacherAuth) {
- self.authAlertView.isFinish = YES;
- self.authAlertView.rate = 1.0f;
- }
- else {
- self.authAlertView.isFinish = NO;
- if (hasDegreeAuth || hasTeacherAuth) {
- self.authAlertView.rate = 0.9f;
- }
- else {
- self.authAlertView.rate = 0.8f;
- }
- }
- MJWeakSelf;
- [self.authAlertView authEducationAction:^{
- [weakSelf toAuthEducation];
- }];
- [self.authAlertView showAlertView];
-
- }
- - (BadgeIntroduceView *)intruduceAlert {
- if (!_intruduceAlert) {
- _intruduceAlert = [BadgeIntroduceView shareInstance];
- _intruduceAlert.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
- }
- return _intruduceAlert;
- }
- - (void)showDescAlert {
- [self.intruduceAlert showAlertInView:[NSObject getKeyWindow]];
- }
- - (void)toUserCenter {
- UserSettingViewController *ctrl = [[UserSettingViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)toAuthDetail {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- - (PublicNoticeView *)noticeView {
- if (!_noticeView) {
- _noticeView = [PublicNoticeView shareInstance];
- MJWeakSelf;
- [_noticeView moreCallback:^{
- [weakSelf moreNotice];
- }];
- }
- return _noticeView;
- }
- #pragma mark -- lazying
- - (dispatch_group_t)requestGroup {
- if (!_requestGroup) {
- _requestGroup = dispatch_group_create();
- }
- return _requestGroup;
- }
- - (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 whiteColor];
- _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14];
- _noticeScrollView.titlesGroup = self.titleArray;
- }
- return _noticeScrollView;
- }
- - (NSMutableArray *)noticeArray {
- if (!_noticeArray) {
- _noticeArray = [NSMutableArray array];
- }
- return _noticeArray;
- }
- - (NSMutableArray *)titleArray {
- if (!_titleArray) {
- _titleArray = [NSMutableArray array];
- }
- return _titleArray;
- }
- - (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];
- }
- }
- - (HomeRecentCourseView *)courseView {
- if (!_courseView) {
- _courseView = [HomeRecentCourseView shareInstance];
- MJWeakSelf;
- [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) {
- [weakSelf joinRoomAction:type roomId:courseModel];
- }];
- }
- return _courseView;
- }
- - (void)joinRoomAction:(RECENTCOURSE_TYPE)type roomId:(RecentCourseModel *)courseModel {
- if (type == RECENTCOURSE_TYPE_ACCOMPANY) {
- AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- detailVC.studentId = courseModel.studentId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课
- MusicRoomViewController *ctrl = [[MusicRoomViewController alloc] init];
- ctrl.courseId = courseModel.courseId;
- ctrl.courseGroupId = courseModel.courseGroupId;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST, courseModel.courseGroupId,courseModel.courseId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (HomeBodyView *)bodyView {
- if (!_bodyView) {
- _bodyView = [HomeBodyView shareInstance];
- MJWeakSelf;
- [_bodyView homebodyViewAction:^(HOMEBODYACTION action) {
- [weakSelf bodyViewOperation:action];
- }];
- }
- return _bodyView;
- }
- - (void)bodyViewOperation:(HOMEBODYACTION)action {
- switch (action) {
- case HOMEBODYACTION_COURSE: // 我的课程
- {
- MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case HOMEBODYACTION_HOMEWORK: // 课后作业
- {
- HomeworkListViewController *ctrl = [[HomeworkListViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case HOMEBODYACTION_EVALUATE: // 待评价列表
- {
- EvaluateCourseListViewController *ctrl = [[EvaluateCourseListViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case HOMEBODYACTION_MUSIC: // 我的曲谱
- {
- MyMusicViewController *musicCtrl = [[MyMusicViewController alloc] init];
- [self.navigationController pushViewController:musicCtrl animated:YES];
- }
- break;
- case HOMEBODYACTION_RECEIVE: // 我收到的评价
- {
- ReceiveEvaluateListController *ctrl = [[ReceiveEvaluateListController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case HOMEBODYACTION_INCOME: // 我的收入
- {
- MyIncomeViewController *incomeCtrl = [[MyIncomeViewController alloc] init];
- [self.navigationController pushViewController:incomeCtrl animated:YES];
- }
- break;
- case HOMEBODYACTION_MUSICROOM: // 琴房
- {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/pianoRoom"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- default:
- break;
- }
- }
- - (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];
- }
- }
- }
- #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 - 28), BUTTONHEIGHT)];
- _buttonScrollView.backgroundColor = [UIColor clearColor];
- _buttonScrollView.pagingEnabled = YES;
- _buttonScrollView.showsHorizontalScrollIndicator = NO;
- _buttonScrollView.showsVerticalScrollIndicator = NO;
- _buttonScrollView.delegate = self;
- }
- return _buttonScrollView;
- }
- #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.qualityMusicCollectionView) { // 精品曲目
- NSInteger lastRowCount = (self.qualityMusicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.qualityMusicArray.count / 4 + lastRowCount;
- return count;
- }
- else {
- NSInteger lastRowCount = (self.dataArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.dataArray.count / 4 + lastRowCount;
- return 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.qualityMusicCollectionView) {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 4 + 4 > self.qualityMusicArray.count ? self.qualityMusicArray.count - indexPath.item * 4: 4;
- NSRange range = NSMakeRange(indexPath.item * 4, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.qualityMusicArray subarrayWithRange:range]];
- HomeQualityMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeQualityMusicCollectionCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- else {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 4 + 4 > self.dataArray.count ? self.dataArray.count - indexPath.item * 4: 4;
- NSRange range = NSMakeRange(indexPath.item * 4, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.dataArray subarrayWithRange:range]];
- HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- }
- - (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];
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- return CGSizeMake(100, 140);
- }
- else if (collectionView == self.qualityMusicCollectionView) {
- return CGSizeMake(KPortraitWidth * 0.83, 320);
- }
- else {
- return CGSizeMake(KPortraitWidth * 0.83, 320);
- }
- }
- #pragma mark ----- 专辑
- - (HomeAlbumView *)albumView {
- if (!_albumView) {
- _albumView = [HomeAlbumView 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, 11, 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;
- }
- - (NSMutableArray *)albumArray {
- if (!_albumArray) {
- _albumArray = [NSMutableArray array];
- }
- return _albumArray;
- }
- - (void)moreAlbumDetail {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ----- 精品曲目
- - (HomeQualityMusic *)qualityMusicView {
- if (!_qualityMusicView) {
- _qualityMusicView = [HomeQualityMusic shareInstance];
- MJWeakSelf;
- [_qualityMusicView homeMusicMore:^{
- [weakSelf moreHotMusic:YES];
- }];
- [_qualityMusicView.musicContentView addSubview:self.qualityMusicCollectionView];
- [self.qualityMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_qualityMusicView.musicContentView);
- }];
- }
- return _qualityMusicView;
- }
- - (UICollectionView *)qualityMusicCollectionView {
- if (!_qualityMusicCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _qualityMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _qualityMusicCollectionView.backgroundColor = [UIColor clearColor];
- _qualityMusicCollectionView.delegate = self;
- _qualityMusicCollectionView.dataSource = self;
- _qualityMusicCollectionView.showsVerticalScrollIndicator = NO;
- _qualityMusicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _qualityMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _qualityMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_qualityMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeQualityMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeQualityMusicCollectionCell"];
- }
- return _qualityMusicCollectionView;
- }
- #pragma mark ---- 更多曲目
- - (HomeHotMusicView *)hotMusicView {
- if (!_hotMusicView) {
- _hotMusicView = [HomeHotMusicView shareInstance];
- MJWeakSelf;
- [_hotMusicView homeMusicMore:^{
- [weakSelf moreHotMusic:NO];
- }];
- [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
- [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
- }];
- }
- return _hotMusicView;
- }
- - (void)moreHotMusic:(BOOL)isQuality {
- NSString *type = isQuality ? @"?type=fine" : @"?type=list";
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-list",type];
- [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;
- }
- - (HomeBannerView *)bannerView {
- if (!_bannerView) {
- _bannerView = [HomeBannerView shareInstance];
- [_bannerView.bannerContentView addSubview:self.bannerScroll];
- }
- return _bannerView;
- }
- - (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 - 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 - 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
|