HomeViewController.m 56 KB

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