|
@@ -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
|