瀏覽代碼

Notification view

Marino Faggiana 8 年之前
父節點
當前提交
bcc7b5387c
共有 4 個文件被更改,包括 99 次插入87 次删除
  1. 1 1
      iOSClient/AppDelegate.h
  2. 1 1
      iOSClient/AppDelegate.m
  3. 91 80
      iOSClient/Main/CCMain.m
  4. 6 5
      iOSClient/Notification/CCNotification.swift

+ 1 - 1
iOSClient/AppDelegate.h

@@ -71,7 +71,7 @@
 @property BOOL hasServerShareeSupport;
 @property BOOL hasServerCapabilitiesSupport;
 @property OCCapabilities *capabilities;
-@property (nonatomic, strong) NSMutableDictionary *listOfNotifications;
+@property (nonatomic, strong) NSMutableArray<OCCommunication *> *listOfNotifications;
 
 // Network Operation
 @property (nonatomic, strong) NSOperationQueue *netQueue;

+ 1 - 1
iOSClient/AppDelegate.m

@@ -142,7 +142,7 @@
     self.sharesUserAndGroup = [[NSMutableDictionary alloc] init];
     
     // Initialization Notification
-    self.listOfNotifications = [[NSMutableDictionary alloc] init];
+    self.listOfNotifications = [[NSMutableArray alloc] init];
     
     // Verify Session in progress and Init date task
     self.sessionDateLastDownloadTasks = [NSDate date];

+ 91 - 80
iOSClient/Main/CCMain.m

@@ -536,7 +536,7 @@
     // Notification
     if ([app.listOfNotifications count] > 0) {
         
-        buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_notification] style:UIBarButtonItemStylePlain target:self action:@selector(getNotificationsOfServerSuccess:)];
+        buttonNotification = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_notification] style:UIBarButtonItemStylePlain target:self action:@selector(viewNotification)];
         buttonNotification.tintColor = COLOR_BRAND;
         buttonNotification.enabled = true;
     }
@@ -1034,88 +1034,24 @@
 {
     AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
     
-    // Insert/update listOfNotifications in Dictionary App.listOfNotifications
-    if ([listOfNotifications isKindOfClass:[NSArray class]]) {
-      
-        for (OCNotifications *notification in listOfNotifications)
-            [appDelegate.listOfNotifications setObject:notification forKey:[NSString stringWithFormat:@"%lu", (unsigned long)notification.idNotification]];
-        
-    } else {
+    // Order by date
         
-        if ([app.listOfNotifications count] > 0) {
-            
-            CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
-            
-            notificationVC.view.superview.frame = CGRectMake(100,100,self.view.bounds.size.width-100,self.view.bounds.size.height-100);
+    NSArray *sorted = [listOfNotifications sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
             
-            [self presentViewController:notificationVC animated:YES completion:nil];
-        }
-    }
-    
-    // Test if is already open, otherwise view the messages
-    //if ([JSAlertView isOpenAlertWindows])
-    //    return;
-    
-    
-    /*
-    for (NSString *idNotification in app.listOfNotifications) {
+        OCNotifications *notification1 = obj1, *notification2 = obj2;
         
-        OCNotifications *notification = [app.listOfNotifications objectForKey:idNotification];
+        return [notification2.date compare: notification1.date];
         
-        // No Action request
-        if ([notification.actions count] == 0) {
-            
-            [JSAlertView alert:notification.subject withTitle:nil buttons:@[NSLocalizedString(@"_close_", nil),NSLocalizedString(@"_postpone_", nil)] withCompletionHandler:^(NSInteger buttonIndex, NSString *buttonTitle) {
-                
-                NSLog(@"Pressed %@ at index %ld", buttonTitle, (long)buttonIndex);
-                
-                if ([buttonTitle isEqualToString:NSLocalizedString(@"_close_", nil)]) {
-                    
-                    if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
-                        
-                        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-                        
-                        metadataNet.action  = actionSetNotificationServer;
-                        metadataNet.identifier = idNotification;
-                        metadataNet.options = @"DELETE";
-                        metadataNet.serverUrl =  [NSString stringWithFormat:@"%@/%@/%@", app.activeUrl, k_url_acces_remote_notification_api, idNotification];
-                        
-                        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-                    }
-                }
-            }];
+        /*
+        if ([notification1.date compare: notification2.date] == NSOrderedDescending) {
+            return NSOrderedDescending;
+        } else {
+            return NSOrderedAscending;
         }
+        */
+    }];
         
-        // Action request
-        else {
-            
-            NSMutableArray *buttons = [NSMutableArray new];
-            for (OCNotificationsAction *action in notification.actions)
-                [buttons addObject:action.label];
-            
-            // Add button postpone
-            [buttons addObject:NSLocalizedString(@"_postpone_", nil)];
-            
-            [JSAlertView alert:notification.subject withTitle:nil buttons:buttons withCompletionHandler:^(NSInteger buttonIndex, NSString *buttonTitle) {
-                
-                NSLog(@"Pressed %@ at index %ld", buttonTitle, (long)buttonIndex);
-                
-                for (OCNotificationsAction *action in notification.actions)
-                    if ([action.label isEqualToString:buttonTitle]) {
-                        
-                        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-                        
-                        metadataNet.action  = actionSetNotificationServer;
-                        metadataNet.identifier = idNotification;
-                        metadataNet.serverUrl =  action.link;
-                        metadataNet.options = action.type;
-                        
-                        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
-                    }
-            }];
-        }
-    }
-    */
+    appDelegate.listOfNotifications = [[NSMutableArray alloc] initWithArray:sorted];
     
     // Update NavigationBar
     if (!_isSelectedMode)
@@ -1123,14 +1059,89 @@
 }
 
 - (void)getNotificationsOfServerFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
-{
-    NSLog(@"Error Notification");
-    
+{    
     // Update NavigationBar
     if (!_isSelectedMode)
         [self setUINavigationBarDefault];
 }
 
+- (void)viewNotification
+{
+    if ([app.listOfNotifications count] > 0) {
+        
+        CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
+        
+        notificationVC.view.superview.frame = CGRectMake(100,100,self.view.bounds.size.width-100,self.view.bounds.size.height-100);
+        
+        [self presentViewController:notificationVC animated:YES completion:nil];
+    }
+    
+    // Test if is already open, otherwise view the messages
+    //if ([JSAlertView isOpenAlertWindows])
+    //    return;
+    
+    
+    /*
+     for (NSString *idNotification in app.listOfNotifications) {
+     
+     OCNotifications *notification = [app.listOfNotifications objectForKey:idNotification];
+     
+     // No Action request
+     if ([notification.actions count] == 0) {
+     
+     [JSAlertView alert:notification.subject withTitle:nil buttons:@[NSLocalizedString(@"_close_", nil),NSLocalizedString(@"_postpone_", nil)] withCompletionHandler:^(NSInteger buttonIndex, NSString *buttonTitle) {
+     
+     NSLog(@"Pressed %@ at index %ld", buttonTitle, (long)buttonIndex);
+     
+     if ([buttonTitle isEqualToString:NSLocalizedString(@"_close_", nil)]) {
+     
+     if ([app.typeCloud isEqualToString:typeCloudOwnCloud] || [app.typeCloud isEqualToString:typeCloudNextcloud]) {
+     
+     CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
+     
+     metadataNet.action  = actionSetNotificationServer;
+     metadataNet.identifier = idNotification;
+     metadataNet.options = @"DELETE";
+     metadataNet.serverUrl =  [NSString stringWithFormat:@"%@/%@/%@", app.activeUrl, k_url_acces_remote_notification_api, idNotification];
+     
+     [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+     }
+     }
+     }];
+     }
+     
+     // Action request
+     else {
+     
+     NSMutableArray *buttons = [NSMutableArray new];
+     for (OCNotificationsAction *action in notification.actions)
+     [buttons addObject:action.label];
+     
+     // Add button postpone
+     [buttons addObject:NSLocalizedString(@"_postpone_", nil)];
+     
+     [JSAlertView alert:notification.subject withTitle:nil buttons:buttons withCompletionHandler:^(NSInteger buttonIndex, NSString *buttonTitle) {
+     
+     NSLog(@"Pressed %@ at index %ld", buttonTitle, (long)buttonIndex);
+     
+     for (OCNotificationsAction *action in notification.actions)
+     if ([action.label isEqualToString:buttonTitle]) {
+     
+     CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
+     
+     metadataNet.action  = actionSetNotificationServer;
+     metadataNet.identifier = idNotification;
+     metadataNet.serverUrl =  action.link;
+     metadataNet.options = action.type;
+     
+     [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+     }
+     }];
+     }
+     }
+     */
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ==== Request Server  ====
 #pragma --------------------------------------------------------------------------------------------

+ 6 - 5
iOSClient/Notification/CCNotification.swift

@@ -57,10 +57,7 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
 
     func getSataSourceAt(indexPath: IndexPath) -> OCNotifications {
         
-        let idsNotification: [String] = appDelegate.listOfNotifications.allKeys as! [String]
-        
-        let idNotification : String! = idsNotification[indexPath.row]
-        let notification = appDelegate.listOfNotifications[idNotification] as! OCNotifications
+        let notification = appDelegate.listOfNotifications.object(at: indexPath.row) as! OCNotifications
         
         return notification
     }
@@ -200,7 +197,11 @@ class CCNotification: UITableViewController, OCNetworkingDelegate {
     
     func setNotificationServerSuccess(_ metadataNet: CCMetadataNet!) {
         
-        appDelegate.listOfNotifications.removeObject(forKey: metadataNet.identifier)
+        let listOfNotifications = appDelegate.listOfNotifications as NSArray as! [OCNotifications]
+        
+        if let index = listOfNotifications.index(where: {$0.idNotification == Int(metadataNet.identifier)})  {
+            appDelegate.listOfNotifications.removeObject(at: index)
+        }
         
         self.tableView.reloadData()