123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #import "FMSingerSongListViewController.h"
- #import "FMLoadMoreFooterView.h"
- #import "FMMusicViewController.h"
- #import "NSDate+Additions.h"
- #import "FMSongListTableViewCell.h"
- @interface FMSingerSongListViewController ()<UIScrollViewDelegate>
- {
- NSMutableArray * array ;
- BOOL isLoadingMore;
- BOOL isCanLoadMore;
- FMLoadMoreFooterView * footerView;
- int song_total;
- }
- @end
- @implementation FMSingerSongListViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
-
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self.navigationController setNavigationBarHidden:YES animated:NO];
- self.view.backgroundColor = [UIColor whiteColor];
- self.navigation.leftImage = [UIImage imageNamed:@"nav_backbtn.png"];
-
- self.navigation.rightImage = [UIImage imageNamed:@"nav_music.png"];
- self.navigation.title = [NSString stringWithFormat:@"%@(歌曲%d)",_singerModel.name,_singerModel.songs_total];
- self.navigation.navigaionBackColor = [UIColor colorWithRed:192.0f/255.0f green:37.0f/255.0f blue:62.0f/255.0f alpha:1.0f];
-
- _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)];
- _tableView.delegate =self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.view addSubview:_tableView];
-
-
- if (_singerModel.songs_total<20) {
- song_total = _singerModel.songs_total;
- isLoadingMore = NO;
- }else{
- song_total = 20;
- isLoadingMore = YES;
- }
- if (isLoadingMore) {
- footerView = [[FMLoadMoreFooterView alloc] initWithFrame:CGRectMake(0, 0, _tableView.size.width, 70)];
- _tableView.tableFooterView = footerView;
- }
- [ProgressHUD show:nil];
- [self getSongsList];
-
- }
- -(void)rightButtonClickEvent
- {
- if (globle.isPlaying) {
- FMMusicViewController * pushController = [FMMusicViewController shareMusicViewController];
- pushController.only = NO;
- [self.navigationController pushViewController:pushController animated:YES];
- }
- }
- -(void)getSongsList
- {
- MCDataEngine * network = [MCDataEngine new];
- [network getSingerSongListWith:_singerModel.ting_uid :song_total WithCompletionHandler:^(FMSongList *songList) {
- array = songList.songLists;
- [_tableView reloadData];
- [ProgressHUD dismiss];
- } errorHandler:^(NSError *error) {
-
- }];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
-
- return [array count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString * dentifier = @"cell";
- FMSongListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dentifier];
- if (cell == nil) {
- cell = [[FMSongListTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:dentifier];
- }
- FMSongListModel * model = [array objectAtIndex:indexPath.row];
- cell.model = model;
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 60;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- FMSongListModel * model = [array objectAtIndex:indexPath.row];
- FMMusicViewController * pushController = [FMMusicViewController shareMusicViewController];
- pushController.songListModel = model;
- pushController.array = array;
- pushController.index = indexPath.row;
- pushController.only = NO;
- [pushController playMusicWithSongLink:model];
- [self.navigationController pushViewController:pushController animated:YES];
- }
- -(void)loadMore
- {
- if (isLoadingMore) {
- [footerView.activeView startAnimating];
- song_total+=20;
- [self performSelector:@selector(loadMoreData) withObject:nil afterDelay:0.1];
- isLoadingMore = NO;
- footerView.titleLabel.text = @"获取中...";
- }
- }
- -(void)loadMoreData
- {
- MCDataEngine * network = [MCDataEngine new];
- [network getSingerSongListWith:_singerModel.ting_uid :song_total WithCompletionHandler:^(FMSongList *songList) {
-
- array = songList.songLists;
- [_tableView reloadData];
- if (song_total> _singerModel.songs_total){
- song_total = _singerModel.songs_total;
- isCanLoadMore = YES;
- }else{
- isCanLoadMore = NO;
- }
- [self loadMoreCompleted];
- } errorHandler:^(NSError *error) {
-
- }];
- }
- -(void)loadMoreCompleted
- {
- isLoadingMore = YES;
- if (isCanLoadMore) {
- _tableView.tableFooterView = nil;
- }else{
- [footerView.activeView stopAnimating];
- }
- }
- #define DEFAULT_HEIGHT_OFFSET 44.0f
- #pragma mark UIScrollViewDelegate
- - (void) scrollViewDidScroll:(UIScrollView *)scrollView
- {
- if (isLoadingMore && !isCanLoadMore) {
- CGFloat scrollPosition = scrollView.contentSize.height - scrollView.frame.size.height - scrollView.contentOffset.y;
- if (scrollPosition < DEFAULT_HEIGHT_OFFSET) {
- [self loadMore];
- }
- }
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
-
- }
- @end
|