HomeViewController.m 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. //
  2. // HomeViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "HomeViewController.h"
  8. #import "KSBaseWKWebViewController.h"
  9. #import "NoticeMessageViewController.h"
  10. #import "SubjectChooseViewController.h"
  11. #import "HomeNavView.h"
  12. #import "HomeBannerView.h"
  13. #import <UIButton+WebCache.h>
  14. #import "TYCyclePagerView.h"
  15. #import "TYPageControl.h"
  16. #import "HomeBannerCell.h"
  17. #import "HomeBannerView.h"
  18. #import "HomeBannerCell.h"
  19. #import "HomeButtonView.h"
  20. #import "KSHomeButton.h"
  21. #import "HomeHotAlbumView.h"
  22. #import "HomeHotAlbumCell.h"
  23. #import "HomeHotCourseView.h"
  24. #import "HomeIntroduceView.h"
  25. #import "TeacherShowCell.h"
  26. #import "HotInformationHeadView.h"
  27. #import "TeacherStyleModel.h"
  28. #import "HomeInformationCell.h"
  29. #import "HomeMessageModel.h"
  30. #import "StudentInfoModel.h"
  31. #import "UserInfoManager.h"
  32. #import "HomeCourseTipsView.h"
  33. #import "HomeLiveCouseCell.h"
  34. #import "HomeLiveGroupModel.h"
  35. #import "HomeVideoCourseCell.h"
  36. #import "HomeVideoGroupModel.h"
  37. #define BUTTONWIDTH (80)
  38. #define BUTTONHEIGHT (80)
  39. @interface HomeViewController ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
  40. @property (nonatomic, strong) UITableView *tableView;
  41. @property (nonatomic, strong) HomeNavView *navView;
  42. @property (nonatomic, strong) UIView *tableHeaderView; // headView;
  43. @property (nonatomic, strong) TYPageControl *pageControl;
  44. @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
  45. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  46. @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
  47. @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
  48. @property (nonatomic, strong) UIScrollView *buttonScrollView;
  49. @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
  50. @property (nonatomic, assign) NSInteger buttonDotWidth;
  51. @property (nonatomic, strong) HomeHotAlbumView *albumView; // albumView container
  52. @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
  53. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  54. @property (nonatomic, strong) HomeHotCourseView *courseView; // course container
  55. @property (nonatomic, strong) UIScrollView *courseScroll; // 课程scroll
  56. @property (nonatomic, strong) UITableView *liveCourseTable; // 直播课table
  57. @property (nonatomic, strong) UITableView *videoCourseTable; // 视频课table
  58. @property (nonatomic, strong) NSMutableArray *videoCourseArray;
  59. @property (nonatomic, strong) NSMutableArray *liveCourseArray;
  60. @property (nonatomic, strong) HomeIntroduceView *teacherView; // teacher container
  61. @property (nonatomic, strong) UICollectionView *infoCollectionView; // 老师风采简介
  62. @property (nonatomic, strong) NSMutableArray *teacherArray;
  63. @property (nonatomic, strong) HotInformationHeadView *informationHeadView; // information Header
  64. @property (nonatomic, strong) StudentInfoModel *mineInfo;
  65. @property (nonatomic, assign) BOOL hasCourseTips;
  66. @property (nonatomic, strong) HomeCourseTipsView *tipsCourseView;
  67. @property (nonatomic, assign) BOOL isChooseLive; // 是否选择直播课
  68. @property (nonatomic, assign) NSInteger courseCount;
  69. @end
  70. @implementation HomeViewController
  71. - (void)viewDidLoad {
  72. [super viewDidLoad];
  73. // Do any additional setup after loading the view.
  74. self.ks_prefersNavigationBarHidden = YES;
  75. self.isChooseLive = YES;
  76. [self configNavView];
  77. // [self requestUserInfo];
  78. [self configUI];
  79. }
  80. - (void)viewWillAppear:(BOOL)animated {
  81. [super viewWillAppear:animated];
  82. [self requestData];
  83. }
  84. - (void)configNavView {
  85. [self.scrollView removeFromSuperview];
  86. [self.view addSubview:self.navView];
  87. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.right.top.mas_equalTo(self.view);
  89. make.height.mas_equalTo(kNaviBarHeight);
  90. }];
  91. }
  92. - (void)configUI {
  93. [self.scrollView removeFromSuperview];
  94. [self.view addSubview:self.tableView];
  95. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.right.bottom.mas_equalTo(self.view);
  97. make.top.mas_equalTo(self.navView.mas_bottom);
  98. }];
  99. if (@available(iOS 11.0, *)) {
  100. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  101. } else {
  102. // Fallback on earlier versions
  103. self.automaticallyAdjustsScrollViewInsets = NO;
  104. }
  105. self.tableView.tableHeaderView = self.tableHeaderView;
  106. MJWeakSelf;
  107. self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  108. [weakSelf requestData];
  109. }];
  110. }
  111. - (void)requestData {
  112. [self requestUserInfo]; // 获取老师声部
  113. // 栅栏函数
  114. [self requestCourseInfo];
  115. [self requestTeacherStyle];
  116. }
  117. - (void)requestCourseInfo {
  118. [KSNetworkingManager homeQueryLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
  119. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  120. NSDictionary *sourceDic = [dic dictionaryValueForKey:@"data"];
  121. NSArray *liveList = [sourceDic arrayValueForKey:@"liveList"];
  122. NSMutableArray *liveCourse = [NSMutableArray array];
  123. for (NSDictionary *parm in liveList) {
  124. HomeLiveGroupModel *model = [[HomeLiveGroupModel alloc] initWithDictionary:parm];
  125. [liveCourse addObject:model];
  126. }
  127. self.liveCourseArray = [NSMutableArray arrayWithArray:liveCourse];
  128. NSArray *videoList = [sourceDic arrayValueForKey:@"videoList"];
  129. NSMutableArray *videoCourse = [NSMutableArray array];
  130. for (NSDictionary *parm in videoList) {
  131. HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
  132. [videoCourse addObject:model];
  133. }
  134. self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
  135. }
  136. else {
  137. [self MBPShow:MESSAGEKEY];
  138. }
  139. } faliure:^(NSError * _Nonnull error) {
  140. }];
  141. }
  142. - (void)requestUserInfo {
  143. [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  144. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  145. self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  146. NSString *rongToken = UserDefault(RongTokenKey);
  147. if ([NSString isEmptyString:rongToken]) {
  148. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  149. }
  150. [self refreshNavView];
  151. }
  152. else {
  153. [self MBPShow:MESSAGEKEY];
  154. }
  155. } faliure:^(NSError * _Nonnull error) {
  156. }];
  157. }
  158. - (void)requestTeacherStyle {
  159. [KSNetworkingManager homeQueryTeacherStyle:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
  160. [self.tableView.mj_header endRefreshing];
  161. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  162. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  163. NSMutableArray *styleArray = [NSMutableArray array];
  164. for (NSDictionary *parm in sourceArray) {
  165. TeacherStyleModel *model = [[TeacherStyleModel alloc] initWithDictionary:parm];
  166. [styleArray addObject:model];
  167. }
  168. self.teacherArray = [NSMutableArray arrayWithArray:styleArray];
  169. }
  170. else {
  171. [self MBPShow:MESSAGEKEY];
  172. }
  173. // 回调
  174. [self refreshUIDisplay];
  175. } faliure:^(NSError * _Nonnull error) {
  176. [self.tableView.mj_header endRefreshing];
  177. }];
  178. }
  179. - (void)refreshNavView {
  180. NSString *subjectName = @"";
  181. if ([NSString isEmptyString:self.mineInfo.subjectName]) {
  182. subjectName = @"请选择乐器";
  183. }
  184. else {
  185. subjectName = self.mineInfo.subjectName;
  186. }
  187. self.navView.subjectName.text = subjectName;
  188. }
  189. - (void)refreshUIDisplay {
  190. [self.tableHeaderView removeAllSubViews];
  191. CGFloat tableHeaderHeight = 0.0f;
  192. NSMutableArray *banner = [NSMutableArray array];
  193. for (NSInteger i = 0; i < 4; i++) {
  194. HomeMessageModel *model = [[HomeMessageModel alloc] init];
  195. [banner addObject:model];
  196. }
  197. self.bannerArray = [NSMutableArray arrayWithArray:banner];
  198. if (self.bannerArray.count) {
  199. [self.tableHeaderView addSubview:self.bannerView];
  200. CGFloat bannerHeight = [HomeBannerView getViewHeight];
  201. tableHeaderHeight += bannerHeight;
  202. [self.bannerView mas_remakeConstraints:^(MASConstraintMaker *make) {
  203. make.left.right.mas_equalTo(self.tableHeaderView);
  204. make.top.mas_equalTo(self.tableHeaderView.mas_top);
  205. make.height.mas_equalTo(bannerHeight);
  206. }];
  207. [self refreshBannaerView];
  208. }
  209. NSMutableArray *buttonArr = [NSMutableArray array];
  210. for (NSInteger i = 0; i < 4; i++) {
  211. HomeMessageModel *model = [[HomeMessageModel alloc] init];
  212. [buttonArr addObject:model];
  213. }
  214. self.buttonArray = [NSMutableArray arrayWithArray:buttonArr];
  215. if (self.buttonArray.count) {
  216. [self.tableHeaderView addSubview:self.buttonContainer];
  217. CGFloat buttonViewHeight = [HomeButtonView getViewHeight];
  218. [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
  219. make.left.right.mas_equalTo(self.tableHeaderView);
  220. make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
  221. make.height.mas_equalTo(buttonViewHeight);
  222. }];
  223. tableHeaderHeight += buttonViewHeight;
  224. [self showButtonMessage];
  225. }
  226. // 如果有最近课程
  227. self.hasCourseTips = YES;
  228. if (self.hasCourseTips) { // 课程提醒
  229. [self.tableHeaderView addSubview:self.tipsCourseView];
  230. CGFloat tipsViewHeight = [HomeCourseTipsView getViewHeight];
  231. [self.tipsCourseView mas_remakeConstraints:^(MASConstraintMaker *make) {
  232. make.left.right.mas_equalTo(self.tableHeaderView);
  233. make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
  234. make.height.mas_equalTo(tipsViewHeight);
  235. }];
  236. tableHeaderHeight += tipsViewHeight;
  237. // 渲染页面
  238. }
  239. NSMutableArray *albumArr = [NSMutableArray array];
  240. for (NSInteger i = 0; i < 10; i++) {
  241. HomeMessageModel *model = [[HomeMessageModel alloc] init];
  242. [albumArr addObject:model];
  243. }
  244. self.albumArray = [NSMutableArray arrayWithArray:albumArr];
  245. if (self.albumArray.count) { // 热门专辑
  246. [self.tableHeaderView addSubview:self.albumView];
  247. CGFloat albumHeight = [HomeHotAlbumView getViewHeight];
  248. [self.albumView mas_remakeConstraints:^(MASConstraintMaker *make) {
  249. make.left.right.mas_equalTo(self.tableHeaderView);
  250. make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
  251. make.height.mas_equalTo(albumHeight);
  252. }];
  253. tableHeaderHeight += albumHeight;
  254. }
  255. // 课程
  256. if (self.liveCourseArray.count && self.videoCourseArray.count) {
  257. self.courseCount = self.liveCourseArray.count >= self.videoCourseArray.count ? self.videoCourseArray.count : self.liveCourseArray.count;
  258. [self.tableHeaderView addSubview:self.courseView];
  259. // 根据课程返回数据显示高度
  260. CGFloat courseViewHeight = [self.courseView getViewHeightWithCount:self.courseCount];
  261. [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
  262. make.left.right.mas_equalTo(self.tableHeaderView);
  263. make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
  264. make.height.mas_equalTo(courseViewHeight);
  265. }];
  266. [self.courseScroll removeAllSubViews];
  267. self.courseScroll.contentSize = CGSizeMake(KPortraitWidth * 2, courseViewHeight - 59);
  268. [self.courseScroll addSubview:self.liveCourseTable];
  269. [self.liveCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
  270. make.left.mas_equalTo(self.courseScroll);
  271. make.top.bottom.mas_equalTo(self.courseView.courseContainer);
  272. make.width.mas_equalTo(KPortraitWidth);
  273. }];
  274. [self.courseScroll addSubview:self.videoCourseTable];
  275. [self.videoCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
  276. make.left.mas_equalTo(_courseScroll.mas_left).offset(KPortraitWidth);
  277. make.top.bottom.mas_equalTo(self.courseView.courseContainer);
  278. make.width.mas_equalTo(KPortraitWidth);
  279. }];
  280. tableHeaderHeight += courseViewHeight;
  281. [self.liveCourseTable reloadData];
  282. [self.videoCourseTable reloadData];
  283. }
  284. if (self.teacherArray.count) {
  285. [self.tableHeaderView addSubview:self.teacherView];
  286. CGFloat teacherContentHeight = [self.teacherView getViewHeightWithSourceCount:self.teacherArray.count];
  287. [self.teacherView mas_remakeConstraints:^(MASConstraintMaker *make) {
  288. make.left.right.mas_equalTo(self.tableHeaderView);
  289. make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
  290. make.height.mas_equalTo(teacherContentHeight);
  291. }];
  292. tableHeaderHeight += teacherContentHeight;
  293. }
  294. [self.tableHeaderView addSubview:self.informationHeadView];
  295. CGFloat informationHeadHeight = [HotInformationHeadView getViewHeight];
  296. [self.informationHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
  297. make.left.right.mas_equalTo(self.tableHeaderView);
  298. make.top.mas_equalTo(self.tableHeaderView.mas_top).offset(tableHeaderHeight);
  299. make.height.mas_equalTo(informationHeadHeight);
  300. }];
  301. tableHeaderHeight += informationHeadHeight;
  302. // test
  303. NSMutableArray *sourceArray = [NSMutableArray array];
  304. for (NSInteger i = 0; i < 4; i++) {
  305. HomeMessageModel *model = [[HomeMessageModel alloc] init];
  306. [sourceArray addObject:model];
  307. }
  308. self.dataArray = [NSMutableArray arrayWithArray:sourceArray];
  309. self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
  310. [self.tableView reloadData];
  311. }
  312. - (void)refreshBannaerView {
  313. if (self.bannerArray.count > 1) {
  314. self.bannerScroll.autoScrollInterval = 3.0f;
  315. [self.bannerScroll addSubview:self.pageControl];
  316. }
  317. else {
  318. self.bannerScroll.autoScrollInterval = 0;
  319. [self.pageControl removeFromSuperview];
  320. }
  321. _pageControl.numberOfPages = self.bannerArray.count;
  322. [self.bannerScroll reloadData];
  323. }
  324. - (void)showButtonMessage {
  325. // 添加按钮
  326. if (self.buttonArray.count > 4) { // 大于4个显示底部滚动视图
  327. self.buttonContainer.buttonPageCtrl.hidden = NO;
  328. self.buttonContainer.buttonDotLeft.constant = 0;
  329. NSInteger addPage = (self.buttonArray.count % 4) > 0 ? 1 : 0;
  330. NSInteger pageCount = self.buttonArray.count / 4 + addPage;
  331. self.buttonDotWidth = 36 / pageCount;
  332. self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
  333. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth * pageCount, BUTTONHEIGHT);
  334. }
  335. else {
  336. self.buttonContainer.buttonPageCtrl.hidden = YES;
  337. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, BUTTONHEIGHT);
  338. }
  339. self.buttonScrollView.contentOffset = CGPointMake(0, 0);
  340. [self.buttonScrollView removeAllSubViews];
  341. CGFloat buttonSpace = (kScreenWidth - 4 * BUTTONWIDTH) / 5;
  342. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  343. HomeMessageModel *model = self.buttonArray[i];
  344. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  345. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:model.coverImage]];
  346. buttonView.buttonTitle.text = model.title;
  347. buttonView.frame = CGRectMake(buttonSpace + (i % 4) * (BUTTONWIDTH + buttonSpace) + (i / 4) * KPortraitWidth, 0, BUTTONWIDTH, BUTTONHEIGHT);
  348. buttonView.actionButton.tag = 3000 + i;
  349. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  350. [self.buttonScrollView addSubview:buttonView];
  351. }
  352. }
  353. - (void)HomeTopButtonAction:(UIButton *)sender {
  354. NSInteger index = sender.tag - 3000;
  355. if ([self checkIsLoginToLoginView:YES]) {
  356. HomeMessageModel *model = self.buttonArray[index];
  357. if (![NSString isEmptyString:model.linkUrl]) {
  358. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  359. webCtrl.url = model.linkUrl;
  360. [self.navigationController pushViewController:webCtrl animated:YES];
  361. }
  362. }
  363. }
  364. #pragma mark - TYCyclePagerViewDataSource代理
  365. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  366. return self.bannerArray.count;
  367. }
  368. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  369. HomeMessageModel *model = self.bannerArray[index];
  370. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  371. [cell configCellWithModel:model];
  372. return cell;
  373. }
  374. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  375. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  376. layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
  377. layout.itemSpacing = 0;
  378. return layout;
  379. }
  380. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  381. if (pageView == self.bannerScroll) {
  382. [self.pageControl setCurrentPage:toIndex animate:YES];
  383. }
  384. }
  385. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  386. HomeMessageModel *model = self.bannerArray[index];
  387. if (![NSString isEmptyString:model.linkUrl]) {
  388. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  389. webCtrl.url = model.linkUrl;
  390. [self.navigationController pushViewController:webCtrl animated:YES];
  391. }
  392. }
  393. #pragma mark ----- table data source
  394. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  395. if (tableView == self.tableView) { // 资讯
  396. return self.dataArray.count;
  397. }
  398. else if (tableView == self.liveCourseTable) { // 直播课列表
  399. return self.courseCount;
  400. }
  401. else { // 视频课列表
  402. return self.courseCount;
  403. }
  404. }
  405. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  406. if (tableView == self.tableView) {
  407. HomeMessageModel *model = self.dataArray[indexPath.row];
  408. HomeInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeInformationCell"];
  409. ROWINDEX rowIndex = ROWINDEX_MIDDLE;
  410. if (indexPath.row == 0) {
  411. rowIndex = ROWINDEX_TOP;
  412. }
  413. else if (indexPath.row == self.dataArray.count - 1) {
  414. rowIndex = ROWINDEX_BOTTOM;
  415. }
  416. [cell configCellWithSource:model rowIndex:rowIndex];
  417. return cell;
  418. }
  419. else if (tableView == self.liveCourseTable) {
  420. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
  421. HomeLiveCouseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLiveCouseCell"];
  422. [cell configWithSource:model];
  423. return cell;
  424. }
  425. else {
  426. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  427. HomeVideoCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeVideoCourseCell"];
  428. [cell configWithSource:model];
  429. return cell;
  430. }
  431. }
  432. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  433. if (tableView == self.tableView) {
  434. HomeMessageModel *model = self.dataArray[indexPath.row];
  435. if (![NSString isEmptyString:model.linkUrl]) {
  436. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  437. webCtrl.url = model.linkUrl;
  438. [self.navigationController pushViewController:webCtrl animated:YES];
  439. }
  440. }
  441. else if (tableView == self.liveCourseTable) { // 直播课详情
  442. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
  443. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  444. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId];
  445. ctrl.url = url;
  446. [self.navigationController pushViewController:ctrl animated:YES];
  447. }
  448. else if (tableView == self.videoCourseTable) { //
  449. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  450. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
  451. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  452. ctrl.url = url;
  453. [self.navigationController pushViewController:ctrl animated:YES];
  454. }
  455. }
  456. #pragma mark ---- collection data source
  457. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  458. return 1;
  459. }
  460. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  461. if (collectionView == self.albumCollectionView) {
  462. return self.albumArray.count;
  463. }
  464. else { // 老师风采
  465. return self.teacherArray.count;
  466. }
  467. }
  468. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  469. if (collectionView == self.albumCollectionView) {
  470. HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
  471. return cell;
  472. }
  473. else {
  474. TeacherStyleModel *model = self.teacherArray[indexPath.item];
  475. TeacherShowCell *showCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TeacherShowCell" forIndexPath:indexPath];
  476. MJWeakSelf;
  477. [showCell configWithStyleModel:model callback:^(NSString *videoUrl) {
  478. [weakSelf playVideo:videoUrl];
  479. }];
  480. return showCell;
  481. }
  482. }
  483. - (void)playVideo:(NSString *)videoUrl {
  484. if ([NSString isEmptyString:videoUrl]) {
  485. return;
  486. }
  487. // 播放视频
  488. }
  489. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  490. if (collectionView == self.albumCollectionView) { // 专辑详情
  491. }
  492. else { // 老师风采详情
  493. TeacherStyleModel *model = self.teacherArray[indexPath.item];
  494. [self displayTeacherDetail:model.userId];
  495. }
  496. }
  497. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  498. if (collectionView == self.albumCollectionView) {
  499. return CGSizeMake(120, 140);
  500. }
  501. else {
  502. return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 164);
  503. }
  504. }
  505. // 老师风采
  506. - (void)displayTeacherDetail:(NSString *)teacherId {
  507. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  508. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
  509. [self.navigationController pushViewController:ctrl animated:YES];
  510. }
  511. #pragma mark ---- scroll view delegate
  512. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  513. if (scrollView == self.buttonScrollView) {
  514. NSInteger index = (NSInteger)(scrollView.contentOffset.x / kScreenWidth);
  515. [UIView animateWithDuration:0.3f animations:^{
  516. self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth;
  517. }];
  518. }
  519. else if (scrollView == self.courseScroll) {
  520. NSLog(@"------");
  521. }
  522. }
  523. #pragma mark ---- lazying
  524. - (NSMutableArray *)buttonArray {
  525. if (!_buttonArray) {
  526. _buttonArray = [NSMutableArray array];
  527. }
  528. return _buttonArray;
  529. }
  530. - (NSMutableArray *)bannerArray {
  531. if (!_bannerArray) {
  532. _bannerArray = [NSMutableArray array];
  533. }
  534. return _bannerArray;
  535. }
  536. - (NSMutableArray *)albumArray {
  537. if (!_albumArray) {
  538. _albumArray = [NSMutableArray array];
  539. }
  540. return _albumArray;
  541. }
  542. - (NSMutableArray *)liveCourseArray {
  543. if (!_liveCourseArray) {
  544. _liveCourseArray = [NSMutableArray array];
  545. }
  546. return _liveCourseArray;
  547. }
  548. - (NSMutableArray *)videoCourseArray {
  549. if (!_videoCourseArray) {
  550. _videoCourseArray = [NSMutableArray array];
  551. }
  552. return _videoCourseArray;
  553. }
  554. - (NSMutableArray *)teacherArray {
  555. if (!_teacherArray) {
  556. _teacherArray = [NSMutableArray array];
  557. }
  558. return _teacherArray;
  559. }
  560. #pragma mark ----- 最近上课
  561. - (HomeCourseTipsView *)tipsCourseView {
  562. if (!_tipsCourseView) {
  563. _tipsCourseView = [HomeCourseTipsView shareInstance];
  564. MJWeakSelf;
  565. [_tipsCourseView joinRoomCallback:^(COURSETYPE type, NSString * _Nonnull courseId) {
  566. [weakSelf joinRoomAction:type courseId:courseId];
  567. }];
  568. }
  569. return _tipsCourseView;
  570. }
  571. - (void)joinRoomAction:(COURSETYPE)type courseId:(NSString *)courseId {
  572. if (type == COURSETYPE_ACCOMPANY) { // 陪练课详情
  573. }
  574. else { // 直播课详情
  575. }
  576. }
  577. #pragma mark ----- 专辑
  578. - (HomeHotAlbumView *)albumView {
  579. if (!_albumView) {
  580. _albumView = [HomeHotAlbumView shareInstance];
  581. MJWeakSelf;
  582. [_albumView homeAlbumMore:^{
  583. [weakSelf moreAlbumDetail];
  584. }];
  585. [_albumView.albumContentView addSubview:self.albumCollectionView];
  586. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  587. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  588. }];
  589. }
  590. return _albumView;
  591. }
  592. - (UICollectionView *)albumCollectionView {
  593. if (!_albumCollectionView) {
  594. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  595. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  596. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  597. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  598. _albumCollectionView.backgroundColor = [UIColor clearColor];
  599. _albumCollectionView.delegate = self;
  600. _albumCollectionView.dataSource = self;
  601. _albumCollectionView.showsVerticalScrollIndicator = NO;
  602. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  603. [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
  604. }
  605. return _albumCollectionView;
  606. }
  607. - (void)moreAlbumDetail {
  608. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  609. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @""];
  610. [self.navigationController pushViewController:ctrl animated:YES];
  611. }
  612. #pragma mark ------ 推荐课程
  613. - (HomeHotCourseView *)courseView {
  614. if (!_courseView) {
  615. _courseView = [HomeHotCourseView shareInstance];
  616. MJWeakSelf;
  617. [_courseView courseActionCallback:^(COURSE_ACTION action) {
  618. [weakSelf homeCourseChooseAction:action];
  619. }];
  620. [_courseView.courseContainer addSubview:self.courseScroll];
  621. [self.courseScroll mas_makeConstraints:^(MASConstraintMaker *make) {
  622. make.left.right.bottom.top.mas_equalTo(_courseView.courseContainer);
  623. }];
  624. }
  625. return _courseView;
  626. }
  627. - (UIScrollView *)courseScroll {
  628. if (!_courseScroll) {
  629. _courseScroll = [[UIScrollView alloc] initWithFrame:CGRectZero];
  630. _courseScroll.pagingEnabled = YES;
  631. _courseScroll.scrollEnabled = NO;
  632. _courseScroll.showsHorizontalScrollIndicator = NO;
  633. _courseScroll.showsVerticalScrollIndicator = NO;
  634. _courseScroll.delegate = self;
  635. }
  636. return _courseScroll;
  637. }
  638. - (UITableView *)liveCourseTable {
  639. if (!_liveCourseTable) {
  640. _liveCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  641. _liveCourseTable.delegate = self;
  642. _liveCourseTable.dataSource = self;
  643. _liveCourseTable.rowHeight = 126;
  644. _liveCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  645. _liveCourseTable.backgroundColor = [UIColor clearColor];
  646. _liveCourseTable.showsVerticalScrollIndicator = NO;
  647. [_liveCourseTable registerNib:[UINib nibWithNibName:@"HomeLiveCouseCell" bundle:nil] forCellReuseIdentifier:@"HomeLiveCouseCell"];
  648. _liveCourseTable.scrollEnabled = NO;
  649. }
  650. return _liveCourseTable;
  651. }
  652. - (UITableView *)videoCourseTable {
  653. if (!_videoCourseTable) {
  654. _videoCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  655. _videoCourseTable.delegate = self;
  656. _videoCourseTable.dataSource = self;
  657. _videoCourseTable.rowHeight = 126;
  658. _videoCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  659. _videoCourseTable.backgroundColor = [UIColor clearColor];
  660. _videoCourseTable.showsVerticalScrollIndicator = NO;
  661. [_videoCourseTable registerNib:[UINib nibWithNibName:@"HomeVideoCourseCell" bundle:nil] forCellReuseIdentifier:@"HomeVideoCourseCell"];
  662. _videoCourseTable.scrollEnabled = NO;
  663. }
  664. return _videoCourseTable;
  665. }
  666. - (void)homeCourseChooseAction:(COURSE_ACTION)action {
  667. switch (action) {
  668. case COURSE_ACTION_LIVE:
  669. {
  670. if (self.isChooseLive == YES) {
  671. return;
  672. }
  673. self.isChooseLive = YES;
  674. }
  675. break;
  676. case COURSE_ACTION_VIDEO:
  677. {
  678. if (self.isChooseLive == NO) {
  679. return;
  680. }
  681. self.isChooseLive = NO;
  682. }
  683. break;
  684. case COURSE_ACTION_MORE: // 更多
  685. {
  686. NSString *url = @"";
  687. if (self.isChooseLive) { // 直播课 列表
  688. url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"];
  689. }
  690. else { // 视频课列表
  691. url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"];
  692. }
  693. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  694. ctrl.url = url;
  695. [self.navigationController pushViewController:ctrl animated:YES];
  696. }
  697. break;
  698. default:
  699. break;
  700. }
  701. }
  702. - (void)setIsChooseLive:(BOOL)isChooseLive {
  703. _isChooseLive = isChooseLive;
  704. // 切换
  705. [UIView animateWithDuration:0.3f animations:^{
  706. if (isChooseLive) {
  707. [self.courseScroll setContentOffset:CGPointZero animated:YES];
  708. }
  709. else {
  710. [self.courseScroll setContentOffset:CGPointMake(KPortraitWidth, 0) animated:YES];
  711. }
  712. }];
  713. }
  714. #pragma mark --- 老师风采
  715. - (HomeIntroduceView *)teacherView {
  716. if (!_teacherView) {
  717. _teacherView = [HomeIntroduceView shareInstance];
  718. MJWeakSelf;
  719. [_teacherView introduceMore:^{
  720. [weakSelf teacherMoreIntorduce];
  721. }];
  722. [_teacherView.teacherContainer addSubview:self.infoCollectionView];
  723. [self.infoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  724. make.bottom.top.mas_equalTo(_teacherView.teacherContainer);
  725. make.left.mas_equalTo(_teacherView.mas_left).offset(14);
  726. make.right.mas_equalTo(_teacherView.mas_right).offset(-14);
  727. }];
  728. }
  729. return _teacherView;
  730. }
  731. - (void)teacherMoreIntorduce {
  732. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  733. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherList"];
  734. [self.navigationController pushViewController:ctrl animated:YES];
  735. }
  736. - (UICollectionView *)infoCollectionView {
  737. if (!_infoCollectionView) {
  738. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  739. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  740. _infoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  741. _infoCollectionView.backgroundColor = [UIColor clearColor];
  742. _infoCollectionView.delegate = self;
  743. _infoCollectionView.dataSource = self;
  744. _infoCollectionView.showsVerticalScrollIndicator = NO;
  745. _infoCollectionView.showsHorizontalScrollIndicator = NO;
  746. [_infoCollectionView registerNib:[UINib nibWithNibName:@"TeacherShowCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TeacherShowCell"];
  747. }
  748. return _infoCollectionView;
  749. }
  750. #pragma mark ---- button container
  751. - (HomeButtonView *)buttonContainer {
  752. if (!_buttonContainer) {
  753. _buttonContainer = [HomeButtonView shareInstance];
  754. [_buttonContainer.buttonContentView addSubview:self.buttonScrollView];
  755. }
  756. return _buttonContainer;
  757. }
  758. - (UIScrollView *)buttonScrollView {
  759. if (!_buttonScrollView) {
  760. _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, BUTTONHEIGHT)];
  761. _buttonScrollView.backgroundColor = [UIColor clearColor];
  762. _buttonScrollView.pagingEnabled = YES;
  763. _buttonScrollView.showsHorizontalScrollIndicator = NO;
  764. _buttonScrollView.showsVerticalScrollIndicator = NO;
  765. _buttonScrollView.delegate = self;
  766. }
  767. return _buttonScrollView;
  768. }
  769. - (UIView *)tableHeaderView {
  770. if (!_tableHeaderView) {
  771. _tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
  772. _tableHeaderView.backgroundColor = [UIColor clearColor];
  773. }
  774. return _tableHeaderView;
  775. }
  776. - (HomeBannerView *)bannerView {
  777. if (!_bannerView) {
  778. _bannerView = [HomeBannerView shareInstance];
  779. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  780. }
  781. return _bannerView;
  782. }
  783. - (TYCyclePagerView *)bannerScroll {
  784. if (!_bannerScroll) {
  785. _bannerScroll = [[TYCyclePagerView alloc] init];
  786. _bannerScroll.backgroundColor = [UIColor clearColor];
  787. _bannerScroll.frame = CGRectMake(0, 0, kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
  788. _bannerScroll.isInfiniteLoop = YES;
  789. _bannerScroll.autoScrollInterval = 3.0f;
  790. _bannerScroll.reloadDataNeedResetIndex = YES;
  791. _bannerScroll.dataSource = self;
  792. _bannerScroll.delegate = self;
  793. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  794. }
  795. return _bannerScroll;
  796. }
  797. #pragma mark ---- 更多资讯
  798. - (HotInformationHeadView *)informationHeadView {
  799. if (!_informationHeadView) {
  800. _informationHeadView = [HotInformationHeadView shareInstance];
  801. MJWeakSelf;
  802. [_informationHeadView moreInformationCallback:^{
  803. [weakSelf moreInformation];
  804. }];
  805. }
  806. return _informationHeadView;
  807. }
  808. - (void)moreInformation {
  809. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  810. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherList"];
  811. [self.navigationController pushViewController:ctrl animated:YES];
  812. }
  813. - (UITableView *)tableView {
  814. if (!_tableView) {
  815. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  816. _tableView.delegate = self;
  817. _tableView.dataSource = self;
  818. _tableView.rowHeight = 108;
  819. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  820. _tableView.backgroundColor = [UIColor clearColor];
  821. _tableView.showsVerticalScrollIndicator = NO;
  822. [_tableView registerNib:[UINib nibWithNibName:@"HomeInformationCell" bundle:nil] forCellReuseIdentifier:@"HomeInformationCell"];
  823. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  824. bottomView.backgroundColor = [UIColor clearColor];
  825. _tableView.tableFooterView = bottomView;
  826. }
  827. return _tableView;
  828. }
  829. - (HomeNavView *)navView {
  830. if (!_navView) {
  831. _navView = [HomeNavView shareInstance];
  832. MJWeakSelf;
  833. [_navView homeNavAction:^(NAVACTION action) {
  834. [weakSelf navAction:action];
  835. }];
  836. }
  837. return _navView;
  838. }
  839. - (void)navAction:(NAVACTION)action {
  840. if (action == NAVACTION_SUBJECT) {
  841. [self showInstrumentView];;
  842. }
  843. else { // 消息中心
  844. NoticeMessageViewController *ctrl = [[NoticeMessageViewController alloc] init];
  845. [self.navigationController pushViewController:ctrl animated:YES];
  846. }
  847. }
  848. - (void)showInstrumentView {
  849. SubjectChooseViewController *ctrl = [[SubjectChooseViewController alloc] init];
  850. MJWeakSelf;
  851. [ctrl chooseSubjectCallback:^{
  852. [weakSelf requestUserInfo];
  853. }];
  854. [self.navigationController pushViewController:ctrl animated:YES];
  855. }
  856. - (void)dealloc {
  857. [[NSNotificationCenter defaultCenter] removeObserver:self];
  858. }
  859. /*
  860. #pragma mark - Navigation
  861. // In a storyboard-based application, you will often want to do a little preparation before navigation
  862. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  863. // Get the new view controller using [segue destinationViewController].
  864. // Pass the selected object to the new view controller.
  865. }
  866. */
  867. @end