HomeViewController.m 49 KB

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