~urbanape/ubuntuone-ios-client/2.0-13-prerelease

« back to all changes in this revision

Viewing changes to musicstreaming/view_controllers/AlbumViewController.m

  • Committer: Zachery Bir
  • Date: 2011-06-22 16:06:39 UTC
  • Revision ID: zachery.bir@canonical.com-20110622160639-3d4iv7jpoe7rvt15
When on 3G, show a disabled cache button. If that cache button is tapped, alert the user that caching is disabled on 3G. Also, fix playlist checkmarks getting inadvertently re-used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#import "NSDate+Extras.h"
28
28
#import "StreamingPlayer.h"
29
29
#import "Downloader.h"
 
30
#import "UIAlertView+Blocks.h"
30
31
 
31
32
@interface AlbumViewController (Private)
32
33
- (void)setupHeaderAndFooter;
141
142
        Song *song = [self.songs objectAtIndex:indexPath.row];
142
143
        
143
144
    // explicitly re-set the default state of the button/spinner
144
 
    [cell.cacheButton setImage:[UIImage imageNamed:@"uncached"] forState:UIControlStateNormal];
 
145
    [cell.cacheButton setImage:(canCache ? [UIImage imageNamed:@"uncached"] : [UIImage imageNamed:@"uncached-disabled"]) forState:UIControlStateNormal];
145
146
    [cell.spinner stopAnimating];
146
147
    
147
148
    cell.cacheButton.tag = indexPath.row;
179
180
        }
180
181
        
181
182
        cell.evenRow = (0 == indexPath.row % 2);
182
 
        [cell.cacheButton setEnabled:canCache];
183
183
        if (song.cachedSongPath == nil && !canStream)
184
184
        {
185
185
                cell.songNameLabel.textColor = [UIColor lightGrayColor];
270
270
- (void)toggleCacheForSong:(id)sender
271
271
{
272
272
    // This is a binary toggle, and right now, we don't bother trying to cancel a download in progress.
273
 
    
274
273
    int row = [(UIButton *)sender tag];
275
274
 
276
275
        NSIndexPath *songPath = [NSIndexPath indexPathForRow:row inSection:0];
292
291
        }
293
292
        else
294
293
        {
295
 
            [cell.spinner startAnimating];
296
 
            [[Downloader sharedDownloader] downloadFile:[[Subsonic sharedSubsonic] getStreamingURLForSongId:song.songId] withName:song.songId completionBlock:^(NSString *path) {
297
 
                                dispatch_async(dispatch_get_main_queue(), ^(void) {
298
 
                                        song.cachedSongPath = path;
299
 
                                        SaveContext();
300
 
                                        SongUITableViewCell *cell = (SongUITableViewCell *)[self.tableView cellForRowAtIndexPath:songPath];
301
 
                                        [cell.spinner stopAnimating];
302
 
                                        [cell.cacheButton setImage:[UIImage imageNamed:@"cached"] forState:UIControlStateNormal];
303
 
                                });
304
 
                        }];
 
294
                        if (canCache)
 
295
                        {
 
296
                                [cell.spinner startAnimating];
 
297
                                [[Downloader sharedDownloader] downloadFile:[[Subsonic sharedSubsonic] getStreamingURLForSongId:song.songId] withName:song.songId completionBlock:^(NSString *path) {
 
298
                                        dispatch_async(dispatch_get_main_queue(), ^(void) {
 
299
                                                song.cachedSongPath = path;
 
300
                                                SaveContext();
 
301
                                                SongUITableViewCell *cell = (SongUITableViewCell *)[self.tableView cellForRowAtIndexPath:songPath];
 
302
                                                [cell.spinner stopAnimating];
 
303
                                                [cell.cacheButton setImage:[UIImage imageNamed:@"cached"] forState:UIControlStateNormal];
 
304
                                        });
 
305
                                }];
 
306
                        }
 
307
                        else
 
308
                        {
 
309
                                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 
310
                                if (![defaults boolForKey:@"acknowledged-no-cache-on-3g"])
 
311
                                {
 
312
                                        RIButtonItem *dismissButton = [RIButtonItem item];
 
313
                                        dismissButton.label = NSLocalizedString(@"Dismiss", @"");
 
314
                                        dismissButton.action = ^
 
315
                                        {
 
316
                                                [defaults setBool:YES forKey:@"acknowledged-no-cache-on-3g"];
 
317
                                        };
 
318
 
 
319
                                        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Caching Disabled", @"")
 
320
                                                                                                                                                message:NSLocalizedString(@"Caching songs can only be done on WiFi networks.", @"")
 
321
                                                                                                                           cancelButtonItem:nil otherButtonItems:dismissButton, nil];
 
322
                                        [alertView show];
 
323
                                        [alertView release];
 
324
 
 
325
                                }
 
326
                        }
305
327
        }
306
328
    }
307
329
}