18
18
// along with this program. If not, see <http://www.gnu.org/licenses/>.
20
20
#import "AlbumListViewController.h"
22
21
#import "AlbumListParser.h"
23
22
#import "AlbumArtistUITableViewCell.h"
25
24
#import "AlbumViewController.h"
26
#import "AsynchronousImageViewCached.h"
25
#import "NSString+Extras.h"
27
@interface AlbumListViewController ()
28
- (void)configureCell:(AlbumArtistUITableViewCell*)cell forTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath;
28
31
@implementation AlbumListViewController
32
35
AlbumListViewController *albumListViewController = [[[AlbumListViewController alloc] initWithTitle:NSLocalizedString(@"Albums", @"")] autorelease];
33
36
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:albumListViewController] autorelease];
34
37
nav.navigationBar.barStyle = UIBarStyleBlack;
38
nav.tabBarItem.image = [UIImage imageNamed:@"albums"];
42
46
self.tableView.rowHeight = 60.0f;
43
47
[super viewDidLoad];
45
loader = [[ImageLoader alloc] init];
49
loader = [[AlbumArtLoader alloc] init];
46
50
loader.delegate = self;
47
51
loader.imageSize = 120;
54
- (void)viewDidUnload;
56
[super viewDidUnload];
57
loader.delegate = nil;
58
[loader release], loader = nil;
50
61
#pragma mark - Data Loading
52
63
- (void)loadLocalData
64
75
for (Album *a in self.tableData)
66
NSString *index = [[a.title substringToIndex:1] uppercaseString];
77
NSString *index = [[a.title dearticlizedIndex] uppercaseString];
67
78
NSMutableArray *group = [self.groupedTableData objectForKey:index];
126
- (void)updateReachability:(Reachability*)reachability;
128
[super updateReachability:reachability];
130
for (AlbumArtistUITableViewCell *cell in [self.tableView visibleCells])
132
[self configureCell:cell forTableView:self.tableView indexPath:[self.tableView indexPathForCell:cell]];
114
136
#pragma mark - UITableView
116
138
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
123
145
cell = [[[AlbumArtistUITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AlbumArtistCellIdentifier] autorelease];
124
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
147
[self configureCell:cell forTableView:tableView indexPath:indexPath];
151
- (void)configureCell:(AlbumArtistUITableViewCell*)cell forTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath;
129
155
if (self.searchDisplayController.searchResultsTableView == tableView)
131
a = [self.searchResults objectAtIndex:indexPath.row];
157
album = [self.searchResults objectAtIndex:indexPath.row];
132
158
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
140
166
NSString *index = [self.indexes objectAtIndex:indexPath.section];
141
a = [[self.groupedTableData objectForKey:index] objectAtIndex:indexPath.row];
167
album = [[self.groupedTableData objectForKey:index] objectAtIndex:indexPath.row];
145
a = [self.tableData objectAtIndex:indexPath.row];
171
album = [self.tableData objectAtIndex:indexPath.row];
149
cell.albumNameLabel.text = a.title;
150
cell.artistNameLabel.text = a.artist;
175
cell.albumNameLabel.text = album.title;
176
cell.artistNameLabel.text = album.artist;
178
NSError *error = nil;
179
cell.coverArtView.image = [loader imageForArtID:album.coverArtId error:&error];
182
// Let's see if we need to wait for non-dragging/decelerating
183
// if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
185
[loader download:album.coverArtId];
188
if (canStream || [album hasCachedSongs])
154
UIImage *img = [loader imageForArtID:a.coverArtId];
158
cell.coverArtView.image = img;
162
cell.coverArtView.image = [UIImage imageNamed:@"default-album-art.png"];
164
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
166
[loader download:a.coverArtId];
190
cell.albumNameLabel.textColor = [UIColor blackColor];
172
cell.coverArtView.image = [UIImage imageNamed:@"default-album-art.png"];
194
cell.albumNameLabel.textColor = [UIColor lightGrayColor];
195
cell.accessoryType = UITableViewCellAccessoryNone;
178
199
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
193
214
selection = [self.tableData objectAtIndex:indexPath.row];
196
AlbumViewController *albumViewController = [[AlbumViewController alloc] initWithStyle:UITableViewStylePlain];
197
albumViewController.album = selection;
198
albumViewController.artist = selection.artist;
199
[self.navigationController pushViewController:albumViewController animated:YES];
200
[albumViewController release];
217
if (canStream || [selection hasCachedSongs])
219
AlbumViewController *albumViewController = [[AlbumViewController alloc] initWithStyle:UITableViewStylePlain];
220
albumViewController.album = selection;
221
albumViewController.artist = selection.artist;
222
[self.navigationController pushViewController:albumViewController animated:YES];
223
[albumViewController release];
227
[tableView deselectRowAtIndexPath:indexPath animated:YES];
214
242
for (NSIndexPath *indexPath in [self.tableView indexPathsForVisibleRows])
216
244
Album *album = [self.tableData objectAtIndex:indexPath.row];
245
// This will prompt the album art to download, but doesn't try to load the image when it's done?
217
246
[loader download:album.coverArtId];
222
250
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
224
252
[super scrollViewDidEndDragging:scrollView willDecelerate:decelerate];