new_BGMListController.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. //
  2. // new_BGMListController.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/5/25.
  6. // Copyright © 2019年 xfg. All rights reserved.
  7. //
  8. #import "new_BGMListController.h"
  9. @interface new_BGMListController ()<new_bgmSureDelegate,new_bgmcategoryDelegate,UITextFieldDelegate>
  10. {
  11. UIButton *leftBtn,*RecommendBTn,*FindBtn,*collectionBTn,*searchCancelBtn;
  12. UILabel *titleLa;
  13. UIView *contentView;
  14. UITextField *searchField;
  15. int findPage,Recommendpage,collectionpage,typepage;
  16. }
  17. @property (nonatomic, strong)UIView *headerView;
  18. @property (nonatomic, strong)new_bgmListView *musicListview,*searchListview;
  19. @property (nonatomic, strong)new_BGMcategory *musiccategoryview;
  20. @end
  21. @implementation new_BGMListController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.view.backgroundColor =kBlackColor;
  25. findPage =1;
  26. Recommendpage =1;
  27. collectionpage =1;
  28. typepage =1;
  29. // Do any additional setup after loading the view.
  30. }
  31. - (void)viewWillAppear:(BOOL)animated
  32. {
  33. [super viewWillAppear:animated];
  34. [self drawContent];
  35. if (_type_id)
  36. {
  37. [self getTypeList];
  38. }
  39. self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
  40. self.navigationController.navigationBar.hidden =YES;
  41. }
  42. - (void)leftAction
  43. {
  44. if (self.navigationController.viewControllers.count >1)
  45. {
  46. [self.navigationController popViewControllerAnimated:YES];
  47. }else
  48. {
  49. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  50. }
  51. }
  52. - (void)ListAction:(UIButton *)sender
  53. {
  54. __block typeof(self)blockself =self;
  55. switch (sender.tag)
  56. {
  57. case 1:
  58. {
  59. RecommendBTn.selected =YES;
  60. FindBtn.selected =NO;
  61. collectionBTn.selected =NO;
  62. self.headerView.frame =CGRectMake(0, 0, kScreenW, 120 );
  63. self.musicListview.tableview.tableHeaderView =self.headerView;
  64. }
  65. break;
  66. case 2:
  67. {
  68. RecommendBTn.selected =NO;
  69. FindBtn.selected =YES;
  70. collectionBTn.selected =NO;
  71. }
  72. break;
  73. case 3:
  74. {
  75. RecommendBTn.selected =NO;
  76. FindBtn.selected =NO;
  77. collectionBTn.selected =YES;
  78. self.headerView.frame =CGRectMake(0, 0, kScreenW, 120);
  79. self.musicListview.tableview.tableHeaderView =self.headerView;
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. if (sender.tag ==1 )
  86. {
  87. [self getrecommendList];
  88. }
  89. if (sender.tag ==2)
  90. {
  91. // //发现
  92. // if(self.musiccategoryview.dataSource.count <=0)
  93. // {
  94. // //执行请求分类菜单
  95. // [Music_manager MusicManagerget_type_list:^(id response) {
  96. // if (response && [response isKindOfClass:[NSArray class]])
  97. // {
  98. // NSArray *datasource =response;
  99. // [blockself showWithFindHeader:datasource];
  100. // }
  101. // [blockself getFindList];
  102. // }];
  103. // }else
  104. // {
  105. // [blockself showWithFindHeader:self.musiccategoryview.dataSource];
  106. // [self getFindList];
  107. // }
  108. }
  109. if (sender.tag ==3)
  110. {
  111. [self getmusic_collection];
  112. }
  113. }
  114. //发现头部的显示数据
  115. - (void)showWithFindHeader:(NSArray *)datasource
  116. {
  117. CGFloat need_h =0;
  118. if (datasource.count%4 !=0)
  119. {
  120. need_h =(kScreenW-4) /4*(datasource.count/4 +1);
  121. }else
  122. {
  123. need_h =(kScreenW-4) /4*datasource.count/4;
  124. }
  125. self.musiccategoryview.frame =CGRectMake(0, 120, _headerView.width, need_h);
  126. self.headerView.frame =CGRectMake(0, 0, kScreenW, 120 +need_h);
  127. self.musiccategoryview.dataSource =datasource;
  128. self.musiccategoryview.delegate =self;
  129. self.musicListview.tableview.tableHeaderView =self.headerView;
  130. }
  131. //发现列表数据
  132. - (void)getFindList
  133. {
  134. __block typeof(self)blockself =self;
  135. Recommendpage =1;
  136. collectionpage =1;
  137. // //执行发现下音乐列表
  138. // [Music_manager MusicManagerget_find_music:findPage andcallback:^(id response) {
  139. // if (response && [response isKindOfClass:[NSArray class]])
  140. // {
  141. // [blockself.musicListview setDatasource:response andPage:blockself->findPage];
  142. // NSArray *responseData =response;
  143. // if (responseData.count>=20)
  144. // {
  145. // blockself->findPage ++;
  146. // }
  147. // }
  148. // }];
  149. }
  150. //推荐列表数据
  151. - (void)getrecommendList
  152. {
  153. __block typeof(self)blockself =self;
  154. findPage =1;
  155. collectionpage =1;
  156. // //执行发现下音乐列表
  157. // [Music_manager MusicManagerget_recommend_music:findPage andcallback:^(id response) {
  158. // if (response && [response isKindOfClass:[NSArray class]])
  159. // {
  160. // [blockself.musicListview setDatasource:response andPage:blockself->Recommendpage];
  161. // NSArray *responseData =response;
  162. // if (responseData.count>=20)
  163. // {
  164. // blockself->Recommendpage ++;
  165. // }
  166. // }
  167. // }];
  168. }
  169. //收藏列表的数据
  170. - (void)getmusic_collection
  171. {
  172. __block typeof(self)blockself =self;
  173. findPage =1;
  174. Recommendpage =1;
  175. // //执行发现下音乐列表
  176. // [Music_manager MusicManagerget_my_collection:collectionpage andcallback:^(id response) {
  177. // if (response && [response isKindOfClass:[NSArray class]])
  178. // {
  179. // [blockself.musicListview setDatasource:response andPage:blockself->collectionpage];
  180. // NSArray *responseData =response;
  181. // if (responseData.count>=20)
  182. // {
  183. // blockself->collectionpage ++;
  184. // }
  185. // }
  186. // }];
  187. }
  188. //类别下的数据列表
  189. - (void)getTypeList
  190. {
  191. __block typeof(self)blockself =self;
  192. // //执行发现下音乐列表
  193. // [Music_manager MusicManagerGetget_music_listWithid:_type_id page:typepage andcallback:^(id response) {
  194. // if (response && [response isKindOfClass:[NSArray class]])
  195. // {
  196. // [blockself.musicListview setDatasource:response andPage:blockself->typepage];
  197. // NSArray *responseData =response;
  198. // if (responseData.count>=20)
  199. // {
  200. // blockself->typepage ++;
  201. // }
  202. // }
  203. // }];
  204. }
  205. //根据搜索键来获取音乐列表
  206. - (void)searchWithMusic:(NSString *)key
  207. {
  208. __block typeof(self)blockself =self;
  209. // [Music_manager MusicManagerserchWithkey:key page:1 andcallback:^(id response) {
  210. // if (response && [response isKindOfClass:[NSArray class]])
  211. // {
  212. // [blockself.searchListview setDatasource:response andPage:1];
  213. // NSArray *responseData =response;
  214. // if (responseData.count>=20)
  215. // {
  216. //
  217. // }
  218. // }
  219. // }];
  220. }
  221. - (void)SearchcancelAction
  222. {
  223. [self searchListview].hidden =YES;
  224. searchField.text =@"";
  225. [searchField resignFirstResponder];
  226. }
  227. #pragma 代理
  228. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  229. {
  230. [searchField mas_updateConstraints:^(MASConstraintMaker *make) {
  231. make.right.equalTo(contentView).offset(-160 );
  232. }];
  233. [self searchListview].hidden =NO;
  234. return YES;
  235. }
  236. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
  237. {
  238. [searchField mas_updateConstraints:^(MASConstraintMaker *make) {
  239. make.right.equalTo(contentView).offset(-30 );
  240. }];
  241. return YES;
  242. }
  243. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  244. {
  245. [self searchWithMusic:textField.text];
  246. return YES;
  247. }
  248. - (void)SureUseobj:(music_obj *)model
  249. {
  250. if (model)
  251. {
  252. __block typeof(self)blockself =self;
  253. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  254. [blockself.musicListview.player pause];
  255. blockself.nav.useMusicBlock(model);
  256. }];
  257. }
  258. }
  259. - (void)itemSelect:(new_bgmcategoryModel *)model
  260. {
  261. new_BGMListController *vc =[new_BGMListController new];
  262. vc.nav =self.nav;
  263. vc.type_id =model.type_id;
  264. [self.navigationController pushViewController:vc animated:YES];
  265. }
  266. #pragma 懒加载
  267. - (UIView *)headerView
  268. {
  269. if (!_headerView)
  270. {
  271. _headerView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 120)];
  272. _headerView.layer.masksToBounds =YES;
  273. RecommendBTn =[[UIButton alloc]init];
  274. [_headerView addSubview:RecommendBTn];
  275. [RecommendBTn mas_makeConstraints:^(MASConstraintMaker *make) {
  276. make.height.equalTo(@(90));
  277. make.top.equalTo(_headerView).offset(30);
  278. }];
  279. [RecommendBTn setTitle:ASLocalizedString(@"推荐")forState:0];
  280. RecommendBTn.tag =1;
  281. [RecommendBTn setTitleColor:kGrayColor forState:0];
  282. [RecommendBTn setTitleColor:kBlackColor forState:UIControlStateSelected];
  283. FindBtn =[[UIButton alloc]init];
  284. [_headerView addSubview:FindBtn];
  285. [FindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  286. make.height.equalTo(@(90));
  287. make.top.equalTo(_headerView).offset(30);
  288. }];
  289. [FindBtn setTitle:ASLocalizedString(@"发现")forState:0];
  290. FindBtn.tag =2;
  291. [FindBtn setTitleColor:kGrayColor forState:0];
  292. [FindBtn setTitleColor:kBlackColor forState:UIControlStateSelected];
  293. collectionBTn =[[UIButton alloc]init];
  294. [_headerView addSubview:collectionBTn];
  295. [collectionBTn mas_makeConstraints:^(MASConstraintMaker *make) {
  296. make.height.equalTo(@(90));
  297. make.top.equalTo(_headerView).offset(30);
  298. }];
  299. [collectionBTn setTitle:ASLocalizedString(@"收藏")forState:0];
  300. collectionBTn.tag =3;
  301. [collectionBTn setTitleColor:kGrayColor forState:0];
  302. [collectionBTn setTitleColor:kBlackColor forState:UIControlStateSelected];
  303. NSArray *btnary =@[RecommendBTn,FindBtn,collectionBTn];
  304. [btnary mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10 leadSpacing:100 tailSpacing:100];
  305. [RecommendBTn addTarget:self action:@selector(ListAction:) forControlEvents:UIControlEventTouchUpInside];
  306. [FindBtn addTarget:self action:@selector(ListAction:) forControlEvents:UIControlEventTouchUpInside];
  307. [collectionBTn addTarget:self action:@selector(ListAction:) forControlEvents:UIControlEventTouchUpInside];
  308. [_headerView addSubview:self.musiccategoryview];
  309. self.musiccategoryview.frame =CGRectMake(0, 120, _headerView.width, 0);
  310. [self ListAction:FindBtn];
  311. }
  312. return _headerView;
  313. }
  314. - (new_BGMcategory *)musiccategoryview
  315. {
  316. if (!_musiccategoryview)
  317. {
  318. _musiccategoryview =[[new_BGMcategory alloc]init];
  319. }
  320. return _musiccategoryview;
  321. }
  322. - (new_bgmListView *)searchListview
  323. {
  324. if (!_searchListview)
  325. {
  326. _searchListview =[[new_bgmListView alloc]init];
  327. [contentView addSubview:_searchListview];
  328. [_searchListview mas_makeConstraints:^(MASConstraintMaker *make) {
  329. make.width.bottom.centerX.equalTo(contentView);
  330. if (searchField)
  331. {
  332. make.top.equalTo(searchField.mas_bottom);
  333. }else
  334. {
  335. make.top.equalTo(contentView).offset(90);
  336. }
  337. }];
  338. _searchListview.delegate =self;
  339. _searchListview.backgroundColor =kWhiteColor;
  340. }
  341. [_searchListview bringSubviewToFront:contentView];
  342. return _searchListview;
  343. }
  344. - (new_bgmListView *)musicListview
  345. {
  346. if (!_musicListview)
  347. {
  348. _musicListview =[[new_bgmListView alloc]init];
  349. [contentView addSubview:_musicListview];
  350. [_musicListview mas_makeConstraints:^(MASConstraintMaker *make) {
  351. make.width.bottom.centerX.equalTo(contentView);
  352. if (searchField)
  353. {
  354. make.top.equalTo(searchField.mas_bottom);
  355. }else
  356. {
  357. make.top.equalTo(contentView).offset(90);
  358. }
  359. }];
  360. _musicListview.delegate =self;
  361. if (!_type_id)
  362. {
  363. _musicListview.tableview.tableHeaderView =self.headerView;
  364. }
  365. }
  366. return _musicListview;
  367. }
  368. - (void)drawContent
  369. {
  370. if (!contentView)
  371. {
  372. contentView =[[UIView alloc]init];
  373. [self.view addSubview:contentView];
  374. NSLog(@"%.2f",kStatusBarHeight);
  375. [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  376. make.centerX.width.height.equalTo(self.view);
  377. make.top.mas_equalTo(kStatusBarHeight);
  378. }];
  379. contentView.layer.cornerRadius =10.;
  380. contentView.backgroundColor =kWhiteColor;
  381. leftBtn =[UIButton new];
  382. [contentView addSubview:leftBtn];
  383. [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  384. make.left.equalTo(contentView);
  385. make.top.equalTo(contentView);
  386. make.width.height.equalTo(@(90));
  387. }];
  388. if (_type_id)
  389. {
  390. [leftBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:0];
  391. }else
  392. {
  393. [leftBtn setImage:[UIImage imageNamed:@"new_bgm_close"] forState:0];
  394. }
  395. [leftBtn addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
  396. titleLa =[UILabel new];
  397. [contentView addSubview:titleLa];
  398. [titleLa mas_makeConstraints:^(MASConstraintMaker *make) {
  399. make.centerY.equalTo(leftBtn);
  400. make.height.equalTo(leftBtn);
  401. make.centerX.width.equalTo(contentView);
  402. }];
  403. titleLa.textColor =kBlackColor;
  404. titleLa.font =[UIFont fontWithName:@"Helvetica-Bold" size:18.];
  405. titleLa.textAlignment =1;
  406. titleLa.text =ASLocalizedString(@"选择音乐");
  407. if (!_type_id)
  408. {
  409. searchField =[[UITextField alloc]init];
  410. [contentView addSubview:searchField];
  411. [searchField mas_makeConstraints:^(MASConstraintMaker *make) {
  412. make.top.equalTo(leftBtn.mas_bottom).offset(30);
  413. make.left.equalTo(contentView).offset(30);
  414. make.right.equalTo(contentView).offset(-30 );
  415. make.height.equalTo(@(70));
  416. }];
  417. searchField.backgroundColor =UIColorFromRGB(0xf1f1f1);
  418. searchField.textAlignment =0;
  419. searchField.delegate =self;
  420. searchField.attributedPlaceholder =[self backplaceholder];
  421. searchField.layer.cornerRadius =2.;
  422. searchCancelBtn =[UIButton new];
  423. [contentView addSubview:searchCancelBtn];
  424. [searchCancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  425. make.left.equalTo(searchField.mas_right).offset(30);
  426. make.centerY.height.equalTo(searchField);
  427. make.width.equalTo(@(130));
  428. }];
  429. [searchCancelBtn setTitle:ASLocalizedString(@"取消")forState:0];
  430. [searchCancelBtn setTitleColor:UIColorFromRGB(0xfb3763) forState:0];
  431. searchCancelBtn.titleLabel.font =[UIFont systemFontOfSize:15.];
  432. [searchCancelBtn addTarget:self action:@selector(SearchcancelAction) forControlEvents:UIControlEventTouchUpInside];
  433. }
  434. [self musicListview];
  435. }
  436. }
  437. - (NSAttributedString *)backplaceholder
  438. {
  439. NSMutableAttributedString *backattr =[NSMutableAttributedString new];
  440. NSTextAttachment *img =[[NSTextAttachment alloc]init];
  441. img.image =[UIImage imageNamed:@"ic_edit_search_gray"];
  442. img.bounds =CGRectMake(0, -2, 15, 15);
  443. NSAttributedString *imgattr =[NSAttributedString attributedStringWithAttachment:img];
  444. NSAttributedString *strattr =[[NSAttributedString alloc]initWithString:ASLocalizedString(@" 搜索音乐")attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.],NSForegroundColorAttributeName:kGrayColor}];
  445. [backattr appendAttributedString:imgattr];
  446. [backattr appendAttributedString:strattr];
  447. return backattr;
  448. }
  449. - (void)didReceiveMemoryWarning {
  450. [super didReceiveMemoryWarning];
  451. // Dispose of any resources that can be recreated.
  452. }
  453. - (void)viewDidDisappear:(BOOL)animated
  454. {
  455. [super viewDidDisappear:animated];
  456. // NSLog(@"musicListview%@",self.musicListview);
  457. // NSLog(@"%@",self.musicListview.player);
  458. //
  459. // NSLog(@"searchListview%@",self.searchListview);
  460. // NSLog(@"%@",self.searchListview.player);
  461. [self.musicListview.player pause];
  462. [self.searchListview.player pause];
  463. // if (self.searchListview.player) {
  464. // self.searchListview.player = nil;
  465. // }
  466. }
  467. /*
  468. #pragma mark - Navigation
  469. // In a storyboard-based application, you will often want to do a little preparation before navigation
  470. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  471. // Get the new view controller using [segue destinationViewController].
  472. // Pass the selected object to the new view controller.
  473. }
  474. */
  475. @end