HomeViewController.m 72 KB

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