HomeViewController.m 88 KB

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