YOUPAILZHotMusicVC.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //
  2. // YOUPAILZHotMusicVC.m
  3. // YOUQU
  4. //
  5. // Created by CY on 2021/12/10.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZHotMusicVC.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAILZHotMusicCell.h"
  11. @interface YOUPAILZHotMusicVC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, weak) UITextField *youpaipsearchTF;
  13. @property (nonatomic, weak) UIButton *cancelSearchBtn;
  14. @property (nonatomic, strong) NSString *youpaippageCode;
  15. @property (nonatomic, weak) UITableView *youpaiptableView;
  16. @property (nonatomic, strong) NSMutableArray <YOUPAILZMusicListItemModel *>*youpaipdataSource;
  17. @end
  18. @implementation YOUPAILZHotMusicVC
  19. - (void)viewWillDisappear:(BOOL)animated {
  20. [super viewWillDisappear:animated];
  21. [self.view endEditing:YES];
  22. }
  23. - (void)viewWillAppear:(BOOL)animated{
  24. [super viewWillAppear:animated];
  25. [self youpaifrequestMusicListWithStatus:kRefreshNormal];
  26. }
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  30. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifkeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  31. [self youpaifinitUI];
  32. }
  33. - (void)youpaifinitUI{
  34. // UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 25.0f, 34.0f)];
  35. // UIImageView *searchImgV = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 11.0f, 12.0f, 12.0f)];
  36. // searchImgV.image = [UIImage imageNamed:@"vqu_image_music_search"];
  37. // [leftView addSubview:searchImgV];
  38. // UITextField *searchTF = [[UITextField alloc]init];
  39. // searchTF.layer.cornerRadius = 17.0f;
  40. // searchTF.clipsToBounds = YES;
  41. // searchTF.tintColor = ZYPinkColor;
  42. // searchTF.leftViewMode = UITextFieldViewModeAlways;
  43. // searchTF.leftView = leftView;
  44. // searchTF.font = LCFont(11.0f);
  45. // NSMutableAttributedString* placeholder = [[NSMutableAttributedString alloc]initWithString:@"搜搜你喜欢的音乐、歌手"];
  46. // [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x6C6B70) range:NSMakeRange(0, placeholder.length)];
  47. // searchTF.attributedPlaceholder = placeholder;
  48. // searchTF.backgroundColor = [HexColorFromRGB(0x4F4B5B) colorWithAlphaComponent:0.43f];
  49. // searchTF.returnKeyType = UIReturnKeySearch;
  50. // searchTF.textColor = [UIColor whiteColor];
  51. // [self.view addSubview:searchTF];
  52. // self.youpaipsearchTF = searchTF;
  53. // [searchTF mas_makeConstraints:^(MASConstraintMaker *make) {
  54. // make.left.offset(14.0f);
  55. // make.right.offset(-14.0f);
  56. // make.top.offset(12.0f);
  57. // make.height.offset(34.0f);
  58. // }];
  59. //
  60. // UIButton *cancelSearchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  61. // [cancelSearchBtn setTitle:@"取消" forState:UIControlStateNormal];
  62. // [cancelSearchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  63. // cancelSearchBtn.titleLabel.font = LCFont(14.0f);
  64. // [cancelSearchBtn addTarget:self action:@selector(youpaifcancelSearchBtnClick) forControlEvents:UIControlEventTouchUpInside];
  65. // cancelSearchBtn.hidden = YES;
  66. // [self.view addSubview:cancelSearchBtn];
  67. // self.cancelSearchBtn = cancelSearchBtn;
  68. // [cancelSearchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  69. // make.right.offset(-14.0f);
  70. // make.centerY.equalTo(searchTF);
  71. // }];
  72. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  73. tableView.delegate = self;
  74. tableView.dataSource = self;
  75. tableView.rowHeight = 60.0f;
  76. tableView.estimatedRowHeight = 60.0f;
  77. tableView.estimatedSectionHeaderHeight = 0.0f;
  78. tableView.estimatedSectionFooterHeight = 0.0f;
  79. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  80. tableView.backgroundColor = [UIColor clearColor];
  81. tableView.showsVerticalScrollIndicator = NO;
  82. [self.view addSubview:tableView];
  83. self.youpaiptableView = tableView;
  84. @weakify(self);
  85. [tableView setRefreshHeaderWithBlock:^{
  86. @strongify(self);
  87. [self youpaifrequestMusicListWithStatus:kRefreshHeader];
  88. }];
  89. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.right.offset(0.0f);
  91. make.top.offset(0.0f);
  92. // make.top.equalTo(searchTF.mas_bottom).offset(12.0f);
  93. make.bottom.offset(-SafeHeight);
  94. }];
  95. }
  96. - (void)youpaifcancelSearchBtnClick{
  97. [self.view endEditing:YES];
  98. self.youpaipsearchTF.text = @"";
  99. }
  100. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  101. return self.youpaipdataSource.count;
  102. }
  103. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  104. NSString *cellID = @"YOUPAILZHotMusicCell";
  105. YOUPAILZHotMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  106. if (cell == nil) {
  107. cell = [[YOUPAILZHotMusicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  108. }
  109. [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row]];
  110. return cell;
  111. }
  112. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  113. return CGFLOAT_MIN;
  114. }
  115. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  116. return CGFLOAT_MIN;
  117. }
  118. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  119. }
  120. //键盘即将隐藏
  121. - (void)youpaifkeyboardWillHide:(NSNotification *)note{
  122. [self.view layoutIfNeeded];
  123. if (self.keyboardWillHideBlock) {
  124. self.keyboardWillHideBlock();
  125. }
  126. self.cancelSearchBtn.hidden = YES;
  127. [self.view layoutIfNeeded];
  128. [UIView animateWithDuration:0.25f animations:^{
  129. [self.youpaipsearchTF mas_remakeConstraints:^(MASConstraintMaker *make) {
  130. make.left.offset(14.0f);
  131. make.right.offset(-14.0f);
  132. make.top.offset(12.0f);
  133. make.height.offset(34.0f);
  134. }];
  135. [self.view layoutIfNeeded];
  136. }];
  137. }
  138. //键盘即将弹出
  139. - (void)youpaifkeyboardWillShow:(NSNotification *)note{
  140. CGRect keyboardF = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  141. CGFloat keyboardH = keyboardF.size.height;
  142. if (self.keyboardWillShowBlock) {
  143. self.keyboardWillShowBlock(keyboardH);
  144. }
  145. self.cancelSearchBtn.hidden = NO;
  146. [self.view layoutIfNeeded];
  147. [UIView animateWithDuration:0.25f animations:^{
  148. [self.youpaipsearchTF mas_remakeConstraints:^(MASConstraintMaker *make) {
  149. make.left.offset(14.0f);
  150. make.right.equalTo(self.cancelSearchBtn.mas_left).offset(-10.0f);
  151. make.top.offset(12.0f);
  152. make.height.offset(34.0f);
  153. }];
  154. [self.view layoutIfNeeded];
  155. }];
  156. }
  157. /// 设置加载更多
  158. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  159. __weak typeof(self) weakSelf = self;
  160. [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
  161. [weakSelf youpaifrequestMusicListWithStatus:kRefreshFooter];
  162. }];
  163. }
  164. /// 获取列表数据
  165. - (void)youpaifrequestMusicListWithStatus:(kRefreshStatus)status{
  166. if (status != kRefreshFooter) {
  167. self.youpaippageCode = @"0";
  168. }
  169. @weakify(self);;
  170. [LCHttpHelper requestWithURLString:GetAllSongs parameters:@{@"pageCode":self.youpaippageCode,@"number":@(10)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  171. @strongify(self);;
  172. [self.youpaiptableView endRefreshing:kRefreshAll];
  173. NSDictionary* dict = (NSDictionary*)responseObject;
  174. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  175. if (code == 0) {//成功
  176. if (status != kRefreshFooter) {
  177. [self.youpaipdataSource removeAllObjects];
  178. }
  179. NSDictionary *data = [dict objectForKey:@"data"];
  180. NSArray <YOUPAILZMusicListItemModel *>*list = [YOUPAILZMusicListItemModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"list"]];
  181. [self.youpaipdataSource addObjectsFromArray:list];
  182. [self.youpaiptableView reloadData];
  183. // NSInteger totalCount = [[[data objectForKey:@"meta"] objectForKey:@"totalCount"] integerValue];
  184. self.youpaippageCode = [data objectForKey:@"pageCode"];
  185. [self youpaifrefreshFooterWithHidden:NO];
  186. }
  187. } failure:^(NSError *error) {
  188. [self.youpaiptableView endRefreshing:kRefreshAll];
  189. }];
  190. }
  191. - (NSMutableArray *)youpaipdataSource{
  192. if (!_youpaipdataSource) {
  193. _youpaipdataSource = [NSMutableArray array];
  194. }
  195. return _youpaipdataSource;
  196. }
  197. #pragma mark - JXCategoryListContentViewDelegate
  198. - (UIView *)listView{
  199. return self.view;
  200. }
  201. @end