HomeViewController.m 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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 "NotiferMessageViewController.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 "HomeAlbumModel.h"
  24. #import "HomeHotCourseView.h"
  25. #import "HomeIntroduceView.h"
  26. #import "TeacherShowCell.h"
  27. #import "HotInformationHeadView.h"
  28. #import "TeacherStyleModel.h"
  29. #import "HomeInformationCell.h"
  30. #import "HomeMessageModel.h"
  31. #import "StudentInfoModel.h"
  32. #import "UserInfoManager.h"
  33. #import "HomeCourseTipsView.h"
  34. #import "HomeLiveCouseCell.h"
  35. #import "HomeLiveGroupModel.h"
  36. #import "HomeVideoCourseCell.h"
  37. #import "HomeVideoGroupModel.h"
  38. #import "WMPlayer.h" // 播放相关
  39. #import "AppDelegate.h"
  40. #import "KSNewsAlert.h"
  41. #import "RecentCourseModel.h"
  42. #import "AccompanyDetailViewController.h"
  43. #define BUTTONWIDTH (65)
  44. #define BUTTONHEIGHT (80)
  45. @interface HomeViewController ()<TYCyclePagerViewDataSource,TYCyclePagerViewDelegate,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,WMPlayerDelegate>
  46. {
  47. WMPlayer *_wmPlayer;
  48. CGRect _playerFrame;
  49. }
  50. @property (nonatomic, strong) UIView *bgView;
  51. @property (nonatomic, assign) BOOL isRatation;
  52. @property (nonatomic, strong) UITableView *tableView;
  53. @property (nonatomic, strong) HomeNavView *navView;
  54. @property (nonatomic, strong) UIView *tableHeaderView; // headView;
  55. @property (nonatomic, strong) TYPageControl *pageControl;
  56. @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
  57. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  58. @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
  59. @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
  60. @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
  61. @property (nonatomic, strong) UIScrollView *buttonScrollView;
  62. @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
  63. @property (nonatomic, assign) NSInteger buttonDotWidth;
  64. @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
  65. @property (nonatomic, strong) HomeHotAlbumView *albumView; // albumView container
  66. @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
  67. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  68. @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
  69. @property (nonatomic, strong) HomeHotCourseView *courseView; // course container
  70. @property (nonatomic, strong) UIScrollView *courseScroll; // 课程scroll
  71. @property (nonatomic, strong) UITableView *liveCourseTable; // 直播课table
  72. @property (nonatomic, strong) UITableView *videoCourseTable; // 视频课table
  73. @property (nonatomic, strong) NSMutableArray *videoCourseArray;
  74. @property (nonatomic, strong) NSMutableArray *liveCourseArray;
  75. @property (nonatomic, assign) CGFloat courseViewHeight;
  76. @property (nonatomic, strong) HomeIntroduceView *teacherView; // teacher container
  77. @property (nonatomic, strong) UICollectionView *infoCollectionView; // 老师风采简介
  78. @property (nonatomic, strong) NSMutableArray *teacherArray;
  79. @property (nonatomic, assign) CGFloat teachViewHeight;
  80. @property (nonatomic, strong) HotInformationHeadView *informationHeadView; // information Header
  81. @property (nonatomic, assign) CGFloat informationHeight;
  82. @property (nonatomic, strong) StudentInfoModel *mineInfo;
  83. @property (nonatomic, assign) BOOL hasCourseTips;
  84. @property (nonatomic, strong) HomeCourseTipsView *tipsCourseView;
  85. @property (nonatomic, assign) CGFloat tipsViewHeight;
  86. @property (nonatomic, assign) BOOL isChooseLive; // 是否选择直播课
  87. @property (nonatomic, assign) NSInteger courseCount;
  88. @property (nonatomic, assign) BOOL isFirstLoad;
  89. @end
  90. @implementation HomeViewController
  91. - (void)viewDidLoad {
  92. [super viewDidLoad];
  93. // Do any additional setup after loading the view.
  94. self.ks_prefersNavigationBarHidden = YES;
  95. self.isChooseLive = YES;
  96. self.isFirstLoad = YES;
  97. [self configNavView];
  98. [self configUI];
  99. }
  100. - (void)viewWillAppear:(BOOL)animated {
  101. [super viewWillAppear:animated];
  102. if (self.isFirstLoad == YES) {
  103. [self requestUserInfo:YES]; // 获取声部
  104. }
  105. else {
  106. [self requestUserInfo:NO];
  107. }
  108. [self requestUnreadCount];
  109. }
  110. - (void)requestUnreadCount {
  111. [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  112. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  113. NSArray *countArray = [dic arrayValueForKey:@"data"];
  114. NSInteger courseCount = 0;
  115. NSInteger sysCount = 0;
  116. NSInteger noticeCount = 0;
  117. for (NSDictionary *parm in countArray) {
  118. if ([[parm stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
  119. courseCount = [parm integerValueForKey:@"value"];
  120. }
  121. if ([[parm stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
  122. sysCount = [parm integerValueForKey:@"value"];
  123. }
  124. if ([[parm stringValueForKey:@"key"] isEqualToString:@"NOTICE"]) {
  125. noticeCount = [parm integerValueForKey:@"value"];
  126. }
  127. }
  128. if (courseCount != 0 || sysCount != 0 || noticeCount != 0) {
  129. self.navView.dotView.hidden = NO;
  130. }
  131. else {
  132. self.navView.dotView.hidden = YES;
  133. }
  134. }
  135. else {
  136. [self MBPShow:MESSAGEKEY];
  137. }
  138. } faliure:^(NSError * _Nonnull error) {
  139. }];
  140. }
  141. - (void)configNavView {
  142. [self.scrollView removeFromSuperview];
  143. [self.view addSubview:self.navView];
  144. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.left.right.top.mas_equalTo(self.view);
  146. make.height.mas_equalTo(kNaviBarHeight);
  147. }];
  148. }
  149. - (void)configUI {
  150. [self.scrollView removeFromSuperview];
  151. [self.view addSubview:self.tableView];
  152. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  153. make.left.right.bottom.mas_equalTo(self.view);
  154. make.top.mas_equalTo(self.navView.mas_bottom);
  155. }];
  156. if (@available(iOS 11.0, *)) {
  157. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  158. } else {
  159. // Fallback on earlier versions
  160. self.automaticallyAdjustsScrollViewInsets = NO;
  161. }
  162. self.tableView.tableHeaderView = self.tableHeaderView;
  163. MJWeakSelf;
  164. self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  165. [weakSelf requestData];
  166. }];
  167. // 配置 首页显示
  168. [self addDisplayView];
  169. }
  170. - (void)addDisplayView {
  171. CGFloat tableHeaderHeight = 0.0f;
  172. [self.tableHeaderView addSubview:self.bannerView];
  173. // banner
  174. self.bannerViewHeight = [HomeBannerView getViewHeight];
  175. tableHeaderHeight += self.bannerViewHeight;
  176. [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.left.right.mas_equalTo(self.tableHeaderView);
  178. make.top.mas_equalTo(self.tableHeaderView.mas_top);
  179. make.height.mas_equalTo(self.bannerViewHeight);
  180. }];
  181. // button
  182. [self.tableHeaderView addSubview:self.buttonContainer];
  183. self.buttonViewHeight = [HomeButtonView getViewHeight];
  184. [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  185. make.left.right.mas_equalTo(self.tableHeaderView);
  186. make.top.mas_equalTo(self.bannerView.mas_bottom);
  187. make.height.mas_equalTo(self.buttonViewHeight);
  188. }];
  189. tableHeaderHeight += self.buttonViewHeight;
  190. // 课程提醒
  191. [self.tableHeaderView addSubview:self.tipsCourseView];
  192. self.tipsViewHeight = CGFLOAT_MIN;
  193. self.tipsCourseView.hidden = YES;
  194. [self.tipsCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
  195. make.left.right.mas_equalTo(self.tableHeaderView);
  196. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  197. make.height.mas_equalTo(self.tipsViewHeight);
  198. }];
  199. tableHeaderHeight += self.tipsViewHeight;
  200. // 专辑
  201. [self.tableHeaderView addSubview:self.albumView];
  202. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  203. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  204. make.left.right.mas_equalTo(self.tableHeaderView);
  205. make.top.mas_equalTo(self.tipsCourseView.mas_bottom);
  206. make.height.mas_equalTo(self.albumViewHeight);
  207. }];
  208. tableHeaderHeight += self.albumViewHeight;
  209. // 课程
  210. [self.tableHeaderView addSubview:self.courseView];
  211. self.courseViewHeight = [self.courseView getViewHeightWithCount:10];
  212. [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
  213. make.left.right.mas_equalTo(self.tableHeaderView);
  214. make.top.mas_equalTo(self.albumView.mas_bottom);
  215. make.height.mas_equalTo(self.courseViewHeight);
  216. }];
  217. self.courseScroll.contentSize = CGSizeMake(KPortraitWidth * 2, self.courseViewHeight - 59);
  218. [self.courseScroll addSubview:self.liveCourseTable];
  219. [self.liveCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
  220. make.left.mas_equalTo(self.courseScroll);
  221. make.top.bottom.mas_equalTo(self.courseView.courseContainer);
  222. make.width.mas_equalTo(KPortraitWidth);
  223. }];
  224. [self.courseScroll addSubview:self.videoCourseTable];
  225. [self.videoCourseTable mas_makeConstraints:^(MASConstraintMaker *make) {
  226. make.left.mas_equalTo(_courseScroll.mas_left).offset(KPortraitWidth);
  227. make.top.bottom.mas_equalTo(self.courseView.courseContainer);
  228. make.width.mas_equalTo(KPortraitWidth);
  229. }];
  230. tableHeaderHeight += self.courseViewHeight;
  231. // 老师风采
  232. [self.tableHeaderView addSubview:self.teacherView];
  233. self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:4];
  234. [self.teacherView mas_makeConstraints:^(MASConstraintMaker *make) {
  235. make.left.right.mas_equalTo(self.tableHeaderView);
  236. make.top.mas_equalTo(self.courseView.mas_bottom);
  237. make.height.mas_equalTo(self.teachViewHeight);
  238. }];
  239. tableHeaderHeight += self.teachViewHeight;
  240. [self.tableHeaderView addSubview:self.informationHeadView];
  241. self.informationHeight = [HotInformationHeadView getViewHeight];
  242. [self.informationHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
  243. make.left.right.mas_equalTo(self.tableHeaderView);
  244. make.top.mas_equalTo(self.teacherView.mas_bottom);
  245. make.height.mas_equalTo(self.informationHeight);
  246. }];
  247. tableHeaderHeight += self.informationHeight;
  248. self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
  249. [self.tableView reloadData];
  250. }
  251. - (void)refreshTableHeadHeight {
  252. CGFloat tableHeaderHeight = self.bannerViewHeight + self.buttonViewHeight + self.tipsViewHeight + self.albumViewHeight + self.courseViewHeight + self.teachViewHeight + self.informationHeight;
  253. self.tableHeaderView.frame = CGRectMake(0, 0, KPortraitWidth, tableHeaderHeight);
  254. [self.tableView reloadData];
  255. }
  256. - (void)requestData {
  257. [self requestNewsList]; //
  258. [self requestCourseInfo];
  259. [self requestTeacherStyle];
  260. [self requestHotAlbum];
  261. }
  262. - (void)requestNewsList {
  263. [KSNetworkingManager homeNewsList:KS_POST success:^(NSDictionary * _Nonnull dic) {
  264. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  265. NSDictionary *result = [dic dictionaryValueForKey:@"data"];
  266. // banner
  267. NSArray *bannerArray = [result arrayValueForKey:@"banner"];
  268. NSMutableArray *bannerInfoArray = [NSMutableArray array];
  269. for (NSDictionary *parm in bannerArray) {
  270. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  271. [bannerInfoArray addObject:model];
  272. }
  273. self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
  274. [self.bannerScroll reloadData];
  275. // button
  276. NSArray *buttonArray = [result arrayValueForKey:@"appMenu"];
  277. NSMutableArray *buttonInfoArray = [NSMutableArray array];
  278. for (NSDictionary *parm in buttonArray) {
  279. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  280. [buttonInfoArray addObject:model];
  281. }
  282. self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
  283. [self showButtonMessage];
  284. // news
  285. NSArray *flashArray = [result arrayValueForKey:@"flashPage"];
  286. if (flashArray.count) {
  287. HomeMessageModel *newsModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]];
  288. [self showNewsWithSource:newsModel];
  289. }
  290. // information
  291. NSArray *information = [result arrayValueForKey:@"information"];
  292. NSMutableArray *informationInfoArray = [NSMutableArray array];
  293. for (NSDictionary *parm in information) {
  294. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  295. [informationInfoArray addObject:model];
  296. }
  297. self.dataArray = [NSMutableArray arrayWithArray:informationInfoArray];
  298. [self.tableView reloadData];
  299. }
  300. else {
  301. [self MBPShow:MESSAGEKEY];
  302. }
  303. } faliure:^(NSError * _Nonnull error) {
  304. }];
  305. }
  306. - (void)requestHotAlbum {
  307. [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
  308. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  309. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  310. NSMutableArray *albumArray = [NSMutableArray array];
  311. for (NSDictionary *parm in sourceArray) {
  312. HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
  313. [albumArray addObject:model];
  314. }
  315. self.albumArray = [NSMutableArray arrayWithArray:albumArray];
  316. }
  317. else {
  318. [self MBPShow:MESSAGEKEY];
  319. }
  320. [self refreshAlbumView];
  321. } faliure:^(NSError * _Nonnull error) {
  322. }];
  323. }
  324. - (void)refreshAlbumView {
  325. if (self.albumArray.count) {
  326. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  327. self.albumView.hidden = NO;
  328. }
  329. else {
  330. self.albumViewHeight = CGFLOAT_MIN;
  331. self.albumView.hidden = YES;
  332. }
  333. [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
  334. make.height.mas_equalTo(self.albumViewHeight);
  335. }];
  336. [self.albumCollectionView reloadData];
  337. [self refreshTableHeadHeight];
  338. }
  339. - (void)requestCourseInfo {
  340. [self showhud];
  341. [KSNetworkingManager homeQueryLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
  342. [self removehub];
  343. [self.tableView.mj_header endRefreshing];
  344. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  345. NSDictionary *sourceDic = [dic dictionaryValueForKey:@"data"];
  346. NSArray *liveList = [sourceDic arrayValueForKey:@"liveList"];
  347. NSMutableArray *liveCourse = [NSMutableArray array];
  348. for (NSDictionary *parm in liveList) {
  349. HomeLiveGroupModel *model = [[HomeLiveGroupModel alloc] initWithDictionary:parm];
  350. [liveCourse addObject:model];
  351. }
  352. self.liveCourseArray = [NSMutableArray arrayWithArray:liveCourse];
  353. NSArray *videoList = [sourceDic arrayValueForKey:@"videoList"];
  354. NSMutableArray *videoCourse = [NSMutableArray array];
  355. for (NSDictionary *parm in videoList) {
  356. HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
  357. [videoCourse addObject:model];
  358. }
  359. self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
  360. // 最近课程
  361. NSDictionary *parm = [sourceDic dictionaryValueForKey:@"recentCourses"];
  362. if (parm == nil) {
  363. [self refreshCourseView:nil];
  364. }
  365. else {
  366. RecentCourseModel *model = [[RecentCourseModel alloc] initWithDictionary:parm];
  367. [self refreshCourseView:model];
  368. }
  369. }
  370. else {
  371. [self MBPShow:MESSAGEKEY];
  372. }
  373. [self refreshCourseView];
  374. } faliure:^(NSError * _Nonnull error) {
  375. [self removehub];
  376. [self.tableView.mj_header endRefreshing];
  377. }];
  378. }
  379. - (void)refreshCourseView:(RecentCourseModel *)model {
  380. if (model) {
  381. self.tipsViewHeight = 80.0f;
  382. [self.tipsCourseView configWithCourseMessage:model];
  383. self.tipsCourseView.hidden = NO;
  384. [self.tipsCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
  385. make.height.mas_equalTo(80.0f);
  386. }];
  387. }
  388. else {
  389. self.tipsViewHeight = CGFLOAT_MIN;
  390. self.tipsCourseView.hidden = YES;
  391. [self.tipsCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
  392. make.height.mas_equalTo(CGFLOAT_MIN);
  393. }];
  394. }
  395. [self refreshTableHeadHeight];
  396. }
  397. - (void)refreshCourseView {
  398. // 课程
  399. if (self.liveCourseArray.count && self.videoCourseArray.count) {
  400. self.courseCount = self.liveCourseArray.count >= self.videoCourseArray.count ? self.videoCourseArray.count : self.liveCourseArray.count;
  401. // 根据课程返回数据显示高度
  402. self.courseViewHeight = [self.courseView getViewHeightWithCount:self.courseCount];
  403. }
  404. else {
  405. self.courseViewHeight = CGFLOAT_MIN;
  406. }
  407. [self.courseView mas_updateConstraints:^(MASConstraintMaker *make) {
  408. make.height.mas_equalTo(self.courseViewHeight);
  409. }];
  410. [self.liveCourseTable reloadData];
  411. [self.videoCourseTable reloadData];
  412. [self refreshTableHeadHeight];
  413. }
  414. - (void)requestUserInfo:(BOOL)checkSubject {
  415. self.isFirstLoad = NO;
  416. [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  417. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  418. self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  419. NSString *rongToken = UserDefault(RongTokenKey);
  420. if ([NSString isEmptyString:rongToken]) {
  421. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  422. }
  423. [self refreshNavView:checkSubject];
  424. }
  425. else {
  426. [self MBPShow:MESSAGEKEY];
  427. }
  428. } faliure:^(NSError * _Nonnull error) {
  429. }];
  430. }
  431. - (void)requestTeacherStyle {
  432. [KSNetworkingManager homeQueryTeacherStyle:KS_POST page:1 rows:10 success:^(NSDictionary * _Nonnull dic) {
  433. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  434. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  435. NSMutableArray *styleArray = [NSMutableArray array];
  436. for (NSDictionary *parm in sourceArray) {
  437. TeacherStyleModel *model = [[TeacherStyleModel alloc] initWithDictionary:parm];
  438. [styleArray addObject:model];
  439. }
  440. self.teacherArray = [NSMutableArray arrayWithArray:styleArray];
  441. }
  442. else {
  443. [self MBPShow:MESSAGEKEY];
  444. }
  445. // 回调
  446. [self refreshTeachView];
  447. } faliure:^(NSError * _Nonnull error) {
  448. }];
  449. }
  450. - (void)refreshTeachView {
  451. if (self.teacherArray.count) {
  452. self.teachViewHeight = [self.teacherView getViewHeightWithSourceCount:self.teacherArray.count];
  453. self.teacherView.hidden = NO;
  454. }
  455. else {
  456. self.teachViewHeight = CGFLOAT_MIN;
  457. self.teacherView.hidden = YES;
  458. }
  459. [self.teacherView mas_updateConstraints:^(MASConstraintMaker *make) {
  460. make.height.mas_equalTo(self.teachViewHeight);
  461. }];
  462. [self.infoCollectionView reloadData];
  463. [self refreshTableHeadHeight];
  464. }
  465. - (void)refreshNavView:(BOOL)checkSubject {
  466. if (checkSubject) {
  467. if ([NSString isEmptyString:self.mineInfo.subjectName]) {
  468. [self showInstrumentView:YES];
  469. }
  470. else {
  471. [self requestData];
  472. }
  473. }
  474. [self.navView.userAvatal sd_setImageWithURL:[NSURL URLWithString:[self.mineInfo.heardUrl getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  475. NSString *userName = @"";
  476. if ([NSString isEmptyString:self.mineInfo.username]) {
  477. userName = [NSString stringWithFormat:@"游客%@",self.mineInfo.userId];
  478. }
  479. else {
  480. userName = self.mineInfo.username;
  481. }
  482. self.navView.userName.text = userName;
  483. }
  484. - (void)refreshBannaerView {
  485. if (self.bannerArray.count > 1) {
  486. self.bannerScroll.autoScrollInterval = 3.0f;
  487. [self.bannerScroll addSubview:self.pageControl];
  488. }
  489. else {
  490. self.bannerScroll.autoScrollInterval = 0;
  491. [self.pageControl removeFromSuperview];
  492. }
  493. _pageControl.numberOfPages = self.bannerArray.count;
  494. [self.bannerScroll reloadData];
  495. }
  496. - (void)showButtonMessage {
  497. // 添加按钮
  498. if (self.buttonArray.count > 5) { // 大于4个显示底部滚动视图
  499. self.buttonContainer.buttonPageCtrl.hidden = NO;
  500. self.buttonContainer.buttonDotLeft.constant = 0;
  501. NSInteger addPage = (self.buttonArray.count % 5) > 0 ? 1 : 0;
  502. NSInteger pageCount = self.buttonArray.count / 5 + addPage;
  503. self.buttonDotWidth = 36 / pageCount;
  504. self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
  505. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth * pageCount, BUTTONHEIGHT);
  506. }
  507. else {
  508. self.buttonContainer.buttonPageCtrl.hidden = YES;
  509. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, BUTTONHEIGHT);
  510. }
  511. self.buttonScrollView.contentOffset = CGPointMake(0, 0);
  512. [self.buttonScrollView removeAllSubViews];
  513. CGFloat buttonSpace = (kScreenWidth - 5 * BUTTONWIDTH) / 6;
  514. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  515. HomeMessageModel *model = self.buttonArray[i];
  516. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  517. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
  518. buttonView.buttonTitle.text = model.title;
  519. buttonView.frame = CGRectMake(buttonSpace + (i % 5) * (BUTTONWIDTH + buttonSpace) + (i / 5) * KPortraitWidth, 0, BUTTONWIDTH, BUTTONHEIGHT);
  520. buttonView.actionButton.tag = 3000 + i;
  521. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  522. [self.buttonScrollView addSubview:buttonView];
  523. }
  524. }
  525. - (void)HomeTopButtonAction:(UIButton *)sender {
  526. NSInteger index = sender.tag - 3000;
  527. if ([self checkIsLoginToLoginView:YES]) {
  528. HomeMessageModel *model = self.buttonArray[index];
  529. if (![NSString isEmptyString:model.linkUrl]) {
  530. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  531. webCtrl.url = model.linkUrl;
  532. [self.navigationController pushViewController:webCtrl animated:YES];
  533. }
  534. }
  535. }
  536. #pragma mark - TYCyclePagerViewDataSource代理
  537. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  538. return self.bannerArray.count;
  539. }
  540. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  541. HomeMessageModel *model = self.bannerArray[index];
  542. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  543. [cell configCellWithModel:model];
  544. return cell;
  545. }
  546. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  547. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  548. layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
  549. layout.itemSpacing = 0;
  550. return layout;
  551. }
  552. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  553. if (pageView == self.bannerScroll) {
  554. [self.pageControl setCurrentPage:toIndex animate:YES];
  555. }
  556. }
  557. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  558. HomeMessageModel *model = self.bannerArray[index];
  559. if (![NSString isEmptyString:model.linkUrl]) {
  560. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  561. webCtrl.url = model.linkUrl;
  562. [self.navigationController pushViewController:webCtrl animated:YES];
  563. }
  564. }
  565. #pragma mark ----- table data source
  566. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  567. if (tableView == self.tableView) { // 资讯
  568. return self.dataArray.count;
  569. }
  570. else if (tableView == self.liveCourseTable) { // 直播课列表
  571. return self.courseCount;
  572. }
  573. else { // 视频课列表
  574. return self.courseCount;
  575. }
  576. }
  577. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  578. if (tableView == self.tableView) {
  579. HomeMessageModel *model = self.dataArray[indexPath.row];
  580. HomeInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeInformationCell"];
  581. ROWINDEX rowIndex = ROWINDEX_MIDDLE;
  582. if (indexPath.row == 0) {
  583. rowIndex = ROWINDEX_TOP;
  584. }
  585. else if (indexPath.row == self.dataArray.count - 1) {
  586. rowIndex = ROWINDEX_BOTTOM;
  587. }
  588. [cell configCellWithSource:model rowIndex:rowIndex];
  589. return cell;
  590. }
  591. else if (tableView == self.liveCourseTable) {
  592. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
  593. HomeLiveCouseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLiveCouseCell"];
  594. [cell configWithSource:model];
  595. return cell;
  596. }
  597. else {
  598. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  599. HomeVideoCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeVideoCourseCell"];
  600. [cell configWithSource:model];
  601. return cell;
  602. }
  603. }
  604. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  605. if (tableView == self.tableView) {
  606. HomeMessageModel *model = self.dataArray[indexPath.row];
  607. if (![NSString isEmptyString:model.linkUrl]) {
  608. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  609. webCtrl.url = model.linkUrl;
  610. [self.navigationController pushViewController:webCtrl animated:YES];
  611. }
  612. else {
  613. // 跳转
  614. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  615. webCtrl.url = [NSString stringWithFormat:@"%@%@%@",WEBHOST,@"/#/specialdetail?id=",model.internalBaseClassIdentifier];
  616. [self.navigationController pushViewController:webCtrl animated:YES];
  617. }
  618. }
  619. else if (tableView == self.liveCourseTable) { // 直播课详情
  620. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
  621. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  622. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId];
  623. ctrl.url = url;
  624. [self.navigationController pushViewController:ctrl animated:YES];
  625. }
  626. else if (tableView == self.videoCourseTable) { //
  627. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  628. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
  629. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  630. ctrl.url = url;
  631. [self.navigationController pushViewController:ctrl animated:YES];
  632. }
  633. }
  634. #pragma mark ---- collection data source
  635. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  636. return 1;
  637. }
  638. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  639. if (collectionView == self.albumCollectionView) {
  640. return self.albumArray.count;
  641. }
  642. else { // 老师风采
  643. return self.teacherArray.count;
  644. }
  645. }
  646. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  647. if (collectionView == self.albumCollectionView) {
  648. HomeAlbumModel *model = self.albumArray[indexPath.item];
  649. HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
  650. [cell configWithAlbumModel:model];
  651. return cell;
  652. }
  653. else {
  654. TeacherStyleModel *model = self.teacherArray[indexPath.item];
  655. TeacherShowCell *showCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TeacherShowCell" forIndexPath:indexPath];
  656. MJWeakSelf;
  657. [showCell configWithStyleModel:model callback:^(NSString *videoUrl) {
  658. [weakSelf playVideo:videoUrl];
  659. }];
  660. return showCell;
  661. }
  662. }
  663. - (void)playVideo:(NSString *)videoUrl {
  664. if ([NSString isEmptyString:videoUrl]) {
  665. return;
  666. }
  667. // 播放视频
  668. [self playVideoWithUrl:videoUrl];
  669. }
  670. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  671. if (collectionView == self.albumCollectionView) { // 专辑详情
  672. HomeAlbumModel *model = self.albumArray[indexPath.item];
  673. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  674. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
  675. [self.navigationController pushViewController:ctrl animated:YES];
  676. }
  677. else { // 老师风采详情
  678. TeacherStyleModel *model = self.teacherArray[indexPath.item];
  679. [self displayTeacherDetail:model.userId];
  680. }
  681. }
  682. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  683. if (collectionView == self.albumCollectionView) {
  684. return CGSizeMake(110, 140);
  685. }
  686. else {
  687. return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 164);
  688. }
  689. }
  690. // 老师风采
  691. - (void)displayTeacherDetail:(NSString *)teacherId {
  692. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  693. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
  694. [self.navigationController pushViewController:ctrl animated:YES];
  695. }
  696. #pragma mark ---- scroll view delegate
  697. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  698. if (scrollView == self.buttonScrollView) {
  699. NSInteger index = (NSInteger)(scrollView.contentOffset.x / kScreenWidth);
  700. [UIView animateWithDuration:0.3f animations:^{
  701. self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth;
  702. }];
  703. }
  704. else if (scrollView == self.courseScroll) {
  705. }
  706. }
  707. #pragma mark ---- lazying
  708. - (NSMutableArray *)buttonArray {
  709. if (!_buttonArray) {
  710. _buttonArray = [NSMutableArray array];
  711. }
  712. return _buttonArray;
  713. }
  714. - (NSMutableArray *)bannerArray {
  715. if (!_bannerArray) {
  716. _bannerArray = [NSMutableArray array];
  717. }
  718. return _bannerArray;
  719. }
  720. - (NSMutableArray *)albumArray {
  721. if (!_albumArray) {
  722. _albumArray = [NSMutableArray array];
  723. }
  724. return _albumArray;
  725. }
  726. - (NSMutableArray *)liveCourseArray {
  727. if (!_liveCourseArray) {
  728. _liveCourseArray = [NSMutableArray array];
  729. }
  730. return _liveCourseArray;
  731. }
  732. - (NSMutableArray *)videoCourseArray {
  733. if (!_videoCourseArray) {
  734. _videoCourseArray = [NSMutableArray array];
  735. }
  736. return _videoCourseArray;
  737. }
  738. - (NSMutableArray *)teacherArray {
  739. if (!_teacherArray) {
  740. _teacherArray = [NSMutableArray array];
  741. }
  742. return _teacherArray;
  743. }
  744. #pragma mark ----- 最近上课
  745. - (HomeCourseTipsView *)tipsCourseView {
  746. if (!_tipsCourseView) {
  747. _tipsCourseView = [HomeCourseTipsView shareInstance];
  748. MJWeakSelf;
  749. [_tipsCourseView joinRoomCallback:^(COURSETYPE type, RecentCourseModel * _Nonnull courseModel) {
  750. [weakSelf joinRoomAction:type courseMessage:courseModel];
  751. }];
  752. }
  753. return _tipsCourseView;
  754. }
  755. - (void)joinRoomAction:(COURSETYPE)type courseMessage:(RecentCourseModel *)courseModel {
  756. if (type == COURSETYPE_ACCOMPANY) { // 陪练课详情
  757. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  758. detailVC.courseId = courseModel.courseId;
  759. detailVC.courseGroupId = courseModel.courseGroupId;
  760. detailVC.teacherId = courseModel.teacherId;
  761. [self.navigationController pushViewController:detailVC animated:YES];
  762. }
  763. else { // 直播课详情
  764. }
  765. }
  766. #pragma mark ----- 专辑
  767. - (HomeHotAlbumView *)albumView {
  768. if (!_albumView) {
  769. _albumView = [HomeHotAlbumView shareInstance];
  770. MJWeakSelf;
  771. [_albumView homeAlbumMore:^{
  772. [weakSelf moreAlbumDetail];
  773. }];
  774. [_albumView.albumContentView addSubview:self.albumCollectionView];
  775. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  776. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  777. }];
  778. }
  779. return _albumView;
  780. }
  781. - (UICollectionView *)albumCollectionView {
  782. if (!_albumCollectionView) {
  783. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  784. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  785. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  786. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  787. _albumCollectionView.backgroundColor = [UIColor clearColor];
  788. _albumCollectionView.delegate = self;
  789. _albumCollectionView.dataSource = self;
  790. _albumCollectionView.showsVerticalScrollIndicator = NO;
  791. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  792. [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
  793. }
  794. return _albumCollectionView;
  795. }
  796. - (void)moreAlbumDetail {
  797. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  798. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
  799. [self.navigationController pushViewController:ctrl animated:YES];
  800. }
  801. #pragma mark ------ 推荐课程
  802. - (HomeHotCourseView *)courseView {
  803. if (!_courseView) {
  804. _courseView = [HomeHotCourseView shareInstance];
  805. MJWeakSelf;
  806. [_courseView courseActionCallback:^(COURSE_ACTION action) {
  807. [weakSelf homeCourseChooseAction:action];
  808. }];
  809. [_courseView.courseContainer addSubview:self.courseScroll];
  810. [self.courseScroll mas_makeConstraints:^(MASConstraintMaker *make) {
  811. make.left.right.bottom.top.mas_equalTo(_courseView.courseContainer);
  812. }];
  813. }
  814. return _courseView;
  815. }
  816. - (UIScrollView *)courseScroll {
  817. if (!_courseScroll) {
  818. _courseScroll = [[UIScrollView alloc] initWithFrame:CGRectZero];
  819. _courseScroll.pagingEnabled = YES;
  820. _courseScroll.scrollEnabled = NO;
  821. _courseScroll.showsHorizontalScrollIndicator = NO;
  822. _courseScroll.showsVerticalScrollIndicator = NO;
  823. _courseScroll.delegate = self;
  824. }
  825. return _courseScroll;
  826. }
  827. - (UITableView *)liveCourseTable {
  828. if (!_liveCourseTable) {
  829. _liveCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  830. _liveCourseTable.delegate = self;
  831. _liveCourseTable.dataSource = self;
  832. _liveCourseTable.rowHeight = 126;
  833. _liveCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  834. _liveCourseTable.backgroundColor = [UIColor clearColor];
  835. _liveCourseTable.showsVerticalScrollIndicator = NO;
  836. [_liveCourseTable registerNib:[UINib nibWithNibName:@"HomeLiveCouseCell" bundle:nil] forCellReuseIdentifier:@"HomeLiveCouseCell"];
  837. _liveCourseTable.scrollEnabled = NO;
  838. }
  839. return _liveCourseTable;
  840. }
  841. - (UITableView *)videoCourseTable {
  842. if (!_videoCourseTable) {
  843. _videoCourseTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  844. _videoCourseTable.delegate = self;
  845. _videoCourseTable.dataSource = self;
  846. _videoCourseTable.rowHeight = 126;
  847. _videoCourseTable.separatorStyle = UITableViewCellSeparatorStyleNone;
  848. _videoCourseTable.backgroundColor = [UIColor clearColor];
  849. _videoCourseTable.showsVerticalScrollIndicator = NO;
  850. [_videoCourseTable registerNib:[UINib nibWithNibName:@"HomeVideoCourseCell" bundle:nil] forCellReuseIdentifier:@"HomeVideoCourseCell"];
  851. _videoCourseTable.scrollEnabled = NO;
  852. }
  853. return _videoCourseTable;
  854. }
  855. - (void)homeCourseChooseAction:(COURSE_ACTION)action {
  856. switch (action) {
  857. case COURSE_ACTION_LIVE:
  858. {
  859. if (self.isChooseLive == YES) {
  860. return;
  861. }
  862. self.isChooseLive = YES;
  863. }
  864. break;
  865. case COURSE_ACTION_VIDEO:
  866. {
  867. if (self.isChooseLive == NO) {
  868. return;
  869. }
  870. self.isChooseLive = NO;
  871. }
  872. break;
  873. case COURSE_ACTION_MORE: // 更多
  874. {
  875. NSString *url = @"";
  876. if (self.isChooseLive) { // 直播课 列表
  877. url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"];
  878. }
  879. else { // 视频课列表
  880. url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"];
  881. }
  882. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  883. ctrl.url = url;
  884. [self.navigationController pushViewController:ctrl animated:YES];
  885. }
  886. break;
  887. default:
  888. break;
  889. }
  890. }
  891. - (void)setIsChooseLive:(BOOL)isChooseLive {
  892. _isChooseLive = isChooseLive;
  893. // 切换
  894. [UIView animateWithDuration:0.3f animations:^{
  895. if (isChooseLive) {
  896. [self.courseScroll setContentOffset:CGPointZero animated:YES];
  897. }
  898. else {
  899. [self.courseScroll setContentOffset:CGPointMake(KPortraitWidth, 0) animated:YES];
  900. }
  901. }];
  902. }
  903. #pragma mark --- 老师风采
  904. - (HomeIntroduceView *)teacherView {
  905. if (!_teacherView) {
  906. _teacherView = [HomeIntroduceView shareInstance];
  907. MJWeakSelf;
  908. [_teacherView introduceMore:^{
  909. [weakSelf teacherMoreIntorduce];
  910. }];
  911. [_teacherView.teacherContainer addSubview:self.infoCollectionView];
  912. [self.infoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  913. make.bottom.top.mas_equalTo(_teacherView.teacherContainer);
  914. make.left.mas_equalTo(_teacherView.mas_left).offset(14);
  915. make.right.mas_equalTo(_teacherView.mas_right).offset(-14);
  916. }];
  917. }
  918. return _teacherView;
  919. }
  920. - (void)teacherMoreIntorduce {
  921. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  922. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherElegant"];
  923. [self.navigationController pushViewController:ctrl animated:YES];
  924. }
  925. - (UICollectionView *)infoCollectionView {
  926. if (!_infoCollectionView) {
  927. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  928. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  929. _infoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  930. _infoCollectionView.backgroundColor = [UIColor clearColor];
  931. _infoCollectionView.delegate = self;
  932. _infoCollectionView.dataSource = self;
  933. _infoCollectionView.showsVerticalScrollIndicator = NO;
  934. _infoCollectionView.showsHorizontalScrollIndicator = NO;
  935. [_infoCollectionView registerNib:[UINib nibWithNibName:@"TeacherShowCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TeacherShowCell"];
  936. }
  937. return _infoCollectionView;
  938. }
  939. #pragma mark ---- button container
  940. - (HomeButtonView *)buttonContainer {
  941. if (!_buttonContainer) {
  942. _buttonContainer = [HomeButtonView shareInstance];
  943. [_buttonContainer.buttonContentView addSubview:self.buttonScrollView];
  944. }
  945. return _buttonContainer;
  946. }
  947. - (UIScrollView *)buttonScrollView {
  948. if (!_buttonScrollView) {
  949. _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, BUTTONHEIGHT)];
  950. _buttonScrollView.backgroundColor = [UIColor clearColor];
  951. _buttonScrollView.pagingEnabled = YES;
  952. _buttonScrollView.showsHorizontalScrollIndicator = NO;
  953. _buttonScrollView.showsVerticalScrollIndicator = NO;
  954. _buttonScrollView.delegate = self;
  955. }
  956. return _buttonScrollView;
  957. }
  958. - (UIView *)tableHeaderView {
  959. if (!_tableHeaderView) {
  960. _tableHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
  961. _tableHeaderView.backgroundColor = [UIColor clearColor];
  962. }
  963. return _tableHeaderView;
  964. }
  965. - (HomeBannerView *)bannerView {
  966. if (!_bannerView) {
  967. _bannerView = [HomeBannerView shareInstance];
  968. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  969. }
  970. return _bannerView;
  971. }
  972. - (TYCyclePagerView *)bannerScroll {
  973. if (!_bannerScroll) {
  974. _bannerScroll = [[TYCyclePagerView alloc] init];
  975. _bannerScroll.backgroundColor = [UIColor clearColor];
  976. _bannerScroll.frame = CGRectMake(0, 0, kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
  977. _bannerScroll.isInfiniteLoop = YES;
  978. _bannerScroll.autoScrollInterval = 3.0f;
  979. _bannerScroll.reloadDataNeedResetIndex = YES;
  980. _bannerScroll.dataSource = self;
  981. _bannerScroll.delegate = self;
  982. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  983. }
  984. return _bannerScroll;
  985. }
  986. #pragma mark ---- 更多资讯
  987. - (HotInformationHeadView *)informationHeadView {
  988. if (!_informationHeadView) {
  989. _informationHeadView = [HotInformationHeadView shareInstance];
  990. MJWeakSelf;
  991. [_informationHeadView moreInformationCallback:^{
  992. [weakSelf moreInformation];
  993. }];
  994. }
  995. return _informationHeadView;
  996. }
  997. - (void)moreInformation {
  998. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  999. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/special"];
  1000. [self.navigationController pushViewController:ctrl animated:YES];
  1001. }
  1002. - (UITableView *)tableView {
  1003. if (!_tableView) {
  1004. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  1005. _tableView.delegate = self;
  1006. _tableView.dataSource = self;
  1007. _tableView.rowHeight = 108;
  1008. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  1009. _tableView.backgroundColor = [UIColor clearColor];
  1010. _tableView.showsVerticalScrollIndicator = NO;
  1011. [_tableView registerNib:[UINib nibWithNibName:@"HomeInformationCell" bundle:nil] forCellReuseIdentifier:@"HomeInformationCell"];
  1012. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  1013. bottomView.backgroundColor = [UIColor clearColor];
  1014. _tableView.tableFooterView = bottomView;
  1015. }
  1016. return _tableView;
  1017. }
  1018. - (HomeNavView *)navView {
  1019. if (!_navView) {
  1020. _navView = [HomeNavView shareInstance];
  1021. MJWeakSelf;
  1022. [_navView homeNavAction:^(NAVACTION action) {
  1023. [weakSelf navAction:action];
  1024. }];
  1025. }
  1026. return _navView;
  1027. }
  1028. - (void)navAction:(NAVACTION)action {
  1029. if (action == NAVACTION_SUBJECT) {
  1030. [self showInstrumentView:NO];
  1031. }
  1032. else { // 消息中心
  1033. NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init];
  1034. [self.navigationController pushViewController:ctrl animated:YES];
  1035. }
  1036. }
  1037. - (void)showInstrumentView:(BOOL)hideBackButton {
  1038. SubjectChooseViewController *ctrl = [[SubjectChooseViewController alloc] init];
  1039. MJWeakSelf;
  1040. [ctrl chooseSubjectCallback:^{
  1041. [weakSelf requestUserInfo:NO];
  1042. [weakSelf requestData];
  1043. }];
  1044. if (hideBackButton) {
  1045. ctrl.isModalPresent = YES;
  1046. CustomNavViewController *navCrtl = [[CustomNavViewController alloc] initWithRootViewController:ctrl];
  1047. navCrtl.modalPresentationStyle = UIModalPresentationFullScreen;
  1048. [self.navigationController presentViewController:navCrtl animated:YES completion:nil];
  1049. }
  1050. else {
  1051. [self.navigationController pushViewController:ctrl animated:YES];
  1052. }
  1053. }
  1054. #pragma mark ------ WMPlayer
  1055. - (void)playVideoWithUrl:(NSString *)fileUrl {
  1056. fileUrl = [fileUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  1057. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  1058. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  1059. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  1060. playModel.videoURL = [NSURL URLWithString:fileUrl];
  1061. _wmPlayer.playerModel = playModel;
  1062. _wmPlayer.delegate = self;
  1063. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  1064. _bgView.backgroundColor = [UIColor blackColor];
  1065. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  1066. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  1067. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  1068. [_wmPlayer play];
  1069. }
  1070. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  1071. [wmplayer removePlayer];
  1072. [_bgView removeFromSuperview];
  1073. [self setNeedsStatusBarAppearanceUpdate];
  1074. }
  1075. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  1076. self.isRatation = !self.isRatation;
  1077. if (self.isRatation) {
  1078. [wmplayer removeFromSuperview];
  1079. [UIView animateWithDuration:1.0f animations:^{
  1080. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  1081. } completion:^(BOOL finished) {
  1082. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  1083. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  1084. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  1085. }];
  1086. }
  1087. else {
  1088. [wmplayer removeFromSuperview];
  1089. [UIView animateWithDuration:1.0f animations:^{
  1090. // 复原
  1091. wmplayer.transform = CGAffineTransformIdentity;
  1092. } completion:^(BOOL finished) {
  1093. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  1094. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  1095. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  1096. }];
  1097. }
  1098. }
  1099. - (void)dealloc {
  1100. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1101. }
  1102. - (void)showNewsWithSource:(HomeMessageModel *)sourceModel {
  1103. // 登录之后才弹窗
  1104. if ([self checkIsLoginToLoginView:NO]) {
  1105. NSString *useId = UserDefault(UIDKey);
  1106. NSMutableArray *newArray = UserDefault(useId);
  1107. if (newArray.count) {
  1108. if ([newArray containsObject:sourceModel.coverImage]) {
  1109. return;
  1110. }
  1111. else {
  1112. [self displayAlert:sourceModel];
  1113. }
  1114. }
  1115. else {
  1116. [self displayAlert:sourceModel];
  1117. }
  1118. }
  1119. }
  1120. - (void)displayAlert:(HomeMessageModel *)sourceModel {
  1121. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1122. if (appDelegate.isShowMemoAlert) {
  1123. return;
  1124. }
  1125. NSString *useId = UserDefault(UIDKey);
  1126. UserDefaultRemoveObjectForKey(useId);
  1127. NSMutableArray *sourceArray = [NSMutableArray arrayWithArray:UserDefault(useId)];
  1128. [sourceArray addObject:sourceModel.coverImage];
  1129. UserDefaultSetObjectForKey(sourceArray, useId);
  1130. KSNewsAlert *newAlert = [KSNewsAlert shareInstance];
  1131. MJWeakSelf;
  1132. [newAlert evaluateWithMessage:sourceModel.coverImage linkUrl:sourceModel.linkUrl callbackAction:^(BOOL isSure, NSString * _Nonnull linkUrl) {
  1133. appDelegate.isShowFlashAlert = NO;
  1134. if (isSure) {
  1135. if (![NSString isEmptyString:linkUrl]) {
  1136. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1137. webCtrl.url = [linkUrl getUrlEndcodeString];
  1138. [weakSelf.navigationController pushViewController:webCtrl animated:YES];
  1139. }
  1140. }
  1141. [appDelegate showMemoAlert]; // 检测是否需要弹窗版本更新
  1142. }];
  1143. [newAlert showAlert];
  1144. appDelegate.isShowFlashAlert = YES;
  1145. }
  1146. /*
  1147. #pragma mark - Navigation
  1148. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1149. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1150. // Get the new view controller using [segue destinationViewController].
  1151. // Pass the selected object to the new view controller.
  1152. }
  1153. */
  1154. @end