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