123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901 |
- //
- // TenantMoreViewController.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2023/9/12.
- //
- #import "TenantMoreViewController.h"
- #import "MorePageNavView.h"
- #import "MorePageSearchView.h"
- #import "TenantHomeBannerView.h"
- #import "TYCyclePagerView.h"
- #import "TYPageControl.h"
- #import "HomeBannerCell.h"
- #import "TenantHotAlbumView.h"
- #import "TenantHotAlbumCell.h"
- #import "HomeAlbumModel.h"
- #import "KSPremissionAlert.h"
- #import <RecordCheckManager.h>
- #import "TenantRecommendMusicView.h"
- #import "TenantNewMusicView.h"
- #import "TenantHotMusicView.h"
- #import "TenantMusicCollectionViewCell.h"
- #import "KSBaseWKWebViewController.h"
- #import "UserInfo.h"
- #import "UserInfoManager.h"
- #import "InstrumentChooseViewController.h"
- #import "TenantDragView.h"
- #import "ToneTuningViewController.h"
- #import "HomeMusicSheetLayout.h"
- #define COLLECTION_WIDTH ((NSInteger)(IS_IPAD ? KPortraitWidth * 0.7 : KPortraitWidth * 0.83))
- #define COLLECTION_HEIGHT (243)
- @interface TenantMoreViewController ()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,TYCyclePagerViewDataSource,TYCyclePagerViewDelegate>
- @property (nonatomic, copy) SwitchDarkCallback callback;
- @property (nonatomic, strong) MorePageNavView *navView;
- @property (nonatomic, strong) MorePageSearchView *searchView;
- // banner
- @property (nonatomic, strong) TYPageControl *pageControl;
- @property (nonatomic, strong) TenantHomeBannerView *bannerView; // banner container
- @property (nonatomic, strong) TYCyclePagerView *bannerScroll; // 活动
- @property (nonatomic, strong) NSMutableArray *bannerArray; // banner 数据
- @property (nonatomic, assign) CGFloat bannerViewHeight; // banner 高度
- // 专辑
- @property (nonatomic, strong) TenantHotAlbumView *albumView;
- @property (nonatomic, strong) NSMutableArray *albumArray;
- @property (nonatomic, strong) UICollectionView *albumCollectionView; // 专辑容器
- @property (nonatomic, assign) CGFloat albumViewHeight; // album 高度
- // 推荐
- @property (nonatomic, strong) TenantRecommendMusicView *recommendMusicView;
- @property (nonatomic, strong) UICollectionView *recommendMusicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *recommendMusicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat recommendMusicViewHeight; // music 高度
- // 最新曲目
- @property (nonatomic, strong) TenantNewMusicView *newestMusicView;
- @property (nonatomic, strong) UICollectionView *newestMusicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *newestMusicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat newestMusicViewHeight; // music 高度
- // 热门曲谱
- @property (nonatomic, strong) TenantHotMusicView *hotMusicView;
- @property (nonatomic, strong) UICollectionView *musicCollectionView; // 曲谱容器
- @property (nonatomic, strong) NSMutableArray *musicArray; // 曲谱数据
- @property (nonatomic, assign) CGFloat hotMusicViewHeight; // music 高度
- @property (nonatomic, strong) dispatch_group_t requestGroup;
- @property (nonatomic, strong) UserInfo *mineInfo;
- @property (nonatomic, strong) TenantDragView *suspendButton;
- @end
- @implementation TenantMoreViewController
- - (void)swithToDarkPageAction:(SwitchDarkCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self configUI];
- }
- - (void)configUI {
- self.view.backgroundColor = HexRGB(0xFAFAFA);
- UIImage *bgImage = [UIImage imageNamed:@"tenant_light_bg"];
- CGFloat height = bgImage.size.height / bgImage.size.width * KPortraitWidth;
- UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
- bgImageView.contentMode = UIViewContentModeRedraw;
- [self.view addSubview:bgImageView];
- [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(height);
- }];
- self.scrollView.backgroundColor = [UIColor clearColor];
- [self.view bringSubviewToFront:self.scrollView];
- MJWeakSelf;
- self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf requestData];
- }];
- [self.view addSubview:self.navView];
- CGFloat navHeight = [MorePageNavView getViewHeight];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(navHeight);
- }];
-
- // 搜索
- [self.view addSubview:self.searchView];
- CGFloat searchHeight = [MorePageSearchView getViewHeight];
- [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.navView.mas_bottom);
- make.height.mas_equalTo(searchHeight);
- }];
-
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(self.view);
- make.top.mas_equalTo(self.searchView.mas_bottom);
- }];
-
- // banner
- [self.scrollView addSubview:self.bannerView];
- self.bannerViewHeight = CGFLOAT_MIN;
- [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.left.right.mas_equalTo(self.view);
- make.height.mas_equalTo(self.bannerViewHeight);
- }];
-
- // 专辑
- [self.scrollView addSubview:self.albumView];
- self.albumViewHeight = [TenantHotAlbumView getViewHeight];
- [self.albumView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.bannerView.mas_bottom);
- make.height.mas_equalTo(self.albumViewHeight);
- }];
-
- // 推荐曲目
- [self.scrollView addSubview:self.recommendMusicView];
- self.recommendMusicViewHeight = [TenantRecommendMusicView getViewHeight];
- [self.recommendMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.albumView.mas_bottom);
- make.height.mas_equalTo(self.recommendMusicViewHeight);
- }];
-
- // 最新
- [self.scrollView addSubview:self.newestMusicView];
- self.newestMusicViewHeight = [TenantNewMusicView getViewHeight];
- [self.newestMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.recommendMusicView.mas_bottom);
- make.height.mas_equalTo(self.newestMusicViewHeight);
- }];
-
- // 热门
- [self.scrollView addSubview:self.hotMusicView];
- self.hotMusicViewHeight = [TenantHotMusicView getViewHeight];
- [self.hotMusicView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.newestMusicView.mas_bottom);
- make.height.mas_equalTo(self.hotMusicViewHeight);
- make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(-10);
- }];
-
- [self showFloatingWindow];
- }
- - (void)showFloatingWindow {
- if (![self.view.subviews containsObject:self.suspendButton]) {
- [self.view addSubview:self.suspendButton];
- }
- [self.view bringSubviewToFront:self.suspendButton];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self requestData];
- }
- - (void)requestData {
- [self requestUserInfo];
- [self requestNewsList];
- [self requestHotAlbum];
- [self requestHomeMusicMessage];
- [self requestUserInfo];
- dispatch_group_notify(self.requestGroup, dispatch_get_main_queue(), ^{
- // [LOADING_MANAGER removeHUD];
- [self.scrollView.mj_header endRefreshing];
- [self refreshView];
- });
- }
- - (void)requestUserInfo {
- [KSNetworkingManager queryStudentInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- self.mineInfo = [[UserInfo alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self refreshHeader];
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)refreshHeader {
- self.navView.tenantName.text = [NSString returnNoNullStringWithString:self.mineInfo.tenantName];
- // self.searchView.subjectLabel.text = [NSString returnNoNullStringWithString:self.mineInfo.subjectName];
- }
- // banner
- - (void)requestNewsList {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeNewsList:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- // banner
- NSArray *bannerArray = [result ks_arrayValueForKey:@"banner"];
- NSMutableArray *bannerInfoArray = [NSMutableArray array];
- for (NSDictionary *parm in bannerArray) {
- HomeMessageModel *model = [[HomeMessageModel alloc] initWithDictionary:parm];
- [bannerInfoArray addObject:model];
- }
- self.bannerArray = [NSMutableArray arrayWithArray:bannerInfoArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestHotAlbum {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager HomeHotAlbumRequest:KS_POST page:1 rows:10 version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
- NSMutableArray *albumArray = [NSMutableArray array];
- for (NSDictionary *parm in sourceArray) {
- HomeAlbumModel *model = [[HomeAlbumModel alloc] initWithDictionary:parm];
- [albumArray addObject:model];
- }
- self.albumArray = [NSMutableArray arrayWithArray:albumArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
-
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)requestHomeMusicMessage {
- dispatch_group_enter(self.requestGroup);
- [KSNetworkingManager homeAppMusicSheetRequest:KS_POST version:[USER_MANAGER getCurrentVersion] success:^(NSDictionary * _Nonnull dic) {
- dispatch_group_leave(self.requestGroup);
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- NSArray *hotMusicSheet = [result ks_arrayValueForKey:@"hotMusicSheet"]; // 热门曲目
- NSMutableArray *hotArray = [NSMutableArray array];
- for (NSDictionary *parm in hotMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [hotArray addObject:model];
- }
- self.musicArray = [NSMutableArray arrayWithArray:hotArray];
-
- NSArray *newMusicSheet = [result ks_arrayValueForKey:@"newMusicSheet"]; // 最新曲目
- NSMutableArray *newMusicArray = [NSMutableArray array];
- for (NSDictionary *parm in newMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [newMusicArray addObject:model];
- }
- self.newestMusicArray = [NSMutableArray arrayWithArray:newMusicArray];
-
- NSArray *topMusicSheet = [result ks_arrayValueForKey:@"topMusicSheet"]; // 推荐曲目
- NSMutableArray *topMusicArray = [NSMutableArray array];
- for (NSDictionary *parm in topMusicSheet) {
- HomeMusicModel *model = [[HomeMusicModel alloc] initWithDictionary:parm];
- [topMusicArray addObject:model];
- }
- self.recommendMusicArray = [NSMutableArray arrayWithArray:topMusicArray];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- dispatch_group_leave(self.requestGroup);
- }];
- }
- - (void)refreshView {
- [self refreshBannerView];
- [self refreshAlbumView];
- [self refreshMusicView];
- }
- - (void)refreshBannerView {
- if (self.bannerArray.count) {
- self.bannerView.hidden = NO;
- CGFloat bannerViewHeight = [TenantHomeBannerView getViewHeight];
- [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(bannerViewHeight);
- }];
- }
- else {
- self.bannerView.hidden = YES;
- [self.bannerView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(CGFLOAT_MIN);
- }];
- }
- if (self.bannerArray.count > 1) {
- self.bannerScroll.autoScrollInterval = 3.0f;
- [self.bannerScroll addSubview:self.pageControl];
- }
- else {
- self.bannerScroll.autoScrollInterval = 0;
- [self.pageControl removeFromSuperview];
- }
- self.pageControl.numberOfPages = self.bannerArray.count;
- [self.bannerScroll reloadData];
- }
- - (void)refreshAlbumView {
- if (self.albumArray.count) {
- self.albumViewHeight = [TenantHotAlbumView getViewHeight];
- self.albumView.hidden = NO;
- }
- else {
- self.albumViewHeight = CGFLOAT_MIN;
- self.albumView.hidden = YES;
- }
- [self.albumView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.albumViewHeight);
- }];
- [self.albumCollectionView reloadData];
- }
- - (void)refreshMusicView {
-
- if (self.recommendMusicArray.count) {
- self.recommendMusicViewHeight = [TenantRecommendMusicView getViewHeight];
- self.recommendMusicView.hidden = NO;
- }
- else {
- self.recommendMusicViewHeight = CGFLOAT_MIN;
- self.recommendMusicView.hidden = YES;
- }
-
- [self.recommendMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.recommendMusicViewHeight);
- }];
- [self.recommendMusicCollectionView reloadData];
-
- if (self.newestMusicArray.count) {
- self.newestMusicViewHeight = [TenantNewMusicView getViewHeight];
- self.newestMusicView.hidden = NO;
- }
- else {
- self.newestMusicViewHeight = CGFLOAT_MIN;
- self.newestMusicView.hidden = YES;
- }
-
- [self.newestMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.newestMusicViewHeight);
- }];
- [self.newestMusicCollectionView reloadData];
-
- if (self.musicArray.count) {
- self.hotMusicViewHeight = [TenantHotMusicView getViewHeight];
- self.hotMusicView.hidden = NO;
- }
- else {
- self.hotMusicViewHeight = CGFLOAT_MIN;
- self.hotMusicView.hidden = YES;
- }
- [self.hotMusicView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(self.hotMusicViewHeight);
- }];
- [self.musicCollectionView reloadData];
- }
- #pragma mark - TYCyclePagerViewDataSource代理
- - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
- return self.bannerArray.count;
- }
- - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
- HomeMessageModel *model = self.bannerArray[index];
- HomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"HomeBannerCell" forIndex:index];
- [cell configCellWithModel:model];
- return cell;
- }
- - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
- TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
- layout.itemSize = CGSizeMake(KPortraitWidth - 26, (KPortraitWidth - 26) / 347 * 132);
- layout.itemSpacing = 0;
- return layout;
-
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
- if (pageView == self.bannerScroll) {
- [self.pageControl setCurrentPage:toIndex animate:YES];
- }
- }
- - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
-
- HomeMessageModel *model = self.bannerArray[index];
- if (![NSString isEmptyString:model.linkUrl]) {
- if ([model.linkType isEqualToString:@"OUT"]) {
- // 外部浏览器打开
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[model.linkUrl getUrlEndcodeString]] options: @{} completionHandler: nil];
- }
- else {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [model.linkUrl getUrlEndcodeString];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- }
- }
- #pragma mark ---- collection data source
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (collectionView == self.albumCollectionView) {
- return self.albumArray.count;
- }
- else if (collectionView == self.recommendMusicCollectionView) {
- NSInteger lastRowCount = (self.recommendMusicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.recommendMusicArray.count / 4 + lastRowCount;
- return count;
- }
- else if (collectionView == self.newestMusicCollectionView) {
- NSInteger lastRowCount = (self.newestMusicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.newestMusicArray.count / 4 + lastRowCount;
- return count;
- }
- else {
- NSInteger lastRowCount = (self.musicArray.count % 4) > 0 ? 1 : 0;
- NSInteger count = self.musicArray.count / 4 + lastRowCount;
- return count;
- }
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- HomeAlbumModel *model = self.albumArray[indexPath.item];
- TenantHotAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantHotAlbumCell" forIndexPath:indexPath];
- [cell configWithAlbumModel:model];
- return cell;
- }
- else if (collectionView == self.recommendMusicCollectionView) {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 3 + 3 > self.recommendMusicArray.count ? self.recommendMusicArray.count - indexPath.item * 3: 3;
- NSRange range = NSMakeRange(indexPath.item * 3, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.recommendMusicArray subarrayWithRange:range]];
- TenantMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantMusicCollectionViewCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- else if (collectionView == self.newestMusicCollectionView) {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 3 + 3 > self.newestMusicArray.count ? self.newestMusicArray.count - indexPath.item * 3: 3;
- NSRange range = NSMakeRange(indexPath.item * 3, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.newestMusicArray subarrayWithRange:range]];
- TenantMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantMusicCollectionViewCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- else {
- NSMutableArray *songArray = [NSMutableArray array];
- NSInteger length = indexPath.item * 3 + 3 > self.musicArray.count ? self.musicArray.count - indexPath.item * 3: 3;
- NSRange range = NSMakeRange(indexPath.item * 3, length);
-
- songArray = [NSMutableArray arrayWithArray:[self.musicArray subarrayWithRange:range]];
- TenantMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TenantMusicCollectionViewCell" forIndexPath:indexPath];
- MJWeakSelf;
- [cell configWithSourceArray:songArray callback:^(NSString * _Nonnull songId) {
- [weakSelf displaySongDetail:songId];
- }];
- return cell;
- }
- }
- - (void)displaySongDetail:(NSString *)songId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", TENANT_WEBHOST, @"/#/music-detail?id=",songId];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- HomeAlbumModel *model = self.albumArray[indexPath.item];
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@%@", TENANT_WEBHOST, @"/#/music-album-detail/",model.internalBaseClassIdentifier];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if (collectionView == self.albumCollectionView) {
- return CGSizeMake(110, 145);
- }
- else {
- return CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT);
- }
- }
- #pragma mark --- lazying
- - (MorePageNavView *)navView {
- if (!_navView) {
- _navView = [MorePageNavView shareInstance];
- MJWeakSelf;
- [_navView trainPageSwitch:^{
- [weakSelf switchTrainPageAction];
- }];
- }
- return _navView;
- }
- - (void)switchTrainPageAction {
- if (self.callback) {
- self.callback();
- }
- }
- - (MorePageSearchView *)searchView {
- if (!_searchView) {
- _searchView = [MorePageSearchView shareInstance];
- MJWeakSelf;
- [_searchView morePageSearch:^(TENANTSEARCH type) {
- if (type == TENANTSEARCH_SEARCH) {
- [weakSelf showSearchPage];
- }
- else {
- [weakSelf showInstrumentView];
- }
- }];
- }
- return _searchView;
- }
- - (void)showSearchPage {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@/#/music-songbook/search", TENANT_WEBHOST];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- - (void)showInstrumentView {
- InstrumentChooseViewController *ctrl = [[InstrumentChooseViewController alloc] init];
- MJWeakSelf;
- [ctrl chooseCallback:^{
- [weakSelf requestData];
- }];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (TenantHomeBannerView *)bannerView {
- if (!_bannerView) {
- _bannerView = [TenantHomeBannerView shareInstance];
- [_bannerView.bannerContentView addSubview:self.bannerScroll];
- }
- return _bannerView;
- }
- - (TYCyclePagerView *)bannerScroll {
- if (!_bannerScroll) {
- _bannerScroll = [[TYCyclePagerView alloc] init];
- _bannerScroll.backgroundColor = [UIColor clearColor];
- _bannerScroll.frame = CGRectMake(0, 0, KPortraitWidth - 26, (KPortraitWidth - 26) / 347 * 132);
- _bannerScroll.isInfiniteLoop = YES;
- _bannerScroll.autoScrollInterval = 3.0f;
- _bannerScroll.reloadDataNeedResetIndex = YES;
- _bannerScroll.dataSource = self;
- _bannerScroll.delegate = self;
- [_bannerScroll registerNib:[UINib nibWithNibName:@"HomeBannerCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBannerCell"];
- if (@available(iOS 11.0, *)) {
- _bannerScroll.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _bannerScroll.collectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- }
- return _bannerScroll;
- }
- - (TYPageControl *)pageControl {
- if (!_pageControl) {
- _pageControl = [[TYPageControl alloc] init];
- _pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
- _pageControl.pageIndicatorSpaing = 4.0f;
- _pageControl.frame = CGRectMake(0, (KPortraitWidth - 26) * 132 / 347 - 20, KPortraitWidth-26 - 12, 12);
- _pageControl.currentPageIndicatorTintColor = HexRGB(0xffffff);
- _pageControl.pageIndicatorTintColor = HexRGB(0xffffff);
- _pageControl.pageIndicatorSize = CGSizeMake(5, 5);
- _pageControl.currentPageIndicatorSize = CGSizeMake(12, 5);
- }
- return _pageControl;
- }
- - (NSMutableArray *)bannerArray {
- if (!_bannerArray) {
- _bannerArray = [NSMutableArray array];
- }
- return _bannerArray;
- }
- - (dispatch_group_t)requestGroup {
- if (!_requestGroup) {
- _requestGroup = dispatch_group_create();
- }
- return _requestGroup;
- }
- #pragma mark ----- 专辑
- - (TenantHotAlbumView *)albumView {
- if (!_albumView) {
- _albumView = [TenantHotAlbumView shareInstance];
- MJWeakSelf;
- [_albumView homeAlbumMore:^{
- [weakSelf moreAlbumDetail];
- }];
- [_albumView.albumContentView addSubview:self.albumCollectionView];
- [self.albumCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_albumView.albumContentView);
- }];
- }
- return _albumView;
- }
- - (UICollectionView *)albumCollectionView {
- if (!_albumCollectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 11, 12, 14);
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- _albumCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _albumCollectionView.backgroundColor = [UIColor clearColor];
- _albumCollectionView.delegate = self;
- _albumCollectionView.dataSource = self;
- _albumCollectionView.showsVerticalScrollIndicator = NO;
- _albumCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _albumCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _albumCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_albumCollectionView registerNib:[UINib nibWithNibName:@"TenantHotAlbumCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantHotAlbumCell"];
- }
- return _albumCollectionView;
- }
- - (NSMutableArray *)albumArray {
- if (!_albumArray) {
- _albumArray = [NSMutableArray array];
- }
- return _albumArray;
- }
- - (void)moreAlbumDetail {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-album"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark --- 推荐曲目
- - (TenantRecommendMusicView *)recommendMusicView {
- if (!_recommendMusicView) {
- _recommendMusicView = [TenantRecommendMusicView shareInstance];
- MJWeakSelf;
- [_recommendMusicView homeMusicMore:^{
- [weakSelf moreRecommendMusic];
- }];
- [_recommendMusicView.musicContentView addSubview:self.recommendMusicCollectionView];
- [self.recommendMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_recommendMusicView.musicContentView);
- }];
- }
- return _recommendMusicView;
- }
- - (UICollectionView *)recommendMusicCollectionView {
- if (!_recommendMusicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, KPortraitWidth - COLLECTION_WIDTH) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _recommendMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _recommendMusicCollectionView.backgroundColor = [UIColor clearColor];
- _recommendMusicCollectionView.delegate = self;
- _recommendMusicCollectionView.dataSource = self;
- _recommendMusicCollectionView.showsVerticalScrollIndicator = NO;
- _recommendMusicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _recommendMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _recommendMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_recommendMusicCollectionView registerNib:[UINib nibWithNibName:@"TenantMusicCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantMusicCollectionViewCell"];
- }
- return _recommendMusicCollectionView;
- }
- - (NSMutableArray *)recommendMusicArray {
- if (!_recommendMusicArray) {
- _recommendMusicArray = [NSMutableArray array];
- }
- return _recommendMusicArray;
- }
- - (void)moreRecommendMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ---- 最新曲目
- - (TenantNewMusicView *)newestMusicView {
- if (!_newestMusicView) {
- if (!_newestMusicView) {
- _newestMusicView = [TenantNewMusicView shareInstance];
- MJWeakSelf;
- [_newestMusicView homeMusicMore:^{
- [weakSelf moreNewMusic];
- }];
- [_newestMusicView.musicContentView addSubview:self.newestMusicCollectionView];
- [self.newestMusicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_newestMusicView.musicContentView);
- }];
- }
- return _newestMusicView;
- }
- return _newestMusicView;
- }
- - (UICollectionView *)newestMusicCollectionView {
- if (!_newestMusicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, (KPortraitWidth - COLLECTION_WIDTH)) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _newestMusicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _newestMusicCollectionView.backgroundColor = [UIColor clearColor];
- _newestMusicCollectionView.delegate = self;
- _newestMusicCollectionView.dataSource = self;
- _newestMusicCollectionView.showsVerticalScrollIndicator = NO;
- _newestMusicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _newestMusicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _newestMusicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_newestMusicCollectionView registerNib:[UINib nibWithNibName:@"TenantMusicCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantMusicCollectionViewCell"];
- }
- return _newestMusicCollectionView;
- }
- - (NSMutableArray *)newestMusicArray {
- if (!_newestMusicArray) {
- _newestMusicArray = [NSMutableArray array];
- }
- return _newestMusicArray;
- }
- - (void)moreNewMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- #pragma mark ---- 更多曲目
- - (TenantHotMusicView *)hotMusicView {
- if (!_hotMusicView) {
- _hotMusicView = [TenantHotMusicView shareInstance];
- MJWeakSelf;
- [_hotMusicView homeMusicMore:^{
- [weakSelf moreHotMusic];
- }];
- [_hotMusicView.musicContentView addSubview:self.musicCollectionView];
- [self.musicCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.top.mas_equalTo(_hotMusicView.musicContentView);
- }];
- }
- return _hotMusicView;
- }
- - (void)moreHotMusic {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@", TENANT_WEBHOST, @"/#/music-list"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (UICollectionView *)musicCollectionView {
- if (!_musicCollectionView) {
- HomeMusicSheetLayout *layout = [[HomeMusicSheetLayout alloc] initWithSectionInset:UIEdgeInsetsMake(0, 11, 0, (KPortraitWidth - COLLECTION_WIDTH)) andMiniLineSapce:10 andMiniInterItemSpace:10 andItemSize:CGSizeMake(COLLECTION_WIDTH, COLLECTION_HEIGHT)];
- _musicCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _musicCollectionView.backgroundColor = [UIColor clearColor];
- _musicCollectionView.delegate = self;
- _musicCollectionView.dataSource = self;
- _musicCollectionView.showsVerticalScrollIndicator = NO;
- _musicCollectionView.showsHorizontalScrollIndicator = NO;
- if (@available(iOS 11.0, *)) {
- _musicCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- // Fallback on earlier versions
- if (@available(iOS 13.0, *)) {
- _musicCollectionView.automaticallyAdjustsScrollIndicatorInsets = NO;
- } else {
- // Fallback on earlier versions
- }
- }
- [_musicCollectionView registerNib:[UINib nibWithNibName:@"TenantMusicCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"TenantMusicCollectionViewCell"];
- }
- return _musicCollectionView;
- }
- - (TenantDragView *)suspendButton {
- if (!_suspendButton) {
- _suspendButton = [[TenantDragView alloc] initWithFrame:CGRectMake(KPortraitWidth - TenantDragButtonWidth, KPortraitHeight - kTabBarHeight - TenantDragButtonHeight - 100, TenantDragButtonWidth, TenantDragButtonHeight)];
- MJWeakSelf;
- [_suspendButton clickAction:^{
- [weakSelf showDragWindowDetail];
- }];
- }
- return _suspendButton;
- }
- - (void)showDragWindowDetail {
- ToneTuningViewController *ctrl = [[ToneTuningViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|