HomeViewController.m 50 KB

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