Browse Source

Improve Notification view

marinofaggiana 5 years ago
parent
commit
bea888b4dc

+ 0 - 3
iOSClient/AppDelegate.h

@@ -64,9 +64,6 @@
 @property double currentLatitude;
 @property double currentLongitude;
 
-// Notification
-@property (nonatomic, strong) NSMutableArray<OCCommunication *> *listOfNotifications;
-
 // Networking 
 @property (nonatomic, copy) void (^backgroundSessionCompletionHandler)(void);
 

+ 0 - 3
iOSClient/AppDelegate.m

@@ -72,9 +72,6 @@
     // UserDefaults
     self.ncUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:[NCBrandOptions sharedInstance].capabilitiesGroups];
         
-    // Initialization Notification
-    self.listOfNotifications = [NSMutableArray new];
-    
     // Background Fetch
     [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
 

+ 8 - 16
iOSClient/Images.xcassets/notification.imageset/Contents.json

@@ -1,23 +1,15 @@
 {
   "images" : [
     {
-      "idiom" : "universal",
-      "filename" : "notification.png",
-      "scale" : "1x"
-    },
-    {
-      "idiom" : "universal",
-      "filename" : "notification@2x.png",
-      "scale" : "2x"
-    },
-    {
-      "idiom" : "universal",
-      "filename" : "notification@3x.png",
-      "scale" : "3x"
+      "filename" : "notification.pdf",
+      "idiom" : "universal"
     }
   ],
   "info" : {
-    "version" : 1,
-    "author" : "xcode"
+    "author" : "xcode",
+    "version" : 1
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
   }
-}
+}

BIN
iOSClient/Images.xcassets/notification.imageset/notification.pdf


BIN
iOSClient/Images.xcassets/notification.imageset/notification.png


BIN
iOSClient/Images.xcassets/notification.imageset/notification@2x.png


BIN
iOSClient/Images.xcassets/notification.imageset/notification@3x.png


+ 1 - 22
iOSClient/Main/CCMain.m

@@ -396,10 +396,7 @@
             [appDelegate.player pause];
         }
         [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_menuDetailClose object:nil];
-                
-        // remove all Notification Messages
-        [appDelegate.listOfNotifications removeAllObjects];
-        
+                        
         // Not Photos Video in library ? then align and Init Auto Upload
         NSArray *recordsPhotoLibrary = [[NCManageDatabase sharedInstance] getPhotoLibraryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", appDelegate.activeAccount]];
         if ([recordsPhotoLibrary count] == 0) {
@@ -990,24 +987,6 @@
     [self tableViewSelect:false];
 }
 
-/*
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== View Notification  ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)viewNotification
-{
-    if ([appDelegate.listOfNotifications count] > 0) {
-        
-        CCNotification *notificationVC = [[UIStoryboard storyboardWithName:@"CCNotification" bundle:nil] instantiateViewControllerWithIdentifier:@"CCNotification"];
-        
-        [notificationVC setModalPresentationStyle:UIModalPresentationFormSheet];
-        
-        [self presentViewController:notificationVC animated:YES completion:nil];
-    }
-}
-*/
-
 #pragma mark -
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Peek & Pop  =====

+ 0 - 64
iOSClient/Networking/NCService.swift

@@ -205,71 +205,7 @@ class NCService: NSObject {
                 }
                 
                 // ------ GET OTHER SERVICE -------------------------------------------------------------
-                
-                // Get Notification
-                if (capabilities!.isNotificationServerEnabled) {
-                    
-                    OCNetworking.sharedManager().getNotificationWithAccount(account!, completion: { (account, listOfNotifications, message, errorCode) in
-                        
-                        if errorCode == 0 && account == self.appDelegate.activeAccount {
-                            
-                            DispatchQueue.global().async {
-                                
-                                let sortedListOfNotifications = (listOfNotifications! as NSArray).sortedArray(using: [
-                                    NSSortDescriptor(key: "date", ascending: false)
-                                    ])
-                                
-                                var old = ""
-                                var new = ""
                                 
-                                for notification in listOfNotifications! {
-                                    // download icon
-                                    let id = (notification as! OCNotifications).idNotification
-                                    if let icon = (notification as! OCNotifications).icon {
-                                        
-                                        NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, account: self.appDelegate.activeAccount, closure: { (imageNamePath) in })                                        
-                                    }
-                                    new = new + String(describing: id)
-                                }
-                                for notification in self.appDelegate.listOfNotifications! {
-                                    let id = (notification as! OCNotifications).idNotification
-                                    old = old + String(describing: id)
-                                }
-                                
-                                DispatchQueue.main.async {
-                                    
-                                    if (new != old) {
-                                        self.appDelegate.listOfNotifications = NSMutableArray.init(array: sortedListOfNotifications)
-                                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: k_notificationCenter_reloadDataNotification), object: nil)
-                                    }
-                                    
-                                    // Update Main NavigationBar
-                                    if (self.appDelegate.activeMain.isSelectedMode == false && self.appDelegate.activeMain != nil) {
-                                        self.appDelegate.activeMain.setUINavigationBarDefault()
-                                    }
-                                }
-                            }
-                            
-                        } else {
-                            
-                            // Update Main NavigationBar
-                            if (self.appDelegate.activeMain.isSelectedMode == false && self.appDelegate.activeMain != nil) {
-                                self.appDelegate.activeMain.setUINavigationBarDefault()
-                            }
-                        }
-                    })
-                    
-                } else {
-                    
-                    // Remove all Notification
-                    self.appDelegate.listOfNotifications.removeAllObjects()
-                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: k_notificationCenter_reloadDataNotification), object: nil)
-                    // Update Main NavigationBar
-                    if (self.appDelegate.activeMain != nil && self.appDelegate.activeMain.isSelectedMode == false) {
-                        self.appDelegate.activeMain.setUINavigationBarDefault()
-                    }
-                }
-                
                 // Get External Sites
                 if (capabilities!.isExternalSitesServerEnabled) {
                     

+ 68 - 19
iOSClient/Notification/CCNotification.swift

@@ -24,9 +24,10 @@
 import UIKit
 import NCCommunication
 
-class CCNotification: UITableViewController, CCNotificationCelllDelegate {
+class CCNotification: UITableViewController, CCNotificationCelllDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var listOfNotifications = [OCNotifications]()
     
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -38,6 +39,10 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
         self.tableView.estimatedRowHeight = 50.0
         self.tableView.allowsSelection = false
         
+        // empty Data Source
+        self.tableView.emptyDataSetSource = self
+        self.tableView.emptyDataSetDelegate = self
+        
         // Register to receive notification reload data
         NotificationCenter.default.addObserver(self, selector: #selector(reloadDatasource), name: Notification.Name(rawValue: k_notificationCenter_reloadDataNotification), object: nil)
 
@@ -48,6 +53,12 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
         reloadDatasource()
     }
     
+    override func viewWillAppear(_ animated: Bool) {
+        super.viewWillAppear(animated)
+        
+        getNetwokingNotification()
+    }
+    
     @objc func changeTheming() {
         appDelegate.changeTheming(self, tableView: tableView, collectionView: nil, form: false)
     }
@@ -60,6 +71,26 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
         self.dismiss(animated: true, completion: nil)
     }
     
+    // MARK: DZNEmpty
+    
+    func backgroundColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? {
+        return NCBrandColor.sharedInstance.backgroundView
+    }
+    
+    func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
+        return CCGraphics.changeThemingColorImage(UIImage.init(named: "notification"), width: 300, height: 300, color: NCBrandColor.sharedInstance.graySoft)
+    }
+    
+    func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
+        let text = "\n"+NSLocalizedString("_no_notification_", comment: "")
+        let attributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 20), NSAttributedString.Key.foregroundColor: UIColor.lightGray]
+        return NSAttributedString.init(string: text, attributes: attributes)
+    }
+    
+    func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -> Bool {
+        return true
+    }
+    
     // MARK: - Table
 
     @objc func reloadDatasource() {
@@ -68,7 +99,7 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
     
     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
     
-        let numRecord = appDelegate.listOfNotifications.count
+        let numRecord = listOfNotifications.count
         return numRecord
     }
     
@@ -77,7 +108,7 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
         let cell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCNotificationCell
         cell.delegate = self
         
-        let notification = appDelegate.listOfNotifications.object(at: indexPath.row) as! OCNotifications
+        let notification = listOfNotifications[indexPath.row] // object(at: indexPath.row) //as! OCNotifications
         let urlIcon = URL(string: notification.icon)
         var image : UIImage?
         
@@ -215,18 +246,14 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
             
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 
-                let listOfNotifications = self.appDelegate.listOfNotifications as NSArray as! [OCNotifications]
+                //let listOfNotifications = self.appDelegate.listOfNotifications as NSArray as! [OCNotifications]
                 
-                if let index = listOfNotifications.firstIndex(where: {$0.idNotification == notification!.idNotification})  {
-                    self.appDelegate.listOfNotifications.removeObject(at: index)
+                if let index = self.listOfNotifications.firstIndex(where: {$0.idNotification == notification!.idNotification})  {
+                    self.listOfNotifications.remove(at: index)
                 }
                 
                 self.reloadDatasource()
                 
-                if self.appDelegate.listOfNotifications.count == 0 {
-                    self.viewClose()
-                }
-                
             } else if errorCode != 0 {
                 NCContentPresenter.shared.messageNotification("_error_", description: message, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
             } else {
@@ -244,19 +271,13 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
                 OCNetworking.sharedManager().setNotificationWithAccount(self.appDelegate.activeAccount, serverUrl: (action as! OCNotificationsAction).link, type: (action as! OCNotificationsAction).type, completion: { (account, message, errorCode) in
                     
                     if errorCode == 0 && account == self.appDelegate.activeAccount {
-                        
-                        let listOfNotifications = self.appDelegate.listOfNotifications as NSArray as! [OCNotifications]
-                        
-                        if let index = listOfNotifications.firstIndex(where: {$0.idNotification == notification!.idNotification})  {
-                            self.appDelegate.listOfNotifications.removeObject(at: index)
+                                                
+                        if let index = self.listOfNotifications.firstIndex(where: {$0.idNotification == notification!.idNotification})  {
+                            self.listOfNotifications.remove(at: index)
                         }
                         
                         self.reloadDatasource()
                         
-                        if self.appDelegate.listOfNotifications.count == 0 {
-                            self.viewClose()
-                        }
-                        
                     } else if errorCode != 0 {
                         NCContentPresenter.shared.messageNotification("_error_", description: message, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
                     } else {
@@ -266,6 +287,34 @@ class CCNotification: UITableViewController, CCNotificationCelllDelegate {
             }
         }
     }
+    
+    // MARK: Load notification networking
+    func getNetwokingNotification() {
+        
+        NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: 0)
+        
+        OCNetworking.sharedManager().getNotificationWithAccount(appDelegate.activeAccount, completion: { (account, listOfNotifications, message, errorCode) in
+            
+            if errorCode == 0 && account == self.appDelegate.activeAccount {
+                    
+                self.listOfNotifications.removeAll()
+                let sortedListOfNotifications = (listOfNotifications! as NSArray).sortedArray(using: [NSSortDescriptor(key: "date", ascending: false)])
+                    
+                for notification in sortedListOfNotifications {
+                    // download icon
+                    if let icon = (notification as! OCNotifications).icon {
+                        NCUtility.sharedInstance.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, account: self.appDelegate.activeAccount, closure: { (imageNamePath) in })
+                    }
+                    
+                    self.listOfNotifications.append(notification as! OCNotifications)
+                }
+                
+                self.reloadDatasource()
+            }
+            
+            NCUtility.sharedInstance.stopActivityIndicator()
+        })
+    }
 }
 
 // MARK: - Class UITableViewCell

+ 2 - 2
iOSClient/Offline/NCOffline.swift

@@ -94,8 +94,8 @@ class NCOffline: UIViewController, UIGestureRecognizerDelegate, NCListCellDelega
         refreshControl.addTarget(self, action: #selector(loadDatasource), for: .valueChanged)
         
         // empty Data Source
-        self.collectionView.emptyDataSetDelegate = self;
-        self.collectionView.emptyDataSetSource = self;
+        self.collectionView.emptyDataSetDelegate = self
+        self.collectionView.emptyDataSetSource = self
         
         // 3D Touch peek and pop
         if traitCollection.forceTouchCapability == .available {

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -617,6 +617,7 @@
 // Notification
 
 "_notification_"                    = "Notification";
+"_no_notification_"                 = "No notification yet";
 
 // Photo Browser