123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997 |
- //
- // HomeViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "HomeViewController.h"
- #import "KSBaseWKWebViewController.h"
- #import "NoticeMessageViewController.h"
- #import "SubjectChooseViewController.h"
- #import "HomeNavView.h"
- #import "HomeBannerView.h"
- #import <UIButton+WebCache.h>
- #import "TYCyclePagerView.h"
- #import "TYPageControl.h"
- #import "HomeBannerCell.h"
- #import "HomeBannerView.h"
- #import "HomeBannerCell.h"
- #import "HomeButtonView.h"
- #import "KSHomeButton.h"
- #import "HomeHotAlbumView.h"
- #import "HomeHotAlbumCell.h"
- #import "HomeHotCourseView.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 "HomeLiveCouseCell.h"
- #import "HomeLiveGroupModel.h"
- #import "HomeVideoCourseCell.h"
- #import "HomeVideoGroupModel.h"
- #define BUTTONWIDTH (80)
- #define BUTTONHEIGHT (80)
- @interface HomeViewController ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
- @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, strong) HomeButtonView *buttonContainer; // button container
- @property (nonatomic, strong) UIScrollView *buttonScrollView;
- @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
- @property (nonatomic, assign) NSInteger buttonDotWidth;
- @property (nonatomic, strong) HomeHotAlbumView *albumView; // albumView container
- @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
- @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
- @property (nonatomic, strong) HomeHotCourseView *courseView; // course container
- @property (nonatomic, strong) UIScrollView *courseScroll; // 课程scroll
- @property (nonatomic, strong) UITableView *liveCourseTable; // 直播课table
- @property (nonatomic, strong) UITableView *videoCourseTable; // 视频课table
- @property (nonatomic, strong) NSMutableArray *videoCourseArray;
- @property (nonatomic, strong) NSMutableArray *liveCourseArray;
- @property (nonatomic, strong) HomeIntroduceView *teacherView; // teacher container
- @property (nonatomic, strong) UICollectionView *infoCollectionView; // 老师风采简介
- @property (nonatomic, strong) NSMutableArray *teacherArray;
- @property (nonatomic, strong) HotInformationHeadView *informationHeadView; // information Header
- @property (nonatomic, strong) StudentInfoModel *mineInfo;
- @property (nonatomic, assign) BOOL hasCourseTips;
- @property (nonatomic, strong) HomeCourseTipsView *tipsCourseView;
- @property (nonatomic, assign) BOOL isChooseLive; // 是否选择直播课
- @property (nonatomic, assign) NSInteger courseCount;
- @end
- @implementation HomeViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- self.isChooseLive = YES;
- [self configNavView];
- // [self requestUserInfo];
- [self configUI];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self requestData];
- }
- - (void)configNavView {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
- }
- - (void)configUI {
- [self.scrollView removeFromSuperview];
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(self.view);
- make.top.mas_equalTo(self.navView.mas_bottom);
- }];
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- self.tableView.tableHeaderView = self.tableHeaderView;
- MJWeakSelf;
- self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- }];
- }
- - (void)requestData {
- [self requestUserInfo]; // 获取老师声部
- // 栅栏函数
- [self requestCourseInfo];
- [self requestTeacherStyle];
- }
- - (void)requestCourseInfo {
- [KSNetworkingManager homeQueryLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
- 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];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestUserInfo {
- [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];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestTeacherStyle {
-
- [KSNetworkingManager homeQueryTeacherStyle:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
- [self.tableView.mj_header endRefreshing];
- 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];
- }
- // 回调
- [self refreshUIDisplay];
- } faliure:^(NSError * _Nonnull error) {
- [self.tableView.mj_header endRefreshing];
- }];
- }
- - (void)refreshNavView {
- NSString *subjectName = @"";
- if ([NSString isEmptyString:self.mineInfo.subjectName]) {
- subjectName = @"请选择乐器";
- }
- else {
- subjectName = self.mineInfo.subjectName;
- }
- self.navView.subjectName.text = subjectName;
- }
- - (void)refreshUIDisplay {
- [self.tableHeaderView removeAllSubViews];
-
- CGFloat tableHeaderHeight = 0.0f;
-
- NSMutableArray *banner = [NSMutableArray array];
-
- for (NSInteger i = 0; i < 4; i++) {
- HomeMessageModel *model = [[HomeMessageModel alloc] init];
- [banner addObject:model];
- }
- self.bannerArray = [NSMutableArray arrayWithArray:banner];
-
- if (self.bannerArray.count) {
- [self.tableHeaderView addSubview:self.bannerView];
- CGFloat bannerHeight = [HomeBannerView getViewHeight];
- tableHeaderHeight += bannerHeight;
- [self.bannerView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top);
- make.height.mas_equalTo(bannerHeight);
- }];
- [self refreshBannaerView];
- }
- NSMutableArray *buttonArr = [NSMutableArray array];
-
- for (NSInteger i = 0; i < 4; i++) {
- HomeMessageModel *model = [[HomeMessageModel alloc] init];
- [buttonArr addObject:model];
- }
- self.buttonArray = [NSMutableArray arrayWithArray:buttonArr];
-
- if (self.buttonArray.count) {
- [self.tableHeaderView addSubview:self.buttonContainer];
- CGFloat buttonViewHeight = [HomeButtonView getViewHeight];
- [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
- make.height.mas_equalTo(buttonViewHeight);
- }];
- tableHeaderHeight += buttonViewHeight;
- [self showButtonMessage];
- }
-
- // 如果有最近课程
- self.hasCourseTips = YES;
- if (self.hasCourseTips) { // 课程提醒
- [self.tableHeaderView addSubview:self.tipsCourseView];
- CGFloat tipsViewHeight = [HomeCourseTipsView getViewHeight];
- [self.tipsCourseView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
- make.height.mas_equalTo(tipsViewHeight);
- }];
- tableHeaderHeight += tipsViewHeight;
- // 渲染页面
- }
-
- NSMutableArray *albumArr = [NSMutableArray array];
- for (NSInteger i = 0; i < 10; i++) {
- HomeMessageModel *model = [[HomeMessageModel alloc] init];
- [albumArr addObject:model];
- }
- self.albumArray = [NSMutableArray arrayWithArray:albumArr];
-
- if (self.albumArray.count) { // 热门专辑
- [self.tableHeaderView addSubview:self.albumView];
- CGFloat albumHeight = [HomeHotAlbumView getViewHeight];
- [self.albumView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
- make.height.mas_equalTo(albumHeight);
- }];
- tableHeaderHeight += albumHeight;
- }
-
- // 课程
- if (self.liveCourseArray.count && self.videoCourseArray.count) {
- self.courseCount = self.liveCourseArray.count >= self.videoCourseArray.count ? self.videoCourseArray.count : self.liveCourseArray.count;
- [self.tableHeaderView addSubview:self.courseView];
- // 根据课程返回数据显示高度
- CGFloat courseViewHeight = [self.courseView getViewHeightWithCount:self.courseCount];
- [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
- make.height.mas_equalTo(courseViewHeight);
- }];
- [self.courseScroll removeAllSubViews];
- self.courseScroll.contentSize = CGSizeMake(KPortraitWidth * 2, courseViewHeight - 59);
- [self.courseScroll addSubview:self.liveCourseTable];
- [self.liveCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.courseScroll);
- make.top.bottom.mas_equalTo(self.courseView.courseContainer);
- make.width.mas_equalTo(KPortraitWidth);
- }];
- [self.courseScroll addSubview:self.videoCourseTable];
- [self.videoCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(_courseScroll.mas_left).offset(KPortraitWidth);
- make.top.bottom.mas_equalTo(self.courseView.courseContainer);
- make.width.mas_equalTo(KPortraitWidth);
- }];
- tableHeaderHeight += courseViewHeight;
- [self.liveCourseTable reloadData];
- [self.videoCourseTable reloadData];
- }
- if (self.teacherArray.count) {
- [self.tableHeaderView addSubview:self.teacherView];
- CGFloat teacherContentHeight = [self.teacherView getViewHeightWithSourceCount:self.teacherArray.count];
-
- [self.teacherView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
- make.height.mas_equalTo(teacherContentHeight);
- }];
- tableHeaderHeight += teacherContentHeight;
- }
-
- [self.tableHeaderView addSubview:self.informationHeadView];
- CGFloat informationHeadHeight = [HotInformationHeadView getViewHeight];
- [self.informationHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.tableHeaderView);
- make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
- make.height.mas_equalTo(informationHeadHeight);
- }];
- tableHeaderHeight += informationHeadHeight;
-
- // test
- NSMutableArray *sourceArray = [NSMutableArray array];
-
- for (NSInteger i = 0; i < 4; i++) {
- HomeMessageModel *model = [[HomeMessageModel alloc] init];
- [sourceArray addObject:model];
- }
- self.dataArray = [NSMutableArray arrayWithArray:sourceArray];
-
- self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
- [self.tableView reloadData];
- }
- - (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 > 4) { // 大于4个显示底部滚动视图
- self.buttonContainer.buttonPageCtrl.hidden = NO;
- self.buttonContainer.buttonDotLeft.constant = 0;
- NSInteger addPage = (self.buttonArray.count % 4) > 0 ? 1 : 0;
- NSInteger pageCount = self.buttonArray.count / 4 + addPage;
- self.buttonDotWidth = 36 / pageCount;
- self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
- self.buttonScrollView.contentSize = CGSizeMake(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 - 4 * BUTTONWIDTH) / 5;
- 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]];
- buttonView.buttonTitle.text = model.title;
- buttonView.frame = CGRectMake(buttonSpace + (i % 4) * (BUTTONWIDTH + buttonSpace) + (i / 4) * 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(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
- 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.courseCount;
- }
- else { // 视频课列表
- return self.courseCount;
- }
- }
- - (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) {
- 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 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) {
- HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
- return cell;
- }
- else {
- TeacherStyleModel *model = self.teacherArray[indexPath.item];
- TeacherShowCell *showCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TeacherShowCell" forIndexPath:indexPath];
- MJWeakSelf;
- [showCell configWithStyleModel:model callback:^(NSString *videoUrl) {
- [weakSelf playVideo:videoUrl];
- }];
- return showCell;
- }
- }
- - (void)playVideo:(NSString *)videoUrl {
- if ([NSString isEmptyString:videoUrl]) {
- return;
- }
- // 播放视频
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) { // 专辑详情
-
- }
- 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(120, 140);
- }
- else {
- return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 164);
- }
- }
- // 老师风采
- - (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;
- }];
- }
- else if (scrollView == self.courseScroll) {
- NSLog(@"------");
- }
- }
-
- #pragma mark ---- lazying
- - (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 ----- 最近上课
- - (HomeCourseTipsView *)tipsCourseView {
- if (!_tipsCourseView) {
- _tipsCourseView = [HomeCourseTipsView shareInstance];
- MJWeakSelf;
- [_tipsCourseView joinRoomCallback:^(COURSETYPE type, NSString * _Nonnull courseId) {
- [weakSelf joinRoomAction:type courseId:courseId];
- }];
- }
- return _tipsCourseView;
- }
- - (void)joinRoomAction:(COURSETYPE)type courseId:(NSString *)courseId {
- if (type == COURSETYPE_ACCOMPANY) { // 陪练课详情
-
- }
- else { // 直播课详情
-
- }
- }
- #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;
- [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
- }
- return _albumCollectionView;
- }
- - (void)moreAlbumDetail {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @""];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ------ 推荐课程
- - (HomeHotCourseView *)courseView {
- if (!_courseView) {
- _courseView = [HomeHotCourseView shareInstance];
- MJWeakSelf;
- [_courseView courseActionCallback:^(COURSE_ACTION action) {
- [weakSelf homeCourseChooseAction:action];
- }];
- [_courseView.courseContainer addSubview:self.courseScroll];
- [self.courseScroll mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_courseView.courseContainer);
- }];
- }
- return _courseView;
- }
- - (UIScrollView *)courseScroll {
- if (!_courseScroll) {
- _courseScroll = [[UIScrollView alloc] initWithFrame:CGRectZero];
- _courseScroll.pagingEnabled = YES;
- _courseScroll.scrollEnabled = NO;
- _courseScroll.showsHorizontalScrollIndicator = NO;
- _courseScroll.showsVerticalScrollIndicator = NO;
- _courseScroll.delegate = self;
- }
- return _courseScroll;
- }
- - (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;
- }
- - (void)homeCourseChooseAction:(COURSE_ACTION)action {
- switch (action) {
- case COURSE_ACTION_LIVE:
- {
- if (self.isChooseLive == YES) {
- return;
- }
- self.isChooseLive = YES;
- }
- break;
- case COURSE_ACTION_VIDEO:
- {
- if (self.isChooseLive == NO) {
- return;
- }
- self.isChooseLive = NO;
- }
- break;
- case COURSE_ACTION_MORE: // 更多
- {
- NSString *url = @"";
- if (self.isChooseLive) { // 直播课 列表
- url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"];
- }
- else { // 视频课列表
- url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"];
- }
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = url;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- default:
- break;
- }
- }
- - (void)setIsChooseLive:(BOOL)isChooseLive {
- _isChooseLive = isChooseLive;
- // 切换
- [UIView animateWithDuration:0.3f animations:^{
- if (isChooseLive) {
- [self.courseScroll setContentOffset:CGPointZero animated:YES];
- }
- else {
- [self.courseScroll setContentOffset:CGPointMake(KPortraitWidth, 0) animated:YES];
- }
- }];
- }
- #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.mas_left).offset(14);
- make.right.mas_equalTo(_teacherView.mas_right).offset(-14);
- }];
- }
- return _teacherView;
- }
- - (void)teacherMoreIntorduce {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherList"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UICollectionView *)infoCollectionView {
- if (!_infoCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- _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"];
- }
- 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"];
- }
- return _bannerScroll;
- }
- #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, @"/#/teacherList"];
- [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 = 108;
- _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)navAction:(NAVACTION)action {
- if (action == NAVACTION_SUBJECT) {
- [self showInstrumentView];;
- }
- else { // 消息中心
- NoticeMessageViewController *ctrl = [[NoticeMessageViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (void)showInstrumentView {
- SubjectChooseViewController *ctrl = [[SubjectChooseViewController alloc] init];
- MJWeakSelf;
- [ctrl chooseSubjectCallback:^{
- [weakSelf requestUserInfo];
- }];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- /*
- #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
|