MusicSquareViewController.m 25 KB

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