TenantMoreViewController.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. //
  2. // TenantMoreViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2023/9/12.
  6. //
  7. #import "TenantMoreViewController.h"
  8. #import "MorePageNavView.h"
  9. #import "MorePageSearchView.h"
  10. #import "TenantHomeBannerView.h"
  11. #import "TYCyclePagerView.h"
  12. #import "TYPageControl.h"
  13. #import "HomeBannerCell.h"
  14. #import "TenantHotAlbumView.h"
  15. #import "TenantHotAlbumCell.h"
  16. #import "HomeAlbumModel.h"
  17. #import "KSPremissionAlert.h"
  18. #import <RecordCheckManager.h>
  19. #import "TenantRecommendMusicView.h"
  20. #import "TenantNewMusicView.h"
  21. #import "TenantHotMusicView.h"
  22. #import "TenantMusicCollectionViewCell.h"
  23. #import "KSBaseWKWebViewController.h"
  24. #import "UserInfo.h"
  25. #import "UserInfoManager.h"
  26. #import "InstrumentChooseViewController.h"
  27. #import "TenantDragView.h"
  28. #import "ToneTuningViewController.h"
  29. #import "HomeMusicSheetLayout.h"
  30. #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
  31. #define COLLECTION_HEIGHT (243)
  32. @interface TenantMoreViewController ()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
  33. @property (nonatomic, copy) SwitchDarkCallback callback;
  34. @property (nonatomic, strong) MorePageNavView *navView;
  35. @property (nonatomic, strong) MorePageSearchView *searchView;
  36. // banner
  37. @property (nonatomic, strong) TYPageControl *pageControl;
  38. @property (nonatomic, strong) TenantHomeBannerView *bannerView; // banner container
  39. @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
  40. @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
  41. @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
  42. // 专辑
  43. @property (nonatomic, strong) TenantHotAlbumView *albumView;
  44. @property (nonatomic, strong) NSMutableArray *albumArray;
  45. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  46. @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
  47. // 推荐
  48. @property (nonatomic, strong) TenantRecommendMusicView *recommendMusicView;
  49. @property (nonatomic, strong) UICollectionView *recommendMusicCollectionView; // 曲谱容器
  50. @property (nonatomic, strong) NSMutableArray *recommendMusicArray; // 曲谱数据
  51. @property (nonatomic, assign) CGFloat recommendMusicViewHeight; // music 高度
  52. // 最新曲目
  53. @property (nonatomic, strong) TenantNewMusicView *newestMusicView;
  54. @property (nonatomic, strong) UICollectionView *newestMusicCollectionView; // 曲谱容器
  55. @property (nonatomic, strong) NSMutableArray *newestMusicArray; // 曲谱数据
  56. @property (nonatomic, assign) CGFloat newestMusicViewHeight; // music 高度
  57. // 热门曲谱
  58. @property (nonatomic, strong) TenantHotMusicView *hotMusicView;
  59. @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
  60. @property (nonatomic, strong) NSMutableArray *musicArray; // 曲谱数据
  61. @property (nonatomic, assign) CGFloat hotMusicViewHeight; // music 高度
  62. @property (nonatomic, strong) dispatch_group_t requestGroup;
  63. @property (nonatomic, strong) UserInfo *mineInfo;
  64. @property (nonatomic, strong) TenantDragView *suspendButton;
  65. @end
  66. @implementation TenantMoreViewController
  67. - (void)swithToDarkPageAction:(SwitchDarkCallback)callback {
  68. if (callback) {
  69. self.callback = callback;
  70. }
  71. }
  72. - (void)viewDidLoad {
  73. [super viewDidLoad];
  74. // Do any additional setup after loading the view.
  75. [self configUI];
  76. }
  77. - (void)configUI {
  78. self.view.backgroundColor = HexRGB(0xFAFAFA);
  79. UIImage *bgImage = [UIImage imageNamed:@"tenant_light_bg"];
  80. CGFloat height = bgImage.size.height / bgImage.size.width * KPortraitWidth;
  81. UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
  82. bgImageView.contentMode = UIViewContentModeRedraw;
  83. [self.view addSubview:bgImageView];
  84. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.right.top.mas_equalTo(self.view);
  86. make.height.mas_equalTo(height);
  87. }];
  88. self.scrollView.backgroundColor = [UIColor clearColor];
  89. [self.view bringSubviewToFront:self.scrollView];
  90. MJWeakSelf;
  91. self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  92. [weakSelf requestData];
  93. }];
  94. [self.view addSubview:self.navView];
  95. CGFloat navHeight = [MorePageNavView getViewHeight];
  96. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.right.top.mas_equalTo(self.view);
  98. make.height.mas_equalTo(navHeight);
  99. }];
  100. // 搜索
  101. [self.view addSubview:self.searchView];
  102. CGFloat searchHeight = [MorePageSearchView getViewHeight];
  103. [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.right.mas_equalTo(self.view);
  105. make.top.mas_equalTo(self.navView.mas_bottom);
  106. make.height.mas_equalTo(searchHeight);
  107. }];
  108. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  109. make.left.right.bottom.mas_equalTo(self.view);
  110. make.top.mas_equalTo(self.searchView.mas_bottom);
  111. }];
  112. // banner
  113. [self.scrollView addSubview:self.bannerView];
  114. self.bannerViewHeight = CGFLOAT_MIN;
  115. [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.top.mas_equalTo(self.scrollView.mas_top);
  117. make.left.right.mas_equalTo(self.view);
  118. make.height.mas_equalTo(self.bannerViewHeight);
  119. }];
  120. // 专辑
  121. [self.scrollView addSubview:self.albumView];
  122. self.albumViewHeight = [TenantHotAlbumView getViewHeight];
  123. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.right.mas_equalTo(self.view);
  125. make.top.mas_equalTo(self.bannerView.mas_bottom);
  126. make.height.mas_equalTo(self.albumViewHeight);
  127. }];
  128. // 推荐曲目
  129. [self.scrollView addSubview:self.recommendMusicView];
  130. self.recommendMusicViewHeight = [TenantRecommendMusicView getViewHeight];
  131. [self.recommendMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.left.right.mas_equalTo(self.view);
  133. make.top.mas_equalTo(self.albumView.mas_bottom);
  134. make.height.mas_equalTo(self.recommendMusicViewHeight);
  135. }];
  136. // 最新
  137. [self.scrollView addSubview:self.newestMusicView];
  138. self.newestMusicViewHeight = [TenantNewMusicView getViewHeight];
  139. [self.newestMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  140. make.left.right.mas_equalTo(self.view);
  141. make.top.mas_equalTo(self.recommendMusicView.mas_bottom);
  142. make.height.mas_equalTo(self.newestMusicViewHeight);
  143. }];
  144. // 热门
  145. [self.scrollView addSubview:self.hotMusicView];
  146. self.hotMusicViewHeight = [TenantHotMusicView getViewHeight];
  147. [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.left.right.mas_equalTo(self.view);
  149. make.top.mas_equalTo(self.newestMusicView.mas_bottom);
  150. make.height.mas_equalTo(self.hotMusicViewHeight);
  151. make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
  152. }];
  153. [self showFloatingWindow];
  154. }
  155. - (void)showFloatingWindow {
  156. if (![self.view.subviews containsObject:self.suspendButton]) {
  157. [self.view addSubview:self.suspendButton];
  158. }
  159. [self.view bringSubviewToFront:self.suspendButton];
  160. }
  161. - (void)viewWillAppear:(BOOL)animated {
  162. [super viewWillAppear:animated];
  163. [self requestData];
  164. }
  165. - (void)requestData {
  166. [self requestUserInfo];
  167. [self requestNewsList];
  168. [self requestHotAlbum];
  169. [self requestHomeMusicMessage];
  170. [self requestUserInfo];
  171. dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
  172. // [LOADING_MANAGER removeHUD];
  173. [self.scrollView.mj_header endRefreshing];
  174. [self refreshView];
  175. });
  176. }
  177. - (void)requestUserInfo {
  178. [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  179. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  180. self.mineInfo = [[UserInfo alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  181. }
  182. else {
  183. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  184. }
  185. [self refreshHeader];
  186. } faliure:^(NSError * _Nonnull error) {
  187. }];
  188. }
  189. - (void)refreshHeader {
  190. self.navView.tenantName.text = [NSString returnNoNullStringWithString:self.mineInfo.tenantName];
  191. // self.searchView.subjectLabel.text = [NSString returnNoNullStringWithString:self.mineInfo.subjectName];
  192. }
  193. // banner
  194. - (void)requestNewsList {
  195. dispatch_group_enter(self.requestGroup);
  196. [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  197. dispatch_group_leave(self.requestGroup);
  198. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  199. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  200. // banner
  201. NSArray *bannerArray = [result ks_arrayValueForKey:@"banner"];
  202. NSMutableArray *bannerInfoArray = [NSMutableArray array];
  203. for (NSDictionary *parm in bannerArray) {
  204. HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
  205. [bannerInfoArray addObject:model];
  206. }
  207. self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
  208. }
  209. else {
  210. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  211. }
  212. } faliure:^(NSError * _Nonnull error) {
  213. dispatch_group_leave(self.requestGroup);
  214. }];
  215. }
  216. - (void)requestHotAlbum {
  217. dispatch_group_enter(self.requestGroup);
  218. [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  219. dispatch_group_leave(self.requestGroup);
  220. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  221. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  222. NSMutableArray *albumArray = [NSMutableArray array];
  223. for (NSDictionary *parm in sourceArray) {
  224. HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
  225. [albumArray addObject:model];
  226. }
  227. self.albumArray = [NSMutableArray arrayWithArray:albumArray];
  228. }
  229. else {
  230. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  231. }
  232. } faliure:^(NSError * _Nonnull error) {
  233. dispatch_group_leave(self.requestGroup);
  234. }];
  235. }
  236. - (void)requestHomeMusicMessage {
  237. dispatch_group_enter(self.requestGroup);
  238. [KSNetworkingManager homeAppMusicSheetRequest:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  239. dispatch_group_leave(self.requestGroup);
  240. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  241. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  242. NSArray *hotMusicSheet = [result ks_arrayValueForKey:@"hotMusicSheet"]; // 热门曲目
  243. NSMutableArray *hotArray = [NSMutableArray array];
  244. for (NSDictionary *parm in hotMusicSheet) {
  245. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  246. [hotArray addObject:model];
  247. }
  248. self.musicArray = [NSMutableArray arrayWithArray:hotArray];
  249. NSArray *newMusicSheet = [result ks_arrayValueForKey:@"newMusicSheet"]; // 最新曲目
  250. NSMutableArray *newMusicArray = [NSMutableArray array];
  251. for (NSDictionary *parm in newMusicSheet) {
  252. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  253. [newMusicArray addObject:model];
  254. }
  255. self.newestMusicArray = [NSMutableArray arrayWithArray:newMusicArray];
  256. NSArray *topMusicSheet = [result ks_arrayValueForKey:@"topMusicSheet"]; // 推荐曲目
  257. NSMutableArray *topMusicArray = [NSMutableArray array];
  258. for (NSDictionary *parm in topMusicSheet) {
  259. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  260. [topMusicArray addObject:model];
  261. }
  262. self.recommendMusicArray = [NSMutableArray arrayWithArray:topMusicArray];
  263. }
  264. else {
  265. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  266. }
  267. } faliure:^(NSError * _Nonnull error) {
  268. dispatch_group_leave(self.requestGroup);
  269. }];
  270. }
  271. - (void)refreshView {
  272. [self refreshBannerView];
  273. [self refreshAlbumView];
  274. [self refreshMusicView];
  275. }
  276. - (void)refreshBannerView {
  277. if (self.bannerArray.count) {
  278. self.bannerView.hidden = NO;
  279. CGFloat bannerViewHeight = [TenantHomeBannerView getViewHeight];
  280. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  281. make.height.mas_equalTo(bannerViewHeight);
  282. }];
  283. }
  284. else {
  285. self.bannerView.hidden = YES;
  286. [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
  287. make.height.mas_equalTo(CGFLOAT_MIN);
  288. }];
  289. }
  290. if (self.bannerArray.count > 1) {
  291. self.bannerScroll.autoScrollInterval = 3.0f;
  292. [self.bannerScroll addSubview:self.pageControl];
  293. }
  294. else {
  295. self.bannerScroll.autoScrollInterval = 0;
  296. [self.pageControl removeFromSuperview];
  297. }
  298. self.pageControl.numberOfPages = self.bannerArray.count;
  299. [self.bannerScroll reloadData];
  300. }
  301. - (void)refreshAlbumView {
  302. if (self.albumArray.count) {
  303. self.albumViewHeight = [TenantHotAlbumView getViewHeight];
  304. self.albumView.hidden = NO;
  305. }
  306. else {
  307. self.albumViewHeight = CGFLOAT_MIN;
  308. self.albumView.hidden = YES;
  309. }
  310. [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
  311. make.height.mas_equalTo(self.albumViewHeight);
  312. }];
  313. [self.albumCollectionView reloadData];
  314. }
  315. - (void)refreshMusicView {
  316. if (self.recommendMusicArray.count) {
  317. self.recommendMusicViewHeight = [TenantRecommendMusicView getViewHeight];
  318. self.recommendMusicView.hidden = NO;
  319. }
  320. else {
  321. self.recommendMusicViewHeight = CGFLOAT_MIN;
  322. self.recommendMusicView.hidden = YES;
  323. }
  324. [self.recommendMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  325. make.height.mas_equalTo(self.recommendMusicViewHeight);
  326. }];
  327. [self.recommendMusicCollectionView reloadData];
  328. if (self.newestMusicArray.count) {
  329. self.newestMusicViewHeight = [TenantNewMusicView getViewHeight];
  330. self.newestMusicView.hidden = NO;
  331. }
  332. else {
  333. self.newestMusicViewHeight = CGFLOAT_MIN;
  334. self.newestMusicView.hidden = YES;
  335. }
  336. [self.newestMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  337. make.height.mas_equalTo(self.newestMusicViewHeight);
  338. }];
  339. [self.newestMusicCollectionView reloadData];
  340. if (self.musicArray.count) {
  341. self.hotMusicViewHeight = [TenantHotMusicView getViewHeight];
  342. self.hotMusicView.hidden = NO;
  343. }
  344. else {
  345. self.hotMusicViewHeight = CGFLOAT_MIN;
  346. self.hotMusicView.hidden = YES;
  347. }
  348. [self.hotMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  349. make.height.mas_equalTo(self.hotMusicViewHeight);
  350. }];
  351. [self.musicCollectionView reloadData];
  352. }
  353. #pragma mark - TYCyclePagerViewDataSource代理
  354. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  355. return self.bannerArray.count;
  356. }
  357. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  358. HomeMessageModel *model = self.bannerArray[index];
  359. HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
  360. [cell configCellWithModel:model];
  361. return cell;
  362. }
  363. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  364. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  365. layout.itemSize = CGSizeMake(KPortraitWidth - 26, (KPortraitWidth - 26) / 347 * 132);
  366. layout.itemSpacing = 0;
  367. return layout;
  368. }
  369. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  370. if (pageView == self.bannerScroll) {
  371. [self.pageControl setCurrentPage:toIndex animate:YES];
  372. }
  373. }
  374. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
  375. HomeMessageModel *model = self.bannerArray[index];
  376. if (![NSString isEmptyString:model.linkUrl]) {
  377. if ([model.linkType isEqualToString:@"OUT"]) {
  378. // 外部浏览器打开
  379. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[model.linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
  380. }
  381. else {
  382. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  383. webCtrl.url = [model.linkUrl getUrlEndcodeString];
  384. [self.navigationController pushViewController:webCtrl animated:YES];
  385. }
  386. }
  387. }
  388. #pragma mark ---- collection data source
  389. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  390. return 1;
  391. }
  392. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  393. if (collectionView == self.albumCollectionView) {
  394. return self.albumArray.count;
  395. }
  396. else if (collectionView == self.recommendMusicCollectionView) {
  397. NSInteger lastRowCount = (self.recommendMusicArray.count % 4) > 0 ? 1 : 0;
  398. NSInteger count = self.recommendMusicArray.count / 4 + lastRowCount;
  399. return count;
  400. }
  401. else if (collectionView == self.newestMusicCollectionView) {
  402. NSInteger lastRowCount = (self.newestMusicArray.count % 4) > 0 ? 1 : 0;
  403. NSInteger count = self.newestMusicArray.count / 4 + lastRowCount;
  404. return count;
  405. }
  406. else {
  407. NSInteger lastRowCount = (self.musicArray.count % 4) > 0 ? 1 : 0;
  408. NSInteger count = self.musicArray.count / 4 + lastRowCount;
  409. return count;
  410. }
  411. }
  412. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  413. if (collectionView == self.albumCollectionView) {
  414. HomeAlbumModel *model = self.albumArray[indexPath.item];
  415. TenantHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantHotAlbumCell" forIndexPath:indexPath];
  416. [cell configWithAlbumModel:model];
  417. return cell;
  418. }
  419. else if (collectionView == self.recommendMusicCollectionView) {
  420. NSMutableArray *songArray = [NSMutableArray array];
  421. NSInteger length = indexPath.item * 3 + 3 > self.recommendMusicArray.count ? self.recommendMusicArray.count - indexPath.item * 3: 3;
  422. NSRange range = NSMakeRange(indexPath.item * 3, length);
  423. songArray = [NSMutableArray arrayWithArray:[self.recommendMusicArray subarrayWithRange:range]];
  424. TenantMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantMusicCollectionViewCell" forIndexPath:indexPath];
  425. MJWeakSelf;
  426. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  427. [weakSelf displaySongDetail:songId];
  428. }];
  429. return cell;
  430. }
  431. else if (collectionView == self.newestMusicCollectionView) {
  432. NSMutableArray *songArray = [NSMutableArray array];
  433. NSInteger length = indexPath.item * 3 + 3 > self.newestMusicArray.count ? self.newestMusicArray.count - indexPath.item * 3: 3;
  434. NSRange range = NSMakeRange(indexPath.item * 3, length);
  435. songArray = [NSMutableArray arrayWithArray:[self.newestMusicArray subarrayWithRange:range]];
  436. TenantMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantMusicCollectionViewCell" forIndexPath:indexPath];
  437. MJWeakSelf;
  438. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  439. [weakSelf displaySongDetail:songId];
  440. }];
  441. return cell;
  442. }
  443. else {
  444. NSMutableArray *songArray = [NSMutableArray array];
  445. NSInteger length = indexPath.item * 3 + 3 > self.musicArray.count ? self.musicArray.count - indexPath.item * 3: 3;
  446. NSRange range = NSMakeRange(indexPath.item * 3, length);
  447. songArray = [NSMutableArray arrayWithArray:[self.musicArray subarrayWithRange:range]];
  448. TenantMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantMusicCollectionViewCell" forIndexPath:indexPath];
  449. MJWeakSelf;
  450. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  451. [weakSelf displaySongDetail:songId];
  452. }];
  453. return cell;
  454. }
  455. }
  456. - (void)displaySongDetail:(NSString *)songId {
  457. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  458. ctrl.url = [NSString stringWithFormat:@"%@%@%@", TENANT_WEBHOST, @"/#/music-detail?id=",songId];
  459. [self.navigationController pushViewController:ctrl animated:YES];
  460. }
  461. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  462. if (collectionView == self.albumCollectionView) {
  463. HomeAlbumModel *model = self.albumArray[indexPath.item];
  464. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  465. ctrl.url = [NSString stringWithFormat:@"%@%@%@", TENANT_WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
  466. [self.navigationController pushViewController:ctrl animated:YES];
  467. }
  468. }
  469. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  470. if (collectionView == self.albumCollectionView) {
  471. return CGSizeMake(110, 145);
  472. }
  473. else {
  474. return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
  475. }
  476. }
  477. #pragma mark --- lazying
  478. - (MorePageNavView *)navView {
  479. if (!_navView) {
  480. _navView = [MorePageNavView shareInstance];
  481. MJWeakSelf;
  482. [_navView trainPageSwitch:^{
  483. [weakSelf switchTrainPageAction];
  484. }];
  485. }
  486. return _navView;
  487. }
  488. - (void)switchTrainPageAction {
  489. if (self.callback) {
  490. self.callback();
  491. }
  492. }
  493. - (MorePageSearchView *)searchView {
  494. if (!_searchView) {
  495. _searchView = [MorePageSearchView shareInstance];
  496. MJWeakSelf;
  497. [_searchView morePageSearch:^(TENANTSEARCH type) {
  498. if (type == TENANTSEARCH_SEARCH) {
  499. [weakSelf showSearchPage];
  500. }
  501. else {
  502. [weakSelf showInstrumentView];
  503. }
  504. }];
  505. }
  506. return _searchView;
  507. }
  508. - (void)showSearchPage {
  509. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  510. webCtrl.url = [NSString stringWithFormat:@"%@/#/music-songbook/search", TENANT_WEBHOST];
  511. [self.navigationController pushViewController:webCtrl animated:YES];
  512. }
  513. - (void)showInstrumentView {
  514. InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
  515. MJWeakSelf;
  516. [ctrl chooseCallback:^{
  517. [weakSelf requestData];
  518. }];
  519. [self.navigationController pushViewController:ctrl animated:YES];
  520. }
  521. - (TenantHomeBannerView *)bannerView {
  522. if (!_bannerView) {
  523. _bannerView = [TenantHomeBannerView shareInstance];
  524. [_bannerView.bannerContentView addSubview:self.bannerScroll];
  525. }
  526. return _bannerView;
  527. }
  528. - (TYCyclePagerView *)bannerScroll {
  529. if (!_bannerScroll) {
  530. _bannerScroll = [[TYCyclePagerView alloc] init];
  531. _bannerScroll.backgroundColor = [UIColor clearColor];
  532. _bannerScroll.frame = CGRectMake(0, 0, KPortraitWidth - 26, (KPortraitWidth - 26) / 347 * 132);
  533. _bannerScroll.isInfiniteLoop = YES;
  534. _bannerScroll.autoScrollInterval = 3.0f;
  535. _bannerScroll.reloadDataNeedResetIndex = YES;
  536. _bannerScroll.dataSource = self;
  537. _bannerScroll.delegate = self;
  538. [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
  539. if (@available(iOS 11.0, *)) {
  540. _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  541. } else {
  542. // Fallback on earlier versions
  543. if (@available(iOS 13.0, *)) {
  544. _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  545. } else {
  546. // Fallback on earlier versions
  547. }
  548. }
  549. }
  550. return _bannerScroll;
  551. }
  552. - (TYPageControl *)pageControl {
  553. if (!_pageControl) {
  554. _pageControl = [[TYPageControl alloc] init];
  555. _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  556. _pageControl.pageIndicatorSpaing = 4.0f;
  557. _pageControl.frame = CGRectMake(0, (KPortraitWidth - 26) * 132 / 347 - 20, KPortraitWidth-26 - 12, 12);
  558. _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
  559. _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
  560. _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
  561. _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
  562. }
  563. return _pageControl;
  564. }
  565. - (NSMutableArray *)bannerArray {
  566. if (!_bannerArray) {
  567. _bannerArray = [NSMutableArray array];
  568. }
  569. return _bannerArray;
  570. }
  571. - (dispatch_group_t)requestGroup {
  572. if (!_requestGroup) {
  573. _requestGroup = dispatch_group_create();
  574. }
  575. return _requestGroup;
  576. }
  577. #pragma mark ----- 专辑
  578. - (TenantHotAlbumView *)albumView {
  579. if (!_albumView) {
  580. _albumView = [TenantHotAlbumView shareInstance];
  581. MJWeakSelf;
  582. [_albumView homeAlbumMore:^{
  583. [weakSelf moreAlbumDetail];
  584. }];
  585. [_albumView.albumContentView addSubview:self.albumCollectionView];
  586. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  587. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  588. }];
  589. }
  590. return _albumView;
  591. }
  592. - (UICollectionView *)albumCollectionView {
  593. if (!_albumCollectionView) {
  594. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  595. layout.sectionInset = UIEdgeInsetsMake(12, 11, 12, 14);
  596. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  597. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  598. _albumCollectionView.backgroundColor = [UIColor clearColor];
  599. _albumCollectionView.delegate = self;
  600. _albumCollectionView.dataSource = self;
  601. _albumCollectionView.showsVerticalScrollIndicator = NO;
  602. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  603. if (@available(iOS 11.0, *)) {
  604. _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  605. } else {
  606. // Fallback on earlier versions
  607. if (@available(iOS 13.0, *)) {
  608. _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  609. } else {
  610. // Fallback on earlier versions
  611. }
  612. }
  613. [_albumCollectionView registerNib:[UINib nibWithNibName:@"TenantHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantHotAlbumCell"];
  614. }
  615. return _albumCollectionView;
  616. }
  617. - (NSMutableArray *)albumArray {
  618. if (!_albumArray) {
  619. _albumArray = [NSMutableArray array];
  620. }
  621. return _albumArray;
  622. }
  623. - (void)moreAlbumDetail {
  624. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  625. ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-album"];
  626. [self.navigationController pushViewController:ctrl animated:YES];
  627. }
  628. #pragma mark --- 推荐曲目
  629. - (TenantRecommendMusicView *)recommendMusicView {
  630. if (!_recommendMusicView) {
  631. _recommendMusicView = [TenantRecommendMusicView shareInstance];
  632. MJWeakSelf;
  633. [_recommendMusicView homeMusicMore:^{
  634. [weakSelf moreRecommendMusic];
  635. }];
  636. [_recommendMusicView.musicContentView addSubview:self.recommendMusicCollectionView];
  637. [self.recommendMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  638. make.left.right.bottom.top.mas_equalTo(_recommendMusicView.musicContentView);
  639. }];
  640. }
  641. return _recommendMusicView;
  642. }
  643. - (UICollectionView *)recommendMusicCollectionView {
  644. if (!_recommendMusicCollectionView) {
  645. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, KPortraitWidth - COLLECTION_WIDTH) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  646. _recommendMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  647. _recommendMusicCollectionView.backgroundColor = [UIColor clearColor];
  648. _recommendMusicCollectionView.delegate = self;
  649. _recommendMusicCollectionView.dataSource = self;
  650. _recommendMusicCollectionView.showsVerticalScrollIndicator = NO;
  651. _recommendMusicCollectionView.showsHorizontalScrollIndicator = NO;
  652. if (@available(iOS 11.0, *)) {
  653. _recommendMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  654. } else {
  655. // Fallback on earlier versions
  656. if (@available(iOS 13.0, *)) {
  657. _recommendMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  658. } else {
  659. // Fallback on earlier versions
  660. }
  661. }
  662. [_recommendMusicCollectionView registerNib:[UINib nibWithNibName:@"TenantMusicCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantMusicCollectionViewCell"];
  663. }
  664. return _recommendMusicCollectionView;
  665. }
  666. - (NSMutableArray *)recommendMusicArray {
  667. if (!_recommendMusicArray) {
  668. _recommendMusicArray = [NSMutableArray array];
  669. }
  670. return _recommendMusicArray;
  671. }
  672. - (void)moreRecommendMusic {
  673. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  674. ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-list"];
  675. [self.navigationController pushViewController:ctrl animated:YES];
  676. }
  677. #pragma mark ---- 最新曲目
  678. - (TenantNewMusicView *)newestMusicView {
  679. if (!_newestMusicView) {
  680. if (!_newestMusicView) {
  681. _newestMusicView = [TenantNewMusicView shareInstance];
  682. MJWeakSelf;
  683. [_newestMusicView homeMusicMore:^{
  684. [weakSelf moreNewMusic];
  685. }];
  686. [_newestMusicView.musicContentView addSubview:self.newestMusicCollectionView];
  687. [self.newestMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  688. make.left.right.bottom.top.mas_equalTo(_newestMusicView.musicContentView);
  689. }];
  690. }
  691. return _newestMusicView;
  692. }
  693. return _newestMusicView;
  694. }
  695. - (UICollectionView *)newestMusicCollectionView {
  696. if (!_newestMusicCollectionView) {
  697. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, (KPortraitWidth - COLLECTION_WIDTH)) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  698. _newestMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  699. _newestMusicCollectionView.backgroundColor = [UIColor clearColor];
  700. _newestMusicCollectionView.delegate = self;
  701. _newestMusicCollectionView.dataSource = self;
  702. _newestMusicCollectionView.showsVerticalScrollIndicator = NO;
  703. _newestMusicCollectionView.showsHorizontalScrollIndicator = NO;
  704. if (@available(iOS 11.0, *)) {
  705. _newestMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  706. } else {
  707. // Fallback on earlier versions
  708. if (@available(iOS 13.0, *)) {
  709. _newestMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  710. } else {
  711. // Fallback on earlier versions
  712. }
  713. }
  714. [_newestMusicCollectionView registerNib:[UINib nibWithNibName:@"TenantMusicCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantMusicCollectionViewCell"];
  715. }
  716. return _newestMusicCollectionView;
  717. }
  718. - (NSMutableArray *)newestMusicArray {
  719. if (!_newestMusicArray) {
  720. _newestMusicArray = [NSMutableArray array];
  721. }
  722. return _newestMusicArray;
  723. }
  724. - (void)moreNewMusic {
  725. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  726. ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-list"];
  727. [self.navigationController pushViewController:ctrl animated:YES];
  728. }
  729. #pragma mark ---- 更多曲目
  730. - (TenantHotMusicView *)hotMusicView {
  731. if (!_hotMusicView) {
  732. _hotMusicView = [TenantHotMusicView shareInstance];
  733. MJWeakSelf;
  734. [_hotMusicView homeMusicMore:^{
  735. [weakSelf moreHotMusic];
  736. }];
  737. [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
  738. [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  739. make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
  740. }];
  741. }
  742. return _hotMusicView;
  743. }
  744. - (void)moreHotMusic {
  745. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  746. ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-list"];
  747. [self.navigationController pushViewController:ctrl animated:YES];
  748. }
  749. - (UICollectionView *)musicCollectionView {
  750. if (!_musicCollectionView) {
  751. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, (KPortraitWidth - COLLECTION_WIDTH)) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  752. _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  753. _musicCollectionView.backgroundColor = [UIColor clearColor];
  754. _musicCollectionView.delegate = self;
  755. _musicCollectionView.dataSource = self;
  756. _musicCollectionView.showsVerticalScrollIndicator = NO;
  757. _musicCollectionView.showsHorizontalScrollIndicator = NO;
  758. if (@available(iOS 11.0, *)) {
  759. _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  760. } else {
  761. // Fallback on earlier versions
  762. if (@available(iOS 13.0, *)) {
  763. _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  764. } else {
  765. // Fallback on earlier versions
  766. }
  767. }
  768. [_musicCollectionView registerNib:[UINib nibWithNibName:@"TenantMusicCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantMusicCollectionViewCell"];
  769. }
  770. return _musicCollectionView;
  771. }
  772. - (TenantDragView *)suspendButton {
  773. if (!_suspendButton) {
  774. _suspendButton = [[TenantDragView alloc] initWithFrame:CGRectMake(KPortraitWidth - TenantDragButtonWidth, KPortraitHeight - kTabBarHeight - TenantDragButtonHeight - 100, TenantDragButtonWidth, TenantDragButtonHeight)];
  775. MJWeakSelf;
  776. [_suspendButton clickAction:^{
  777. [weakSelf showDragWindowDetail];
  778. }];
  779. }
  780. return _suspendButton;
  781. }
  782. - (void)showDragWindowDetail {
  783. ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
  784. [self.navigationController pushViewController:ctrl animated:YES];
  785. }
  786. /*
  787. #pragma mark - Navigation
  788. // In a storyboard-based application, you will often want to do a little preparation before navigation
  789. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  790. // Get the new view controller using [segue destinationViewController].
  791. // Pass the selected object to the new view controller.
  792. }
  793. */
  794. @end