Skip to content

Instantly share code, notes, and snippets.

@digal
Created August 26, 2013 14:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digal/6341782 to your computer and use it in GitHub Desktop.
Save digal/6341782 to your computer and use it in GitHub Desktop.
[[[[[[[[[RACAbleWithStart(client, networkReachabilityStatus)
filter:^BOOL(NSNumber* statusNumber) {
AFNetworkReachabilityStatus status = statusNumber.intValue;
BOOL autoLoadOn3G = [[NSUserDefaults standardUserDefaults] boolForKey:KEY_AUTOLOAD_3G];
return (status == AFNetworkReachabilityStatusReachableViaWiFi
|| (autoLoadOn3G && status == AFNetworkReachabilityStatusReachableViaWWAN));
}]
take:1]
flattenMap: ^(id value){
return [client rac_getModelOfClass:PFMProgram.class fromPath:@"getSubscribePrograms" params:@{}];
}]
flattenMap:^RACStream *(NSArray *programs) {
return programs.rac_sequence.signal;
}] doNext:^(PFMProgram *program) {
int newPodcasts = program.countPodcasts - program.numOfPodcastsAtLastSync;
((NSMutableDictionary*)self.lastSyncCount)[@(program.programId)] = @(newPodcasts);
}]
flattenMap:^RACStream *(PFMProgram *program) {
int autoLoadNum = [[NSUserDefaults standardUserDefaults] integerForKey:KEY_AUTOLOAD_NUMBER];
if (autoLoadNum == 0) { autoLoadNum = 3; }
int newPodcasts = program.countPodcasts - program.numOfPodcastsAtLastSync;
int limit = MIN(autoLoadNum, newPodcasts);
program.numOfPodcastsAtLastSync = program.countPodcasts;
if (limit > 0) {
NSLog(@"Downloading %d last issues for program %@", limit, program.name);
return [client rac_getModelOfClass:PFMPodcast.class fromPath:@"getPodcastsByProgram" params:@{@"id": @(program.programId), @"limit":@(limit)}];
} else {
NSLog(@"No last issues for program %@", program.name);
return [RACSignal empty];
}
}]
flattenMap:^RACStream *(NSArray *podcasts) {
return podcasts.rac_sequence.signal;
}]
doError:^(NSError *error) {
handleError(error);
}]
subscribeNext:^(PFMPodcast *podcast) {
[[PFMDownloadManager manager] enqueuePodcast:podcast];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment