NewHomeViewController.m 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. //
  2. // NewHomeViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/8/29.
  6. //
  7. #import "NewHomeViewController.h"
  8. #import "KSBaseWKWebViewController.h"
  9. #import "NotiferMessageViewController.h"
  10. #import "HomeNavSearchView.h"
  11. #import "KSScanViewController.h"
  12. #import "HomeBannerView.h"
  13. #import <UIButton+WebCache.h>
  14. #import "TYCyclePagerView.h"
  15. #import "TYPageControl.h"
  16. #import "HomeBannerCell.h"
  17. #import "HomeBannerCell.h"
  18. #import "HomeButtonView.h"
  19. #import "KSHomeButton.h"
  20. #import "PublicNoticeView.h"
  21. #import "SDCycleScrollView.h"
  22. #import "NoticeSourceModel.h"
  23. #import "AppDelegate.h"
  24. #import "StudentInfoModel.h"
  25. #import "UserInfoManager.h"
  26. #import "HomeRecentCourseView.h"
  27. #import "AccompanyDetailViewController.h"
  28. #import "MusicRoomDetailViewController.h"
  29. #import "HomeHotAlbumView.h"
  30. #import "HomeAlbumModel.h"
  31. #import "HomeHotAlbumCell.h"
  32. #import "HomeHotMusicView.h"
  33. #import "HomeHotMusicCollectionCell.h"
  34. #import "KSPremissionAlert.h"
  35. #import "RecordCheckManager.h"
  36. #import "KSAccompanyWebViewController.h"
  37. #import "HomeHotTalentView.h"
  38. #import "HomeHotTalentCell.h"
  39. #import "TalentTeacherModel.h"
  40. #import "HomeHotVideoCourseView.h"
  41. #import "HomeHotVideoCell.h"
  42. #import "HomeVideoGroupModel.h"
  43. #import "HomeHotLiveCourseView.h"
  44. #import "HomeHotLiveCell.h"
  45. #import "HomeLiveGroupModel.h"
  46. #import "JXCategoryView.h"
  47. #import "JXPagerListRefreshView.h"
  48. #import "HomePageBodyView.h"
  49. #import "HomeInformationBodyView.h"
  50. #define BUTTONWIDTH (65)
  51. #define BUTTONHEIGHT (80)
  52. @interface NewHomeViewController ()<JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate,SDCycleScrollViewDelegate,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  53. @property (nonatomic, strong) StudentInfoModel *mineInfo;
  54. @property (nonatomic, strong) HomeNavSearchView *navView;
  55. @property (nonatomic, strong) HomeMessageModel *flashModel;
  56. @property (nonatomic, assign) BOOL isFirstLoad;
  57. // banner
  58. @property (nonatomic, strong) TYPageControl *pageControl;
  59. @property (nonatomic, strong) HomeBannerView *bannerView; // banner container
  60. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  61. @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
  62. @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
  63. // 按钮
  64. @property (nonatomic, strong) HomeButtonView *buttonContainer; // button container
  65. @property (nonatomic, strong) UIScrollView *buttonScrollView;
  66. @property (nonatomic, strong) NSMutableArray *buttonArray; // button 内容
  67. @property (nonatomic, assign) NSInteger buttonDotWidth;
  68. @property (nonatomic, assign) CGFloat buttonViewHeight; // button view 高度
  69. // 公告
  70. @property (nonatomic, strong) PublicNoticeView *noticeView;
  71. @property (nonatomic, strong) SDCycleScrollView *noticeScrollView;
  72. @property (nonatomic, strong) NSMutableArray *noticeArray; // notice数据
  73. @property (nonatomic, strong) NSMutableArray *noticeTitleArray; // 标题数组
  74. @property (nonatomic, assign) CGFloat noticeViewHeight;
  75. // 最近课程
  76. @property (nonatomic, strong) HomeRecentCourseView *courseView;
  77. @property (nonatomic, assign) CGFloat courseViewHeight;
  78. @property (nonatomic, strong) RecentCourseModel *recentCourseModel;
  79. // 热门专辑
  80. @property (nonatomic, strong) HomeHotAlbumView *albumView;
  81. @property (nonatomic, strong) NSMutableArray *albumArray;
  82. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  83. @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
  84. // 热门曲谱
  85. @property (nonatomic, strong) HomeHotMusicView *hotMusicView;
  86. @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
  87. @property (nonatomic, strong) NSMutableArray *musicArray; // 曲谱数据
  88. @property (nonatomic, assign) CGFloat musicViewHeight; // music 高度
  89. // 推荐达人
  90. @property (nonatomic, strong) HomeHotTalentView *talentView;
  91. @property (nonatomic, strong) UICollectionView *talentCollectionView; // 推荐达人容器
  92. @property (nonatomic, strong) NSMutableArray *talentArray; // 推荐达人数据
  93. @property (nonatomic, assign) CGFloat talentViewHeight; // talent 高度
  94. // 视频课
  95. @property (nonatomic, strong) HomeHotVideoCourseView *videoCourseView;
  96. @property (nonatomic, strong) UICollectionView *videoCollectionView; // 视频课容器
  97. @property (nonatomic, strong) NSMutableArray *videoCourseArray; // 视频课数据
  98. @property (nonatomic, assign) CGFloat videoViewHeight; // video 高度
  99. // 直播课
  100. @property (nonatomic, strong) HomeHotLiveCourseView *liveCourseView;
  101. @property (nonatomic, strong) UICollectionView *liveCollectionView; // 直播课容器
  102. @property (nonatomic, strong) NSMutableArray *liveCourseArray; // 直播课数据
  103. @property (nonatomic, assign) CGFloat liveViewHeight; // live 高度
  104. @property (nonatomic, strong) dispatch_group_t requestGroup;
  105. // 顶部数据容器
  106. @property (nonatomic, strong) UIView *headView;
  107. @property (nonatomic, strong) JXCategoryTitleView *myCategoryView;
  108. @property (nonatomic, assign) NSInteger currentIndex;
  109. @property (nonatomic, strong) NSMutableArray *listViewArray;
  110. @property (nonatomic, assign) CGFloat headViewHeight;
  111. @end
  112. @implementation NewHomeViewController
  113. - (void)viewDidLoad {
  114. [super viewDidLoad];
  115. // Do any additional setup after loading the view.
  116. self.ks_prefersNavigationBarHidden = YES;
  117. _titles = @[@"达人风采",@"热门资讯"];
  118. self.isFirstLoad = YES;
  119. [self configNavView];
  120. [self configUI];
  121. [self requestData];
  122. }
  123. - (void)requestTrackAuth {
  124. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  125. [appDelegate appTrackActionAuth];
  126. }
  127. - (void)configNavView {
  128. [self.scrollView removeFromSuperview];
  129. [self.view addSubview:self.navView];
  130. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.left.right.top.mas_equalTo(self.view);
  132. make.height.mas_equalTo(kNaviBarHeight);
  133. }];
  134. // [self.view bringSubviewToFront:self.scrollView];
  135. [self.view bringSubviewToFront:self.navView];
  136. // [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  137. // make.left.right.mas_equalTo(self.view);
  138. // make.top.mas_equalTo(self.view.mas_top).offset(kNaviBarHeight);
  139. // make.bottom.mas_equalTo(self.view.mas_bottom);
  140. // }];
  141. // self.scrollView.backgroundColor = [UIColor clearColor];
  142. // self.scrollView.scrollEnabled = NO;
  143. // MJWeakSelf;
  144. // self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  145. // [weakSelf requestData];
  146. // }];
  147. }
  148. - (void)configHeadView {
  149. UIView *headBgView = [[UIView alloc] init];
  150. headBgView.backgroundColor = [UIColor whiteColor];
  151. [self.headView addSubview:headBgView];
  152. // banner
  153. [self.headView addSubview:self.bannerView];
  154. self.bannerViewHeight = [HomeBannerView getViewHeight];
  155. [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
  156. make.left.right.top.mas_equalTo(self.headView);
  157. make.height.mas_equalTo(self.bannerViewHeight);
  158. }];
  159. // 按钮
  160. [self.headView addSubview:self.buttonContainer];
  161. self.buttonViewHeight = CGFLOAT_MIN;
  162. [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  163. make.left.right.mas_equalTo(self.headView);
  164. make.top.mas_equalTo(self.bannerView.mas_bottom);
  165. make.height.mas_equalTo(CGFLOAT_MIN);
  166. }];
  167. self.buttonContainer.hidden = YES;
  168. // 公告
  169. [self.headView addSubview:self.noticeView];
  170. self.noticeViewHeight = CGFLOAT_MIN;
  171. [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
  172. make.left.right.mas_equalTo(self.headView);
  173. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  174. make.height.mas_equalTo(CGFLOAT_MIN);
  175. }];
  176. [self.noticeView.adView addSubview:self.noticeScrollView];
  177. [self.noticeScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  178. make.top.left.right.bottom.mas_equalTo(self.noticeView.adView);
  179. }];
  180. self.noticeView.hidden = YES;
  181. // 最近课程
  182. [self.headView addSubview:self.courseView];
  183. self.courseViewHeight = CGFLOAT_MIN;
  184. [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
  185. make.left.right.mas_equalTo(self.headView);
  186. make.top.mas_equalTo(self.noticeView.mas_bottom);
  187. make.height.mas_equalTo(CGFLOAT_MIN);
  188. }];
  189. self.courseView.hidden = YES;
  190. // 热门专辑
  191. [self.headView addSubview:self.albumView];
  192. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  193. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  194. make.left.right.mas_equalTo(self.headView);
  195. make.top.mas_equalTo(self.courseView.mas_bottom);
  196. make.height.mas_equalTo(self.albumViewHeight);
  197. }];
  198. // 热门曲目
  199. [self.headView addSubview:self.hotMusicView];
  200. self.musicViewHeight = [HomeHotMusicView getViewHeight];
  201. [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  202. make.left.right.mas_equalTo(self.headView);
  203. make.top.mas_equalTo(self.albumView.mas_bottom);
  204. make.height.mas_equalTo(self.musicViewHeight);
  205. }];
  206. // 推荐达人
  207. [self.headView addSubview:self.talentView];
  208. self.talentViewHeight = CGFLOAT_MIN;
  209. [self.talentView mas_makeConstraints:^(MASConstraintMaker *make) {
  210. make.left.right.mas_equalTo(self.headView);
  211. make.top.mas_equalTo(self.hotMusicView.mas_bottom);
  212. make.height.mas_equalTo(self.talentViewHeight);
  213. }];
  214. self.talentView.hidden = YES;
  215. // 视频课
  216. [self.headView addSubview:self.videoCourseView];
  217. self.videoViewHeight = CGFLOAT_MIN;
  218. [self.videoCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
  219. make.left.right.mas_equalTo(self.headView);
  220. make.top.mas_equalTo(self.talentView.mas_bottom);
  221. make.height.mas_equalTo(self.videoViewHeight);
  222. }];
  223. self.videoCourseView.hidden = YES;
  224. // 直播
  225. [self.headView addSubview:self.liveCourseView];
  226. self.liveViewHeight = CGFLOAT_MIN;
  227. [self.liveCourseView mas_makeConstraints:^(MASConstraintMaker *make) {
  228. make.left.right.mas_equalTo(self.headView);
  229. make.top.mas_equalTo(self.videoCourseView.mas_bottom);
  230. make.height.mas_equalTo(self.liveViewHeight);
  231. }];
  232. self.liveCourseView.hidden = YES;
  233. [headBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  234. make.left.right.mas_equalTo(self.headView);
  235. make.top.mas_equalTo(self.bannerView.mas_top);
  236. make.bottom.mas_equalTo(self.buttonContainer.mas_bottom);
  237. }];
  238. headBgView.layer.masksToBounds = YES;
  239. headBgView.layer.cornerRadius = 10.0f;
  240. headBgView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
  241. [self refreshHeadHeight];
  242. }
  243. - (void)refreshHeadHeight {
  244. self.headViewHeight = self.bannerViewHeight + self.buttonViewHeight + self.noticeViewHeight + self.courseViewHeight + self.albumViewHeight + self.musicViewHeight + self.talentViewHeight + self.liveViewHeight + self.videoViewHeight;
  245. [self.pagerView reloadData];
  246. }
  247. - (void)configUI {
  248. [self configHeadView];
  249. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, kNaviBarHeight, kScreenWidth, 50)];
  250. self.categoryView.backgroundColor = [UIColor clearColor];
  251. self.categoryView.titles = self.titles;
  252. self.categoryView.delegate = self;
  253. self.categoryView.titleFont = [UIFont systemFontOfSize:16.0f];
  254. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
  255. self.categoryView.titleSelectedColor = HexRGB(0x000000);
  256. self.categoryView.titleColor = HexRGB(0x808080);
  257. self.categoryView.titleColorGradientEnabled = YES;
  258. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  259. lineView.indicatorColor = THEMECOLOR;
  260. lineView.indicatorWidth = 55;
  261. self.categoryView.indicators = @[lineView];
  262. _pagerView = [self preferredPagingView];
  263. self.pagerView.frame = CGRectMake(0, kNaviBarHeight, kScreenWidth, kScreenHeight - kNaviBarHeight - kTabBarHeight);
  264. self.pagerView.mainTableView.gestureDelegate = self;
  265. [self.view addSubview:self.pagerView];
  266. self.pagerView.backgroundColor = [UIColor clearColor];
  267. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  268. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  269. }
  270. - (void)viewDidAppear:(BOOL)animated {
  271. [super viewDidAppear:animated];
  272. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  273. }
  274. - (JXPagerView *)preferredPagingView {
  275. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  276. }
  277. - (void)viewWillAppear:(BOOL)animated {
  278. [super viewWillAppear:animated];
  279. if (self.isFirstLoad == YES) {
  280. [self requestUserInfo:YES]; // 获取声部
  281. [self requestTrackAuth];
  282. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  283. [appDelegate handleNotiferSource];
  284. }
  285. else {
  286. [self requestUserInfo:YES];
  287. }
  288. [self requestUnreadCount];
  289. }
  290. - (void)requestUnreadCount {
  291. [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  292. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  293. NSArray *countArray = [dic arrayValueForKey:@"data"];
  294. NSInteger courseCount = 0;
  295. NSInteger sysCount = 0;
  296. for (NSDictionary *parm in countArray) {
  297. if ([[parm stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
  298. courseCount = [parm integerValueForKey:@"value"];
  299. }
  300. if ([[parm stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
  301. sysCount = [parm integerValueForKey:@"value"];
  302. }
  303. }
  304. if (courseCount != 0 || sysCount != 0) {
  305. self.navView.dotView.hidden = NO;
  306. }
  307. else {
  308. self.navView.dotView.hidden = YES;
  309. }
  310. }
  311. else {
  312. [self MBPShow:MESSAGEKEY];
  313. }
  314. } faliure:^(NSError * _Nonnull error) {
  315. }];
  316. }
  317. - (void)requestUserInfo:(BOOL)checkSubject {
  318. self.isFirstLoad = NO;
  319. [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  320. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  321. self.mineInfo = [[StudentInfoModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  322. NSString *rongToken = UserDefault(RongTokenKey);
  323. if ([NSString isEmptyString:rongToken]) {
  324. [USER_MANAGER queryUserInfoConnectRongCloud:YES];
  325. }
  326. // [self refreshNavView:checkSubject];
  327. }
  328. else {
  329. [self MBPShow:MESSAGEKEY];
  330. }
  331. } faliure:^(NSError * _Nonnull error) {
  332. }];
  333. }
  334. - (void)requestNewsList {
  335. dispatch_group_enter(self.requestGroup);
  336. [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  337. dispatch_group_leave(self.requestGroup);
  338. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  339. NSDictionary *result = [dic dictionaryValueForKey:@"data"];
  340. // banner
  341. NSArray *bannerArray = [result arrayValueForKey:@"banner"];
  342. NSMutableArray *bannerInfoArray = [NSMutableArray array];
  343. for (NSDictionary *parm in bannerArray) {
  344. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  345. [bannerInfoArray addObject:model];
  346. }
  347. self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
  348. // button
  349. NSArray *buttonArray = [result arrayValueForKey:@"appMenu"];
  350. NSMutableArray *buttonInfoArray = [NSMutableArray array];
  351. for (NSDictionary *parm in buttonArray) {
  352. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  353. [buttonInfoArray addObject:model];
  354. }
  355. self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
  356. // news
  357. NSArray *flashArray = [result arrayValueForKey:@"flashPage"];
  358. if (flashArray.count) {
  359. self.flashModel = [[HomeMessageModel alloc] initWithDictionary:[flashArray firstObject]];
  360. }
  361. // information
  362. NSArray *information = [result arrayValueForKey:@"information"];
  363. NSMutableArray *informationInfoArray = [NSMutableArray array];
  364. for (NSDictionary *parm in information) {
  365. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  366. [informationInfoArray addObject:model];
  367. }
  368. self.dataArray = [NSMutableArray arrayWithArray:informationInfoArray];
  369. }
  370. else {
  371. [self MBPShow:MESSAGEKEY];
  372. }
  373. } faliure:^(NSError * _Nonnull error) {
  374. dispatch_group_leave(self.requestGroup);
  375. }];
  376. }
  377. - (void)requestHotAlbum {
  378. dispatch_group_enter(self.requestGroup);
  379. [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  380. dispatch_group_leave(self.requestGroup);
  381. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  382. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  383. NSMutableArray *albumArray = [NSMutableArray array];
  384. for (NSDictionary *parm in sourceArray) {
  385. HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
  386. [albumArray addObject:model];
  387. }
  388. self.albumArray = [NSMutableArray arrayWithArray:albumArray];
  389. }
  390. else {
  391. [self MBPShow:MESSAGEKEY];
  392. }
  393. } faliure:^(NSError * _Nonnull error) {
  394. dispatch_group_leave(self.requestGroup);
  395. }];
  396. }
  397. - (void)requestCourseInfo {
  398. dispatch_group_enter(self.requestGroup);
  399. [KSNetworkingManager homeQueryLiveAndVideo:KS_GET version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  400. dispatch_group_leave(self.requestGroup);
  401. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  402. NSDictionary *sourceDic = [dic dictionaryValueForKey:@"data"];
  403. NSArray *liveList = [sourceDic arrayValueForKey:@"liveList"];
  404. NSMutableArray *liveCourse = [NSMutableArray array];
  405. for (NSDictionary *parm in liveList) {
  406. HomeLiveGroupModel *model = [[HomeLiveGroupModel alloc] initWithDictionary:parm];
  407. [liveCourse addObject:model];
  408. }
  409. self.liveCourseArray = [NSMutableArray arrayWithArray:liveCourse];
  410. NSArray *videoList = [sourceDic arrayValueForKey:@"videoList"];
  411. NSMutableArray *videoCourse = [NSMutableArray array];
  412. for (NSDictionary *parm in videoList) {
  413. HomeVideoGroupModel *model = [[HomeVideoGroupModel alloc] initWithDictionary:parm];
  414. [videoCourse addObject:model];
  415. }
  416. self.videoCourseArray = [NSMutableArray arrayWithArray:videoCourse];
  417. // 最近课程
  418. NSDictionary *parm = [sourceDic dictionaryValueForKey:@"recentCourses"];
  419. if (parm == nil) {
  420. self.recentCourseModel = nil;
  421. }
  422. else {
  423. self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
  424. }
  425. }
  426. else {
  427. [self MBPShow:MESSAGEKEY];
  428. }
  429. } faliure:^(NSError * _Nonnull error) {
  430. dispatch_group_leave(self.requestGroup);
  431. }];
  432. }
  433. - (void)requestNotice {
  434. dispatch_group_enter(self.requestGroup);
  435. [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  436. dispatch_group_leave(self.requestGroup);
  437. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  438. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  439. if (sourceArray.count) {
  440. NSDictionary *parm = [sourceArray firstObject];
  441. NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm];
  442. [self.noticeArray addObject:bannerModel];
  443. [self.noticeTitleArray addObject:bannerModel.title];
  444. }
  445. else {
  446. self.noticeArray = [NSMutableArray array];
  447. self.noticeTitleArray = [NSMutableArray array];
  448. }
  449. }
  450. else {
  451. [self MBPShow:MESSAGEKEY];
  452. }
  453. } faliure:^(NSError * _Nonnull error) {
  454. dispatch_group_leave(self.requestGroup);
  455. }];
  456. }
  457. - (void)requestHotMusic {
  458. dispatch_group_enter(self.requestGroup);
  459. [KSNetworkingManager homeMusicListRequest:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  460. dispatch_group_leave(self.requestGroup);
  461. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  462. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  463. NSMutableArray *musicArray = [NSMutableArray array];
  464. for (NSDictionary *parm in sourceArray) {
  465. HomeHotMusicModel *model = [[HomeHotMusicModel alloc] initWithDictionary:parm];
  466. [musicArray addObject:model];
  467. }
  468. self.musicArray = [NSMutableArray arrayWithArray:musicArray];
  469. }
  470. else {
  471. [self MBPShow:MESSAGEKEY];
  472. }
  473. } faliure:^(NSError * _Nonnull error) {
  474. dispatch_group_leave(self.requestGroup);
  475. }];
  476. }
  477. - (void)requestTalentSource {
  478. dispatch_group_enter(self.requestGroup);
  479. [KSNetworkingManager queryHotTeacherListRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  480. dispatch_group_leave(self.requestGroup);
  481. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  482. NSArray *sourceArray = [dic arrayValueForKey:@"data"];
  483. NSMutableArray *talentArray = [NSMutableArray array];
  484. for (NSDictionary *parm in sourceArray) {
  485. TalentTeacherModel *model = [[TalentTeacherModel alloc] initWithDictionary:parm];
  486. [talentArray addObject:model];
  487. }
  488. self.talentArray = [NSMutableArray arrayWithArray:talentArray];
  489. }
  490. else {
  491. [self MBPShow:MESSAGEKEY];
  492. }
  493. } faliure:^(NSError * _Nonnull error) {
  494. dispatch_group_leave(self.requestGroup);
  495. }];
  496. }
  497. - (void)requestData {
  498. [self showhud];
  499. [self requestNewsList];
  500. [self requestNotice];
  501. [self requestCourseInfo];
  502. // 达人
  503. [self requestTalentSource];
  504. [self requestHotAlbum];
  505. [self requestHotMusic];
  506. dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
  507. [self removehub];
  508. [self.scrollView.mj_header endRefreshing];
  509. [self refreshView];
  510. });
  511. }
  512. - (void)refreshView {
  513. [self refreshBannaerView];
  514. [self showButtonMessage];
  515. [self refreshNotice];
  516. [self refreshCourseView:self.recentCourseModel];
  517. [self refreshAlbumView];
  518. [self refreshMusicView];
  519. // 达人
  520. [self refreshTalentView];
  521. // 课程
  522. [self refreshCourseView];
  523. // 刷新排序
  524. [self refreshViewLocation];
  525. [self refreshHeadHeight];
  526. }
  527. - (void)refreshTalentView {
  528. if (self.talentArray.count) {
  529. self.talentViewHeight = [HomeHotTalentView getViewHeight];
  530. self.talentView.hidden = NO;
  531. }
  532. else {
  533. self.talentViewHeight = CGFLOAT_MIN;
  534. self.talentView.hidden = YES;
  535. }
  536. [self.talentView mas_updateConstraints:^(MASConstraintMaker *make) {
  537. make.height.mas_equalTo(self.talentViewHeight);
  538. }];
  539. [self.talentCollectionView reloadData];
  540. }
  541. - (void)refreshViewLocation {
  542. // 如果有课程和公告 且有按钮
  543. CGFloat buttonViewDefaultHeight = self.buttonArray.count > 5 ? [HomeButtonView getViewHeight] : [HomeButtonView getViewHeight] - 20;
  544. if (self.noticeTitleArray.count && self.recentCourseModel && self.buttonArray.count) {
  545. self.noticeViewHeight = [PublicNoticeView getViewHeight];
  546. [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) {
  547. make.left.right.mas_equalTo(self.headView);
  548. make.top.mas_equalTo(self.bannerView.mas_bottom);
  549. make.height.mas_equalTo(self.noticeViewHeight);
  550. }];
  551. self.buttonViewHeight = buttonViewDefaultHeight;
  552. [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
  553. make.left.right.mas_equalTo(self.headView);
  554. make.top.mas_equalTo(self.noticeView.mas_bottom);
  555. make.height.mas_equalTo(self.buttonViewHeight);
  556. }];
  557. [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
  558. make.left.right.mas_equalTo(self.view);
  559. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  560. make.height.mas_equalTo(91.0f);
  561. }];
  562. }
  563. else {
  564. self.buttonViewHeight = self.buttonArray.count ? buttonViewDefaultHeight : CGFLOAT_MIN;
  565. [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
  566. make.left.right.mas_equalTo(self.headView);
  567. make.top.mas_equalTo(self.bannerView.mas_bottom);
  568. make.height.mas_equalTo(self.buttonViewHeight);
  569. }];
  570. self.noticeViewHeight = self.noticeTitleArray.count ? [PublicNoticeView getViewHeight] : CGFLOAT_MIN;
  571. [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) {
  572. make.left.right.mas_equalTo(self.headView);
  573. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  574. make.height.mas_equalTo(self.noticeViewHeight);
  575. }];
  576. CGFloat courseViewHeight = self.recentCourseModel ? 90.0f : CGFLOAT_MIN;
  577. [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
  578. make.left.right.mas_equalTo(self.headView);
  579. make.top.mas_equalTo(self.noticeView.mas_bottom);
  580. make.height.mas_equalTo(courseViewHeight);
  581. }];
  582. }
  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) {
  599. self.buttonContainer.hidden = NO;
  600. if (self.buttonArray.count > 5) { // 大于4个显示底部滚动视图
  601. self.buttonContainer.buttonPageCtrl.hidden = NO;
  602. self.buttonContainer.buttonDotLeft.constant = 0;
  603. NSInteger addPage = (self.buttonArray.count % 5) > 0 ? 1 : 0;
  604. NSInteger pageCount = self.buttonArray.count / 5 + addPage;
  605. self.buttonDotWidth = 36 / pageCount;
  606. self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
  607. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth * pageCount, BUTTONHEIGHT);
  608. }
  609. else {
  610. self.buttonContainer.buttonPageCtrl.hidden = YES;
  611. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, BUTTONHEIGHT);
  612. }
  613. }
  614. else {
  615. self.buttonContainer.hidden = YES;
  616. self.buttonContainer.buttonPageCtrl.hidden = YES;
  617. self.buttonScrollView.contentSize = CGSizeMake(kScreenWidth, CGFLOAT_MIN);
  618. }
  619. self.buttonScrollView.contentOffset = CGPointMake(0, 0);
  620. [self.buttonScrollView removeAllSubViews];
  621. CGFloat buttonSpace = (kScreenWidth - 5 * BUTTONWIDTH) / 6;
  622. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  623. HomeMessageModel *model = self.buttonArray[i];
  624. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  625. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
  626. buttonView.buttonTitle.text = model.title;
  627. buttonView.frame = CGRectMake(buttonSpace + (i % 5) * (BUTTONWIDTH + buttonSpace) + (i / 5) * KPortraitWidth, 0, BUTTONWIDTH, BUTTONHEIGHT);
  628. buttonView.actionButton.tag = 3000 + i;
  629. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  630. [self.buttonScrollView addSubview:buttonView];
  631. }
  632. }
  633. - (void)HomeTopButtonAction:(UIButton *)sender {
  634. NSInteger index = sender.tag - 3000;
  635. if ([self checkIsLoginToLoginView:YES]) {
  636. HomeMessageModel *model = self.buttonArray[index];
  637. if (![NSString isEmptyString:model.linkUrl]) {
  638. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  639. webCtrl.url = model.linkUrl;
  640. [self.navigationController pushViewController:webCtrl animated:YES];
  641. }
  642. }
  643. }
  644. - (void)refreshNotice {
  645. if (self.noticeTitleArray.count) {
  646. self.noticeView.hidden = NO;
  647. }
  648. else {
  649. self.noticeView.hidden = YES;
  650. }
  651. self.noticeScrollView.titlesGroup = self.noticeTitleArray;
  652. }
  653. - (void)refreshCourseView:(RecentCourseModel *)model {
  654. if (model) {
  655. [self.courseView configCourseMessage:model];
  656. self.courseView.hidden = NO;
  657. }
  658. else {
  659. self.courseView.hidden = YES;
  660. }
  661. }
  662. - (void)refreshAlbumView {
  663. if (self.albumArray.count) {
  664. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  665. self.albumView.hidden = NO;
  666. }
  667. else {
  668. self.albumViewHeight = CGFLOAT_MIN;
  669. self.albumView.hidden = YES;
  670. }
  671. [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
  672. make.height.mas_equalTo(self.albumViewHeight);
  673. }];
  674. [self.albumCollectionView reloadData];
  675. }
  676. - (void)refreshMusicView {
  677. [self.musicCollectionView reloadData];
  678. }
  679. - (void)refreshCourseView {
  680. // 课程
  681. if (self.liveCourseArray.count) {
  682. self.liveViewHeight = [HomeHotLiveCourseView getViewHeight];
  683. self.liveCourseView.hidden = NO;
  684. }
  685. else {
  686. self.liveViewHeight = CGFLOAT_MIN;
  687. self.liveCourseView.hidden = YES;
  688. }
  689. [self.liveCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
  690. make.height.mas_equalTo(self.liveViewHeight);
  691. }];
  692. if (self.videoCourseArray.count) {
  693. self.videoViewHeight = [HomeHotVideoCourseView getViewHeight];
  694. self.videoCourseView.hidden = NO;
  695. }
  696. else {
  697. self.videoViewHeight = CGFLOAT_MIN;
  698. self.videoCourseView.hidden = YES;
  699. }
  700. [self.videoCourseView mas_updateConstraints:^(MASConstraintMaker *make) {
  701. make.height.mas_equalTo(self.videoViewHeight);
  702. }];
  703. [self.videoCollectionView reloadData];
  704. [self.liveCollectionView reloadData];
  705. }
  706. #pragma mark - JXPagerViewDelegate
  707. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  708. return self.headView;
  709. }
  710. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  711. return self.headViewHeight;
  712. }
  713. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  714. return self.categoryView;
  715. }
  716. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  717. return 50;
  718. }
  719. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  720. //和categoryView的item数量一致
  721. return self.titles.count;
  722. }
  723. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  724. if (index == 0) {
  725. HomePageBodyView *listView = [[HomePageBodyView alloc] init];
  726. listView.naviController = self.navigationController;
  727. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  728. self.listViewArray[index] = listView;
  729. listView.selectIndex = index;
  730. [listView beginFirstRefresh];
  731. return listView;
  732. }
  733. else {
  734. HomeInformationBodyView *listView = [[HomeInformationBodyView alloc] init];
  735. listView.naviController = self.navigationController;
  736. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  737. self.listViewArray[index] = listView;
  738. listView.selectIndex = index;
  739. [listView beginFirstRefresh];
  740. return listView;
  741. }
  742. }
  743. #pragma mark - JXCategoryViewDelegate
  744. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  745. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  746. if (self.listViewArray.count > index) {
  747. id value = self.listViewArray[index];
  748. if ([value isKindOfClass:[KSJXBodyView class]]) {
  749. KSJXBodyView *listView = (KSJXBodyView *)value;
  750. [listView beginFirstRefresh];
  751. }
  752. else if ([value isKindOfClass:[kSJXCollectionView class]]) {
  753. kSJXCollectionView *listView = (kSJXCollectionView *)value;
  754. [listView beginFirstRefresh];
  755. }
  756. }
  757. }
  758. #pragma mark - JXPagerMainTableViewGestureDelegate
  759. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  760. //禁止categoryView左右滑动的时候,上下和左右都可以滚动
  761. if (otherGestureRecognizer == self.categoryView.collectionView.panGestureRecognizer) {
  762. return NO;
  763. }
  764. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  765. }
  766. #pragma mark - TYCyclePagerViewDataSource代理
  767. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  768. return self.bannerArray.count;
  769. }
  770. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  771. HomeMessageModel *model = self.bannerArray[index];
  772. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  773. [cell configCellWithModel:model];
  774. return cell;
  775. }
  776. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  777. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  778. layout.itemSize = CGSizeMake(kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
  779. layout.itemSpacing = 0;
  780. return layout;
  781. }
  782. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  783. if (pageView == self.bannerScroll) {
  784. [self.pageControl setCurrentPage:toIndex animate:YES];
  785. }
  786. }
  787. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  788. HomeMessageModel *model = self.bannerArray[index];
  789. if (![NSString isEmptyString:model.linkUrl]) {
  790. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  791. webCtrl.url = model.linkUrl;
  792. [self.navigationController pushViewController:webCtrl animated:YES];
  793. }
  794. }
  795. #pragma mark ---- collection data source
  796. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  797. return 1;
  798. }
  799. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  800. if (collectionView == self.albumCollectionView) { // 专辑
  801. return self.albumArray.count;
  802. }
  803. else if (collectionView == self.musicCollectionView) { // 乐谱
  804. NSInteger lastRowCount = (self.musicArray.count % 3) > 0 ? 1 : 0;
  805. NSInteger count = self.musicArray.count / 3 + lastRowCount;
  806. return count;
  807. }
  808. else if (collectionView == self.talentCollectionView) { // 推荐达人
  809. return self.talentArray.count;
  810. }
  811. else if (collectionView == self.videoCollectionView) { // 视频课
  812. return self.videoCourseArray.count;
  813. }
  814. else { // 直播课
  815. return self.liveCourseArray.count;
  816. }
  817. }
  818. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  819. if (collectionView == self.albumCollectionView) {
  820. HomeAlbumModel *model = self.albumArray[indexPath.item];
  821. HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
  822. [cell configWithAlbumModel:model];
  823. return cell;
  824. }
  825. else if (collectionView == self.musicCollectionView) {
  826. NSMutableArray *songArray = [NSMutableArray array];
  827. NSInteger length = indexPath.item * 3 + 3 > self.musicArray.count ? self.musicArray.count - indexPath.item * 3: 3;
  828. NSRange range = NSMakeRange(indexPath.item * 3, length);
  829. songArray = [NSMutableArray arrayWithArray:[self.musicArray subarrayWithRange:range]];
  830. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  831. MJWeakSelf;
  832. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  833. [weakSelf displaySongDetail:songId];
  834. }];
  835. return cell;
  836. }
  837. else if (collectionView == self.talentCollectionView) {
  838. TalentTeacherModel *talentModel = self.talentArray[indexPath.item];
  839. HomeHotTalentCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotTalentCell" forIndexPath:indexPath];
  840. [cell configWithSource:talentModel];
  841. return cell;
  842. }
  843. else if (collectionView == self.videoCollectionView) {
  844. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.item];
  845. HomeHotVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotVideoCell" forIndexPath:indexPath];
  846. [cell configWithSource:model];
  847. return cell;
  848. }
  849. else {
  850. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.item];
  851. HomeHotLiveCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotLiveCell" forIndexPath:indexPath];
  852. [cell configWithSource:model];
  853. return cell;
  854. }
  855. }
  856. - (void)displaySongDetail:(NSString *)songId {
  857. // 检测权限
  858. PREMISSIONTYPE micEnable = [RecordCheckManager checkPermissionShowAlert:NO showInView:nil];
  859. PREMISSIONTYPE cameraEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
  860. if (micEnable == PREMISSIONTYPE_YES && cameraEnable == PREMISSIONTYPE_YES) { // 如果麦克风和摄像头权限都有
  861. // 跳转到播放页面
  862. KSAccompanyWebViewController *detailCtrl = [[KSAccompanyWebViewController alloc] init];
  863. detailCtrl.url = [NSString stringWithFormat:@"%@/accompany?id=%@",hostURL, songId];
  864. detailCtrl.hiddenNavBar = YES;
  865. detailCtrl.parmDic = @{@"isOpenLight" : @(YES), @"orientation" : @(0),@"isHideTitle" : @(YES)};
  866. [self.navigationController pushViewController:detailCtrl animated:YES];
  867. }
  868. else {
  869. if (micEnable == PREMISSIONTYPE_NO && cameraEnable == PREMISSIONTYPE_NO) { // 如果麦克风权限和摄像头权限都没有
  870. [self showAlertWithMessage:@"请开启相机和麦克风访问权限" type:CHECKDEVICETYPE_BOTH];
  871. }
  872. else if (micEnable == PREMISSIONTYPE_NO) { // 如果没有麦克风权限
  873. [self showAlertWithMessage:@"请开启麦克风访问权限" type:CHECKDEVICETYPE_MIC];
  874. }
  875. else if (cameraEnable == PREMISSIONTYPE_NO) { // 如果没有摄像头权限
  876. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  877. }
  878. }
  879. }
  880. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  881. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  882. } confirm:^{
  883. [self openSettingView];
  884. }];
  885. }
  886. - (void)openSettingView {
  887. if (@available(iOS 10, *)) {
  888. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  889. } else {
  890. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  891. }
  892. }
  893. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  894. if (collectionView == self.albumCollectionView) { // 专辑详情
  895. HomeAlbumModel *model = self.albumArray[indexPath.item];
  896. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  897. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
  898. [self.navigationController pushViewController:ctrl animated:YES];
  899. }
  900. else if (collectionView == self.talentCollectionView) { // 达人风采
  901. TalentTeacherModel *model = self.talentArray[indexPath.item];
  902. [self displayTeacherDetail:[NSString stringWithFormat:@"%.0f",model.userId]];
  903. }
  904. else if (collectionView == self.videoCollectionView) { // 视频课
  905. HomeVideoGroupModel *model = self.videoCourseArray[indexPath.row];
  906. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/videoDetail?groupId=",model.videoGroupId];
  907. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  908. ctrl.url = url;
  909. [self.navigationController pushViewController:ctrl animated:YES];
  910. }
  911. else if (collectionView == self.liveCollectionView) { // 直播课详情
  912. HomeLiveGroupModel *model = self.liveCourseArray[indexPath.row];
  913. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  914. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",model.courseGroupId];
  915. ctrl.url = url;
  916. [self.navigationController pushViewController:ctrl animated:YES];
  917. }
  918. }
  919. // 老师风采
  920. - (void)displayTeacherDetail:(NSString *)teacherId {
  921. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  922. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/teacherHome?teacherId=",teacherId];
  923. [self.navigationController pushViewController:ctrl animated:YES];
  924. }
  925. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  926. if (collectionView == self.albumCollectionView) {
  927. return CGSizeMake(100, 140);
  928. }
  929. else if (collectionView == self.musicCollectionView) {
  930. return CGSizeMake(KPortraitWidth * 0.83, 240);
  931. }
  932. else if (collectionView == self.talentCollectionView) {
  933. return CGSizeMake(110, 146);
  934. }
  935. else if (collectionView == self.videoCollectionView) {
  936. return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 153);
  937. }
  938. else {
  939. return CGSizeMake((KPortraitWidth - 28 - 11) / 2.0f, 153);
  940. }
  941. }
  942. #pragma mark ----- SDCycleScrollViewDelegate
  943. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  944. NoticeSourceModel *noticeModel = self.noticeArray[index];
  945. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  946. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, noticeModel.internalBaseClassIdentifier];
  947. [self.navigationController pushViewController:webCtrl animated:YES];
  948. }
  949. #pragma mark ------- lazying
  950. - (HomeNavSearchView *)navView {
  951. if (!_navView) {
  952. _navView = [HomeNavSearchView shareInstance];
  953. MJWeakSelf;
  954. [_navView homeNavSearchAction:^(HOMENAV_TAG action) {
  955. [weakSelf homeNavAction:action];
  956. }];
  957. }
  958. return _navView;
  959. }
  960. - (void)homeNavAction:(HOMENAV_TAG)action {
  961. switch (action) {
  962. case HOMENAV_TAG_SCAN: // 扫一扫
  963. {
  964. [self showScanView];
  965. }
  966. break;
  967. case HOMENAV_TAG_MESSAGE: // 消息
  968. {
  969. NotiferMessageViewController *ctrl = [[NotiferMessageViewController alloc] init];
  970. [self.navigationController pushViewController:ctrl animated:YES];
  971. }
  972. break;
  973. case HOMENAV_TAG_SEARCH: // 搜索
  974. {
  975. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  976. webCtrl.url = [NSString stringWithFormat:@"%@/music-songbook/search", WEBHOST];
  977. [self.navigationController pushViewController:webCtrl animated:YES];
  978. }
  979. break;
  980. default:
  981. break;
  982. }
  983. }
  984. - (void)showScanView {
  985. // 判断是否有权限
  986. PREMISSIONTYPE albumEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
  987. if (albumEnable == PREMISSIONTYPE_YES) { // 如果有权限
  988. KSScanViewController *ctrl = [[KSScanViewController alloc] init];
  989. [self.navigationController pushViewController:ctrl animated:YES];
  990. }
  991. else {
  992. if (albumEnable == PREMISSIONTYPE_NO) {
  993. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  994. }
  995. }
  996. }
  997. - (dispatch_group_t)requestGroup {
  998. if (!_requestGroup) {
  999. _requestGroup = dispatch_group_create();
  1000. }
  1001. return _requestGroup;
  1002. }
  1003. - (UIView *)headView {
  1004. if (!_headView) {
  1005. _headView = [[UIView alloc] init];
  1006. _headView.backgroundColor = [UIColor clearColor];
  1007. }
  1008. return _headView;
  1009. }
  1010. - (NSMutableArray *)listViewArray {
  1011. if (!_listViewArray) {
  1012. _listViewArray = [NSMutableArray arrayWithArray:@[@"",@""]];
  1013. }
  1014. return _listViewArray;
  1015. }
  1016. - (HomeBannerView *)bannerView {
  1017. if (!_bannerView) {
  1018. _bannerView = [HomeBannerView shareInstance];
  1019. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  1020. }
  1021. return _bannerView;
  1022. }
  1023. #pragma mark --- banner
  1024. - (TYCyclePagerView *)bannerScroll {
  1025. if (!_bannerScroll) {
  1026. _bannerScroll = [[TYCyclePagerView alloc] init];
  1027. _bannerScroll.backgroundColor = [UIColor clearColor];
  1028. _bannerScroll.frame = CGRectMake(0, 0, kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
  1029. _bannerScroll.isInfiniteLoop = YES;
  1030. _bannerScroll.autoScrollInterval = 3.0f;
  1031. _bannerScroll.reloadDataNeedResetIndex = YES;
  1032. _bannerScroll.dataSource = self;
  1033. _bannerScroll.delegate = self;
  1034. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  1035. if (@available(iOS 11.0, *)) {
  1036. _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1037. } else {
  1038. // Fallback on earlier versions
  1039. if (@available(iOS 13.0, *)) {
  1040. _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1041. } else {
  1042. // Fallback on earlier versions
  1043. }
  1044. }
  1045. }
  1046. return _bannerScroll;
  1047. }
  1048. - (TYPageControl *)pageControl {
  1049. if (!_pageControl) {
  1050. _pageControl = [[TYPageControl alloc] init];
  1051. _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  1052. _pageControl.pageIndicatorSpaing = 4.0f;
  1053. _pageControl.frame = CGRectMake(0, (kScreenWidth - 28) * 132 / 347 - 20, kScreenWidth-28 - 12, 12);
  1054. _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
  1055. _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
  1056. _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
  1057. _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
  1058. }
  1059. return _pageControl;
  1060. }
  1061. - (NSMutableArray *)bannerArray {
  1062. if (!_bannerArray) {
  1063. _bannerArray = [NSMutableArray array];
  1064. }
  1065. return _bannerArray;
  1066. }
  1067. #pragma mark ---- scroll view delegate
  1068. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  1069. if (scrollView == self.buttonScrollView) {
  1070. NSInteger index = (NSInteger)(scrollView.contentOffset.x / (KPortraitWidth - 28));
  1071. [UIView animateWithDuration:0.3f animations:^{
  1072. self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth;
  1073. }];
  1074. }
  1075. }
  1076. #pragma mark ---- button container
  1077. - (HomeButtonView *)buttonContainer {
  1078. if (!_buttonContainer) {
  1079. _buttonContainer = [HomeButtonView shareInstance];
  1080. [_buttonContainer.buttonContentView addSubview:self.buttonScrollView];
  1081. }
  1082. return _buttonContainer;
  1083. }
  1084. - (UIScrollView *)buttonScrollView {
  1085. if (!_buttonScrollView) {
  1086. _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, BUTTONHEIGHT)];
  1087. _buttonScrollView.backgroundColor = [UIColor clearColor];
  1088. _buttonScrollView.pagingEnabled = YES;
  1089. _buttonScrollView.showsHorizontalScrollIndicator = NO;
  1090. _buttonScrollView.showsVerticalScrollIndicator = NO;
  1091. _buttonScrollView.delegate = self;
  1092. }
  1093. return _buttonScrollView;
  1094. }
  1095. #pragma mark ---- notice view
  1096. - (PublicNoticeView *)noticeView {
  1097. if (!_noticeView) {
  1098. _noticeView = [PublicNoticeView shareInstance];
  1099. MJWeakSelf;
  1100. [_noticeView moreCallback:^{
  1101. [weakSelf moreNotice];
  1102. }];
  1103. }
  1104. return _noticeView;
  1105. }
  1106. - (NSMutableArray *)noticeArray {
  1107. if (!_noticeArray) {
  1108. _noticeArray = [NSMutableArray array];
  1109. }
  1110. return _noticeArray;
  1111. }
  1112. - (NSMutableArray *)noticeTitleArray {
  1113. if (!_noticeTitleArray) {
  1114. _noticeTitleArray = [NSMutableArray array];
  1115. }
  1116. return _noticeTitleArray;
  1117. }
  1118. - (void)moreNotice {
  1119. if (self.noticeArray.count) {
  1120. NoticeSourceModel *bannerModel = self.noticeArray[0];
  1121. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1122. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
  1123. [self.navigationController pushViewController:webCtrl animated:YES];
  1124. }
  1125. }
  1126. - (SDCycleScrollView *)noticeScrollView {
  1127. if (!_noticeScrollView) {
  1128. _noticeScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage new]];
  1129. _noticeScrollView.onlyDisplayText = YES;
  1130. _noticeScrollView.autoScroll = NO;
  1131. _noticeScrollView.scrollEnabled = NO;
  1132. _noticeScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
  1133. _noticeScrollView.titleLabelTextColor = HexRGB(0x1a1a1a);
  1134. _noticeScrollView.titleLabelBackgroundColor = [UIColor clearColor];
  1135. _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14];
  1136. _noticeScrollView.titlesGroup = self.noticeTitleArray;
  1137. }
  1138. return _noticeScrollView;
  1139. }
  1140. - (HomeRecentCourseView *)courseView {
  1141. if (!_courseView) {
  1142. _courseView = [HomeRecentCourseView shareInstance];
  1143. MJWeakSelf;
  1144. [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) {
  1145. [weakSelf joinRoomAction:type courseMessage:courseModel];
  1146. }];
  1147. }
  1148. return _courseView;
  1149. }
  1150. - (void)joinRoomAction:(RECENTCOURSE_TYPE)type courseMessage:(RecentCourseModel *)courseModel {
  1151. if (type == RECENTCOURSE_TYPE_ACCOMPANY) {
  1152. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  1153. detailVC.courseId = courseModel.courseId;
  1154. detailVC.courseGroupId = courseModel.courseGroupId;
  1155. detailVC.teacherId = courseModel.teacherId;
  1156. [self.navigationController pushViewController:detailVC animated:YES];
  1157. }
  1158. else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课
  1159. MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
  1160. detailVC.courseId = courseModel.courseId;
  1161. detailVC.courseGroupId = courseModel.courseGroupId;
  1162. detailVC.teacherId = courseModel.teacherId;
  1163. [self.navigationController pushViewController:detailVC animated:YES];
  1164. }
  1165. else {
  1166. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1167. NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST,courseModel.courseGroupId,courseModel.courseId];
  1168. ctrl.url = url;
  1169. [self.navigationController pushViewController:ctrl animated:YES];
  1170. }
  1171. }
  1172. #pragma mark ----- 专辑
  1173. - (HomeHotAlbumView *)albumView {
  1174. if (!_albumView) {
  1175. _albumView = [HomeHotAlbumView shareInstance];
  1176. MJWeakSelf;
  1177. [_albumView homeAlbumMore:^{
  1178. [weakSelf moreAlbumDetail];
  1179. }];
  1180. [_albumView.albumContentView addSubview:self.albumCollectionView];
  1181. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1182. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  1183. }];
  1184. }
  1185. return _albumView;
  1186. }
  1187. - (UICollectionView *)albumCollectionView {
  1188. if (!_albumCollectionView) {
  1189. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1190. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1191. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1192. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1193. _albumCollectionView.backgroundColor = [UIColor clearColor];
  1194. _albumCollectionView.delegate = self;
  1195. _albumCollectionView.dataSource = self;
  1196. _albumCollectionView.showsVerticalScrollIndicator = NO;
  1197. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  1198. if (@available(iOS 11.0, *)) {
  1199. _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1200. } else {
  1201. // Fallback on earlier versions
  1202. if (@available(iOS 13.0, *)) {
  1203. _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1204. } else {
  1205. // Fallback on earlier versions
  1206. }
  1207. }
  1208. [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
  1209. }
  1210. return _albumCollectionView;
  1211. }
  1212. - (void)moreAlbumDetail {
  1213. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1214. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
  1215. [self.navigationController pushViewController:ctrl animated:YES];
  1216. }
  1217. #pragma mark ---- 热门曲目
  1218. - (HomeHotMusicView *)hotMusicView {
  1219. if (!_hotMusicView) {
  1220. _hotMusicView = [HomeHotMusicView shareInstance];
  1221. MJWeakSelf;
  1222. [_hotMusicView homeMusicMore:^{
  1223. [weakSelf moreHotMusic];
  1224. }];
  1225. [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
  1226. [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1227. make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
  1228. }];
  1229. }
  1230. return _hotMusicView;
  1231. }
  1232. - (void)moreHotMusic {
  1233. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1234. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  1235. [self.navigationController pushViewController:ctrl animated:YES];
  1236. }
  1237. - (UICollectionView *)musicCollectionView {
  1238. if (!_musicCollectionView) {
  1239. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1240. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1241. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1242. _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1243. _musicCollectionView.backgroundColor = [UIColor clearColor];
  1244. _musicCollectionView.delegate = self;
  1245. _musicCollectionView.dataSource = self;
  1246. _musicCollectionView.showsVerticalScrollIndicator = NO;
  1247. _musicCollectionView.showsHorizontalScrollIndicator = NO;
  1248. if (@available(iOS 11.0, *)) {
  1249. _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1250. } else {
  1251. // Fallback on earlier versions
  1252. if (@available(iOS 13.0, *)) {
  1253. _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1254. } else {
  1255. // Fallback on earlier versions
  1256. }
  1257. }
  1258. [_musicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  1259. }
  1260. return _musicCollectionView;
  1261. }
  1262. #pragma mark ---- talent view
  1263. - (HomeHotTalentView *)talentView {
  1264. if (!_talentView) {
  1265. _talentView = [HomeHotTalentView shareInstance];
  1266. [_talentView.talentContentView addSubview:self.talentCollectionView];
  1267. [self.talentCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1268. make.left.right.bottom.top.mas_equalTo(_talentView.talentContentView);
  1269. }];
  1270. }
  1271. return _talentView;
  1272. }
  1273. - (UICollectionView *)talentCollectionView {
  1274. if (!_talentCollectionView) {
  1275. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1276. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1277. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1278. _talentCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1279. _talentCollectionView.backgroundColor = [UIColor clearColor];
  1280. _talentCollectionView.delegate = self;
  1281. _talentCollectionView.dataSource = self;
  1282. _talentCollectionView.showsVerticalScrollIndicator = NO;
  1283. _talentCollectionView.showsHorizontalScrollIndicator = NO;
  1284. if (@available(iOS 11.0, *)) {
  1285. _talentCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1286. } else {
  1287. // Fallback on earlier versions
  1288. if (@available(iOS 13.0, *)) {
  1289. _talentCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1290. } else {
  1291. // Fallback on earlier versions
  1292. }
  1293. }
  1294. [_talentCollectionView registerNib:[UINib nibWithNibName:@"HomeHotTalentCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotTalentCell"];
  1295. }
  1296. return _talentCollectionView;
  1297. }
  1298. #pragma mark ----- video course
  1299. - (HomeHotVideoCourseView *)videoCourseView {
  1300. if (!_videoCourseView) {
  1301. _videoCourseView = [HomeHotVideoCourseView shareInstance];
  1302. MJWeakSelf;
  1303. [_videoCourseView homeVideoMore:^{
  1304. [weakSelf toVideoMorePage];
  1305. }];
  1306. [_videoCourseView.videoContentView addSubview:self.videoCollectionView];
  1307. [self.videoCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1308. make.left.right.bottom.top.mas_equalTo(_videoCourseView.videoContentView);
  1309. }];
  1310. }
  1311. return _videoCourseView;
  1312. }
  1313. - (UICollectionView *)videoCollectionView {
  1314. if (!_videoCollectionView) {
  1315. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1316. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1317. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1318. _videoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1319. _videoCollectionView.backgroundColor = [UIColor clearColor];
  1320. _videoCollectionView.delegate = self;
  1321. _videoCollectionView.dataSource = self;
  1322. _videoCollectionView.showsVerticalScrollIndicator = NO;
  1323. _videoCollectionView.showsHorizontalScrollIndicator = NO;
  1324. if (@available(iOS 11.0, *)) {
  1325. _videoCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1326. } else {
  1327. // Fallback on earlier versions
  1328. if (@available(iOS 13.0, *)) {
  1329. _videoCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1330. } else {
  1331. // Fallback on earlier versions
  1332. }
  1333. }
  1334. [_videoCollectionView registerNib:[UINib nibWithNibName:@"HomeHotVideoCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotVideoCell"];
  1335. }
  1336. return _videoCollectionView;
  1337. }
  1338. - (void)toVideoMorePage {
  1339. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1340. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/videoClass"];
  1341. [self.navigationController pushViewController:ctrl animated:YES];
  1342. }
  1343. #pragma mark ----- live course
  1344. - (HomeHotLiveCourseView *)liveCourseView {
  1345. if (!_liveCourseView) {
  1346. _liveCourseView = [HomeHotLiveCourseView shareInstance];
  1347. MJWeakSelf;
  1348. [_liveCourseView homeLiveMore:^{
  1349. [weakSelf toLiveMorePage];
  1350. }];
  1351. [_liveCourseView.liveContentView addSubview:self.liveCollectionView];
  1352. [self.liveCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1353. make.left.right.bottom.top.mas_equalTo(_liveCourseView.liveContentView);
  1354. }];
  1355. }
  1356. return _liveCourseView;
  1357. }
  1358. - (UICollectionView *)liveCollectionView {
  1359. if (!_liveCollectionView) {
  1360. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1361. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1362. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1363. _liveCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1364. _liveCollectionView.backgroundColor = [UIColor clearColor];
  1365. _liveCollectionView.delegate = self;
  1366. _liveCollectionView.dataSource = self;
  1367. _liveCollectionView.showsVerticalScrollIndicator = NO;
  1368. _liveCollectionView.showsHorizontalScrollIndicator = NO;
  1369. if (@available(iOS 11.0, *)) {
  1370. _liveCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1371. } else {
  1372. // Fallback on earlier versions
  1373. if (@available(iOS 13.0, *)) {
  1374. _liveCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1375. } else {
  1376. // Fallback on earlier versions
  1377. }
  1378. }
  1379. [_liveCollectionView registerNib:[UINib nibWithNibName:@"HomeHotLiveCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotLiveCell"];
  1380. }
  1381. return _liveCollectionView;
  1382. }
  1383. // 更多直播课
  1384. - (void)toLiveMorePage {
  1385. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1386. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveClass"];
  1387. [self.navigationController pushViewController:ctrl animated:YES];
  1388. }
  1389. /*
  1390. #pragma mark - Navigation
  1391. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1392. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1393. // Get the new view controller using [segue destinationViewController].
  1394. // Pass the selected object to the new view controller.
  1395. }
  1396. */
  1397. @end