123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602 |
- //
- // HomeViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "HomeViewController.h"
- #import "HomeNavView.h"
- #import "KSBaseWKWebViewController.h"
- #import "MyMusicViewController.h"
- #import "HomeworkListViewController.h"
- #import "EvaluateCourseListViewController.h"
- #import "NotiferMessageViewController.h"
- #import "UserInfoManager.h"
- #import "MyIncomeViewController.h"
- #import "ReceiveEvaluateListController.h"
- #import "PublicNoticeView.h"
- #import <SDCycleScrollView.h>
- #import "NoticeSourceModel.h"
- #import "HomeRecentCourseView.h"
- #import "AccompanyDetailViewController.h"
- #import "VipCouseDetailViewController.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 "HomeHotMusicView.h"
- #import "HomeHotMusicCollectionCell.h"
- #import "HomeBannerView.h"
- #import <UIButton+WebCache.h>
- #import "TYCyclePagerView.h"
- #import "TYPageControl.h"
- #import "HomeBannerCell.h"
- #import "HomeAuthAlertView.h"
- #import "KSAwardAlertView.h"
- #import "HomeNewMusicView.h"
- #import "HomeRecommendMusicView.h"
- #import "HomeMusicModel.h"
- #import "HomeDragButton.h"
- #import "ToneTuningViewController.h"
- #import "InstrumentChooseViewController.h"
- #import "HomeTenantView.h"
- #import "HomeTenantPageView.h"
- #import "HomeMusicSheetLayout.h"
- #import "MinePageViewController.h"
- #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
- #define COLLECTION_HEIGHT (320)
- @interface HomeViewController ()<SDCycleScrollViewDelegate,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
- @property (nonatomic, strong) HomeNavView *navView;
- @property (nonatomic, strong) HomeNewHeadView *headView;
- @property (nonatomic, strong) UIView *headBgView;
- @property (nonatomic, strong) UserInfo *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) NSMutableArray *buttonArray; // button 内容
- @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) 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) HomeRecommendMusicView *recommendMusicView;
- @property (nonatomic, strong) UICollectionView *recommendMusicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *recommendMusicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat recommendMusicViewHeight; // music 高度
- // 最新曲目
- @property (nonatomic, strong) HomeNewMusicView *newestMusicView;
- @property (nonatomic, strong) UICollectionView *newestMusicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *newestMusicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat newestMusicViewHeight; // music 高度
- @property (nonatomic, strong) HomeAuthAlertView *authAlertView;
- @property (nonatomic, assign) BOOL isCheck;
- @property (nonatomic, strong) HomeMessageModel *buttonModel;
- @property (nonatomic, strong) HomeDragButton *suspendButton;
- @property (nonatomic, assign) BOOL isSettingSubject;
- // 机构名称
- @property (nonatomic, strong) HomeTenantView *tenantNameView;
- @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 {
- [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
- self.mineInfo = userInfo;
- [self requestData];
- }];
- }
- - (void)requestAwardMessage {
- self.isCheck = NO;
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager checkReceiveRewardRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- BOOL isCheck = [[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"check"];
- self.isCheck = isCheck;
- }
- } 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 ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_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 {
- [LOADING_MANAGER MBShowAUTOHidingInWindow: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 ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *parm = [[dic ks_dictionaryValueForKey:@"data"] ks_dictionaryValueForKey:@"recentCourses"];
- if (parm == nil) {
- self.recentCourseModel = nil;
- }
- else {
- self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshCourseView:(RecentCourseModel *)model {
- if (model) {
- [self.courseView configCourseMessage:model];
- self.courseView.hidden = NO;
- CGFloat height = [HomeRecentCourseView getViewHeight];
- [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(height);
- }];
- }
- else {
- self.courseView.hidden = YES;
- [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- }
- }
- - (void)refreshNotice {
- if (self.titleArray.count) {
- self.noticeView.hidden = NO;
- CGFloat height = [PublicNoticeView getViewHeight];
- [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(height);
- }];
- }
- else {
- self.noticeView.hidden = YES;
- [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- }
- self.noticeScrollView.titlesGroup = self.titleArray;
- }
- - (void)refreshView {
- [self.navView configMessage:self.mineInfo];
- [self.headView configMessage:self.mineInfo];
- [self refreshTenantNameView];
- [self refreshBannerView];
- [self refreshNotice];
- [self refreshButtonView];
- [self refreshCourseView:self.recentCourseModel];
- [self refreshAlbumView];
- [self refreshMusicView];
- // 刷新排序
- if (self.isCheck) {
- [self checkShowAwardAlert];
- }
-
- // 悬浮按钮
- if (self.buttonModel) {
- [self showFloatingWindow];
- }
- else {
- [self removeFloatWindow];
- }
- }
- - (void)refreshTenantNameView {
- CGFloat tenantNameHeight = CGFLOAT_MIN;
- if (self.mineInfo.tenantId > 0) {
- tenantNameHeight = [HomeTenantView getViewHeight];
- self.tenantNameView.hidden = NO;
- }
- else {
- self.tenantNameView.hidden = YES;
- }
- [self.tenantNameView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(tenantNameHeight);
- }];
- [self.tenantNameView configTenantName:self.mineInfo.tenantName];
- }
- - (void)removeFloatWindow {
- if ([self.view.subviews containsObject:self.suspendButton]) {
- [self.suspendButton removeFromSuperview];
- }
- }
- // 显示悬浮窗
- - (void)showFloatingWindow {
- if (![self.view.subviews containsObject:self.suspendButton]) {
- [self.view addSubview:self.suspendButton];
- }
- [self.view bringSubviewToFront:self.suspendButton];
- [self.suspendButton.containerView sd_setImageWithURL:[NSURL URLWithString:[self.buttonModel.coverImage getUrlEndcodeString]]];
- }
- - (void)checkShowAwardAlert {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (appDelegate.isShowMemoAlert) {
- return;
- }
- // 如果今日已提示过,就不再提醒
- NSDictionary *awardAlertDic = UserDefaultObjectForKey(@"awardAlertTime");
- NSString *awardAlertTime = [awardAlertDic ks_stringValueForKey:@"time"];
- NSDate *currendDate = [NSDate date];
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy-MM-dd"];
- NSString *todayString = [dateFormatter stringFromDate:currendDate];
-
- if (![NSString isEmptyString:awardAlertTime]) {
-
- NSString *userId = [awardAlertDic ks_stringValueForKey:@"userId"];
- if ([todayString isEqualToString:awardAlertTime] && [userId isEqualToString:UserDefaultObjectForKey(UIDKey)]) {
- return;
- }
- }
-
- if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
- return;
- }
-
- KSAwardAlertView *alert = [KSAwardAlertView shareInstance];
- MJWeakSelf;
- [alert awardActionCallback:^(BOOL isSure) {
- if (isSure) {
- [weakSelf displayAwardList];
- }
- }];
-
- [alert showAlert];
- NSDictionary *saveDic = @{@"time" :todayString , @"userId" : UserDefaultObjectForKey(UIDKey)};
- UserDefaultSetObjectForKey(saveDic, @"awardAlertTime");
- }
- - (void)displayAwardList {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/awardActivity"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- - (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)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 ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- // banner
- NSArray *bannerArray = [result ks_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 ks_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];
-
- // 首页悬浮按钮
- NSArray *suspensionArray = [result ks_arrayValueForKey:@"suspension"];
- if (suspensionArray.count) {
- self.buttonModel = [[HomeMessageModel alloc] initWithDictionary:[suspensionArray firstObject]];
- }
- else {
- self.buttonModel = nil;
- }
-
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshButtonView {
- [self.buttonContainer.buttonContentView removeAllSubViews];
- // 添加机构专辑
- if (self.mineInfo.tenantAlbumStatus != 0 && [UserDefault(TENANT_ID) integerValue] > 0) {
- HomeMessageModel *buttonModel = [[HomeMessageModel alloc] init];
- buttonModel.title = @"机构教程";
- buttonModel.linkUrl = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/train-tool"];
- buttonModel.coverImage = @"tenantAlbum_button";
- buttonModel.isLocalButton = YES;
- [self.buttonArray addObject:buttonModel];
- }
- CGFloat buttonSpace = (KPortraitWidth - BUTTON_ROWCOUNT * HOME_BUTTONWIDTH) / (BUTTON_ROWCOUNT /*+ 1*/);
- // 添加按钮
- if (self.buttonArray.count) {
- self.buttonContainer.hidden = NO;
- CGFloat xSpace = 0.0f;
- CGFloat ySpace = 0.0f;
- for (NSInteger i = 0; i < self.buttonArray.count; i++) {
- xSpace = buttonSpace / 2 + (i % BUTTON_ROWCOUNT) * (HOME_BUTTONWIDTH + buttonSpace);
- ySpace = (i / BUTTON_ROWCOUNT) * (HOME_BUTTONHEIGHT + HOME_BUTTON_VERTICAL_SPACE);
- HomeMessageModel *model = self.buttonArray[i];
- KSHomeButton *buttonView = [KSHomeButton shareInstance];
- if (model.isLocalButton) {
- [buttonView.buttonImage setImage:[UIImage imageNamed:model.coverImage]];
- }
- else {
- [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
- }
-
- buttonView.buttonTitle.text = model.title;
- buttonView.frame = CGRectMake(xSpace, ySpace, HOME_BUTTONWIDTH, HOME_BUTTONHEIGHT);
- buttonView.actionButton.tag = 3000 + i;
- [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.buttonContainer.buttonContentView addSubview:buttonView];
- }
- }
- else {
- self.buttonContainer.hidden = YES;
- }
-
- // 高度
- CGFloat buttonViewDefaultHeight = [HomeButtonView getViewHeight:self.buttonArray.count];
- self.buttonViewHeight = buttonViewDefaultHeight;
- [self.buttonContainer mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(buttonViewDefaultHeight);
- }];
- }
- - (void)HomeTopButtonAction:(UIButton *)sender {
- NSInteger index = sender.tag - 3000;
- if ([self checkIsLoginToLoginView:YES]) {
- HomeMessageModel *model = self.buttonArray[index];
- if (![NSString isEmptyString:model.linkUrl]) {
- if ([model.linkUrl isEqualToString:@"native-metronome"]) {
- ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if ([model.linkUrl isEqualToString:@"native-homepage"]) {
- [self toMinePage];
- }
- else if ([model.linkUrl isEqualToString:@"native-homework"]) {
- HomeworkListViewController *ctrl = [[HomeworkListViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [model.linkUrl getUrlEndcodeString];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
-
- }
- }
- }
- - (void)toMinePage {
- if (![self.mineInfo.entryStatus isEqualToString:@"PASS"]) { // 跳转老师认证
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- else {
- MinePageViewController *pageCtrl = [[MinePageViewController alloc] init];
- [self.navigationController pushViewController:pageCtrl animated:YES];
- }
- }
- - (void)requestAlbumSource {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager HomeHotAlbumRequest:KS_POST version:[USER_MANAGER getCurrentVersion] subjectIds:[NSString stringWithFormat:@"%.0f",self.mineInfo.defaultSubject] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_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 {
- [LOADING_MANAGER MBShowAUTOHidingInWindow: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)requestHomeMusicMessage {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeAppMusicSheetRequest:KS_POST version:[USER_MANAGER getCurrentVersion] subjectIds:[NSString stringWithFormat:@"%.0f",self.mineInfo.defaultSubject] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- NSArray *hotMusicSheet = [result ks_arrayValueForKey:@"hotMusicSheet"]; // 热门曲目
- NSMutableArray *hotArray = [NSMutableArray array];
- for (NSDictionary *parm in hotMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [hotArray addObject:model];
- }
- self.dataArray = [NSMutableArray arrayWithArray:hotArray];
-
- NSArray *newMusicSheet = [result ks_arrayValueForKey:@"newMusicSheet"]; // 最新曲目
- NSMutableArray *newMusicArray = [NSMutableArray array];
- for (NSDictionary *parm in newMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [newMusicArray addObject:model];
- }
- self.newestMusicArray = [NSMutableArray arrayWithArray:newMusicArray];
-
- NSArray *topMusicSheet = [result ks_arrayValueForKey:@"topMusicSheet"]; // 推荐曲目
- NSMutableArray *topMusicArray = [NSMutableArray array];
- for (NSDictionary *parm in topMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [topMusicArray addObject:model];
- }
- self.recommendMusicArray = [NSMutableArray arrayWithArray:topMusicArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshMusicView {
-
- if (self.recommendMusicArray.count) {
- self.recommendMusicViewHeight = [HomeHotMusicView getViewHeight];
- self.recommendMusicView.hidden = NO;
- }
- else {
- self.recommendMusicViewHeight = CGFLOAT_MIN;
- self.recommendMusicView.hidden = YES;
- }
-
- [self.recommendMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.recommendMusicViewHeight);
- }];
- [self.recommendMusicCollectionView reloadData];
-
- if (self.newestMusicArray.count) {
- self.newestMusicViewHeight = [HomeHotMusicView getViewHeight];
- self.newestMusicView.hidden = NO;
- }
- else {
- self.newestMusicViewHeight = CGFLOAT_MIN;
- self.newestMusicView.hidden = YES;
- }
-
- [self.newestMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.newestMusicViewHeight);
- }];
- [self.newestMusicCollectionView reloadData];
-
- 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 = [HomeNavView getViewHeight];
- [self.view addSubview:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(navHeight);
- }];
- [self.view bringSubviewToFront:self.navView];
-
- // 名称
- [self.view addSubview:self.tenantNameView];
- CGFloat tenantNameHeight = CGFLOAT_MIN;
- [self.tenantNameView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.navView.mas_bottom);
- make.height.mas_equalTo(tenantNameHeight);
- }];
- self.tenantNameView.hidden = YES;
-
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.tenantNameView.mas_bottom);
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }];
- self.scrollView.backgroundColor = [UIColor clearColor];
- MJWeakSelf;
- self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestHomeMessage];
- }];
-
- // 背景
- [self.scrollView addSubview:self.headBgView];
-
-
- // 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.courseView];
- [self.courseView 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.courseView.hidden = YES;
- // banner
- [self.scrollView addSubview:self.bannerView];
- [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.courseView.mas_bottom);
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- self.bannerView.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.bannerView.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.buttonContainer];
- [self.buttonContainer 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.buttonContainer.hidden = YES;
-
- [self.headBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.headView);
- make.top.mas_equalTo(self.headView.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.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.headBgView.mas_bottom);
- make.height.mas_equalTo(self.albumViewHeight);
- }];
-
- [self.scrollView addSubview:self.recommendMusicView];
- CGFloat recommendMusicHeadHeight = [HomeRecommendMusicView getViewHeight];
- [self.recommendMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.albumView.mas_bottom);
- make.height.mas_equalTo(recommendMusicHeadHeight);
- }];
-
- [self.scrollView addSubview:self.newestMusicView];
- CGFloat newMusicHeight = [HomeNewMusicView getViewHeight];
- [self.newestMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.recommendMusicView.mas_bottom);
- make.height.mas_equalTo(newMusicHeight);
- }];
-
- [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.newestMusicView.mas_bottom);
- make.height.mas_equalTo(musicHeadHeight);
- make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
- }];
- }
- - (void)requestHomeMessage {
- [LOADING_MANAGER showHUD];
- [self requestUserInfo];
- }
- - (void)requestData {
- [self requestUnreadCount];
- [self requestHomeButton];
- [self requestRecentCourse];
- [self requestNotice];
- [self requestAlbumSource];
- [self requestHomeMusicMessage];
- [self requestAwardMessage];
-
- dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
- [LOADING_MANAGER removeHUD];
- [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];
- }
- if (self.isSettingSubject == NO) {
- [self requestHomeMessage];
- }
- self.isSettingSubject = NO;
- }
- // track
- - (void)requestTrackAuth {
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate appTrackActionAuth];
- }
- - (void)requestUnreadCount {
- [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *countArray = [dic ks_arrayValueForKey:@"data"];
- NSInteger courseCount = 0;
- NSInteger sysCount = 0;
- for (NSDictionary *parm in countArray) {
- if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
- courseCount = [parm ks_integerValueForKey:@"value"];
- }
- if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
- sysCount = [parm ks_integerValueForKey:@"value"];
- }
- }
- if (courseCount != 0 || sysCount != 0) {
- self.navView.dotView.hidden = NO;
- }
- else {
- self.navView.dotView.hidden = YES;
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow: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
- - (UIView *)headBgView {
- if (!_headBgView) {
- _headBgView = [[UIView alloc] init];
- _headBgView.backgroundColor = [UIColor whiteColor];
- }
- return _headBgView;
- }
- - (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 {
- // 判断是否有权限
- [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
- if (type == PREMISSIONTYPE_YES) {
- KSScanViewController *ctrl = [[KSScanViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else {
- [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 {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- }
- - (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_AUTH:
- {
- [self toAuthDetail];
- }
- break;
- case HOMEHEADACTION_EDUCATION:
- case HOMEHEADACTION_EDUCATIONFINISH:
- { // 不弹窗 直接跳转
- // [self showAuthEducationAlert];
- [self toAuthEducation];
- }
- break;
- case HOMEHEADACTION_SUBJECTCHOOSE:
- {
- [self showChooseSubjectView];
- }
- break;
- default:
- break;
- }
- }
- - (void)showChooseSubjectView {
- InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
- ctrl.isSingleChoose = YES;
- MJWeakSelf;
- [ctrl chooseCallback:^(NSMutableArray * _Nullable chooseArray) {
- NSDictionary *parm = [chooseArray firstObject];
- NSString *subjectId = [parm ks_stringValueForKey:@"subjectId"];
- NSString *subjectName = [parm ks_stringValueForKey:@"subjectName"];
- weakSelf.headView.subjectLabel.text = subjectName;
- [weakSelf setDefaultSubject:subjectId];
- }];
- self.isSettingSubject = YES;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)setDefaultSubject:(NSString *)subjectId {
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager defaultSubjectRequest:KS_POST subjectId:subjectId success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- // 请求数据
- [self requestHomeMessage];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- }];
-
- }
- - (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];
-
- }
- - (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 clearColor];
- _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 if (type == RECENTCOURSE_TYPE_VIP) { //VIP 定制课
- VipCouseDetailViewController *detailVC = [[VipCouseDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- detailVC.studentId = courseModel.studentId;
- [self.navigationController pushViewController:detailVC 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];
- }
- }
- - (void)displaySongDetail:(NSString *)songId {
-
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ---- scroll view delegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
-
- }
- #pragma mark ---- button container
- - (HomeButtonView *)buttonContainer {
- if (!_buttonContainer) {
- _buttonContainer = [HomeButtonView shareInstance];
- }
- return _buttonContainer;
- }
- #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.recommendMusicCollectionView) {
- NSInteger lastRowCount = (self.recommendMusicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.recommendMusicArray.count / 4 + lastRowCount;
- return count;
- }
- else if (collectionView == self.newestMusicCollectionView) {
- NSInteger lastRowCount = (self.newestMusicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.newestMusicArray.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.recommendMusicCollectionView) {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 4 + 4 > self.recommendMusicArray.count ? self.recommendMusicArray.count - indexPath.item * 4: 4;
- NSRange range = NSMakeRange(indexPath.item * 4, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.recommendMusicArray 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.newestMusicCollectionView) {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 4 + 4 > self.newestMusicArray.count ? self.newestMusicArray.count - indexPath.item * 4: 4;
- NSRange range = NSMakeRange(indexPath.item * 4, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.newestMusicArray subarrayWithRange:range]];
- HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" 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, 134);
- }
- else {
- return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
- }
- }
- #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 --- 推荐曲目
- - (HomeRecommendMusicView *)recommendMusicView {
- if (!_recommendMusicView) {
- _recommendMusicView = [HomeRecommendMusicView shareInstance];
- MJWeakSelf;
- [_recommendMusicView homeMusicMore:^{
- [weakSelf moreRecommendMusic];
- }];
- [_recommendMusicView.musicContentView addSubview:self.recommendMusicCollectionView];
- [self.recommendMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_recommendMusicView.musicContentView);
- }];
- }
- return _recommendMusicView;
- }
- - (UICollectionView *)recommendMusicCollectionView {
- if (!_recommendMusicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _recommendMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _recommendMusicCollectionView.backgroundColor = [UIColor clearColor];
- _recommendMusicCollectionView.delegate = self;
- _recommendMusicCollectionView.dataSource = self;
- _recommendMusicCollectionView.showsVerticalScrollIndicator = NO;
- _recommendMusicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _recommendMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _recommendMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_recommendMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
- }
- return _recommendMusicCollectionView;
- }
- - (NSMutableArray *)recommendMusicArray {
- if (!_recommendMusicArray) {
- _recommendMusicArray = [NSMutableArray array];
- }
- return _recommendMusicArray;
- }
- - (void)moreRecommendMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ---- 最新曲目
- - (HomeNewMusicView *)newestMusicView {
- if (!_newestMusicView) {
- if (!_newestMusicView) {
- _newestMusicView = [HomeNewMusicView shareInstance];
- MJWeakSelf;
- [_newestMusicView homeMusicMore:^{
- [weakSelf moreNewMusic];
- }];
- [_newestMusicView.musicContentView addSubview:self.newestMusicCollectionView];
- [self.newestMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_newestMusicView.musicContentView);
- }];
- }
- return _newestMusicView;
- }
- return _newestMusicView;
- }
- - (UICollectionView *)newestMusicCollectionView {
- if (!_newestMusicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _newestMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _newestMusicCollectionView.backgroundColor = [UIColor clearColor];
- _newestMusicCollectionView.delegate = self;
- _newestMusicCollectionView.dataSource = self;
- _newestMusicCollectionView.showsVerticalScrollIndicator = NO;
- _newestMusicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _newestMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _newestMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_newestMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
- }
- return _newestMusicCollectionView;
- }
- - (NSMutableArray *)newestMusicArray {
- if (!_newestMusicArray) {
- _newestMusicArray = [NSMutableArray array];
- }
- return _newestMusicArray;
- }
- - (void)moreNewMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
- [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) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _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, KPortraitWidth, (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, (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]) {
- if ([model.linkType isEqualToString:@"OUT"]) {
- // 外部浏览器打开
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[model.linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
- }
- else {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [model.linkUrl getUrlEndcodeString];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- - (HomeDragButton *)suspendButton {
- if (!_suspendButton) {
- _suspendButton = [[HomeDragButton alloc] initWithFrame:CGRectMake(KPortraitWidth - HomeDragButtonWidth - 10, KPortraitHeight - kTabBarHeight - HomeDragButtonHeight - 12 , HomeDragButtonWidth, HomeDragButtonHeight)];
- MJWeakSelf;
- [_suspendButton clickAction:^{
- [weakSelf showDragWindowDetail];
- }];
- }
- return _suspendButton;
- }
- - (void)showDragWindowDetail {
- NSString *linkUrl = self.buttonModel.linkUrl;
- if ([self.buttonModel.linkType isEqualToString:@"OUT"]) {
- // 外部浏览器打开
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
- }
- else {
- if (![NSString isEmptyString:linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [linkUrl getUrlEndcodeString];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- - (HomeTenantView *)tenantNameView {
- if (!_tenantNameView) {
- _tenantNameView = [HomeTenantView shareInstance];
- }
- return _tenantNameView;
- }
- /*
- #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
|