HomeViewController.m 53 KB

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