HomeViewController.m 50 KB

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