HomeViewController.m 75 KB

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