Skip to content
Browse files

proper LN identification & canceling

  • Loading branch information...
1 parent e16e5f0 commit 3fe79682ca48f061cf987f6ffac6a3ccd27e6b31 Stas Sviridenko committed Apr 5, 2012
Showing with 25 additions and 27 deletions.
  1. +22 −24 MyDay/DetailViewController.m
  2. +1 −1 MyDay/MasterViewController.h
  3. +2 −2 MyDay/MasterViewController.m
View
46 MyDay/DetailViewController.m
@@ -198,38 +198,36 @@ - (void)save {
break;
}
- long oldAlert = [[self.detailItem valueForKey:@"alert"] longValue];
+ // cancel previous LN for this task
+ NSString *uri = [[[self.detailItem objectID] URIRepresentation] absoluteString];
+ NSArray *allNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
+ NSArray *toCancel = [allNotifications filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
+ UILocalNotification *testedNotification = (UILocalNotification *)evaluatedObject;
+ return [[[testedNotification userInfo] valueForKey:@"taskId"] isEqual:uri];
+ }]];
+ for (UILocalNotification *notification in toCancel) {
+ [[UIApplication sharedApplication] cancelLocalNotification:notification];
+ }
- // TODO date can be changed too!
- // TODO #2 should we schedule completed task?
- if (oldAlert != alert) {
-
- if (oldAlert != ALERT_NO) {
- NSArray *allNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
- NSArray *toDiscard = [allNotifications filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
- UILocalNotification *testedNotification = (UILocalNotification *)evaluatedObject;
- return [[[testedNotification userInfo] objectForKey:@"taskId"] isEqual:[self.detailItem objectID]];
- }]];
- for (UILocalNotification *notification in toDiscard) {
- [[UIApplication sharedApplication] cancelLocalNotification:notification];
- }
- }
+ // TODO should we schedule completed task or task in the past?
- if (alert != ALERT_NO) {
- UILocalNotification *notification = [UILocalNotification new];
- notification.alertBody = titleText;
- notification.alertAction = @"";
- notification.fireDate = [NSDate dateWithTimeInterval:-(double)alert sinceDate:compiledDate];
- [notification.userInfo setValue:[self.detailItem objectID] forKey:@"taskId"];
- [[UIApplication sharedApplication] scheduleLocalNotification:notification];
- }
+ // schedule new LN
+ if (alert != ALERT_NO) {
+ UILocalNotification *notification = [UILocalNotification new];
+
+ notification.alertBody = titleText;
+ notification.fireDate = [NSDate dateWithTimeInterval:-(double)alert sinceDate:compiledDate];
+
+ NSString *uri = [[[self.detailItem objectID] URIRepresentation] absoluteString];
+ notification.userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:uri, @"taskId", nil];
+
+ [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
[self.detailItem setValue:[NSNumber numberWithLong:alert] forKey:@"alert"];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate saveContext];
-
}
#pragma mark - Date and time picker
View
2 MyDay/MasterViewController.h
@@ -23,6 +23,6 @@
- (IBAction)iconTapped:(id)sender;
- (IBAction)activeFilterSwitched:(id)sender;
-- (void)showTask:(NSManagedObjectID *)taskId;
+- (void)showTask:(NSString *)managedObjectIdURIRepresentation;
@end
View
4 MyDay/MasterViewController.m
@@ -335,8 +335,8 @@ - (IBAction)activeFilterSwitched:(id)sender {
[self.tableView reloadData];
}
-- (void)showTask:(NSManagedObjectID *)taskId {
- NSLog(@"TODO scroll to task with ID = %@", taskId);
+- (void)showTask:(NSString *)managedObjectIdURIRepresentation {
+ NSLog(@"TODO scroll to task with ID = %@", managedObjectIdURIRepresentation);
}
@end

0 comments on commit 3fe7968

Please sign in to comment.
Something went wrong with that request. Please try again.