MusicSquareViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. //
  2. // MusicSquareViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2024/11/19.
  6. //
  7. #import "MusicSquareViewController.h"
  8. #import "MusicSquareNavView.h"
  9. #import "KSBaseWKWebViewController.h"
  10. #import "UserInfoManager.h"
  11. #import "HomeHotAlbumView.h"
  12. #import "HomeAlbumModel.h"
  13. #import "HomeHotAlbumCell.h"
  14. #import "HomeHotMusicView.h"
  15. #import "HomeNewMusicView.h"
  16. #import "HomeRecommendMusicView.h"
  17. #import "HomeHotMusicCollectionCell.h"
  18. #import "HomeMusicModel.h"
  19. #import "HomeMusicSheetLayout.h"
  20. #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
  21. #define COLLECTION_HEIGHT (320)
  22. @interface MusicSquareViewController ()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
  23. @property (nonatomic, strong) MusicSquareNavView *navView;
  24. // 热门专辑
  25. @property (nonatomic, strong) HomeHotAlbumView *albumView;
  26. @property (nonatomic, strong) NSMutableArray *albumArray;
  27. @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
  28. @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
  29. // 推荐曲目
  30. @property (nonatomic, strong) HomeRecommendMusicView *recommendMusicView;
  31. @property (nonatomic, strong) UICollectionView *recommendMusicCollectionView; // 曲谱容器
  32. @property (nonatomic, strong) NSMutableArray *recommendMusicArray; // 曲谱数据
  33. @property (nonatomic, assign) CGFloat recommendMusicViewHeight; // music 高度
  34. // 最新曲目
  35. @property (nonatomic, strong) HomeNewMusicView *newestMusicView;
  36. @property (nonatomic, strong) UICollectionView *newestMusicCollectionView; // 曲谱容器
  37. @property (nonatomic, strong) NSMutableArray *newestMusicArray; // 曲谱数据
  38. @property (nonatomic, assign) CGFloat newestMusicViewHeight; // music 高度
  39. // 热门曲谱
  40. @property (nonatomic, strong) HomeHotMusicView *hotMusicView;
  41. @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
  42. @property (nonatomic, strong) NSMutableArray *musicArray; // 曲谱数据
  43. @property (nonatomic, assign) CGFloat musicViewHeight; // music 高度
  44. @property (nonatomic, strong) dispatch_group_t requestGroup;
  45. @end
  46. @implementation MusicSquareViewController
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. // Do any additional setup after loading the view.
  50. self.ks_prefersNavigationBarHidden = YES;
  51. [self configUI];
  52. }
  53. - (void)configUI {
  54. [self.view addSubview:self.navView];
  55. CGFloat navHeight = [MusicSquareNavView getViewHeight];
  56. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.left.right.top.mas_equalTo(self.view);
  58. make.height.mas_equalTo(navHeight);
  59. }];
  60. [self.view bringSubviewToFront:self.navView];
  61. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  62. make.top.mas_equalTo(self.navView.mas_bottom);
  63. make.left.right.bottom.mas_equalTo(self.view);
  64. }];
  65. // 热门专辑
  66. [self.scrollView addSubview:self.albumView];
  67. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  68. [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.right.mas_equalTo(self.view);
  70. make.top.mas_equalTo(self.scrollView.mas_top);
  71. make.height.mas_equalTo(self.albumViewHeight);
  72. }];
  73. // 推荐曲目
  74. [self.scrollView addSubview:self.recommendMusicView];
  75. self.recommendMusicViewHeight = [HomeRecommendMusicView getViewHeight];
  76. [self.recommendMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.right.mas_equalTo(self.view);
  78. make.top.mas_equalTo(self.albumView.mas_bottom);
  79. make.height.mas_equalTo(self.recommendMusicViewHeight);
  80. }];
  81. // 最新曲目
  82. [self.scrollView addSubview:self.newestMusicView];
  83. self.newestMusicViewHeight = [HomeNewMusicView getViewHeight];
  84. [self.newestMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.right.mas_equalTo(self.view);
  86. make.top.mas_equalTo(self.recommendMusicView.mas_bottom);
  87. make.height.mas_equalTo(self.newestMusicViewHeight);
  88. }];
  89. // 热门曲目
  90. [self.scrollView addSubview:self.hotMusicView];
  91. self.musicViewHeight = [HomeHotMusicView getViewHeight];
  92. [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.right.mas_equalTo(self.view);
  94. make.top.mas_equalTo(self.newestMusicView.mas_bottom);
  95. make.height.mas_equalTo(self.musicViewHeight);
  96. make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
  97. }];
  98. MJWeakSelf;
  99. self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  100. [weakSelf requestData];
  101. }];
  102. }
  103. - (void)viewWillAppear:(BOOL)animated {
  104. [super viewWillAppear:animated];
  105. [self requestData];
  106. }
  107. - (void)requestData {
  108. [self requestHotAlbum];
  109. [self requestHomeMusicMessage];
  110. dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
  111. [self.scrollView.mj_header endRefreshing];
  112. [self refreshView];
  113. });
  114. }
  115. - (void)requestHotAlbum {
  116. dispatch_group_enter(self.requestGroup);
  117. [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  118. dispatch_group_leave(self.requestGroup);
  119. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  120. NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
  121. NSMutableArray *albumArray = [NSMutableArray array];
  122. for (NSDictionary *parm in sourceArray) {
  123. HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
  124. [albumArray addObject:model];
  125. }
  126. self.albumArray = [NSMutableArray arrayWithArray:albumArray];
  127. }
  128. else {
  129. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  130. }
  131. } faliure:^(NSError * _Nonnull error) {
  132. dispatch_group_leave(self.requestGroup);
  133. }];
  134. }
  135. - (void)requestHomeMusicMessage {
  136. dispatch_group_enter(self.requestGroup);
  137. [KSNetworkingManager homeAppMusicSheetRequest:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
  138. dispatch_group_leave(self.requestGroup);
  139. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  140. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  141. NSArray *hotMusicSheet = [result ks_arrayValueForKey:@"hotMusicSheet"]; // 最热曲目
  142. NSMutableArray *hotArray = [NSMutableArray array];
  143. for (NSDictionary *parm in hotMusicSheet) {
  144. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  145. [hotArray addObject:model];
  146. }
  147. self.musicArray = [NSMutableArray arrayWithArray:hotArray];
  148. NSArray *newMusicSheet = [result ks_arrayValueForKey:@"newMusicSheet"]; // 最新曲目
  149. NSMutableArray *newMusicArray = [NSMutableArray array];
  150. for (NSDictionary *parm in newMusicSheet) {
  151. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  152. [newMusicArray addObject:model];
  153. }
  154. self.newestMusicArray = [NSMutableArray arrayWithArray:newMusicArray];
  155. NSArray *topMusicSheet = [result ks_arrayValueForKey:@"topMusicSheet"]; // 推荐曲目
  156. NSMutableArray *topMusicArray = [NSMutableArray array];
  157. for (NSDictionary *parm in topMusicSheet) {
  158. HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
  159. [topMusicArray addObject:model];
  160. }
  161. self.recommendMusicArray = [NSMutableArray arrayWithArray:topMusicArray];
  162. }
  163. else {
  164. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  165. }
  166. } faliure:^(NSError * _Nonnull error) {
  167. dispatch_group_leave(self.requestGroup);
  168. }];
  169. }
  170. - (void)refreshView {
  171. [self refreshAlbumView];
  172. [self refreshMusicView];
  173. }
  174. - (void)refreshAlbumView {
  175. if (self.albumArray.count) {
  176. self.albumViewHeight = [HomeHotAlbumView getViewHeight];
  177. self.albumView.hidden = NO;
  178. }
  179. else {
  180. self.albumViewHeight = CGFLOAT_MIN;
  181. self.albumView.hidden = YES;
  182. }
  183. [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
  184. make.height.mas_equalTo(self.albumViewHeight);
  185. }];
  186. [self.albumCollectionView reloadData];
  187. }
  188. - (void)refreshMusicView {
  189. if (self.recommendMusicArray.count) {
  190. self.recommendMusicViewHeight = [HomeHotMusicView getViewHeight];
  191. self.recommendMusicView.hidden = NO;
  192. }
  193. else {
  194. self.recommendMusicViewHeight = CGFLOAT_MIN;
  195. self.recommendMusicView.hidden = YES;
  196. }
  197. [self.recommendMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  198. make.height.mas_equalTo(self.recommendMusicViewHeight);
  199. }];
  200. [self.recommendMusicCollectionView reloadData];
  201. if (self.newestMusicArray.count) {
  202. self.newestMusicViewHeight = [HomeHotMusicView getViewHeight];
  203. self.newestMusicView.hidden = NO;
  204. }
  205. else {
  206. self.newestMusicViewHeight = CGFLOAT_MIN;
  207. self.newestMusicView.hidden = YES;
  208. }
  209. [self.newestMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  210. make.height.mas_equalTo(self.newestMusicViewHeight);
  211. }];
  212. [self.newestMusicCollectionView reloadData];
  213. if (self.musicArray.count) {
  214. self.musicViewHeight = [HomeHotMusicView getViewHeight];
  215. self.hotMusicView.hidden = NO;
  216. }
  217. else {
  218. self.musicViewHeight = CGFLOAT_MIN;
  219. self.hotMusicView.hidden = YES;
  220. }
  221. [self.hotMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
  222. make.height.mas_equalTo(self.musicViewHeight);
  223. }];
  224. [self.musicCollectionView reloadData];
  225. }
  226. #pragma mark ---- collection data source
  227. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  228. return 1;
  229. }
  230. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  231. if (collectionView == self.albumCollectionView) { // 专辑
  232. return self.albumArray.count;
  233. }
  234. else if (collectionView == self.recommendMusicCollectionView) {
  235. NSInteger lastRowCount = (self.recommendMusicArray.count % 4) > 0 ? 1 : 0;
  236. NSInteger count = self.recommendMusicArray.count / 4 + lastRowCount;
  237. return count;
  238. }
  239. else if (collectionView == self.newestMusicCollectionView) {
  240. NSInteger lastRowCount = (self.newestMusicArray.count % 4) > 0 ? 1 : 0;
  241. NSInteger count = self.newestMusicArray.count / 4 + lastRowCount;
  242. return count;
  243. }
  244. else { // 乐谱
  245. NSInteger lastRowCount = (self.musicArray.count % 4) > 0 ? 1 : 0;
  246. NSInteger count = self.musicArray.count / 4 + lastRowCount;
  247. return count;
  248. }
  249. }
  250. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  251. if (collectionView == self.albumCollectionView) {
  252. HomeAlbumModel *model = self.albumArray[indexPath.item];
  253. HomeHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotAlbumCell" forIndexPath:indexPath];
  254. [cell configWithAlbumModel:model];
  255. return cell;
  256. }
  257. else if (collectionView == self.recommendMusicCollectionView) {
  258. NSMutableArray *songArray = [NSMutableArray array];
  259. NSInteger length = indexPath.item * 4 + 4 > self.recommendMusicArray.count ? self.recommendMusicArray.count - indexPath.item * 4: 4;
  260. NSRange range = NSMakeRange(indexPath.item * 4, length);
  261. songArray = [NSMutableArray arrayWithArray:[self.recommendMusicArray subarrayWithRange:range]];
  262. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  263. MJWeakSelf;
  264. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  265. [weakSelf displaySongDetail:songId];
  266. }];
  267. return cell;
  268. }
  269. else if (collectionView == self.newestMusicCollectionView) {
  270. NSMutableArray *songArray = [NSMutableArray array];
  271. NSInteger length = indexPath.item * 4 + 4 > self.newestMusicArray.count ? self.newestMusicArray.count - indexPath.item * 4: 4;
  272. NSRange range = NSMakeRange(indexPath.item * 4, length);
  273. songArray = [NSMutableArray arrayWithArray:[self.newestMusicArray subarrayWithRange:range]];
  274. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  275. MJWeakSelf;
  276. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  277. [weakSelf displaySongDetail:songId];
  278. }];
  279. return cell;
  280. }
  281. else {
  282. NSMutableArray *songArray = [NSMutableArray array];
  283. NSInteger length = indexPath.item * 4 + 4 > self.musicArray.count ? self.musicArray.count - indexPath.item * 4: 4;
  284. NSRange range = NSMakeRange(indexPath.item * 4, length);
  285. songArray = [NSMutableArray arrayWithArray:[self.musicArray subarrayWithRange:range]];
  286. HomeHotMusicCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeHotMusicCollectionCell" forIndexPath:indexPath];
  287. MJWeakSelf;
  288. [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
  289. [weakSelf displaySongDetail:songId];
  290. }];
  291. return cell;
  292. }
  293. }
  294. - (void)displaySongDetail:(NSString *)songId {
  295. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  296. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-detail?id=",songId];
  297. [self.navigationController pushViewController:ctrl animated:YES];
  298. }
  299. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  300. if (collectionView == self.albumCollectionView) { // 专辑详情
  301. HomeAlbumModel *model = self.albumArray[indexPath.item];
  302. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  303. ctrl.url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
  304. [self.navigationController pushViewController:ctrl animated:YES];
  305. }
  306. }
  307. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  308. if (collectionView == self.albumCollectionView) {
  309. return CGSizeMake(100, 134);
  310. }
  311. else if (collectionView == self.recommendMusicCollectionView) {
  312. return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
  313. }
  314. else if (collectionView == self.newestMusicCollectionView) {
  315. return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
  316. }
  317. else {
  318. return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
  319. }
  320. }
  321. #pragma mark ---- lazying
  322. - (dispatch_group_t)requestGroup {
  323. if (!_requestGroup) {
  324. _requestGroup = dispatch_group_create();
  325. }
  326. return _requestGroup;
  327. }
  328. - (MusicSquareNavView *)navView {
  329. if (!_navView) {
  330. _navView = [MusicSquareNavView sharedInstance];
  331. MJWeakSelf;
  332. [_navView topSearchAction:^{
  333. [weakSelf searchMusic];
  334. }];
  335. }
  336. return _navView;
  337. }
  338. - (void)searchMusic {
  339. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  340. webCtrl.url = [NSString stringWithFormat:@"%@/#/music-songbook/search", WEBHOST];
  341. [self.navigationController pushViewController:webCtrl animated:YES];
  342. }
  343. #pragma mark ----- 专辑
  344. - (HomeHotAlbumView *)albumView {
  345. if (!_albumView) {
  346. _albumView = [HomeHotAlbumView shareInstance];
  347. MJWeakSelf;
  348. [_albumView homeAlbumMore:^{
  349. [weakSelf moreAlbumDetail];
  350. }];
  351. [_albumView.albumContentView addSubview:self.albumCollectionView];
  352. [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  353. make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
  354. }];
  355. }
  356. return _albumView;
  357. }
  358. - (UICollectionView *)albumCollectionView {
  359. if (!_albumCollectionView) {
  360. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  361. layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
  362. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  363. _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  364. _albumCollectionView.backgroundColor = [UIColor clearColor];
  365. _albumCollectionView.delegate = self;
  366. _albumCollectionView.dataSource = self;
  367. _albumCollectionView.showsVerticalScrollIndicator = NO;
  368. _albumCollectionView.showsHorizontalScrollIndicator = NO;
  369. if (@available(iOS 11.0, *)) {
  370. _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  371. } else {
  372. // Fallback on earlier versions
  373. if (@available(iOS 13.0, *)) {
  374. _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  375. } else {
  376. // Fallback on earlier versions
  377. }
  378. }
  379. [_albumCollectionView registerNib:[UINib nibWithNibName:@"HomeHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotAlbumCell"];
  380. }
  381. return _albumCollectionView;
  382. }
  383. - (void)moreAlbumDetail {
  384. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  385. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-album"];
  386. [self.navigationController pushViewController:ctrl animated:YES];
  387. }
  388. #pragma mark --- 推荐曲目
  389. - (HomeRecommendMusicView *)recommendMusicView {
  390. if (!_recommendMusicView) {
  391. _recommendMusicView = [HomeRecommendMusicView shareInstance];
  392. MJWeakSelf;
  393. [_recommendMusicView homeMusicMore:^{
  394. [weakSelf moreRecommendMusic];
  395. }];
  396. [_recommendMusicView.musicContentView addSubview:self.recommendMusicCollectionView];
  397. [self.recommendMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  398. make.left.right.bottom.top.mas_equalTo(_recommendMusicView.musicContentView);
  399. }];
  400. }
  401. return _recommendMusicView;
  402. }
  403. - (UICollectionView *)recommendMusicCollectionView {
  404. if (!_recommendMusicCollectionView) {
  405. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  406. _recommendMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  407. _recommendMusicCollectionView.backgroundColor = [UIColor clearColor];
  408. _recommendMusicCollectionView.delegate = self;
  409. _recommendMusicCollectionView.dataSource = self;
  410. _recommendMusicCollectionView.showsVerticalScrollIndicator = NO;
  411. _recommendMusicCollectionView.showsHorizontalScrollIndicator = NO;
  412. if (@available(iOS 11.0, *)) {
  413. _recommendMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  414. } else {
  415. // Fallback on earlier versions
  416. if (@available(iOS 13.0, *)) {
  417. _recommendMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  418. } else {
  419. // Fallback on earlier versions
  420. }
  421. }
  422. [_recommendMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  423. }
  424. return _recommendMusicCollectionView;
  425. }
  426. - (NSMutableArray *)recommendMusicArray {
  427. if (!_recommendMusicArray) {
  428. _recommendMusicArray = [NSMutableArray array];
  429. }
  430. return _recommendMusicArray;
  431. }
  432. - (void)moreRecommendMusic {
  433. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  434. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  435. [self.navigationController pushViewController:ctrl animated:YES];
  436. }
  437. #pragma mark ---- 最新曲目
  438. - (HomeNewMusicView *)newestMusicView {
  439. if (!_newestMusicView) {
  440. if (!_newestMusicView) {
  441. _newestMusicView = [HomeNewMusicView shareInstance];
  442. MJWeakSelf;
  443. [_newestMusicView homeMusicMore:^{
  444. [weakSelf moreNewMusic];
  445. }];
  446. [_newestMusicView.musicContentView addSubview:self.newestMusicCollectionView];
  447. [self.newestMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  448. make.left.right.bottom.top.mas_equalTo(_newestMusicView.musicContentView);
  449. }];
  450. }
  451. return _newestMusicView;
  452. }
  453. return _newestMusicView;
  454. }
  455. - (UICollectionView *)newestMusicCollectionView {
  456. if (!_newestMusicCollectionView) {
  457. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  458. _newestMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  459. _newestMusicCollectionView.backgroundColor = [UIColor clearColor];
  460. _newestMusicCollectionView.delegate = self;
  461. _newestMusicCollectionView.dataSource = self;
  462. _newestMusicCollectionView.showsVerticalScrollIndicator = NO;
  463. _newestMusicCollectionView.showsHorizontalScrollIndicator = NO;
  464. if (@available(iOS 11.0, *)) {
  465. _newestMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  466. } else {
  467. // Fallback on earlier versions
  468. if (@available(iOS 13.0, *)) {
  469. _newestMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  470. } else {
  471. // Fallback on earlier versions
  472. }
  473. }
  474. [_newestMusicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  475. }
  476. return _newestMusicCollectionView;
  477. }
  478. - (NSMutableArray *)newestMusicArray {
  479. if (!_newestMusicArray) {
  480. _newestMusicArray = [NSMutableArray array];
  481. }
  482. return _newestMusicArray;
  483. }
  484. - (void)moreNewMusic {
  485. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  486. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  487. [self.navigationController pushViewController:ctrl animated:YES];
  488. }
  489. #pragma mark ---- 热门曲目
  490. - (HomeHotMusicView *)hotMusicView {
  491. if (!_hotMusicView) {
  492. _hotMusicView = [HomeHotMusicView shareInstance];
  493. MJWeakSelf;
  494. [_hotMusicView homeMusicMore:^{
  495. [weakSelf moreHotMusic];
  496. }];
  497. [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
  498. [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  499. make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
  500. }];
  501. }
  502. return _hotMusicView;
  503. }
  504. - (void)moreHotMusic {
  505. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  506. ctrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/music-list"];
  507. [self.navigationController pushViewController:ctrl animated:YES];
  508. }
  509. - (UICollectionView *)musicCollectionView {
  510. if (!_musicCollectionView) {
  511. HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 14, 0, 14) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
  512. _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  513. _musicCollectionView.backgroundColor = [UIColor clearColor];
  514. _musicCollectionView.delegate = self;
  515. _musicCollectionView.dataSource = self;
  516. _musicCollectionView.showsVerticalScrollIndicator = NO;
  517. _musicCollectionView.showsHorizontalScrollIndicator = NO;
  518. if (@available(iOS 11.0, *)) {
  519. _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  520. } else {
  521. // Fallback on earlier versions
  522. if (@available(iOS 13.0, *)) {
  523. _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
  524. } else {
  525. // Fallback on earlier versions
  526. }
  527. }
  528. [_musicCollectionView registerNib:[UINib nibWithNibName:@"HomeHotMusicCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"HomeHotMusicCollectionCell"];
  529. }
  530. return _musicCollectionView;
  531. }
  532. /*
  533. #pragma mark - Navigation
  534. // In a storyboard-based application, you will often want to do a little preparation before navigation
  535. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  536. // Get the new view controller using [segue destinationViewController].
  537. // Pass the selected object to the new view controller.
  538. }
  539. */
  540. @end