NewHomeViewController.m 69 KB

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