HomeViewController.m 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. //
  2. // HomeViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "HomeViewController.h"
  8. #import "HomeNavView.h"
  9. #import "KSBaseWKWebViewController.h"
  10. #import "MyMusicViewController.h"
  11. #import "MyCourseViewController.h"
  12. #import "HomeworkListViewController.h"
  13. #import "EvaluateCourseListViewController.h"
  14. #import "NotiferMessageViewController.h"
  15. #import "UserInfoManager.h"
  16. #import "MyIncomeViewController.h"
  17. #import "ReceiveEvaluateListController.h"
  18. #import "PublicNoticeView.h"
  19. #import "SDCycleScrollView.h"
  20. #import "NoticeSourceModel.h"
  21. #import "HomeRecentCourseView.h"
  22. #import "AccompanyDetailViewController.h"
  23. #import "RecentCourseModel.h"
  24. #import "AppDelegate.h"
  25. #import "MusicRoomViewController.h"
  26. #import "KSScanViewController.h"
  27. #import "KSPremissionAlert.h"
  28. #import "RecordCheckManager.h"
  29. #import "UserSettingViewController.h"
  30. #import "HomeMessageModel.h"
  31. #import "HomeButtonView.h"
  32. #import "KSHomeButton.h"
  33. #import "HomeNewHeadView.h"
  34. #import "HomeAlbumView.h"
  35. #import "HomeAlbumModel.h"
  36. #import "HomeHotAlbumCell.h"
  37. #import "HomeHotMusicView.h"
  38. #import "HomeHotMusicCollectionCell.h"
  39. #import "HomeBannerView.h"
  40. #import <UIButton+WebCache.h>
  41. #import "TYCyclePagerView.h"
  42. #import "TYPageControl.h"
  43. #import "HomeBannerCell.h"
  44. #import "BadgeIntroduceView.h"
  45. #import "HomeAuthAlertView.h"
  46. #import "KSAwardAlertView.h"
  47. #import "HomeNewMusicView.h"
  48. #import "HomeRecommendMusicView.h"
  49. #import "HomeMusicModel.h"
  50. #import "HomeDragButton.h"
  51. #import "SmallToolViewController.h"
  52. #import "InstrumentChooseViewController.h"
  53. #import "HomeTenantView.h"
  54. #import "HomeTenantPageView.h"
  55. #define BUTTONWIDTH (65)
  56. #define BUTTONHEIGHT (70)
  57. @interface HomeViewController ()<SDCycleScrollViewDelegate,UIScrollViewDelegate,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  58. @property (nonatomic, strong) HomeNavView *navView;
  59. @property (nonatomic, strong) HomeNewHeadView *headView;
  60. @property (nonatomic, strong) UserInfo *mineInfo;
  61. @property (nonatomic, strong) PublicNoticeView *noticeView;
  62. @property (nonatomic, strong) SDCycleScrollView *noticeScrollView;
  63. @property (nonatomic, strong) NSMutableArray *noticeArray; // 公告数据
  64. @property (nonatomic, strong) NSMutableArray *titleArray; // 标题数组
  65. @property (nonatomic, strong) HomeBannerView *bannerView; // banner
  66. @property (nonatomic, strong) NSMutableArray *bannerArray; //
  67. @property (nonatomic, strong) TYPageControl *pageControl;
  68. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  69. @property (nonatomic, strong) HomeRecentCourseView *courseView;
  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. @property (nonatomic, assign) BOOL isFirstLoad;
  76. @property (nonatomic, strong) HomeAlbumView *albumView;
  77. @property (nonatomic, strong) NSMutableArray *albumArray; // 热门专辑
  78. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  79. @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
  80. @property (nonatomic, strong) dispatch_group_t requestGroup;
  81. @property (nonatomic, strong) RecentCourseModel *recentCourseModel;
  82. // 热门曲目
  83. @property (nonatomic, strong) HomeHotMusicView *hotMusicView;
  84. @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
  85. @property (nonatomic, assign) CGFloat hotMusicHeight; // music 高度
  86. // 推荐曲目
  87. @property (nonatomic, strong) HomeRecommendMusicView *recommendMusicView;
  88. @property (nonatomic, strong) UICollectionView *recommendMusicCollectionView; // 曲谱容器
  89. @property (nonatomic, strong) NSMutableArray *recommendMusicArray; // 曲谱数据
  90. @property (nonatomic, assign) CGFloat recommendMusicViewHeight; // music 高度
  91. // 最新曲目
  92. @property (nonatomic, strong) HomeNewMusicView *newestMusicView;
  93. @property (nonatomic, strong) UICollectionView *newestMusicCollectionView; // 曲谱容器
  94. @property (nonatomic, strong) NSMutableArray *newestMusicArray; // 曲谱数据
  95. @property (nonatomic, assign) CGFloat newestMusicViewHeight; // music 高度
  96. @property (nonatomic, strong) BadgeIntroduceView *intruduceAlert;
  97. @property (nonatomic, strong) HomeAuthAlertView *authAlertView;
  98. @property (nonatomic, assign) BOOL isCheck;
  99. @property (nonatomic, strong) HomeMessageModel *buttonModel;
  100. @property (nonatomic, strong) HomeDragButton *suspendButton;
  101. @property (nonatomic, assign) BOOL isSettingSubject;
  102. // 机构专辑
  103. @property (nonatomic, strong) HomeTenantPageView *tenantAlbumView;
  104. @property (nonatomic, assign) CGFloat tenantAlbumHeight;
  105. // 机构名称
  106. @property (nonatomic, strong) HomeTenantView *tenantNameView;
  107. @end
  108. @implementation HomeViewController
  109. - (void)viewDidLoad {
  110. [super viewDidLoad];
  111. // Do any additional setup after loading the view.
  112. self.ks_prefersNavigationBarHidden = YES;
  113. self.isFirstLoad = YES;
  114. [self configUI];
  115. }
  116. - (void)requestUserInfo {
  117. [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
  118. self.mineInfo = userInfo;
  119. [self requestData];
  120. }];
  121. }
  122. - (void)requestAwardMessage {
  123. self.isCheck = NO;
  124. dispatch_group_enter(self.requestGroup);
  125. [KSNetworkingManager checkReceiveRewardRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  126. dispatch_group_leave(self.requestGroup);
  127. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  128. BOOL isCheck = [[dic ks_dictionaryValueForKey:@"data"] ks_boolValueForKey:@"check"];
  129. self.isCheck = isCheck;
  130. }
  131. } faliure:^(NSError * _Nonnull error) {
  132. dispatch_group_leave(self.requestGroup);
  133. }];
  134. }
  135. - (void)requestNotice {
  136. dispatch_group_enter(self.requestGroup);
  137. [KSNetworkingManager helpCenterContentListRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
  138. dispatch_group_leave(self.requestGroup);
  139. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  140. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  141. if (sourceArray.count) {
  142. NSDictionary *parm = [sourceArray firstObject];
  143. NoticeSourceModel *bannerModel = [[NoticeSourceModel alloc] initWithDictionary:parm];
  144. [self.noticeArray addObject:bannerModel];
  145. [self.titleArray addObject:bannerModel.title];
  146. }
  147. else {
  148. self.noticeArray = [NSMutableArray array];
  149. self.titleArray = [NSMutableArray array];
  150. }
  151. }
  152. else {
  153. [self MBPShow:MESSAGEKEY];
  154. }
  155. } faliure:^(NSError * _Nonnull error) {
  156. dispatch_group_leave(self.requestGroup);
  157. }];
  158. }
  159. - (void)requestRecentCourse {
  160. dispatch_group_enter(self.requestGroup);
  161. [KSNetworkingManager queryRecentLiveAndVideo:KS_GET success:^(NSDictionary * _Nonnull dic) {
  162. dispatch_group_leave(self.requestGroup);
  163. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  164. NSDictionary *parm = [[dic ks_dictionaryValueForKey:@"data"] ks_dictionaryValueForKey:@"recentCourses"];
  165. if (parm == nil) {
  166. self.recentCourseModel = nil;
  167. }
  168. else {
  169. self.recentCourseModel = [[RecentCourseModel alloc] initWithDictionary:parm];
  170. }
  171. }
  172. else {
  173. [self MBPShow:MESSAGEKEY];
  174. }
  175. } faliure:^(NSError * _Nonnull error) {
  176. dispatch_group_leave(self.requestGroup);
  177. }];
  178. }
  179. - (void)refreshCourseView:(RecentCourseModel *)model {
  180. if (model) {
  181. [self.courseView configCourseMessage:model];
  182. self.courseView.hidden = NO;
  183. }
  184. else {
  185. self.courseView.hidden = YES;
  186. }
  187. }
  188. - (void)refreshNotice {
  189. if (self.titleArray.count) {
  190. self.noticeView.hidden = NO;
  191. }
  192. else {
  193. self.noticeView.hidden = YES;
  194. }
  195. self.noticeScrollView.titlesGroup = self.titleArray;
  196. }
  197. - (void)refreshView {
  198. [self.navView configMessage:self.mineInfo];
  199. [self.headView configMessage:self.mineInfo];
  200. [self refreshTenantNameView];
  201. [self refreshBannerView];
  202. [self refreshButtonView];
  203. [self refreshNotice];
  204. [self refreshCourseView:self.recentCourseModel];
  205. [self refreshAlbumView];
  206. [self refreshMusicView];
  207. // 刷新专辑显示
  208. [self refreshTenantBanner];
  209. // 刷新排序
  210. [self refreshViewLocation];
  211. if (self.isCheck) {
  212. [self checkShowAwardAlert];
  213. }
  214. // 悬浮按钮
  215. if (self.buttonModel) {
  216. [self showFloatingWindow];
  217. }
  218. else {
  219. [self removeFloatWindow];
  220. }
  221. }
  222. - (void)refreshTenantNameView {
  223. CGFloat tenantNameHeight = CGFLOAT_MIN;
  224. if (self.mineInfo.tenantId > 0) {
  225. tenantNameHeight = [HomeTenantView getViewHeight];
  226. self.tenantNameView.hidden = NO;
  227. }
  228. else {
  229. self.tenantNameView.hidden = YES;
  230. }
  231. [self.tenantNameView mas_updateConstraints:^(MASConstraintMaker *make) {
  232. make.height.mas_equalTo(tenantNameHeight);
  233. }];
  234. [self.tenantNameView configTenantName:self.mineInfo.tenantName];
  235. }
  236. - (void)refreshTenantBanner {
  237. if (self.mineInfo.tenantAlbumStatus == 0) {
  238. self.tenantAlbumHeight = CGFLOAT_MIN;
  239. self.tenantAlbumView.hidden = YES;
  240. }
  241. else {
  242. self.tenantAlbumHeight = [HomeTenantPageView getViewHeight];
  243. self.tenantAlbumView.hidden = NO;
  244. }
  245. [self.tenantAlbumView mas_updateConstraints:^(MASConstraintMaker *make) {
  246. make.height.mas_equalTo(self.tenantAlbumHeight);
  247. }];
  248. }
  249. - (void)removeFloatWindow {
  250. if ([self.view.subviews containsObject:self.suspendButton]) {
  251. [self.suspendButton removeFromSuperview];
  252. }
  253. }
  254. // 显示悬浮窗
  255. - (void)showFloatingWindow {
  256. if (![self.view.subviews containsObject:self.suspendButton]) {
  257. [self.view addSubview:self.suspendButton];
  258. }
  259. [self.view bringSubviewToFront:self.suspendButton];
  260. [self.suspendButton.containerView sd_setImageWithURL:[NSURL URLWithString:[self.buttonModel.coverImage getUrlEndcodeString]]];
  261. }
  262. - (void)checkShowAwardAlert {
  263. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  264. if (appDelegate.isShowMemoAlert) {
  265. return;
  266. }
  267. // 如果今日已提示过,就不再提醒
  268. NSDictionary *awardAlertDic = UserDefaultObjectForKey(@"awardAlertTime");
  269. NSString *awardAlertTime = [awardAlertDic ks_stringValueForKey:@"time"];
  270. NSDate *currendDate = [NSDate date];
  271. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  272. [dateFormatter setDateFormat:@"yyyy-MM-dd"];
  273. NSString *todayString = [dateFormatter stringFromDate:currendDate];
  274. if (![NSString isEmptyString:awardAlertTime]) {
  275. NSString *userId = [awardAlertDic ks_stringValueForKey:@"userId"];
  276. if ([todayString isEqualToString:awardAlertTime] && [userId isEqualToString:UserDefaultObjectForKey(UIDKey)]) {
  277. return;
  278. }
  279. }
  280. if (![self.navigationController.visibleViewController isKindOfClass:[HomeViewController class]]) {
  281. return;
  282. }
  283. KSAwardAlertView *alert = [KSAwardAlertView shareInstance];
  284. MJWeakSelf;
  285. [alert awardActionCallback:^(BOOL isSure) {
  286. if (isSure) {
  287. [weakSelf displayAwardList];
  288. }
  289. }];
  290. [alert showAlert];
  291. NSDictionary *saveDic = @{@"time" :todayString , @"userId" : UserDefaultObjectForKey(UIDKey)};
  292. UserDefaultSetObjectForKey(saveDic, @"awardAlertTime");
  293. }
  294. - (void)displayAwardList {
  295. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  296. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/awardActivity"];
  297. [self.navigationController pushViewController:webCtrl animated:YES];
  298. }
  299. - (void)refreshBannerView {
  300. if (self.bannerArray.count) {
  301. self.bannerView.hidden = NO;
  302. CGFloat bannerViewHeight = [HomeBannerView getViewHeight];
  303. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  304. make.height.mas_equalTo(bannerViewHeight);
  305. }];
  306. }
  307. else {
  308. self.bannerView.hidden = YES;
  309. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  310. make.height.mas_equalTo(CGFLOAT_MIN);
  311. }];
  312. }
  313. if (self.bannerArray.count > 1) {
  314. self.bannerScroll.autoScrollInterval = 3.0f;
  315. [self.bannerScroll addSubview:self.pageControl];
  316. }
  317. else {
  318. self.bannerScroll.autoScrollInterval = 0;
  319. [self.pageControl removeFromSuperview];
  320. }
  321. self.pageControl.numberOfPages = self.bannerArray.count;
  322. [self.bannerScroll reloadData];
  323. }
  324. - (void)refreshViewLocation {
  325. // 如果有课程和公告 且有按钮
  326. CGFloat buttonViewDefaultHeight = self.buttonArray.count > 4 ? [HomeButtonView getViewHeight] : [HomeButtonView getViewHeight] - 20;
  327. if (self.titleArray.count && self.recentCourseModel && self.buttonArray.count) {
  328. [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) {
  329. make.left.right.mas_equalTo(self.view);
  330. make.top.mas_equalTo(self.bannerView.mas_bottom);
  331. make.height.mas_equalTo(56.0f);
  332. }];
  333. [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
  334. make.left.right.mas_equalTo(self.view);
  335. make.top.mas_equalTo(self.noticeView.mas_bottom);
  336. make.height.mas_equalTo(buttonViewDefaultHeight);
  337. }];
  338. [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
  339. make.left.right.mas_equalTo(self.view);
  340. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  341. make.height.mas_equalTo(91.0f);
  342. }];
  343. }
  344. else {
  345. CGFloat buttonViewHeight = self.buttonArray.count ? buttonViewDefaultHeight : CGFLOAT_MIN;
  346. [self.buttonContainer mas_remakeConstraints:^(MASConstraintMaker *make) {
  347. make.left.right.mas_equalTo(self.view);
  348. make.top.mas_equalTo(self.bannerView.mas_bottom);
  349. make.height.mas_equalTo(buttonViewHeight);
  350. }];
  351. CGFloat noticeHeight = self.titleArray.count ? [self.noticeView getViewHeight] : CGFLOAT_MIN;
  352. [self.noticeView mas_remakeConstraints:^(MASConstraintMaker *make) {
  353. make.left.right.mas_equalTo(self.view);
  354. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  355. make.height.mas_equalTo(noticeHeight);
  356. }];
  357. CGFloat courseViewHeight = self.recentCourseModel ? 90.0f : CGFLOAT_MIN;
  358. [self.courseView mas_remakeConstraints:^(MASConstraintMaker *make) {
  359. make.left.right.mas_equalTo(self.view);
  360. make.top.mas_equalTo(self.noticeView.mas_bottom);
  361. make.height.mas_equalTo(courseViewHeight);
  362. }];
  363. }
  364. }
  365. - (void)requestHomeButton {
  366. dispatch_group_enter(self.requestGroup);
  367. [KSNetworkingManager homeButtonList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  368. dispatch_group_leave(self.requestGroup);
  369. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  370. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  371. // banner
  372. NSArray *bannerArray = [result ks_arrayValueForKey:@"banner"];
  373. NSMutableArray *bannerInfoArray = [NSMutableArray array];
  374. for (NSDictionary *parm in bannerArray) {
  375. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  376. [bannerInfoArray addObject:model];
  377. }
  378. self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
  379. // button
  380. NSArray *buttonArray = [result ks_arrayValueForKey:@"appMenu"];
  381. NSMutableArray *buttonInfoArray = [NSMutableArray array];
  382. for (NSDictionary *parm in buttonArray) {
  383. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  384. [buttonInfoArray addObject:model];
  385. }
  386. self.buttonArray = [NSMutableArray arrayWithArray:buttonInfoArray];
  387. // 首页悬浮按钮
  388. NSArray *suspensionArray = [result ks_arrayValueForKey:@"suspension"];
  389. if (suspensionArray.count) {
  390. self.buttonModel = [[HomeMessageModel alloc] initWithDictionary:[suspensionArray firstObject]];
  391. }
  392. else {
  393. self.buttonModel = nil;
  394. }
  395. }
  396. else {
  397. [self MBPShow:MESSAGEKEY];
  398. }
  399. } faliure:^(NSError * _Nonnull error) {
  400. dispatch_group_leave(self.requestGroup);
  401. }];
  402. }
  403. - (void)refreshButtonView {
  404. CGFloat containerWidth = (KPortraitWidth - 28);
  405. if (self.buttonArray.count) {
  406. self.buttonContainer.hidden = NO;
  407. // 添加按钮
  408. if (self.buttonArray.count > 4) { // 大于4个显示底部滚动视图
  409. self.buttonContainer.buttonPageCtrl.hidden = NO;
  410. self.buttonContainer.buttonDotLeft.constant = 0;
  411. NSInteger addPage = (self.buttonArray.count % 4) > 0 ? 1 : 0;
  412. NSInteger pageCount = self.buttonArray.count / 4 + addPage;
  413. self.buttonDotWidth = 36 / pageCount;
  414. self.buttonContainer.buttonDotWidth.constant = self.buttonDotWidth;
  415. self.buttonScrollView.contentSize = CGSizeMake(containerWidth * pageCount, BUTTONHEIGHT);
  416. }
  417. else {
  418. self.buttonContainer.buttonPageCtrl.hidden = YES;
  419. self.buttonScrollView.contentSize = CGSizeMake(containerWidth, BUTTONHEIGHT);
  420. }
  421. }
  422. else {
  423. self.buttonContainer.hidden = YES;
  424. self.buttonContainer.buttonPageCtrl.hidden = YES;
  425. self.buttonScrollView.contentSize = CGSizeMake(containerWidth, CGFLOAT_MIN);
  426. }
  427. self.buttonScrollView.contentOffset = CGPointMake(0, 0);
  428. [self.buttonScrollView removeAllSubViews];
  429. CGFloat leftSpace = 10.0f;
  430. CGFloat buttonSpace = (containerWidth - 4 * BUTTONWIDTH - leftSpace * 2) / 3;
  431. for (NSInteger i = 0; i < self.buttonArray.count; i++) {
  432. HomeMessageModel *model = self.buttonArray[i];
  433. KSHomeButton *buttonView = [KSHomeButton shareInstance];
  434. [buttonView.buttonImage sd_setImageWithURL:[NSURL URLWithString:[model.coverImage getUrlEndcodeString]]];
  435. buttonView.buttonTitle.text = model.title;
  436. buttonView.frame = CGRectMake(leftSpace + (i % 4) * (BUTTONWIDTH + buttonSpace) + (i / 4) * containerWidth, 0, BUTTONWIDTH, BUTTONHEIGHT);
  437. buttonView.actionButton.tag = 3000 + i;
  438. [buttonView.actionButton addTarget:self action:@selector(HomeTopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  439. [self.buttonScrollView addSubview:buttonView];
  440. }
  441. }
  442. - (void)HomeTopButtonAction:(UIButton *)sender {
  443. NSInteger index = sender.tag - 3000;
  444. if ([self checkIsLoginToLoginView:YES]) {
  445. HomeMessageModel *model = self.buttonArray[index];
  446. if (![NSString isEmptyString:model.linkUrl]) {
  447. if ([model.linkUrl isEqualToString:@"native-metronome"]) {
  448. SmallToolViewController *ctrl = [[SmallToolViewController alloc] init];
  449. [self.navigationController pushViewController:ctrl animated:YES];
  450. }
  451. else {
  452. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  453. webCtrl.url = model.linkUrl;
  454. [self.navigationController pushViewController:webCtrl animated:YES];
  455. }
  456. }
  457. }
  458. }
  459. - (void)requestAlbumSource {
  460. dispatch_group_enter(self.requestGroup);
  461. [KSNetworkingManager HomeHotAlbumRequest:KS_POST version:[USER_MANAGER getCurrentVersion] subjectIds:[NSString stringWithFormat:@"%.0f",self.mineInfo.defaultSubject] success:^(NSDictionary * _Nonnull dic) {
  462. dispatch_group_leave(self.requestGroup);
  463. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  464. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  465. NSMutableArray *albumArray = [NSMutableArray array];
  466. for (NSDictionary *parm in sourceArray) {
  467. HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
  468. [albumArray addObject:model];
  469. }
  470. self.albumArray = [NSMutableArray arrayWithArray:albumArray];
  471. }
  472. else {
  473. [self MBPShow:MESSAGEKEY];
  474. }
  475. } faliure:^(NSError * _Nonnull error) {
  476. dispatch_group_leave(self.requestGroup);
  477. }];
  478. }
  479. - (void)refreshAlbumView {
  480. if (self.albumArray.count) {
  481. self.albumViewHeight = [HomeAlbumView getViewHeight];
  482. self.albumView.hidden = NO;
  483. }
  484. else {
  485. self.albumViewHeight = CGFLOAT_MIN;
  486. self.albumView.hidden = YES;
  487. }
  488. [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
  489. make.height.mas_equalTo(self.albumViewHeight);
  490. }];
  491. [self.albumCollectionView reloadData];
  492. }
  493. - (void)requestHomeMusicMessage {
  494. dispatch_group_enter(self.requestGroup);
  495. [KSNetworkingManager homeAppMusicSheetRequest:KS_POST version:[USER_MANAGER getCurrentVersion] subjectIds:[NSString stringWithFormat:@"%.0f",self.mineInfo.defaultSubject] success:^(NSDictionary * _Nonnull dic) {
  496. dispatch_group_leave(self.requestGroup);
  497. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  498. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  499. NSArray *hotMusicSheet = [result ks_arrayValueForKey:@"hotMusicSheet"]; // 最热曲目
  500. NSMutableArray *hotArray = [NSMutableArray array];
  501. for (NSDictionary *parm in hotMusicSheet) {
  502. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  503. [hotArray addObject:model];
  504. }
  505. self.dataArray = [NSMutableArray arrayWithArray:hotArray];
  506. NSArray *newMusicSheet = [result ks_arrayValueForKey:@"newMusicSheet"]; // 最新曲目
  507. NSMutableArray *newMusicArray = [NSMutableArray array];
  508. for (NSDictionary *parm in newMusicSheet) {
  509. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  510. [newMusicArray addObject:model];
  511. }
  512. self.newestMusicArray = [NSMutableArray arrayWithArray:newMusicArray];
  513. NSArray *topMusicSheet = [result ks_arrayValueForKey:@"topMusicSheet"]; // 推荐曲目
  514. NSMutableArray *topMusicArray = [NSMutableArray array];
  515. for (NSDictionary *parm in topMusicSheet) {
  516. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  517. [topMusicArray addObject:model];
  518. }
  519. self.recommendMusicArray = [NSMutableArray arrayWithArray:topMusicArray];
  520. }
  521. else {
  522. [self MBPShow:MESSAGEKEY];
  523. }
  524. } faliure:^(NSError * _Nonnull error) {
  525. dispatch_group_leave(self.requestGroup);
  526. }];
  527. }
  528. - (void)refreshMusicView {
  529. if (self.recommendMusicArray.count) {
  530. self.recommendMusicViewHeight = [HomeHotMusicView getViewHeight];
  531. self.recommendMusicView.hidden = NO;
  532. }
  533. else {
  534. self.recommendMusicViewHeight = CGFLOAT_MIN;
  535. self.recommendMusicView.hidden = YES;
  536. }
  537. [self.recommendMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  538. make.height.mas_equalTo(self.recommendMusicViewHeight);
  539. }];
  540. [self.recommendMusicCollectionView reloadData];
  541. if (self.newestMusicArray.count) {
  542. self.newestMusicViewHeight = [HomeHotMusicView getViewHeight];
  543. self.newestMusicView.hidden = NO;
  544. }
  545. else {
  546. self.newestMusicViewHeight = CGFLOAT_MIN;
  547. self.newestMusicView.hidden = YES;
  548. }
  549. [self.newestMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  550. make.height.mas_equalTo(self.newestMusicViewHeight);
  551. }];
  552. [self.newestMusicCollectionView reloadData];
  553. if (self.dataArray.count) {
  554. self.hotMusicHeight = [HomeHotMusicView getViewHeight];
  555. self.hotMusicView.hidden = NO;
  556. }
  557. else {
  558. self.hotMusicHeight = CGFLOAT_MIN;
  559. self.hotMusicView.hidden = YES;
  560. }
  561. [self.hotMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  562. make.height.mas_equalTo(self.hotMusicHeight);
  563. }];
  564. [self.musicCollectionView reloadData];
  565. }
  566. - (void)configUI {
  567. CGFloat navHeight = IS_iPhoneX ? 100 : 70;
  568. [self.view addSubview:self.navView];
  569. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  570. make.width.mas_equalTo(kScreenWidth);
  571. make.right.top.mas_equalTo(self.view);
  572. make.height.mas_equalTo(navHeight);
  573. }];
  574. [self.view bringSubviewToFront:self.navView];
  575. // 名称
  576. [self.view addSubview:self.tenantNameView];
  577. CGFloat tenantNameHeight = CGFLOAT_MIN;
  578. [self.tenantNameView mas_makeConstraints:^(MASConstraintMaker *make) {
  579. make.left.right.mas_equalTo(self.view);
  580. make.top.mas_equalTo(self.navView.mas_bottom);
  581. make.height.mas_equalTo(tenantNameHeight);
  582. }];
  583. self.tenantNameView.hidden = YES;
  584. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  585. make.left.right.mas_equalTo(self.view);
  586. make.top.mas_equalTo(self.tenantNameView.mas_bottom);
  587. make.bottom.mas_equalTo(self.view.mas_bottom);
  588. }];
  589. self.scrollView.backgroundColor = [UIColor clearColor];
  590. MJWeakSelf;
  591. self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  592. [weakSelf requestHomeMessage];
  593. }];
  594. // header
  595. [self.scrollView addSubview:self.headView];
  596. CGFloat headHeight = [self.headView getViewHeight];
  597. [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
  598. make.left.right.mas_equalTo(self.view);
  599. make.top.mas_equalTo(self.scrollView.mas_top);
  600. make.height.mas_equalTo(headHeight);
  601. }];
  602. [self.scrollView addSubview:self.bannerView];
  603. [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
  604. make.left.right.mas_equalTo(self.view);
  605. make.top.mas_equalTo(self.headView.mas_bottom);
  606. make.height.mas_equalTo(CGFLOAT_MIN);
  607. }];
  608. // 按钮
  609. [self.scrollView addSubview:self.buttonContainer];
  610. [self.buttonContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  611. make.left.right.mas_equalTo(self.view);
  612. make.top.mas_equalTo(self.bannerView.mas_bottom);
  613. make.height.mas_equalTo(CGFLOAT_MIN);
  614. }];
  615. self.buttonContainer.hidden = YES;
  616. // 公告
  617. [self.scrollView addSubview:self.noticeView];
  618. [self.noticeView mas_makeConstraints:^(MASConstraintMaker *make) {
  619. make.left.right.mas_equalTo(self.view);
  620. make.top.mas_equalTo(self.buttonContainer.mas_bottom);
  621. make.height.mas_equalTo(CGFLOAT_MIN);
  622. }];
  623. [self.noticeView.adView addSubview:self.noticeScrollView];
  624. [self.noticeScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  625. make.top.left.right.bottom.mas_equalTo(self.noticeView.adView);
  626. }];
  627. self.noticeView.hidden = YES;
  628. // 最近课程
  629. [self.scrollView addSubview:self.courseView];
  630. [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
  631. make.left.right.mas_equalTo(self.view);
  632. make.top.mas_equalTo(self.noticeView.mas_bottom);
  633. make.height.mas_equalTo(CGFLOAT_MIN);
  634. }];
  635. self.courseView.hidden = YES;
  636. [self.scrollView addSubview:self.tenantAlbumView];
  637. self.tenantAlbumHeight = CGFLOAT_MIN;
  638. [self.tenantAlbumView mas_makeConstraints:^(MASConstraintMaker *make) {
  639. make.left.right.mas_equalTo(self.view);
  640. make.top.mas_equalTo(self.courseView.mas_bottom);
  641. make.height.mas_equalTo(self.tenantAlbumHeight);
  642. }];
  643. self.tenantAlbumView.hidden = YES;
  644. [self.scrollView addSubview:self.albumView];
  645. self.albumViewHeight = [HomeAlbumView getViewHeight];
  646. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  647. make.left.right.mas_equalTo(self.view);
  648. make.top.mas_equalTo(self.tenantAlbumView.mas_bottom);
  649. make.height.mas_equalTo(self.albumViewHeight);
  650. }];
  651. [self.scrollView addSubview:self.recommendMusicView];
  652. CGFloat recommendMusicHeadHeight = [HomeRecommendMusicView getViewHeight];
  653. [self.recommendMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  654. make.left.right.mas_equalTo(self.view);
  655. make.top.mas_equalTo(self.albumView.mas_bottom);
  656. make.height.mas_equalTo(recommendMusicHeadHeight);
  657. }];
  658. [self.scrollView addSubview:self.newestMusicView];
  659. CGFloat newMusicHeight = [HomeNewMusicView getViewHeight];
  660. [self.newestMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  661. make.left.right.mas_equalTo(self.view);
  662. make.top.mas_equalTo(self.recommendMusicView.mas_bottom);
  663. make.height.mas_equalTo(newMusicHeight);
  664. }];
  665. [self.scrollView addSubview:self.hotMusicView];
  666. CGFloat musicHeadHeight = [HomeHotMusicView getViewHeight];
  667. [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  668. make.left.right.mas_equalTo(self.view);
  669. make.top.mas_equalTo(self.newestMusicView.mas_bottom);
  670. make.height.mas_equalTo(musicHeadHeight);
  671. make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
  672. }];
  673. }
  674. - (void)requestHomeMessage {
  675. [self showhud];
  676. [self requestUserInfo];
  677. }
  678. - (void)requestData {
  679. [self requestUnreadCount];
  680. [self requestHomeButton];
  681. [self requestRecentCourse];
  682. [self requestNotice];
  683. [self requestAlbumSource];
  684. [self requestHomeMusicMessage];
  685. [self requestAwardMessage];
  686. dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
  687. [self removehub];
  688. [self.scrollView.mj_header endRefreshing];
  689. [self refreshView];
  690. });
  691. }
  692. - (void)viewWillAppear:(BOOL)animated {
  693. [super viewWillAppear:animated];
  694. if (self.isFirstLoad == YES) {
  695. self.isFirstLoad = NO;
  696. [self requestTrackAuth];
  697. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  698. [appDelegate handleNotiferSource];
  699. }
  700. if (self.isSettingSubject == NO) {
  701. [self requestHomeMessage];
  702. }
  703. self.isSettingSubject = NO;
  704. }
  705. // track
  706. - (void)requestTrackAuth {
  707. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  708. [appDelegate appTrackActionAuth];
  709. }
  710. - (void)requestUnreadCount {
  711. [KSNetworkingManager queryCountOfUnreadRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  712. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  713. NSArray *countArray = [dic ks_arrayValueForKey:@"data"];
  714. NSInteger courseCount = 0;
  715. NSInteger sysCount = 0;
  716. for (NSDictionary *parm in countArray) {
  717. if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"COURSE"]) {
  718. courseCount = [parm ks_integerValueForKey:@"value"];
  719. }
  720. if ([[parm ks_stringValueForKey:@"key"] isEqualToString:@"SYSTEM"]) {
  721. sysCount = [parm ks_integerValueForKey:@"value"];
  722. }
  723. }
  724. if (courseCount != 0 || sysCount != 0) {
  725. self.navView.dotView.hidden = NO;
  726. }
  727. else {
  728. self.navView.dotView.hidden = YES;
  729. }
  730. }
  731. else {
  732. [self MBPShow:MESSAGEKEY];
  733. }
  734. } faliure:^(NSError * _Nonnull error) {
  735. }];
  736. }
  737. #pragma mark ----- SDCycleScrollViewDelegate
  738. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  739. NoticeSourceModel *bannerModel = self.noticeArray[index];
  740. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  741. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
  742. [self.navigationController pushViewController:webCtrl animated:YES];
  743. }
  744. #pragma mark ----- lazying
  745. - (HomeNavView *)navView {
  746. if (!_navView) {
  747. _navView = [HomeNavView shareInstance];
  748. MJWeakSelf;
  749. [_navView displayMessageCenter:^(HOMENAV_ACTION action) {
  750. if (action == HOMENAV_ACTION_MESSAGE) {
  751. [weakSelf toMessageCenter];
  752. }
  753. else {
  754. [weakSelf scanAction];
  755. }
  756. }];
  757. }
  758. return _navView;
  759. }
  760. - (void)scanAction {
  761. // 判断是否有权限
  762. PREMISSIONTYPE albumEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
  763. if (albumEnable == PREMISSIONTYPE_YES) { // 如果有权限
  764. KSScanViewController *ctrl = [[KSScanViewController alloc] init];
  765. [self.navigationController pushViewController:ctrl animated:YES];
  766. }
  767. else {
  768. if (albumEnable == PREMISSIONTYPE_NO) {
  769. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  770. }
  771. }
  772. }
  773. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  774. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  775. } confirm:^{
  776. [self openSettingView];
  777. }];
  778. }
  779. - (void)openSettingView {
  780. if (@available(iOS 10, *)) {
  781. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  782. } else {
  783. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  784. }
  785. }
  786. - (void)toMessageCenter {
  787. NotiferMessageViewController *messageCenter = [[NotiferMessageViewController alloc] init];
  788. [self.navigationController pushViewController:messageCenter animated:YES];
  789. }
  790. - (HomeNewHeadView *)headView {
  791. if (!_headView) {
  792. _headView = [HomeNewHeadView shareInstance];
  793. MJWeakSelf;
  794. [_headView authDetailAction:^(HOMEHEADACTION action) {
  795. [weakSelf headAction:action];
  796. }];
  797. }
  798. return _headView;
  799. }
  800. - (void)headAction:(HOMEHEADACTION)type {
  801. switch (type) {
  802. case HOMEHEADACTION_DESC:
  803. {
  804. [self showDescAlert];
  805. }
  806. break;
  807. case HOMEHEADACTION_AUTH:
  808. {
  809. [self toAuthDetail];
  810. }
  811. break;
  812. case HOMEHEADACTION_EDUCATION:
  813. case HOMEHEADACTION_EDUCATIONFINISH:
  814. {
  815. [self showAuthEducationAlert];
  816. }
  817. break;
  818. case HOMEHEADACTION_SUBJECTCHOOSE:
  819. {
  820. [self showChooseSubjectView];
  821. }
  822. break;
  823. default:
  824. break;
  825. }
  826. }
  827. - (void)showChooseSubjectView {
  828. InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
  829. ctrl.isSingleChoose = YES;
  830. MJWeakSelf;
  831. [ctrl chooseCallback:^(NSMutableArray * _Nullable chooseArray) {
  832. NSDictionary *parm = [chooseArray firstObject];
  833. NSString *subjectId = [parm ks_stringValueForKey:@"subjectId"];
  834. NSString *subjectName = [parm ks_stringValueForKey:@"subjectName"];
  835. weakSelf.headView.subjectLabel.text = subjectName;
  836. [weakSelf setDefaultSubject:subjectId];
  837. }];
  838. self.isSettingSubject = YES;
  839. [self.navigationController pushViewController:ctrl animated:YES];
  840. }
  841. - (void)setDefaultSubject:(NSString *)subjectId {
  842. [self showhud];
  843. [KSNetworkingManager defaultSubjectRequest:KS_POST subjectId:subjectId success:^(NSDictionary * _Nonnull dic) {
  844. [self removehub];
  845. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  846. // 请求数据
  847. [self requestHomeMessage];
  848. }
  849. else {
  850. [self MBPShow:MESSAGEKEY];
  851. }
  852. } faliure:^(NSError * _Nonnull error) {
  853. [self removehub];
  854. }];
  855. }
  856. - (void)toAuthEducation {
  857. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  858. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCertUpdate"];
  859. [self.navigationController pushViewController:webCtrl animated:YES];
  860. }
  861. - (void)showAuthEducationAlert {
  862. BOOL hasDegreeAuth = self.mineInfo.degreeFlag;
  863. BOOL hasTeacherAuth = self.mineInfo.teacherFlag;
  864. self.authAlertView = [HomeAuthAlertView shareIntance];
  865. if (hasDegreeAuth) {
  866. [self.authAlertView.educationImage setImage:[UIImage imageNamed:@"choose_instrument"]];
  867. [self.authAlertView.educationStatus setText:@"已认证"];
  868. [self.authAlertView.educationStatus setTextColor:HexRGB(0x999999)];
  869. }
  870. else {
  871. [self.authAlertView.educationImage setImage:[UIImage imageNamed:@""]];
  872. [self.authAlertView.educationStatus setText:@"未认证"];
  873. [self.authAlertView.educationStatus setTextColor:HexRGB(0xff0000)];
  874. }
  875. if (hasTeacherAuth) {
  876. [self.authAlertView.qualificationImage setImage:[UIImage imageNamed:@"choose_instrument"]];
  877. [self.authAlertView.qualificationStatus setText:@"已认证"];
  878. [self.authAlertView.qualificationStatus setTextColor:HexRGB(0x999999)];
  879. }
  880. else {
  881. [self.authAlertView.qualificationImage setImage:[UIImage imageNamed:@""]];
  882. [self.authAlertView.qualificationStatus setText:@"未认证"];
  883. [self.authAlertView.qualificationStatus setTextColor:HexRGB(0xff0000)];
  884. }
  885. if (hasDegreeAuth && hasTeacherAuth) {
  886. self.authAlertView.isFinish = YES;
  887. self.authAlertView.rate = 1.0f;
  888. }
  889. else {
  890. self.authAlertView.isFinish = NO;
  891. if (hasDegreeAuth || hasTeacherAuth) {
  892. self.authAlertView.rate = 0.9f;
  893. }
  894. else {
  895. self.authAlertView.rate = 0.8f;
  896. }
  897. }
  898. MJWeakSelf;
  899. [self.authAlertView authEducationAction:^{
  900. [weakSelf toAuthEducation];
  901. }];
  902. [self.authAlertView showAlertView];
  903. }
  904. - (BadgeIntroduceView *)intruduceAlert {
  905. if (!_intruduceAlert) {
  906. _intruduceAlert = [BadgeIntroduceView shareInstance];
  907. _intruduceAlert.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight);
  908. }
  909. return _intruduceAlert;
  910. }
  911. - (void)showDescAlert {
  912. [self.intruduceAlert showAlertInView:[NSObject getKeyWindow]];
  913. }
  914. - (void)toUserCenter {
  915. UserSettingViewController *ctrl = [[UserSettingViewController alloc] init];
  916. [self.navigationController pushViewController:ctrl animated:YES];
  917. }
  918. - (void)toAuthDetail {
  919. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  920. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  921. [self.navigationController pushViewController:webCtrl animated:YES];
  922. }
  923. - (PublicNoticeView *)noticeView {
  924. if (!_noticeView) {
  925. _noticeView = [PublicNoticeView shareInstance];
  926. MJWeakSelf;
  927. [_noticeView moreCallback:^{
  928. [weakSelf moreNotice];
  929. }];
  930. }
  931. return _noticeView;
  932. }
  933. #pragma mark -- lazying
  934. - (dispatch_group_t)requestGroup {
  935. if (!_requestGroup) {
  936. _requestGroup = dispatch_group_create();
  937. }
  938. return _requestGroup;
  939. }
  940. - (SDCycleScrollView *)noticeScrollView {
  941. if (!_noticeScrollView) {
  942. _noticeScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage new]];
  943. _noticeScrollView.onlyDisplayText = YES;
  944. _noticeScrollView.autoScroll = NO;
  945. _noticeScrollView.scrollEnabled = NO;
  946. _noticeScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
  947. _noticeScrollView.titleLabelTextColor = HexRGB(0x1a1a1a);
  948. _noticeScrollView.titleLabelBackgroundColor = [UIColor whiteColor];
  949. _noticeScrollView.titleLabelTextFont = [UIFont systemFontOfSize:14];
  950. _noticeScrollView.titlesGroup = self.titleArray;
  951. }
  952. return _noticeScrollView;
  953. }
  954. - (NSMutableArray *)noticeArray {
  955. if (!_noticeArray) {
  956. _noticeArray = [NSMutableArray array];
  957. }
  958. return _noticeArray;
  959. }
  960. - (NSMutableArray *)titleArray {
  961. if (!_titleArray) {
  962. _titleArray = [NSMutableArray array];
  963. }
  964. return _titleArray;
  965. }
  966. - (void)moreNotice {
  967. if (self.noticeArray.count) {
  968. NoticeSourceModel *bannerModel = self.noticeArray[0];
  969. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  970. webCtrl.url = [NSString stringWithFormat:@"%@/#/helpCenterDetail?id=%@",WEBHOST, bannerModel.internalBaseClassIdentifier];
  971. [self.navigationController pushViewController:webCtrl animated:YES];
  972. }
  973. }
  974. - (HomeRecentCourseView *)courseView {
  975. if (!_courseView) {
  976. _courseView = [HomeRecentCourseView shareInstance];
  977. MJWeakSelf;
  978. [_courseView joinRoom:^(RECENTCOURSE_TYPE type, RecentCourseModel * _Nonnull courseModel) {
  979. [weakSelf joinRoomAction:type roomId:courseModel];
  980. }];
  981. }
  982. return _courseView;
  983. }
  984. - (void)joinRoomAction:(RECENTCOURSE_TYPE)type roomId:(RecentCourseModel *)courseModel {
  985. if (type == RECENTCOURSE_TYPE_ACCOMPANY) {
  986. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  987. detailVC.courseId = courseModel.courseId;
  988. detailVC.courseGroupId = courseModel.courseGroupId;
  989. detailVC.studentId = courseModel.studentId;
  990. [self.navigationController pushViewController:detailVC animated:YES];
  991. }
  992. else if (type == RECENTCOURSE_TYPE_MUSICCLASS) { // 琴房课
  993. MusicRoomViewController *ctrl = [[MusicRoomViewController alloc] init];
  994. ctrl.courseId = courseModel.courseId;
  995. ctrl.courseGroupId = courseModel.courseGroupId;
  996. [self.navigationController pushViewController:ctrl animated:YES];
  997. }
  998. else {
  999. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1000. ctrl.url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST, courseModel.courseGroupId,courseModel.courseId];
  1001. [self.navigationController pushViewController:ctrl animated:YES];
  1002. }
  1003. }
  1004. - (void)displaySongDetail:(NSString *)songId {
  1005. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1006. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
  1007. [self.navigationController pushViewController:ctrl animated:YES];
  1008. }
  1009. #pragma mark ---- scroll view delegate
  1010. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  1011. if (scrollView == self.buttonScrollView) {
  1012. NSInteger index = (NSInteger)(scrollView.contentOffset.x / (KPortraitWidth - 28));
  1013. [UIView animateWithDuration:0.3f animations:^{
  1014. self.buttonContainer.buttonDotLeft.constant = index * self.buttonDotWidth;
  1015. }];
  1016. }
  1017. }
  1018. #pragma mark ---- button container
  1019. - (HomeButtonView *)buttonContainer {
  1020. if (!_buttonContainer) {
  1021. _buttonContainer = [HomeButtonView shareInstance];
  1022. [_buttonContainer.buttonContentView addSubview:self.buttonScrollView];
  1023. }
  1024. return _buttonContainer;
  1025. }
  1026. - (UIScrollView *)buttonScrollView {
  1027. if (!_buttonScrollView) {
  1028. _buttonScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, (KPortraitWidth - 28), BUTTONHEIGHT)];
  1029. _buttonScrollView.backgroundColor = [UIColor clearColor];
  1030. _buttonScrollView.pagingEnabled = YES;
  1031. _buttonScrollView.showsHorizontalScrollIndicator = NO;
  1032. _buttonScrollView.showsVerticalScrollIndicator = NO;
  1033. _buttonScrollView.delegate = self;
  1034. }
  1035. return _buttonScrollView;
  1036. }
  1037. #pragma mark ---- collection data source
  1038. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  1039. return 1;
  1040. }
  1041. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  1042. if (collectionView == self.albumCollectionView) {
  1043. return self.albumArray.count;
  1044. }
  1045. else if (collectionView == self.recommendMusicCollectionView) {
  1046. NSInteger lastRowCount = (self.recommendMusicArray.count % 4) > 0 ? 1 : 0;
  1047. NSInteger count = self.recommendMusicArray.count / 4 + lastRowCount;
  1048. return count;
  1049. }
  1050. else if (collectionView == self.newestMusicCollectionView) {
  1051. NSInteger lastRowCount = (self.newestMusicArray.count % 4) > 0 ? 1 : 0;
  1052. NSInteger count = self.newestMusicArray.count / 4 + lastRowCount;
  1053. return count;
  1054. }
  1055. else {
  1056. NSInteger lastRowCount = (self.dataArray.count % 4) > 0 ? 1 : 0;
  1057. NSInteger count = self.dataArray.count / 4 + lastRowCount;
  1058. return count;
  1059. }
  1060. }
  1061. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  1062. if (collectionView == self.albumCollectionView) {
  1063. HomeAlbumModel *model = self.albumArray[indexPath.item];
  1064. HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
  1065. [cell configWithAlbumModel:model];
  1066. return cell;
  1067. }
  1068. else if (collectionView == self.recommendMusicCollectionView) {
  1069. NSMutableArray *songArray = [NSMutableArray array];
  1070. NSInteger length = indexPath.item * 4 + 4 > self.recommendMusicArray.count ? self.recommendMusicArray.count - indexPath.item * 4: 4;
  1071. NSRange range = NSMakeRange(indexPath.item * 4, length);
  1072. songArray = [NSMutableArray arrayWithArray:[self.recommendMusicArray subarrayWithRange:range]];
  1073. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  1074. MJWeakSelf;
  1075. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  1076. [weakSelf displaySongDetail:songId];
  1077. }];
  1078. return cell;
  1079. }
  1080. else if (collectionView == self.newestMusicCollectionView) {
  1081. NSMutableArray *songArray = [NSMutableArray array];
  1082. NSInteger length = indexPath.item * 4 + 4 > self.newestMusicArray.count ? self.newestMusicArray.count - indexPath.item * 4: 4;
  1083. NSRange range = NSMakeRange(indexPath.item * 4, length);
  1084. songArray = [NSMutableArray arrayWithArray:[self.newestMusicArray subarrayWithRange:range]];
  1085. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  1086. MJWeakSelf;
  1087. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  1088. [weakSelf displaySongDetail:songId];
  1089. }];
  1090. return cell;
  1091. }
  1092. else {
  1093. NSMutableArray *songArray = [NSMutableArray array];
  1094. NSInteger length = indexPath.item * 4 + 4 > self.dataArray.count ? self.dataArray.count - indexPath.item * 4: 4;
  1095. NSRange range = NSMakeRange(indexPath.item * 4, length);
  1096. songArray = [NSMutableArray arrayWithArray:[self.dataArray subarrayWithRange:range]];
  1097. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  1098. MJWeakSelf;
  1099. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  1100. [weakSelf displaySongDetail:songId];
  1101. }];
  1102. return cell;
  1103. }
  1104. }
  1105. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  1106. if (collectionView == self.albumCollectionView) {
  1107. HomeAlbumModel *model = self.albumArray[indexPath.item];
  1108. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1109. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
  1110. [self.navigationController pushViewController:ctrl animated:YES];
  1111. }
  1112. }
  1113. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  1114. if (collectionView == self.albumCollectionView) {
  1115. return CGSizeMake(100, 140);
  1116. }
  1117. else {
  1118. return CGSizeMake(KPortraitWidth * 0.83, 320);
  1119. }
  1120. }
  1121. #pragma mark ----- 专辑
  1122. - (HomeAlbumView *)albumView {
  1123. if (!_albumView) {
  1124. _albumView = [HomeAlbumView shareInstance];
  1125. MJWeakSelf;
  1126. [_albumView homeAlbumMore:^{
  1127. [weakSelf moreAlbumDetail];
  1128. }];
  1129. [_albumView.albumContentView addSubview:self.albumCollectionView];
  1130. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1131. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  1132. }];
  1133. }
  1134. return _albumView;
  1135. }
  1136. - (UICollectionView *)albumCollectionView {
  1137. if (!_albumCollectionView) {
  1138. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1139. layout.sectionInset = UIEdgeInsetsMake(12, 11, 12, 14);
  1140. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1141. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1142. _albumCollectionView.backgroundColor = [UIColor clearColor];
  1143. _albumCollectionView.delegate = self;
  1144. _albumCollectionView.dataSource = self;
  1145. _albumCollectionView.showsVerticalScrollIndicator = NO;
  1146. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  1147. if (@available(iOS 11.0, *)) {
  1148. _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1149. } else {
  1150. // Fallback on earlier versions
  1151. if (@available(iOS 13.0, *)) {
  1152. _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1153. } else {
  1154. // Fallback on earlier versions
  1155. }
  1156. }
  1157. [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
  1158. }
  1159. return _albumCollectionView;
  1160. }
  1161. - (NSMutableArray *)albumArray {
  1162. if (!_albumArray) {
  1163. _albumArray = [NSMutableArray array];
  1164. }
  1165. return _albumArray;
  1166. }
  1167. - (void)moreAlbumDetail {
  1168. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1169. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
  1170. [self.navigationController pushViewController:ctrl animated:YES];
  1171. }
  1172. #pragma mark --- 推荐曲目
  1173. - (HomeRecommendMusicView *)recommendMusicView {
  1174. if (!_recommendMusicView) {
  1175. _recommendMusicView = [HomeRecommendMusicView shareInstance];
  1176. MJWeakSelf;
  1177. [_recommendMusicView homeMusicMore:^{
  1178. [weakSelf moreRecommendMusic];
  1179. }];
  1180. [_recommendMusicView.musicContentView addSubview:self.recommendMusicCollectionView];
  1181. [self.recommendMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1182. make.left.right.bottom.top.mas_equalTo(_recommendMusicView.musicContentView);
  1183. }];
  1184. }
  1185. return _recommendMusicView;
  1186. }
  1187. - (UICollectionView *)recommendMusicCollectionView {
  1188. if (!_recommendMusicCollectionView) {
  1189. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1190. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1191. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1192. _recommendMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1193. _recommendMusicCollectionView.backgroundColor = [UIColor clearColor];
  1194. _recommendMusicCollectionView.delegate = self;
  1195. _recommendMusicCollectionView.dataSource = self;
  1196. _recommendMusicCollectionView.showsVerticalScrollIndicator = NO;
  1197. _recommendMusicCollectionView.showsHorizontalScrollIndicator = NO;
  1198. if (@available(iOS 11.0, *)) {
  1199. _recommendMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1200. } else {
  1201. // Fallback on earlier versions
  1202. if (@available(iOS 13.0, *)) {
  1203. _recommendMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1204. } else {
  1205. // Fallback on earlier versions
  1206. }
  1207. }
  1208. [_recommendMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  1209. }
  1210. return _recommendMusicCollectionView;
  1211. }
  1212. - (NSMutableArray *)recommendMusicArray {
  1213. if (!_recommendMusicArray) {
  1214. _recommendMusicArray = [NSMutableArray array];
  1215. }
  1216. return _recommendMusicArray;
  1217. }
  1218. - (void)moreRecommendMusic {
  1219. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1220. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  1221. [self.navigationController pushViewController:ctrl animated:YES];
  1222. }
  1223. #pragma mark ---- 最新曲目
  1224. - (HomeNewMusicView *)newestMusicView {
  1225. if (!_newestMusicView) {
  1226. if (!_newestMusicView) {
  1227. _newestMusicView = [HomeNewMusicView shareInstance];
  1228. MJWeakSelf;
  1229. [_newestMusicView homeMusicMore:^{
  1230. [weakSelf moreNewMusic];
  1231. }];
  1232. [_newestMusicView.musicContentView addSubview:self.newestMusicCollectionView];
  1233. [self.newestMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1234. make.left.right.bottom.top.mas_equalTo(_newestMusicView.musicContentView);
  1235. }];
  1236. }
  1237. return _newestMusicView;
  1238. }
  1239. return _newestMusicView;
  1240. }
  1241. - (UICollectionView *)newestMusicCollectionView {
  1242. if (!_newestMusicCollectionView) {
  1243. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1244. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1245. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1246. _newestMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1247. _newestMusicCollectionView.backgroundColor = [UIColor clearColor];
  1248. _newestMusicCollectionView.delegate = self;
  1249. _newestMusicCollectionView.dataSource = self;
  1250. _newestMusicCollectionView.showsVerticalScrollIndicator = NO;
  1251. _newestMusicCollectionView.showsHorizontalScrollIndicator = NO;
  1252. if (@available(iOS 11.0, *)) {
  1253. _newestMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1254. } else {
  1255. // Fallback on earlier versions
  1256. if (@available(iOS 13.0, *)) {
  1257. _newestMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1258. } else {
  1259. // Fallback on earlier versions
  1260. }
  1261. }
  1262. [_newestMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  1263. }
  1264. return _newestMusicCollectionView;
  1265. }
  1266. - (NSMutableArray *)newestMusicArray {
  1267. if (!_newestMusicArray) {
  1268. _newestMusicArray = [NSMutableArray array];
  1269. }
  1270. return _newestMusicArray;
  1271. }
  1272. - (void)moreNewMusic {
  1273. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1274. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  1275. [self.navigationController pushViewController:ctrl animated:YES];
  1276. }
  1277. #pragma mark ---- 更多曲目
  1278. - (HomeHotMusicView *)hotMusicView {
  1279. if (!_hotMusicView) {
  1280. _hotMusicView = [HomeHotMusicView shareInstance];
  1281. MJWeakSelf;
  1282. [_hotMusicView homeMusicMore:^{
  1283. [weakSelf moreHotMusic];
  1284. }];
  1285. [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
  1286. [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  1287. make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
  1288. }];
  1289. }
  1290. return _hotMusicView;
  1291. }
  1292. - (void)moreHotMusic {
  1293. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1294. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  1295. [self.navigationController pushViewController:ctrl animated:YES];
  1296. }
  1297. - (UICollectionView *)musicCollectionView {
  1298. if (!_musicCollectionView) {
  1299. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1300. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  1301. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  1302. _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  1303. _musicCollectionView.backgroundColor = [UIColor clearColor];
  1304. _musicCollectionView.delegate = self;
  1305. _musicCollectionView.dataSource = self;
  1306. _musicCollectionView.showsVerticalScrollIndicator = NO;
  1307. _musicCollectionView.showsHorizontalScrollIndicator = NO;
  1308. if (@available(iOS 11.0, *)) {
  1309. _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1310. } else {
  1311. // Fallback on earlier versions
  1312. if (@available(iOS 13.0, *)) {
  1313. _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1314. } else {
  1315. // Fallback on earlier versions
  1316. }
  1317. }
  1318. [_musicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  1319. }
  1320. return _musicCollectionView;
  1321. }
  1322. - (HomeBannerView *)bannerView {
  1323. if (!_bannerView) {
  1324. _bannerView = [HomeBannerView shareInstance];
  1325. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  1326. }
  1327. return _bannerView;
  1328. }
  1329. - (TYCyclePagerView *)bannerScroll {
  1330. if (!_bannerScroll) {
  1331. _bannerScroll = [[TYCyclePagerView alloc] init];
  1332. _bannerScroll.backgroundColor = [UIColor clearColor];
  1333. _bannerScroll.frame = CGRectMake(0, 0, kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
  1334. _bannerScroll.isInfiniteLoop = YES;
  1335. _bannerScroll.autoScrollInterval = 3.0f;
  1336. _bannerScroll.reloadDataNeedResetIndex = YES;
  1337. _bannerScroll.dataSource = self;
  1338. _bannerScroll.delegate = self;
  1339. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  1340. if (@available(iOS 11.0, *)) {
  1341. _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  1342. } else {
  1343. // Fallback on earlier versions
  1344. if (@available(iOS 13.0, *)) {
  1345. _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  1346. } else {
  1347. // Fallback on earlier versions
  1348. }
  1349. }
  1350. }
  1351. return _bannerScroll;
  1352. }
  1353. - (TYPageControl *)pageControl {
  1354. if (!_pageControl) {
  1355. _pageControl = [[TYPageControl alloc] init];
  1356. _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  1357. _pageControl.pageIndicatorSpaing = 4.0f;
  1358. _pageControl.frame = CGRectMake(0, (kScreenWidth - 28) * 132 / 347 - 20, kScreenWidth-28 - 12, 12);
  1359. _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
  1360. _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
  1361. _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
  1362. _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
  1363. }
  1364. return _pageControl;
  1365. }
  1366. - (NSMutableArray *)bannerArray {
  1367. if (!_bannerArray) {
  1368. _bannerArray = [NSMutableArray array];
  1369. }
  1370. return _bannerArray;
  1371. }
  1372. #pragma mark - TYCyclePagerViewDataSource代理
  1373. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  1374. return self.bannerArray.count;
  1375. }
  1376. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  1377. HomeMessageModel *model = self.bannerArray[index];
  1378. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  1379. [cell configCellWithModel:model];
  1380. return cell;
  1381. }
  1382. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  1383. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  1384. layout.itemSize = CGSizeMake(kScreenWidth - 28, (kScreenWidth - 28) / 347 * 132);
  1385. layout.itemSpacing = 0;
  1386. return layout;
  1387. }
  1388. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  1389. if (pageView == self.bannerScroll) {
  1390. [self.pageControl setCurrentPage:toIndex animate:YES];
  1391. }
  1392. }
  1393. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  1394. HomeMessageModel *model = self.bannerArray[index];
  1395. if (![NSString isEmptyString:model.linkUrl]) {
  1396. if ([model.linkType isEqualToString:@"OUT"]) {
  1397. // 外部浏览器打开
  1398. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:model.linkUrl] options: @{} completionHandler: nil];
  1399. }
  1400. else {
  1401. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1402. webCtrl.url = model.linkUrl;
  1403. [self.navigationController pushViewController:webCtrl animated:YES];
  1404. }
  1405. }
  1406. }
  1407. - (HomeDragButton *)suspendButton {
  1408. if (!_suspendButton) {
  1409. _suspendButton = [[HomeDragButton alloc] initWithFrame:CGRectMake(KPortraitWidth - HomeDragButtonWidth - 10, KPortraitHeight - kTabBarHeight - HomeDragButtonHeight - 12 , HomeDragButtonWidth, HomeDragButtonHeight)];
  1410. MJWeakSelf;
  1411. [_suspendButton clickAction:^{
  1412. [weakSelf showDragWindowDetail];
  1413. }];
  1414. }
  1415. return _suspendButton;
  1416. }
  1417. - (void)showDragWindowDetail {
  1418. NSString *linkUrl = self.buttonModel.linkUrl;
  1419. if ([self.buttonModel.linkType isEqualToString:@"OUT"]) {
  1420. // 外部浏览器打开
  1421. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:linkUrl] options: @{} completionHandler: nil];
  1422. }
  1423. else {
  1424. if (![NSString isEmptyString:linkUrl]) {
  1425. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  1426. webCtrl.url = linkUrl;
  1427. [self.navigationController pushViewController:webCtrl animated:YES];
  1428. }
  1429. }
  1430. }
  1431. - (HomeTenantPageView *)tenantAlbumView {
  1432. if (!_tenantAlbumView) {
  1433. _tenantAlbumView = [HomeTenantPageView shareInstance];
  1434. MJWeakSelf;
  1435. [_tenantAlbumView displayTenatantPage:^{
  1436. [weakSelf showTenantAlbumPageView];
  1437. }];
  1438. }
  1439. return _tenantAlbumView;
  1440. }
  1441. - (void)showTenantAlbumPageView {
  1442. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  1443. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/train-tool"];
  1444. [self.navigationController pushViewController:ctrl animated:YES];
  1445. }
  1446. - (HomeTenantView *)tenantNameView {
  1447. if (!_tenantNameView) {
  1448. _tenantNameView = [HomeTenantView shareInstance];
  1449. }
  1450. return _tenantNameView;
  1451. }
  1452. /*
  1453. #pragma mark - Navigation
  1454. // In a storyboard-based application, you will often want to do a little preparation before navigation
  1455. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  1456. // Get the new view controller using [segue destinationViewController].
  1457. // Pass the selected object to the new view controller.
  1458. }
  1459. */
  1460. @end