FMSingerSongListViewController.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // FMSingerDetailViewController.m
  3. // FreeMusic
  4. //
  5. //
  6. #import "FMSingerSongListViewController.h"
  7. #import "FMLoadMoreFooterView.h"
  8. #import "FMMusicViewController.h"
  9. #import "NSDate+Additions.h"
  10. #import "FMSongListTableViewCell.h"
  11. @interface FMSingerSongListViewController ()<UIScrollViewDelegate>
  12. {
  13. NSMutableArray * array ;
  14. BOOL isLoadingMore;
  15. BOOL isCanLoadMore;
  16. FMLoadMoreFooterView * footerView;
  17. int song_total;
  18. }
  19. @end
  20. @implementation FMSingerSongListViewController
  21. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  22. {
  23. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  24. if (self) {
  25. // Custom initialization
  26. }
  27. return self;
  28. }
  29. - (void)viewDidLoad
  30. {
  31. [super viewDidLoad];
  32. [self.navigationController setNavigationBarHidden:YES animated:NO];
  33. self.view.backgroundColor = [UIColor whiteColor];
  34. self.navigation.leftImage = [UIImage imageNamed:@"nav_backbtn.png"];
  35. // self.navigation.headerImage = [UIImage imageNamed:@"nav_canadaicon.png"];
  36. self.navigation.rightImage = [UIImage imageNamed:@"nav_music.png"];
  37. self.navigation.title = [NSString stringWithFormat:@"%@(歌曲%d)",_singerModel.name,_singerModel.songs_total];
  38. self.navigation.navigaionBackColor = [UIColor colorWithRed:192.0f/255.0f green:37.0f/255.0f blue:62.0f/255.0f alpha:1.0f];
  39. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navigation.size.height+self.navigation.origin.y, self.view.size.width, self.view.size.height-self.navigation.size.height-48.5f)];
  40. _tableView.delegate =self;
  41. _tableView.dataSource = self;
  42. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  43. [self.view addSubview:_tableView];
  44. if (_singerModel.songs_total<20) {
  45. song_total = _singerModel.songs_total;
  46. isLoadingMore = NO;
  47. }else{
  48. song_total = 20;
  49. isLoadingMore = YES;
  50. }
  51. if (isLoadingMore) {
  52. footerView = [[FMLoadMoreFooterView alloc] initWithFrame:CGRectMake(0, 0, _tableView.size.width, 70)];
  53. _tableView.tableFooterView = footerView;
  54. }
  55. [ProgressHUD show:nil];
  56. [self getSongsList];
  57. // Do any additional setup after loading the view.
  58. }
  59. -(void)rightButtonClickEvent
  60. {
  61. if (globle.isPlaying) {
  62. FMMusicViewController * pushController = [FMMusicViewController shareMusicViewController];
  63. pushController.only = NO;
  64. [self.navigationController pushViewController:pushController animated:YES];
  65. }
  66. }
  67. -(void)getSongsList
  68. {
  69. MCDataEngine * network = [MCDataEngine new];
  70. [network getSingerSongListWith:_singerModel.ting_uid :song_total WithCompletionHandler:^(FMSongList *songList) {
  71. array = songList.songLists;
  72. [_tableView reloadData];
  73. [ProgressHUD dismiss];
  74. } errorHandler:^(NSError *error) {
  75. }];
  76. }
  77. #pragma mark - Table view data source
  78. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  79. {
  80. //#warning Potentially incomplete method implementation.
  81. // Return the number of sections.
  82. return 1;
  83. }
  84. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  85. {
  86. //#warning Incomplete method implementation.
  87. // Return the number of rows in the section.
  88. return [array count];
  89. }
  90. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  91. {
  92. NSString * dentifier = @"cell";
  93. FMSongListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dentifier];
  94. if (cell == nil) {
  95. cell = [[FMSongListTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:dentifier];
  96. }
  97. FMSongListModel * model = [array objectAtIndex:indexPath.row];
  98. cell.model = model;
  99. return cell;
  100. }
  101. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  102. {
  103. return 60;
  104. }
  105. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107. FMSongListModel * model = [array objectAtIndex:indexPath.row];
  108. FMMusicViewController * pushController = [FMMusicViewController shareMusicViewController];
  109. pushController.songListModel = model;
  110. pushController.array = array;
  111. pushController.index = indexPath.row;
  112. pushController.only = NO;
  113. [pushController playMusicWithSongLink:model];
  114. [self.navigationController pushViewController:pushController animated:YES];
  115. }
  116. -(void)loadMore
  117. {
  118. if (isLoadingMore) {
  119. [footerView.activeView startAnimating];
  120. song_total+=20;
  121. [self performSelector:@selector(loadMoreData) withObject:nil afterDelay:0.1];
  122. isLoadingMore = NO;
  123. footerView.titleLabel.text = @"获取中...";
  124. }
  125. }
  126. -(void)loadMoreData
  127. {
  128. MCDataEngine * network = [MCDataEngine new];
  129. [network getSingerSongListWith:_singerModel.ting_uid :song_total WithCompletionHandler:^(FMSongList *songList) {
  130. array = songList.songLists;
  131. [_tableView reloadData];
  132. if (song_total> _singerModel.songs_total){
  133. song_total = _singerModel.songs_total;
  134. isCanLoadMore = YES; // signal that there won't be any more items to load
  135. }else{
  136. isCanLoadMore = NO;
  137. }
  138. [self loadMoreCompleted];
  139. } errorHandler:^(NSError *error) {
  140. }];
  141. }
  142. -(void)loadMoreCompleted
  143. {
  144. isLoadingMore = YES;
  145. if (isCanLoadMore) {
  146. _tableView.tableFooterView = nil;
  147. }else{
  148. [footerView.activeView stopAnimating];
  149. }
  150. }
  151. #define DEFAULT_HEIGHT_OFFSET 44.0f
  152. #pragma mark UIScrollViewDelegate
  153. - (void) scrollViewDidScroll:(UIScrollView *)scrollView
  154. {
  155. if (isLoadingMore && !isCanLoadMore) {
  156. CGFloat scrollPosition = scrollView.contentSize.height - scrollView.frame.size.height - scrollView.contentOffset.y;
  157. if (scrollPosition < DEFAULT_HEIGHT_OFFSET) {
  158. [self loadMore];
  159. }
  160. }
  161. }
  162. - (void)didReceiveMemoryWarning
  163. {
  164. [super didReceiveMemoryWarning];
  165. // Dispose of any resources that can be recreated.
  166. }
  167. /*
  168. #pragma mark - Navigation
  169. // In a storyboard-based application, you will often want to do a little preparation before navigation
  170. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  171. {
  172. // Get the new view controller using [segue destinationViewController].
  173. // Pass the selected object to the new view controller.
  174. }
  175. */
  176. @end