HomeViewController.m 61 KB

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