Created
August 26, 2013 14:07
-
-
Save digal/6341782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[[[[[[[[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