HomeViewController.m 61 KB

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