123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599 |
- //
- // HomeViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "HomeViewController.h"
- #import "KSBaseWKWebViewController.h"
- #import "NotiferMessageViewController.h"
- #import "HomeNavView.h"
- #import "HomeBannerView.h"
- #import <UIButton+WebCache.h>
- #import "TYCyclePagerView.h"
- #import "TYPageControl.h"
- #import "HomeBannerCell.h"
- #import "HomeBannerCell.h"
- #import "HomeButtonView.h"
- #import "KSHomeButton.h"
- #import "HomeHotAlbumView.h"
- #import "HomeHotAlbumCell.h"
- #import "HomeAlbumModel.h"
- #import "HomeIntroduceView.h"
- #import "TeacherShowCell.h"
- #import "HotInformationHeadView.h"
- #import "TeacherStyleModel.h"
- #import "HomeInformationCell.h"
- #import "HomeMessageModel.h"
- #import "StudentInfoModel.h"
- #import "UserInfoManager.h"
- #import "HomeCourseTipsView.h"
- #import "HomeLiveCourseView.h"
- #import "HomeVideoCourseView.h"
- #import "HomeLiveCouseCell.h"
- #import "HomeLiveGroupModel.h"
- #import "HomeVideoCourseCell.h"
- #import "HomeVideoGroupModel.h"
- #import "WMPlayer.h" // 播放相关
- #import "AppDelegate.h"
- #import "KSNewsAlert.h"
- #import "RecentCourseModel.h"
- #import "AccompanyDetailViewController.h"
- #import "InstrumentChooseViewController.h"
- #import "UserSettingViewController.h"
- #import "PublicNoticeView.h"
- #import "SDCycleScrollView.h"
- #import "NoticeSourceModel.h"
- #import "MusicRoomDetailViewController.h"
- #import "HomeHotMusicView.h"
- #import "HomeHotMusicCollectionCell.h"
- #define BUTTONWIDTH (65)
- #define BUTTONHEIGHT (80)
- @interface HomeViewController ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,WMPlayerDelegate,SDCycleScrollViewDelegate>
- {
- WMPlayer *_wmPlayer;
- CGRect _playerFrame;
- }
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, assign) BOOL isRatation;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) HomeNavView *navView;
- @property (nonatomic, strong) UIView *tableHeaderView; // headView;
- @property (nonatomic, strong) TYPageControl *pageControl;
- @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
- @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
- @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
- @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
- @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
- @property (nonatomic, strong) UIScrollView *buttonScrollView;
- @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
- @property (nonatomic, assign) NSInteger buttonDotWidth;
- @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
- @property (nonatomic, strong) PublicNoticeView *noticeView;
- @property (nonatomic, strong) SDCycleScrollView *noticeScrollView;
- @property (nonatomic, strong) NSMutableArray *noticeArray; // notice数据
- @property (nonatomic, strong) NSMutableArray *noticeTitleArray; // 标题数组
- @property (nonatomic, strong) HomeHotAlbumView *albumView; // albumView container
- @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
- @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
- @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
- @property (nonatomic, strong) HomeLiveCourseView *liveView;
- @property (nonatomic, strong) HomeVideoCourseView *videoView;
- @property (nonatomic, strong) UITableView *liveCourseTable; // 直播课table
- @property (nonatomic, strong) UITableView *videoCourseTable; // 视频课table
- @property (nonatomic, strong) NSMutableArray *videoCourseArray;
- @property (nonatomic, strong) NSMutableArray *liveCourseArray;
- @property (nonatomic, assign) CGFloat liveViewHeight;
- @property (nonatomic, assign) CGFloat videoViewHeight;
- @property (nonatomic, strong) HomeIntroduceView *teacherView; // teacher container
- @property (nonatomic, strong) UICollectionView *infoCollectionView; // 老师风采简介
- @property (nonatomic, strong) NSMutableArray *teacherArray;
- @property (nonatomic, assign) CGFloat teachViewHeight;
- @property (nonatomic, strong) HotInformationHeadView *informationHeadView; // information Header
- @property (nonatomic, assign) CGFloat informationHeight;
- @property (nonatomic, strong) StudentInfoModel *mineInfo;
- @property (nonatomic, assign) BOOL hasCourseTips;
- @property (nonatomic, strong) HomeCourseTipsView *tipsCourseView;
- @property (nonatomic, assign) CGFloat tipsViewHeight;
- @property (nonatomic, assign) BOOL isChooseLive; // 是否选择直播课
- @property (nonatomic, assign) NSInteger courseCount;
- @property (nonatomic, assign) BOOL isFirstLoad;
- @property (nonatomic, strong) dispatch_group_t requestGroup;
- @property (nonatomic, strong) HomeMessageModel *flashModel;
- @property (nonatomic, strong) RecentCourseModel *recentCourseModel;
- @property (nonatomic, strong) HomeHotMusicView *hotMusicView;
- @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *musicArray; // 曲谱数据
- @end
- @implementation HomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- self.isChooseLive = YES;
- self.isFirstLoad = YES;
- [self configNavView];
- [self configUI];
- }
- - (void)requestTrackAuth {
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate appTrackActionAuth];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if (self.isFirstLoad == YES) {
- [self requestUserInfo:YES]; // 获取声部
- [self requestTrackAuth];
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- [appDelegate handleNotiferSource];
- }
- else {
- [self requestUserInfo:YES];
- }
-
- [self requestUnreadCount];
- }
- - (void)requestUnreadCount {
- [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *countArray = [dic arrayValueForKey:@"data"];
- NSInteger courseCount = 0;
- NSInteger sysCount = 0;
- for (NSDictionary *parm in countArray) {
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
- courseCount = [parm integerValueForKey:@"value"];
- }
- if ([[parm stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
- sysCount = [parm integerValueForKey:@"value"];
- }
- }
- if (courseCount != 0 || sysCount != 0) {
- self.navView.dotView.hidden = NO;
- }
- else {
- self.navView.dotView.hidden = YES;
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)configNavView {
- [self.view addSubview:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
- [self.view bringSubviewToFront:self.scrollView];
- [self.view bringSubviewToFront:self.navView];
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.view.mas_top).offset(kNaviBarHeight);
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }];
- self.scrollView.backgroundColor = [UIColor clearColor];
- MJWeakSelf;
- self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- }];
- }
- - (void)configUI {
- UIView *headBgView = [[UIView alloc] init];
- headBgView.backgroundColor = [UIColor whiteColor];
- [self.scrollView addSubview:headBgView];
-
- [self.scrollView addSubview:self.bannerView];
- // banner
- self.bannerViewHeight = [HomeBannerView getViewHeight];
-
- [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.height.mas_equalTo(self.bannerViewHeight);
- }];
-
- [self.scrollView addSubview:self.buttonContainer];
- self.buttonViewHeight = [HomeButtonView getViewHeight];
- [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(self.buttonViewHeight);
- }];
- [headBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.bannerView.mas_top);
- make.bottom.mas_equalTo(self.buttonContainer.mas_bottom);
- }];
- // headBgView
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, kScreenWidth, self.bannerViewHeight + self.buttonViewHeight) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(14, 14)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = headBgView.bounds;
- maskLayer.path = maskPath.CGPath;
- headBgView.layer.mask = maskLayer;
-
- [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.tipsCourseView];
- self.tipsViewHeight = CGFLOAT_MIN;
- self.tipsCourseView.hidden = YES;
- [self.tipsCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.noticeView.mas_bottom);
- make.height.mas_equalTo(self.tipsViewHeight);
- }];
- // 专辑
- [self.scrollView addSubview:self.albumView];
- self.albumViewHeight = [HomeHotAlbumView getViewHeight];
- [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.tipsCourseView.mas_bottom);
- make.height.mas_equalTo(self.albumViewHeight);
- }];
- // 直播课
- [self.scrollView addSubview:self.liveView];
- self.liveViewHeight = [self.liveView getViewHeightWithCount:10];
- [self.liveView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.albumView.mas_bottom);
- make.height.mas_equalTo(self.liveViewHeight);
- }];
- // 视频课
- [self.scrollView addSubview:self.videoView];
- self.videoViewHeight = [self.videoView getViewHeightWithCount:10];
- [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.liveView.mas_bottom);
- make.height.mas_equalTo(self.videoViewHeight);
- }];
- // 老师风采
- [self.scrollView addSubview:self.teacherView];
- self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:10];
- [self.teacherView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.videoView.mas_bottom);
- make.height.mas_equalTo(self.teachViewHeight);
- }];
- // 资讯头部
- [self.scrollView addSubview:self.informationHeadView];
- self.informationHeight = [HotInformationHeadView getViewHeight];
- [self.informationHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.teacherView.mas_bottom);
- make.height.mas_equalTo(self.informationHeight);
- }];
- // 资讯列表
- [self.scrollView addSubview:self.tableView];
- CGFloat tableHeight = [self getTableHeightWithCount:4];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.informationHeadView.mas_bottom);
- make.bottom.mas_equalTo(self.scrollView.mas_bottom);
- make.height.mas_equalTo(tableHeight);
- }];
- }
- - (CGFloat)getTableHeightWithCount:(NSInteger)count {
- return 108 * count + 10;
- }
- - (void)requestData {
- [self showhud];
- [self requestNewsList];
- [self requestNotice];
- [self requestCourseInfo];
- [self requestTeacherStyle];
- [self requestHotAlbum];
-
- dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
- [self removehub];
- [self.scrollView.mj_header endRefreshing];
- [self refreshView];
- });
- }
- - (void)refreshView {
- [self refreshBannaerView];
- [self showButtonMessage];
- [self refreshNoticeView];
- [self refreshAlbumView];
- [self refreshCourseView:self.recentCourseModel];
- [self refreshCourseView];
- [self refreshTeachView];
- [self refreshTableView];
- if (self.flashModel) {
- [self showNewsWithSource:self.flashModel];
- }
- }
- - (void)requestNotice {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- if (sourceArray.count) {
- NSDictionary *parm = [sourceArray firstObject];
- NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm];
- [self.noticeArray addObject:bannerModel];
- [self.noticeTitleArray addObject:bannerModel.title];
- }
- else {
- self.noticeArray = [NSMutableArray array];
- self.noticeTitleArray = [NSMutableArray array];
- }
-
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshNoticeView {
- if (self.noticeTitleArray.count) {
- self.noticeView.hidden = NO;
- [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(60.0f);
- }];
- }
- else {
- self.noticeView.hidden = YES;
- [self.noticeView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- }
- self.noticeScrollView.titlesGroup = self.noticeTitleArray;
- }
- - (void)requestNewsList {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSDictionary *result = [dic dictionaryValueForKey:@"data"];
- // banner
- NSArray *bannerArray = [result arrayValueForKey:@"banner"];
- NSMutableArray *bannerInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in bannerArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [bannerInfoArray addObject:model];
- }
- self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
-
- // button
- NSArray *buttonArray = [result arrayValueForKey:@"appMenu"];
- NSMutableArray *buttonInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in buttonArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [buttonInfoArray addObject:model];
- }
- self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
-
- // news
- NSArray *flashArray = [result arrayValueForKey:@"flashPage"];
- if (flashArray.count) {
- self.flashModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]];
- }
-
- // information
- NSArray *information = [result arrayValueForKey:@"information"];
- NSMutableArray *informationInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in information) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [informationInfoArray addObject:model];
- }
- self.dataArray = [NSMutableArray arrayWithArray:informationInfoArray];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshTableView {
- CGFloat tableHeight = [self getTableHeightWithCount:self.dataArray.count];
- [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(tableHeight);
- }];
- [self.tableView reloadData];
- }
- - (void)requestHotAlbum {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- NSMutableArray *albumArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
- [albumArray addObject:model];
- }
- self.albumArray = [NSMutableArray arrayWithArray:albumArray];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
-
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshAlbumView {
- if (self.albumArray.count) {
- self.albumViewHeight = [HomeHotAlbumView getViewHeight];
- self.albumView.hidden = NO;
- }
- else {
- self.albumViewHeight = CGFLOAT_MIN;
- self.albumView.hidden = YES;
- }
- [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.albumViewHeight);
- }];
- [self.albumCollectionView reloadData];
- }
- - (void)requestCourseInfo {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeQueryLiveAndVideo:KS_GET version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSDictionary *sourceDic = [dic dictionaryValueForKey:@"data"];
- NSArray *liveList = [sourceDic arrayValueForKey:@"liveList"];
- NSMutableArray *liveCourse = [NSMutableArray array];
- for (NSDictionary *parm in liveList) {
- HomeLiveGroupModel *model = [[HomeLiveGroupModel alloc] initWithDictionary:parm];
- [liveCourse addObject:model];
- }
- self.liveCourseArray = [NSMutableArray arrayWithArray:liveCourse];
-
- NSArray *videoList = [sourceDic arrayValueForKey:@"videoList"];
- NSMutableArray *videoCourse = [NSMutableArray array];
- for (NSDictionary *parm in videoList) {
- HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
- [videoCourse addObject:model];
- }
- self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
-
- // 最近课程
- NSDictionary *parm = [sourceDic dictionaryValueForKey:@"recentCourses"];
- if (parm == nil) {
- self.recentCourseModel = nil;
- }
- else {
- self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
- }
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshCourseView:(RecentCourseModel *)model {
- if (model) {
- self.tipsViewHeight = 80.0f;
- [self.tipsCourseView configWithCourseMessage:model];
- self.tipsCourseView.hidden = NO;
- [self.tipsCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(80.0f);
- }];
- }
- else {
- self.tipsViewHeight = CGFLOAT_MIN;
- self.tipsCourseView.hidden = YES;
- [self.tipsCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- }
- }
- - (void)refreshCourseView {
- // 课程
- if (self.liveCourseArray.count) {
- self.liveViewHeight = [self.liveView getViewHeightWithCount:self.liveCourseArray.count];
- self.liveView.hidden = NO;
- }
- else {
- self.liveViewHeight = CGFLOAT_MIN;
- self.liveView.hidden = YES;
- }
- [self.liveView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.liveViewHeight);
- }];
- if (self.videoCourseArray.count) {
- self.videoViewHeight = [self.videoView getViewHeightWithCount:self.videoCourseArray.count];
- self.videoView.hidden = NO;
- }
- else {
- self.videoViewHeight = CGFLOAT_MIN;
- self.videoView.hidden = YES;
- }
- [self.videoView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.videoViewHeight);
- }];
-
- [self.liveCourseTable reloadData];
- [self.videoCourseTable reloadData];
- }
- - (void)requestUserInfo:(BOOL)checkSubject {
- self.isFirstLoad = NO;
- [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
- NSString *rongToken = UserDefault(RongTokenKey);
- if ([NSString isEmptyString:rongToken]) {
- [USER_MANAGER queryUserInfoConnectRongCloud:YES];
- }
- [self refreshNavView:checkSubject];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestTeacherStyle {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeQueryTeacherStyle:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
- NSMutableArray *styleArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- TeacherStyleModel *model = [[TeacherStyleModel alloc] initWithDictionary:parm];
- [styleArray addObject:model];
- }
- self.teacherArray = [NSMutableArray arrayWithArray:styleArray];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- // 回调
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshTeachView {
- if (self.teacherArray.count) {
- self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:self.teacherArray.count];
- self.teacherView.hidden = NO;
- }
- else {
- self.teachViewHeight = CGFLOAT_MIN;
- self.teacherView.hidden = YES;
- }
- [self.teacherView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.teachViewHeight);
- }];
-
- [self.infoCollectionView reloadData];
- }
- - (void)refreshNavView:(BOOL)checkSubject {
- if (checkSubject) {
- if ([NSString isEmptyString:self.mineInfo.subjectName]) {
- [self showInstrumentView:YES];
- }
- else {
- [self requestData];
- }
- }
-
- [self.navView.userAvatal sd_setImageWithURL:[NSURL URLWithString:[self.mineInfo.heardUrl getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- NSString *userName = @"";
- if ([NSString isEmptyString:self.mineInfo.username]) {
- userName = [NSString stringWithFormat:@"游客%@",self.mineInfo.userId];
- }
- else {
- userName = self.mineInfo.username;
- }
- self.navView.userName.text = userName;
- }
- - (void)refreshBannaerView {
- if (self.bannerArray.count > 1) {
- self.bannerScroll.autoScrollInterval = 3.0f;
- [self.bannerScroll addSubview:self.pageControl];
- }
- else {
- self.bannerScroll.autoScrollInterval = 0;
- [self.pageControl removeFromSuperview];
- }
- _pageControl.numberOfPages = self.bannerArray.count;
- [self.bannerScroll reloadData];
- }
- - (void)showButtonMessage {
- // 添加按钮
- if (self.buttonArray.count > 5) { // 大于4个显示底部滚动视图
- self.buttonContainer.buttonPageCtrl.hidden = NO;
- self.buttonContainer.buttonDotLeft.constant = 0;
- NSInteger addPage = (self.buttonArray.count % 5) > 0 ? 1 : 0;
- NSInteger pageCount = self.buttonArray.count / 5 + addPage;
- self.buttonDotWidth = 36 / pageCount;
- self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
- self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth * pageCount, BUTTONHEIGHT);
- }
- else {
- self.buttonContainer.buttonPageCtrl.hidden = YES;
- self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, BUTTONHEIGHT);
- }
-
- self.buttonScrollView.contentOffset = CGPointMake(0, 0);
- [self.buttonScrollView removeAllSubViews];
- CGFloat buttonSpace = (kScreenWidth - 5 * BUTTONWIDTH) / 6;
- for (NSInteger i = 0; i < self.buttonArray.count; i++) {
- HomeMessageModel *model = self.buttonArray[i];
- KSHomeButton *buttonView = [KSHomeButton shareInstance];
-
- [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
- buttonView.buttonTitle.text = model.title;
- buttonView.frame = CGRectMake(buttonSpace + (i % 5) * (BUTTONWIDTH + buttonSpace) + (i / 5) * KPortraitWidth, 0, BUTTONWIDTH, BUTTONHEIGHT);
- buttonView.actionButton.tag = 3000 + i;
- [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.buttonScrollView addSubview:buttonView];
- }
- }
- - (void)HomeTopButtonAction:(UIButton *)sender {
- NSInteger index = sender.tag - 3000;
- if ([self checkIsLoginToLoginView:YES]) {
- HomeMessageModel *model = self.buttonArray[index];
- if (![NSString isEmptyString:model.linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = model.linkUrl;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- #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 ----- table data source
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (tableView == self.tableView) { // 资讯
- return self.dataArray.count;
- }
- else if (tableView == self.liveCourseTable) { // 直播课列表
- return self.liveCourseArray.count;
- }
- else { // 视频课列表
- return self.videoCourseArray.count;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (tableView == self.tableView) {
- HomeMessageModel *model = self.dataArray[indexPath.row];
- HomeInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeInformationCell"];
- ROWINDEX rowIndex = ROWINDEX_MIDDLE;
- if (indexPath.row == 0 && self.dataArray.count == 1) {
- rowIndex = ROWINDEX_TOP_BOTTOM;
- }
- else if (indexPath.row == 0) {
- rowIndex = ROWINDEX_TOP;
- }
- else if (indexPath.row == self.dataArray.count - 1) {
- rowIndex = ROWINDEX_BOTTOM;
- }
- [cell configCellWithSource:model rowIndex:rowIndex];
- return cell;
- }
- else if (tableView == self.liveCourseTable) {
- HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
- HomeLiveCouseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLiveCouseCell"];
- [cell configWithSource:model];
- return cell;
- }
- else {
- HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
- HomeVideoCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeVideoCourseCell"];
- [cell configWithSource:model];
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (tableView == self.tableView) {
- HomeMessageModel *model = self.dataArray[indexPath.row];
- if (![NSString isEmptyString:model.linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = model.linkUrl;
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- else {
- // 跳转
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@%@",WEBHOST,@"/#/specialdetail?id=",model.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- else if (tableView == self.liveCourseTable) { // 直播课详情
- HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else if (tableView == self.videoCourseTable) { //
- HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
- NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- #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 { // 老师风采
- return self.teacherArray.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 {
- TeacherStyleModel *model = self.teacherArray[indexPath.item];
- TeacherShowCell *showCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TeacherShowCell" forIndexPath:indexPath];
- MJWeakSelf;
- [showCell configWithStyleModel:model callback:^(BOOL isShowVideo, NSString * _Nullable videoUrl) {
- if (isShowVideo) {
- [weakSelf playVideo:videoUrl];
- }
- else {
- [weakSelf displayTeacherDetail:model.userId];
- }
- }];
- return showCell;
- }
- }
- - (void)playVideo:(NSString *)videoUrl {
- if ([NSString isEmptyString:videoUrl]) {
- return;
- }
- // 播放视频
- [self playVideoWithUrl:videoUrl];
-
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) { // 专辑详情
- HomeAlbumModel *model = self.albumArray[indexPath.item];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else { // 老师风采详情
- TeacherStyleModel *model = self.teacherArray[indexPath.item];
- [self displayTeacherDetail:model.userId];
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- return CGSizeMake(100, 140);
- }
- else {
- return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 132);
- }
- }
- // 老师风采
- - (void)displayTeacherDetail:(NSString *)teacherId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ---- scroll view delegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (scrollView == self.buttonScrollView) {
- NSInteger index = (NSInteger)(scrollView.contentOffset.x / kScreenWidth);
-
- [UIView animateWithDuration:0.3f animations:^{
- self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth;
- }];
- }
- }
-
- #pragma mark ----- SDCycleScrollViewDelegate
- - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
- NoticeSourceModel *noticeModel = self.noticeArray[index];
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, noticeModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
-
- }
- #pragma mark ---- lazying
- - (dispatch_group_t)requestGroup {
- if (!_requestGroup) {
- _requestGroup = dispatch_group_create();
- }
- return _requestGroup;
- }
- - (NSMutableArray *)buttonArray {
- if (!_buttonArray) {
- _buttonArray = [NSMutableArray array];
- }
- return _buttonArray;
- }
- - (NSMutableArray *)bannerArray {
- if (!_bannerArray) {
- _bannerArray = [NSMutableArray array];
- }
- return _bannerArray;
- }
- - (NSMutableArray *)albumArray {
- if (!_albumArray) {
- _albumArray = [NSMutableArray array];
- }
- return _albumArray;
- }
- - (NSMutableArray *)liveCourseArray {
- if (!_liveCourseArray) {
- _liveCourseArray = [NSMutableArray array];
- }
- return _liveCourseArray;
- }
- - (NSMutableArray *)videoCourseArray {
- if (!_videoCourseArray) {
- _videoCourseArray = [NSMutableArray array];
- }
- return _videoCourseArray;
- }
- - (NSMutableArray *)teacherArray {
- if (!_teacherArray) {
- _teacherArray = [NSMutableArray array];
- }
- return _teacherArray;
- }
- #pragma mark ----- 公告
- - (PublicNoticeView *)noticeView {
- if (!_noticeView) {
- _noticeView = [PublicNoticeView shareInstance];
- MJWeakSelf;
- [_noticeView moreCallback:^{
- [weakSelf moreNotice];
- }];
- }
- return _noticeView;
- }
- #pragma mark -- lazying
- - (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.noticeTitleArray;
- }
- return _noticeScrollView;
- }
- - (NSMutableArray *)noticeArray {
- if (!_noticeArray) {
- _noticeArray = [NSMutableArray array];
- }
- return _noticeArray;
- }
- - (NSMutableArray *)noticeTitleArray {
- if (!_noticeTitleArray) {
- _noticeTitleArray = [NSMutableArray array];
- }
- return _noticeTitleArray;
- }
- - (void)moreNotice {
- if (self.noticeArray.count) {
- NoticeSourceModel *noticeModel = self.noticeArray[0];
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, noticeModel.internalBaseClassIdentifier];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- /*
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/helpCenter?catalogType=2"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- */
-
- }
- #pragma mark ----- 最近上课
- - (HomeCourseTipsView *)tipsCourseView {
- if (!_tipsCourseView) {
- _tipsCourseView = [HomeCourseTipsView shareInstance];
- MJWeakSelf;
- [_tipsCourseView joinRoomCallback:^(COURSETYPE type, RecentCourseModel * _Nonnull courseModel) {
- [weakSelf joinRoomAction:type courseMessage:courseModel];
- }];
- }
- return _tipsCourseView;
- }
- - (void)joinRoomAction:(COURSETYPE)type courseMessage:(RecentCourseModel *)courseModel {
- if (type == COURSETYPE_ACCOMPANY) { // 陪练课详情
- AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- detailVC.teacherId = courseModel.teacherId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else if (type == COURSETYPE_MUSICROOM) { // 琴房课列表
- MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
- detailVC.courseId = courseModel.courseId;
- detailVC.courseGroupId = courseModel.courseGroupId;
- detailVC.teacherId = courseModel.teacherId;
- [self.navigationController pushViewController:detailVC animated:YES];
- }
- else { // 直播课详情进教室
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST,courseModel.courseGroupId,courseModel.courseId];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- #pragma mark ----- 专辑
- - (HomeHotAlbumView *)albumView {
- if (!_albumView) {
- _albumView = [HomeHotAlbumView shareInstance];
- MJWeakSelf;
- [_albumView homeAlbumMore:^{
- [weakSelf moreAlbumDetail];
- }];
- [_albumView.albumContentView addSubview:self.albumCollectionView];
- [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
- }];
- }
- return _albumView;
- }
- - (UICollectionView *)albumCollectionView {
- if (!_albumCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _albumCollectionView.backgroundColor = [UIColor clearColor];
- _albumCollectionView.delegate = self;
- _albumCollectionView.dataSource = self;
- _albumCollectionView.showsVerticalScrollIndicator = NO;
- _albumCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
- }
- return _albumCollectionView;
- }
- - (void)moreAlbumDetail {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ------ 推荐课程
- - (HomeLiveCourseView *)liveView {
- if (!_liveView) {
- _liveView = [HomeLiveCourseView shareInstance];
- MJWeakSelf;
- [_liveView hotLiveMore:^{
- [weakSelf toLiveMorePage];
- }];
- [_liveView addSubview:self.liveCourseTable];
- [self.liveCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_liveView.liveContainer);
- }];
- }
- return _liveView;
- }
- // 更多直播
- - (void)toLiveMorePage {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (HomeVideoCourseView *)videoView {
- if (!_videoView) {
- _videoView = [HomeVideoCourseView shareInstance];
- MJWeakSelf;
- [_videoView moreHotVideo:^{
- [weakSelf toVideoMorePage];
- }];
- [_videoView addSubview:self.videoCourseTable];
- [self.videoCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_videoView.videoContainer);
- }];
- }
- return _videoView;
- }
- - (void)toVideoMorePage {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UITableView *)liveCourseTable {
- if (!_liveCourseTable) {
- _liveCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _liveCourseTable.delegate = self;
- _liveCourseTable.dataSource = self;
- _liveCourseTable.rowHeight = 126;
- _liveCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
- _liveCourseTable.backgroundColor = [UIColor clearColor];
- _liveCourseTable.showsVerticalScrollIndicator = NO;
- [_liveCourseTable registerNib:[UINib nibWithNibName:@"HomeLiveCouseCell" bundle:nil] forCellReuseIdentifier:@"HomeLiveCouseCell"];
- _liveCourseTable.scrollEnabled = NO;
- }
- return _liveCourseTable;
- }
- - (UITableView *)videoCourseTable {
- if (!_videoCourseTable) {
- _videoCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _videoCourseTable.delegate = self;
- _videoCourseTable.dataSource = self;
- _videoCourseTable.rowHeight = 126;
- _videoCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
- _videoCourseTable.backgroundColor = [UIColor clearColor];
- _videoCourseTable.showsVerticalScrollIndicator = NO;
- [_videoCourseTable registerNib:[UINib nibWithNibName:@"HomeVideoCourseCell" bundle:nil] forCellReuseIdentifier:@"HomeVideoCourseCell"];
- _videoCourseTable.scrollEnabled = NO;
- }
- return _videoCourseTable;
- }
- #pragma mark --- 老师风采
- - (HomeIntroduceView *)teacherView {
- if (!_teacherView) {
- _teacherView = [HomeIntroduceView shareInstance];
- MJWeakSelf;
- [_teacherView introduceMore:^{
- [weakSelf teacherMoreIntorduce];
- }];
- [_teacherView.teacherContainer addSubview:self.infoCollectionView];
- [self.infoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.top.mas_equalTo(_teacherView.teacherContainer);
- make.left.mas_equalTo(_teacherView.teacherContainer.mas_left).offset(14);
- make.right.mas_equalTo(_teacherView.teacherContainer.mas_right).offset(-14);
- }];
- }
- return _teacherView;
- }
- - (void)teacherMoreIntorduce {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherElegant"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UICollectionView *)infoCollectionView {
- if (!_infoCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- layout.itemSize = CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 132);
- _infoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _infoCollectionView.backgroundColor = [UIColor clearColor];
- _infoCollectionView.delegate = self;
- _infoCollectionView.dataSource = self;
- _infoCollectionView.showsVerticalScrollIndicator = NO;
- _infoCollectionView.showsHorizontalScrollIndicator = NO;
- [_infoCollectionView registerNib:[UINib nibWithNibName:@"TeacherShowCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TeacherShowCell"];
- if (@available(iOS 11.0, *)) {
- _infoCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _infoCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- }
- return _infoCollectionView;
- }
- #pragma mark ---- button container
- - (HomeButtonView *)buttonContainer {
- if (!_buttonContainer) {
- _buttonContainer = [HomeButtonView shareInstance];
- [_buttonContainer.buttonContentView addSubview:self.buttonScrollView];
- }
- return _buttonContainer;
- }
- - (UIScrollView *)buttonScrollView {
- if (!_buttonScrollView) {
- _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, BUTTONHEIGHT)];
- _buttonScrollView.backgroundColor = [UIColor clearColor];
- _buttonScrollView.pagingEnabled = YES;
- _buttonScrollView.showsHorizontalScrollIndicator = NO;
- _buttonScrollView.showsVerticalScrollIndicator = NO;
- _buttonScrollView.delegate = self;
- }
- return _buttonScrollView;
- }
- - (UIView *)tableHeaderView {
- if (!_tableHeaderView) {
- _tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
- _tableHeaderView.backgroundColor = [UIColor clearColor];
- }
- return _tableHeaderView;
- }
- - (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.frame = CGRectMake(0, (kScreenWidth - 28) * 132 / 347 - 15, kScreenWidth-28, 10);
- _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
- _pageControl.pageIndicatorTintColor = HexRGBAlpha(0xffffff, 0.5);
- _pageControl.pageIndicatorSize = CGSizeMake(10, 3);
- _pageControl.currentPageIndicatorSize = CGSizeMake(10, 3);
- }
- return _pageControl;
- }
- #pragma mark ---- 更多资讯
- - (HotInformationHeadView *)informationHeadView {
- if (!_informationHeadView) {
- _informationHeadView = [HotInformationHeadView shareInstance];
-
- MJWeakSelf;
- [_informationHeadView moreInformationCallback:^{
- [weakSelf moreInformation];
- }];
- }
- return _informationHeadView;
- }
- - (void)moreInformation {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/special"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.rowHeight = 90;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.showsVerticalScrollIndicator = NO;
- [_tableView registerNib:[UINib nibWithNibName:@"HomeInformationCell" bundle:nil] forCellReuseIdentifier:@"HomeInformationCell"];
- UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
- bottomView.backgroundColor = [UIColor clearColor];
- _tableView.tableFooterView = bottomView;
- }
- return _tableView;
- }
- - (HomeNavView *)navView {
- if (!_navView) {
- _navView = [HomeNavView shareInstance];
- MJWeakSelf;
- [_navView homeNavAction:^(NAVACTION action) {
- [weakSelf navAction:action];
- }];
- }
- return _navView;
- }
- - (void)displayUserCenter {
- UserSettingViewController *ctrl = [[UserSettingViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)navAction:(NAVACTION)action {
- if (action == NAVACTION_USERCENTER) {
- [self displayUserCenter];
- }
- else if (action == NAVACTION_SCAN) { // 扫一扫
- [self showScanView];
- }
- else { // 消息中心
-
- NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (void)showScanView {
-
- }
- - (void)showInstrumentView:(BOOL)hideBackButton {
- InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
- MJWeakSelf;
- [ctrl chooseCallback:^{
- [weakSelf requestUserInfo:NO];
- [weakSelf requestData];
- }];
- if (hideBackButton) {
- ctrl.isModalPresent = YES;
- CustomNavViewController *navCrtl = [[CustomNavViewController alloc] initWithRootViewController:ctrl];
- navCrtl.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.navigationController presentViewController:navCrtl animated:YES completion:nil];
- }
- else {
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- #pragma mark ------ WMPlayer
- - (void)playVideoWithUrl:(NSString *)fileUrl {
- fileUrl = [fileUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
- _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
- WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
- playModel.videoURL = [NSURL URLWithString:fileUrl];
- _wmPlayer.playerModel = playModel;
- _wmPlayer.delegate = self;
- _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
- _bgView.backgroundColor = [UIColor blackColor];
- [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
- [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
-
- [_wmPlayer play];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
- [wmplayer removePlayer];
- [_bgView removeFromSuperview];
- [self setNeedsStatusBarAppearanceUpdate];
- }
- - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
- self.isRatation = !self.isRatation;
-
- if (self.isRatation) {
- [wmplayer removeFromSuperview];
- [UIView animateWithDuration:1.0f animations:^{
- wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- else {
- [wmplayer removeFromSuperview];
-
- [UIView animateWithDuration:1.0f animations:^{
- // 复原
- wmplayer.transform = CGAffineTransformIdentity;
-
- } completion:^(BOOL finished) {
- wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
- [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
- [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
- }];
- }
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)showNewsWithSource:(HomeMessageModel *)sourceModel {
- // 登录之后才弹窗
- if ([self checkIsLoginToLoginView:NO]) {
- NSString *useId = UserDefault(UIDKey);
- NSMutableArray *newArray = UserDefault(useId);
- if (newArray.count) {
- if ([newArray containsObject:sourceModel.coverImage]) {
- return;
- }
- else {
- [self displayAlert:sourceModel];
- }
- }
- else {
- [self displayAlert:sourceModel];
- }
- }
- // [self displayAlert:sourceModel];
- }
- - (void)displayAlert:(HomeMessageModel *)sourceModel {
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (appDelegate.isShowMemoAlert) {
- return;
- }
- NSString *useId = UserDefault(UIDKey);
- UserDefaultRemoveObjectForKey(useId);
- NSMutableArray *sourceArray = [NSMutableArray arrayWithArray:UserDefault(useId)];
- [sourceArray addObject:sourceModel.coverImage];
- UserDefaultSetObjectForKey(sourceArray, useId);
- KSNewsAlert *newAlert = [KSNewsAlert shareInstance];
- MJWeakSelf;
- [newAlert evaluateWithMessage:sourceModel.coverImage linkUrl:sourceModel.linkUrl callbackAction:^(BOOL isSure, NSString * _Nonnull linkUrl) {
- appDelegate.isShowFlashAlert = NO;
- if (isSure) {
- if (![NSString isEmptyString:linkUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = linkUrl;
- [weakSelf.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新
- }];
- [newAlert showAlert];
- appDelegate.isShowFlashAlert = YES;
- }
- #pragma mark ---- 更多曲目
- - (HomeHotMusicView *)hotMusicView {
- if (!_hotMusicView) {
- _hotMusicView = [HomeHotMusicView shareInstance];
- MJWeakSelf;
- [_hotMusicView homeMusicMore:^{
- [weakSelf moreHotMusic];
- }];
- [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
- [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
- }];
- }
- return _hotMusicView;
- }
- - (void)moreHotMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UICollectionView *)musicCollectionView {
- if (!_musicCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _musicCollectionView.backgroundColor = [UIColor clearColor];
- _musicCollectionView.delegate = self;
- _musicCollectionView.dataSource = self;
- _musicCollectionView.showsVerticalScrollIndicator = NO;
- _musicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_musicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
- }
- return _musicCollectionView;
- }
- - (NSMutableArray *)musicArray {
- if (!_musicArray) {
- _musicArray = [NSMutableArray array];
- }
- return _musicArray;
- }
- /*
- #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
|