Ver código fonte

Merge pull request #2448 from nextcloud/Notification

Notification - UPDATE
Marino Faggiana 1 ano atrás
pai
commit
b8401f4d1e

+ 9 - 0
ExternalResources/NCApplicationHandle.swift

@@ -30,6 +30,11 @@ class NCApplicationHandle: NSObject {
 
     let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
 
+    // class: AppDelegate
+    // func applicationWillEnterForeground(_ application: UIApplication)
+    func applicationWillEnterForeground(_ application: UIApplication) {
+    }
+    
     // class: AppDelegate
     // func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void)
     func applicationOpenUserActivity(_ userActivity: NSUserActivity) -> Bool {
@@ -78,4 +83,8 @@ class NCApplicationHandle: NSObject {
     func filterPages(pages: [NCBrandOptions.NCInfoPagingTab], page: NCBrandOptions.NCInfoPagingTab, metadata: tableMetadata) -> ([NCBrandOptions.NCInfoPagingTab], NCBrandOptions.NCInfoPagingTab) {
         return (pages, page)
     }
+
+    // class: NCNotification
+    func didSelectNotification(_ notification: NKNotifications, viewController: UIViewController) {
+    }
 }

+ 3 - 54
iOSClient/Activity/NCActivityTableViewCell.swift

@@ -53,7 +53,7 @@ class NCActivityTableViewCell: UITableViewCell, NCCellProtocol {
     var idActivity: Int = 0
     var activityPreviews: [tableActivityPreview] = []
     var didSelectItemEnable: Bool = true
-    var viewController: UIViewController?
+    var viewController = UIViewController()
 
     var fileAvatarImageView: UIImageView? {
         get { return avatar }
@@ -74,7 +74,7 @@ class NCActivityTableViewCell: UITableViewCell, NCCellProtocol {
 
     @objc func tapAvatarImage() {
         guard let fileUser = fileUser else { return }
-        viewController?.showProfileMenu(userId: fileUser)
+        viewController.showProfileMenu(userId: fileUser)
     }
 }
 
@@ -124,58 +124,7 @@ extension NCActivityTableViewCell: UICollectionViewDelegate {
                 return
             }
 
-            if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "fileId == %@", activitySubjectRich.id)) {
-                if let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) {
-                    do {
-                        let attr = try FileManager.default.attributesOfItem(atPath: filePath)
-                        let fileSize = attr[FileAttributeKey.size] as! UInt64
-                        if fileSize > 0 {
-                            if let viewController = self.viewController {
-                                NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: cell?.imageView.image)
-                            }
-                            return
-                        }
-                    } catch {
-                        print("Error: \(error)")
-                    }
-                }
-            }
-
-            let hud = JGProgressHUD()
-            hud.indicatorView = JGProgressHUDRingIndicatorView()
-            if let indicatorView = hud.indicatorView as? JGProgressHUDRingIndicatorView {
-                indicatorView.ringWidth = 1.5
-            }
-            guard let view = appDelegate.window?.rootViewController?.view else { return }
-            hud.show(in: view)
-
-            NextcloudKit.shared.getFileFromFileId(fileId: String(activityPreview.fileId)) { account, file, data, error in
-                if let file = file {
-                    let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(file: file)
-                    let metadata = NCManageDatabase.shared.convertFileToMetadata(file, isDirectoryE2EE: isDirectoryE2EE)
-                    NCManageDatabase.shared.addMetadata(metadata)
-
-                    let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
-                    let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
-
-                    NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { _ in
-                    }, taskHandler: { _ in
-                    }, progressHandler: { progress in
-                        hud.progress = Float(progress.fractionCompleted)
-                    }) { account, _, _, _, _, _, error in
-                        hud.dismiss()
-                        if account == self.appDelegate.account && error == .success {
-                            NCManageDatabase.shared.addLocalFile(metadata: metadata)
-                            if let viewController = self.viewController {
-                                NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: cell?.imageView.image)
-                            }
-                        }
-                    }
-                } else {
-                    hud.dismiss()
-                    NCContentPresenter.shared.showError(error: error)
-                }
-            }
+            NCActionCenter.shared.viewerFile(account: appDelegate.account, fileId: activitySubjectRich.id, viewController: viewController)
         }
     }
 }

+ 30 - 3
iOSClient/AppDelegate.swift

@@ -60,6 +60,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     private var privacyProtectionWindow: UIWindow?
 
+    struct PushNotificationData {
+        var account: String
+        var json: [String: AnyObject]
+    }
+    var pushNotificationData: PushNotificationData = PushNotificationData(account: "", json: [:])
+
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
 
         NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0)
@@ -113,8 +119,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Activate user account
         if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
 
-            settingAccount(activeAccount.account, urlBase: activeAccount.urlBase, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account))
+            settingAccount(activeAccount.account, urlBase: activeAccount.urlBase, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), initialize: false)
             NCBrandColor.shared.settingThemingColor(account: activeAccount.account)
+            initialize()
 
         } else {
 
@@ -206,6 +213,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     // L' applicazione entrerà in primo piano (dopo il background)
     func applicationWillEnterForeground(_ application: UIApplication) {
+        NCApplicationHandle().applicationWillEnterForeground(application)
         guard !account.isEmpty, let activeAccount = NCManageDatabase.shared.getActiveAccount() else { return }
 
         NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Application will enter in foreground")
@@ -404,6 +412,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     // MARK: - Push Notifications
 
     func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
+        do {
+            let userInfo = notification.request.content.userInfo
+            if let message = userInfo["subject"] as? String {
+                let tableAccounts = NCManageDatabase.shared.getAllAccount()
+                for tableAccount in tableAccounts {
+                    guard let privateKey = CCUtility.getPushNotificationPrivateKey(tableAccount.account),
+                          let decryptedMessage = NCPushNotificationEncryption.shared().decryptPushNotification(message, withDevicePrivateKey: privateKey),
+                          let data = decryptedMessage.data(using: .utf8) else {
+                        continue
+                    }
+                    if let json = try JSONSerialization.jsonObject(with: data) as? [String: AnyObject] {
+                        pushNotificationData = PushNotificationData(account: tableAccount.account, json: json)
+                        print(json)
+                    }
+                }
+            }
+        } catch let error as NSError {
+            print("Failed : \(error.localizedDescription)")
+        }
         completionHandler([.list, .banner, .sound])
     }
 
@@ -562,7 +589,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     // MARK: - Account
 
-    @objc func settingAccount(_ account: String, urlBase: String, user: String, userId: String, password: String) {
+    @objc func settingAccount(_ account: String, urlBase: String, user: String, userId: String, password: String, initialize: Bool = true) {
 
         let accountTestBackup = self.account + "/" + self.userId
         let accountTest = account +  "/" + userId
@@ -583,7 +610,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         }
 
         DispatchQueue.main.async {
-            if UIApplication.shared.applicationState != .background && accountTestBackup != accountTest {
+            if initialize, UIApplication.shared.applicationState != .background && accountTestBackup != accountTest {
                 NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize, second: 0.2)
             }
         }

+ 11 - 0
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -877,6 +877,17 @@ extension NCManageDatabase {
         return tableMetadata.init(value: result)
     }
 
+    func getMetadataFromFileId(_ fileId: String?) -> tableMetadata? {
+
+        let realm = try! Realm()
+        realm.refresh()
+
+        guard let fileId = fileId else { return nil }
+        guard let result = realm.objects(tableMetadata.self).filter("fileId == %@", fileId).first else { return nil }
+
+        return tableMetadata.init(value: result)
+    }
+
     func getMetadataFolder(account: String, urlBase: String, userId: String, serverUrl: String) -> tableMetadata? {
 
         let realm = try! Realm()

+ 0 - 6
iOSClient/Files/NCFiles.swift

@@ -74,12 +74,6 @@ class NCFiles: NCCollectionViewCommon {
         }
         super.initialize()
 
-        /*
-        if let userInfo = notification.userInfo as NSDictionary?, userInfo["atStart"] as? Int == 1 {
-            return
-        }
-        */
-
         reloadDataSource(forced: false)
         reloadDataSourceNetwork()
     }

+ 17 - 4
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -70,6 +70,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     // DECLARE
     internal var layoutKey = ""
     internal var titleCurrentFolder = ""
+    internal var titlePreviusFolder: String?
     internal var enableSearchBar: Bool = false
     internal var headerMenuButtonsCommand: Bool = true
     internal var headerMenuButtonsView: Bool = true
@@ -610,14 +611,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
     // MARK: - Layout
 
     @objc func setNavigationItem() {
-        self.setNavigationHeader()
 
-        guard !isEditMode, layoutKey == NCGlobal.shared.layoutViewFiles else { return }
+        self.setNavigationRightItems()
+        navigationItem.title = titleCurrentFolder
+
+        guard layoutKey == NCGlobal.shared.layoutViewFiles else { return }
         
         // PROFILE BUTTON
         
         let activeAccount = NCManageDatabase.shared.getActiveAccount()
-        
+
         let image = NCUtility.shared.loadUserImage(
             for: appDelegate.user,
                displayName: activeAccount?.displayName,
@@ -671,6 +674,11 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         }
         navigationItem.setLeftBarButton(UIBarButtonItem(customView: button), animated: true)
         navigationItem.leftItemsSupplementBackButton = true
+        if titlePreviusFolder == nil {
+            navigationController?.navigationBar.topItem?.title = getNavigationTitle()
+        } else {
+            navigationController?.navigationBar.topItem?.title = titlePreviusFolder
+        }
     }
 
     func getNavigationTitle() -> String {
@@ -1116,6 +1124,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
                     viewController.isRoot = false
                     viewController.serverUrl = serverUrlPush
+                    viewController.titlePreviusFolder = navigationItem.title
                     viewController.titleCurrentFolder = metadata.fileNameView
 
                     appDelegate.listFilesVC[serverUrlPush] = viewController
@@ -1139,6 +1148,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 if let viewController: NCFavorite = UIStoryboard(name: "NCFavorite", bundle: nil).instantiateInitialViewController() as? NCFavorite {
 
                     viewController.serverUrl = serverUrlPush
+                    viewController.titlePreviusFolder = navigationItem.title
                     viewController.titleCurrentFolder = metadata.fileNameView
 
                     appDelegate.listFavoriteVC[serverUrlPush] = viewController
@@ -1162,6 +1172,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 if let viewController: NCOffline = UIStoryboard(name: "NCOffline", bundle: nil).instantiateInitialViewController() as? NCOffline {
 
                     viewController.serverUrl = serverUrlPush
+                    viewController.titlePreviusFolder = navigationItem.title
                     viewController.titleCurrentFolder = metadata.fileNameView
 
                     appDelegate.listOfflineVC[serverUrlPush] = viewController
@@ -1186,6 +1197,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
                     viewController.isRoot = false
                     viewController.serverUrl = serverUrlPush
+                    viewController.titlePreviusFolder = navigationItem.title
                     viewController.titleCurrentFolder = metadata.fileNameView
 
                     appDelegate.listFilesVC[serverUrlPush] = viewController
@@ -1210,6 +1222,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
                     viewController.isRoot = false
                     viewController.serverUrl = serverUrlPush
+                    viewController.titlePreviusFolder = navigationItem.title
                     viewController.titleCurrentFolder = metadata.fileNameView
 
                     appDelegate.listFilesVC[serverUrlPush] = viewController
@@ -1233,6 +1246,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
                 if let viewController: NCGroupfolders = UIStoryboard(name: "NCGroupfolders", bundle: nil).instantiateInitialViewController() as? NCGroupfolders {
 
                     viewController.serverUrl = serverUrlPush
+                    viewController.titlePreviusFolder = navigationItem.title
                     viewController.titleCurrentFolder = metadata.fileNameView
 
                     appDelegate.listGroupfoldersVC[serverUrlPush] = viewController
@@ -1272,7 +1286,6 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
                 selectOcId.append(metadata.ocId)
             }
             collectionView.reloadItems(at: [indexPath])
-            self.navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(metadataSourceForAllSections.count)"
             return
         }
 

+ 26 - 10
iOSClient/Main/Collection Common/NCSelectableNavigationView.swift

@@ -42,7 +42,8 @@ protocol NCSelectableNavigationView: AnyObject {
     var selectOcId: [String] { get set }
     var titleCurrentFolder: String { get }
     var navigationItem: UINavigationItem { get }
-
+    var navigationController: UINavigationController? { get }
+    var layoutKey: String { get }
     var selectActions: [NCMenuAction] { get }
 
     func reloadDataSource(forced: Bool)
@@ -55,18 +56,21 @@ protocol NCSelectableNavigationView: AnyObject {
 extension NCSelectableNavigationView {
 
     func setNavigationItem() {
-        setNavigationHeader()
+        setNavigationRightItems()
     }
 
-    func setNavigationHeader() {
+    func setNavigationRightItems() {
         if isEditMode {
-            navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "navigationMore"), style: .plain, action: tapSelectMenu)
-            navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: .plain, action: tapSelect)
-            navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(selectableDataSource.count)"
+            let more = UIBarButtonItem(image: UIImage(systemName: "ellipsis"), style: .plain, action: tapSelectMenu)
+            navigationItem.rightBarButtonItems = [more]
         } else {
-            navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_select_", comment: ""), style: UIBarButtonItem.Style.plain, action: tapSelect)
-            navigationItem.leftBarButtonItem = nil
-            navigationItem.title = titleCurrentFolder
+            let select = UIBarButtonItem(title: NSLocalizedString("_select_", comment: ""), style: UIBarButtonItem.Style.plain, action: tapSelect)
+            let notification = UIBarButtonItem(image: UIImage(systemName: "bell"), style: .plain, action: tapNotification)
+            if layoutKey == NCGlobal.shared.layoutViewFiles {
+                navigationItem.rightBarButtonItems = [select, notification]
+            } else {
+                navigationItem.rightBarButtonItems = [select]
+            }
         }
     }
 
@@ -79,9 +83,14 @@ extension NCSelectableNavigationView {
 
     func collectionViewSelectAll() {
         selectOcId = selectableDataSource.compactMap({ $0.primaryKeyValue })
-        navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(selectableDataSource.count)"
         collectionView.reloadData()
     }
+
+    func tapNotification() {
+        if let viewController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? NCNotification {
+            navigationController?.pushViewController(viewController, animated: true)
+        }
+    }
 }
 
 extension NCSelectableNavigationView where Self: UIViewController {
@@ -91,11 +100,18 @@ extension NCSelectableNavigationView where Self: UIViewController {
 
     var selectActions: [NCMenuAction] {
         var actions = [NCMenuAction]()
+
+        actions.append(.cancelAction {
+            self.tapSelect()
+        })
         if selectOcId.count != selectableDataSource.count {
             actions.append(.selectAllAction(action: collectionViewSelectAll))
         }
 
         guard !selectOcId.isEmpty else { return actions }
+
+        actions.append(.seperator(order: 0))
+
         var selectedMetadatas: [tableMetadata] = []
         var selectedMediaMetadatas: [tableMetadata] = []
         var isAnyOffline = false

+ 71 - 0
iOSClient/Main/NCActionCenter.swift

@@ -27,6 +27,7 @@ import Queuer
 import JGProgressHUD
 import SVGKit
 import Photos
+import Alamofire
 
 class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelectDelegate {
     public static let shared: NCActionCenter = {
@@ -170,6 +171,76 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
         }
     }
 
+    func viewerFile(account: String, fileId: String, viewController: UIViewController) {
+
+        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, let hudView = appDelegate.window?.rootViewController?.view else { return }
+        var downloadRequest: DownloadRequest?
+
+        if let metadata = NCManageDatabase.shared.getMetadataFromFileId(fileId) {
+            if let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) {
+                do {
+                    let attr = try FileManager.default.attributesOfItem(atPath: filePath)
+                    let fileSize = attr[FileAttributeKey.size] as? UInt64 ?? 0
+                    if fileSize > 0 {
+                        NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil)
+                        return
+                    }
+                } catch {
+                    print("Error: \(error)")
+                }
+            }
+        }
+
+        let hud = JGProgressHUD()
+        hud.indicatorView = JGProgressHUDRingIndicatorView()
+        if let indicatorView = hud.indicatorView as? JGProgressHUDRingIndicatorView {
+            indicatorView.ringWidth = 1.5
+        }
+        hud.tapOnHUDViewBlock = { _ in
+            if let request = downloadRequest {
+                request.cancel()
+            }
+        }
+        hud.show(in: hudView)
+
+        NextcloudKit.shared.getFileFromFileId(fileId: fileId) { account, file, _, error in
+
+            if error != .success {
+                hud.dismiss()
+                NCContentPresenter.shared.showError(error: error)
+            } else if let file = file {
+
+                let isDirectoryE2EE = NCUtility.shared.isDirectoryE2EE(file: file)
+                let metadata = NCManageDatabase.shared.convertFileToMetadata(file, isDirectoryE2EE: isDirectoryE2EE)
+                NCManageDatabase.shared.addMetadata(metadata)
+
+                let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
+                let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+
+                if metadata.isMovie {
+                    NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil)
+                } else {
+                    NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { request in
+                        downloadRequest = request
+                    }, taskHandler: { _ in
+                    }, progressHandler: { progress in
+                        hud.progress = Float(progress.fractionCompleted)
+                    }) { accountDownload, _, _, _, _, _, error in
+                        hud.dismiss()
+                        if account == accountDownload && error == .success {
+                            NCManageDatabase.shared.addLocalFile(metadata: metadata)
+                            NCViewer.shared.view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil)
+                        }
+                    }
+                }
+            } else {
+                hud.dismiss()
+                let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_file_not_found_")
+                NCContentPresenter.shared.showError(error: error)
+            }
+        }
+    }
+
     // MARK: - Upload
 
     @objc func uploadedFile(_ notification: NSNotification) {

+ 9 - 0
iOSClient/Menu/NCMenuAction.swift

@@ -82,6 +82,15 @@ extension NCMenuAction {
         )
     }
 
+    /// Cancel
+    static func cancelAction(action: @escaping () -> Void) -> NCMenuAction {
+        NCMenuAction(
+            title: NSLocalizedString("_cancel_", comment: ""),
+            icon: NCUtility.shared.loadImage(named: "xmark"),
+            action: { _ in action() }
+        )
+    }
+
     /// Copy files to pasteboard
     static func copyAction(selectOcId: [String], hudView: UIView, order: Int = 0, completion: (() -> Void)? = nil) -> NCMenuAction {
         NCMenuAction(

+ 0 - 8
iOSClient/More/NCMore.swift

@@ -113,14 +113,6 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
         item.order = 20
         functionMenu.append(item)
 
-        // ITEM : Notification
-        item = NKExternalSite()
-        item.name = "_notifications_"
-        item.icon = "bell"
-        item.url = "segueNotification"
-        item.order = 30
-        functionMenu.append(item)
-
         // ITEM : Activity
         item = NKExternalSite()
         item.name = "_activity_"

+ 1 - 1
iOSClient/NCGlobal.swift

@@ -319,7 +319,7 @@ class NCGlobal: NSObject {
     let notificationCenterApplicationDidBecomeActive            = "applicationDidBecomeActive"
     let notificationCenterApplicationWillResignActive           = "applicationWillResignActive"
 
-    @objc let notificationCenterInitialize                      = "initialize"                      // userInfo?: atStart
+    @objc let notificationCenterInitialize                      = "initialize"
     @objc let notificationCenterChangeTheming                   = "changeTheming"
     let notificationCenterRichdocumentGrabFocus                 = "richdocumentGrabFocus"
     let notificationCenterReloadDataNCShare                     = "reloadDataNCShare"

+ 1 - 0
iOSClient/Nextcloud-Bridging-Header.h

@@ -8,3 +8,4 @@
 #import "UIImage+animatedGIF.h"
 #import "CCUtility.h"
 #import "NCPushNotification.h"
+#import "NCPushNotificationEncryption.h"

+ 35 - 27
iOSClient/Notification/NCNotification.swift

@@ -25,12 +25,15 @@
 import UIKit
 import NextcloudKit
 import SwiftyJSON
+import JGProgressHUD
 
 class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmptyDataSetDelegate {
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     var notifications: [NKNotifications] = []
     var emptyDataSet: NCEmptyDataSet?
+    var isReloadDataSourceNetworkInProgress: Bool = false
+
 
     // MARK: - View Life Cycle
 
@@ -43,7 +46,6 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
         tableView.tableFooterView = UIView()
         tableView.rowHeight = UITableView.automaticDimension
         tableView.estimatedRowHeight = 50.0
-        tableView.allowsSelection = false
         tableView.backgroundColor = .systemBackground
 
         // Empty
@@ -55,14 +57,10 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
         super.viewWillAppear(animated)
 
         appDelegate.activeViewController = self
-        
+
         navigationController?.setFileAppreance()
 
         NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
-    }
-
-    override func viewDidAppear(_ animated: Bool) {
-        super.viewDidAppear(animated)
 
         getNetwokingNotification()
     }
@@ -87,26 +85,42 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
 
     func emptyDataSetView(_ view: NCEmptyView) {
 
-        view.emptyImage.image = NCUtility.shared.loadImage(named: "bell", color: .gray, size: UIScreen.main.bounds.width)
-        view.emptyTitle.text = NSLocalizedString("_no_notification_", comment: "")
-        view.emptyDescription.text = ""
+        if isReloadDataSourceNetworkInProgress {
+            view.emptyImage.image = UIImage(named: "networkInProgress")?.image(color: .gray, size: UIScreen.main.bounds.width)
+            view.emptyTitle.text = NSLocalizedString("_request_in_progress_", comment: "")
+            view.emptyDescription.text = ""
+        } else {
+            view.emptyImage.image = NCUtility.shared.loadImage(named: "bell", color: .gray, size: UIScreen.main.bounds.width)
+            view.emptyTitle.text = NSLocalizedString("_no_notification_", comment: "")
+            view.emptyDescription.text = ""
+        }
     }
 
     // MARK: - Table
 
-    @objc func reloadDatasource() {
-        self.tableView.reloadData()
-    }
-
     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         emptyDataSet?.numberOfItemsInSection(notifications.count, section: section)
         return notifications.count
     }
 
+    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+
+        tableView.deselectRow(at: indexPath, animated: true)
+
+        let notification = notifications[indexPath.row]
+
+        if notification.app == "files_sharing" {
+            NCActionCenter.shared.viewerFile(account: appDelegate.account, fileId: notification.objectId, viewController: self)
+        } else {
+            NCApplicationHandle().didSelectNotification(notification, viewController: self)
+        }
+    }
+
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 
         let cell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! NCNotificationCell
         cell.delegate = self
+        cell.selectionStyle = .none
 
         let notification = notifications[indexPath.row]
         let urlIcon = URL(string: notification.icon)
@@ -178,7 +192,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
         cell.secondary.layer.borderWidth = 1
         cell.secondary.layer.borderColor = UIColor.systemGray.cgColor
         cell.secondary.layer.backgroundColor = UIColor.secondarySystemBackground.cgColor
-        cell.secondary.setTitleColor(.black, for: .normal)
+        cell.secondary.setTitleColor(.gray, for: .normal)
 
         // Action
         if let actions = notification.actions,
@@ -231,14 +245,11 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
 
         NextcloudKit.shared.setNotification(serverUrl: nil, idNotification: notification.idNotification , method: "DELETE") { (account, error) in
             if error == .success && account == self.appDelegate.account {
-
                 if let index = self.notifications
                     .firstIndex(where: { $0.idNotification == notification.idNotification })  {
                     self.notifications.remove(at: index)
                 }
-
-                self.reloadDatasource()
-
+                self.tableView.reloadData()
             } else if error != .success {
                 NCContentPresenter.shared.showError(error: error)
             } else {
@@ -265,14 +276,11 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
             }
 
             NextcloudKit.shared.setNotification(serverUrl: serverUrl, idNotification: 0, method: method) { (account, error) in
-
                 if error == .success && account == self.appDelegate.account {
                     if let index = self.notifications.firstIndex(where: { $0.idNotification == notification.idNotification }) {
                         self.notifications.remove(at: index)
                     }
-
-                    self.reloadDatasource()
-
+                    self.tableView.reloadData()
                 } else if error != .success {
                     NCContentPresenter.shared.showError(error: error)
                 } else {
@@ -290,21 +298,21 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
 
     func getNetwokingNotification() {
 
-        NextcloudKit.shared.getNotifications { account, notifications, data, error in
+        isReloadDataSourceNetworkInProgress = true
+        self.tableView.reloadData()
 
+        NextcloudKit.shared.getNotifications { account, notifications, data, error in
             if error == .success && account == self.appDelegate.account {
-
                 self.notifications.removeAll()
                 let sortedListOfNotifications = (notifications! as NSArray).sortedArray(using: [NSSortDescriptor(key: "date", ascending: false)])
-
                 for notification in sortedListOfNotifications {
                     if let icon = (notification as! NKNotifications).icon {
                         NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, account: self.appDelegate.account, completion: { _, _ in })
                     }
                     self.notifications.append(notification as! NKNotifications)
                 }
-
-                self.reloadDatasource()
+                self.isReloadDataSourceNetworkInProgress = false
+                self.tableView.reloadData()
             }
         }
     }

+ 2 - 2
iOSClient/Shares/NCShares.swift

@@ -85,11 +85,11 @@ class NCShares: NCCollectionViewCommon {
     override func reloadDataSourceNetwork(forced: Bool = false) {
         super.reloadDataSourceNetwork(forced: forced)
 
+        if UIApplication.shared.applicationState != .active { return }
+
         isReloadDataSourceNetworkInProgress = true
         collectionView?.reloadData()
 
-        NextcloudKit.shared.nkCommonInstance.writeLog("[TEST] READSHARES")
-
         NextcloudKit.shared.readShares(parameters: NKShareParameter()) { account, shares, data, error in
 
             self.refreshControl.endRefreshing()

+ 0 - 1
iOSClient/Trash/NCTrash+CollectionView.swift

@@ -37,7 +37,6 @@ extension NCTrash: UICollectionViewDelegate {
                 selectOcId.append(tableTrash.fileId)
             }
             collectionView.reloadItems(at: [indexPath])
-            self.navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(datasource.count)"
             return
         }
 

+ 1 - 0
iOSClient/Trash/NCTrash.swift

@@ -46,6 +46,7 @@ class NCTrash: UIViewController, NCSelectableNavigationView, NCTrashListCellDele
     var layoutForView: NCDBLayoutForView?
     var listLayout: NCListLayout!
     var gridLayout: NCGridLayout!
+    var layoutKey = NCGlobal.shared.layoutViewTrash
 
     private let refreshControl = UIRefreshControl()