Selaa lähdekoodia

code improved

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 vuosi sitten
vanhempi
commit
92a46f53fe
2 muutettua tiedostoa jossa 32 lisäystä ja 73 poistoa
  1. 8 8
      iOSClient/Media/NCMedia.swift
  2. 24 65
      iOSClient/Menu/NCMedia+Menu.swift

+ 8 - 8
iOSClient/Media/NCMedia.swift

@@ -198,7 +198,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
               account == appDelegate.account
         else { return }
 
-        self.reloadDataSourceWithCompletion { _ in }
+        self.reloadDataSource { }
     }
 
     @objc func uploadedFile(_ notification: NSNotification) {
@@ -210,7 +210,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
               account == appDelegate.account
         else { return }
 
-        self.reloadDataSourceWithCompletion { _ in }
+        self.reloadDataSource { }
     }
 
     // MARK: - Command
@@ -273,7 +273,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         let home = utilityFileSystem.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId)
         mediaPath = serverUrl.replacingOccurrences(of: home, with: "")
         NCManageDatabase.shared.setAccountMediaPath(mediaPath, account: appDelegate.account)
-        reloadDataSourceWithCompletion { _ in
+        reloadDataSource {
             self.searchNewMedia()
         }
     }
@@ -459,7 +459,7 @@ extension NCMedia {
         }
     }
 
-    @objc func reloadDataSourceWithCompletion(_ completion: @escaping (_ metadatas: [tableMetadata]) -> Void) {
+    @objc func reloadDataSource(completion: @escaping () -> Void) {
         guard !appDelegate.account.isEmpty else { return }
 
         DispatchQueue.global().async {
@@ -468,7 +468,7 @@ extension NCMedia {
                 self.reloadDataThenPerform {
                     self.updateMediaControlVisibility()
                     self.mediaCommandTitle()
-                    completion(self.metadatas)
+                    completion()
                 }
             }
         }
@@ -537,7 +537,7 @@ extension NCMedia {
                         if metadatasChanged.metadatasUpdate.isEmpty {
                             self.researchOldMedia(value: value, limit: limit, withElseReloadDataSource: true)
                         } else {
-                            self.reloadDataSourceWithCompletion { _ in }
+                            self.reloadDataSource { }
                         }
                     }
                 } else {
@@ -561,7 +561,7 @@ extension NCMedia {
             searchOldMedia(value: -999, limit: 0)
         } else {
             if withElseReloadDataSource {
-                self.reloadDataSourceWithCompletion { _ in }
+                self.reloadDataSource { }
             }
         }
     }
@@ -616,7 +616,7 @@ extension NCMedia {
                         let metadatasResult = NCManageDatabase.shared.getMetadatas(predicate: predicateResult)
                         let updateMetadatas = NCManageDatabase.shared.updateMetadatas(metadatas, metadatasResult: metadatasResult)
                         if !updateMetadatas.metadatasUpdate.isEmpty || !updateMetadatas.metadatasDelete.isEmpty {
-                            self.reloadDataSourceWithCompletion { _ in }
+                            self.reloadDataSource { }
                         }
                     }
                 } else if error == .success, files.isEmpty, self.metadatas.isEmpty {

+ 24 - 65
iOSClient/Menu/NCMedia+Menu.swift

@@ -54,6 +54,27 @@ extension NCMedia {
 
             actions.append(.seperator(order: 0))
 
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_select_media_folder_", comment: ""),
+                    icon: utility.loadImage(named: "folder"),
+                    action: { _ in
+                        if let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as? UINavigationController,
+                           let viewController = navigationController.topViewController as? NCSelect {
+
+                            viewController.delegate = self
+                            viewController.typeOfCommandView = .select
+                            viewController.type = "mediaFolder"
+                            viewController.selectIndexPath = self.selectIndexPath
+
+                            self.present(navigationController, animated: true, completion: nil)
+                        }
+                    }
+                )
+            )
+
+            actions.append(.seperator(order: 0))
+
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_media_viewimage_show_", comment: ""),
@@ -63,7 +84,7 @@ extension NCMedia {
                     action: { _ in
                         self.showOnlyImages = true
                         self.showOnlyVideos = false
-                        self.reloadDataSourceWithCompletion { _ in }
+                        self.reloadDataSource { }
                     }
                 )
             )
@@ -77,7 +98,7 @@ extension NCMedia {
                     action: { _ in
                         self.showOnlyImages = false
                         self.showOnlyVideos = true
-                        self.reloadDataSourceWithCompletion { _ in }
+                        self.reloadDataSource { }
                     }
                 )
             )
@@ -91,28 +112,7 @@ extension NCMedia {
                     action: { _ in
                         self.showOnlyImages = false
                         self.showOnlyVideos = false
-                        self.reloadDataSourceWithCompletion { _ in }
-                    }
-                )
-            )
-
-            actions.append(.seperator(order: 0))
-
-            actions.append(
-                NCMenuAction(
-                    title: NSLocalizedString("_select_media_folder_", comment: ""),
-                    icon: utility.loadImage(named: "folder"),
-                    action: { _ in
-                        if let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as? UINavigationController,
-                           let viewController = navigationController.topViewController as? NCSelect {
-
-                            viewController.delegate = self
-                            viewController.typeOfCommandView = .select
-                            viewController.type = "mediaFolder"
-                            viewController.selectIndexPath = self.selectIndexPath
-
-                            self.present(navigationController, animated: true, completion: nil)
-                        }
+                        self.reloadDataSource { }
                     }
                 )
             )
@@ -158,47 +158,6 @@ extension NCMedia {
                 )
             )
 
-            actions.append(.seperator(order: 0))
-
-            actions.append(
-                NCMenuAction(
-                    title: NSLocalizedString("_media_by_modified_date_", comment: ""),
-                    icon: utility.loadImage(named: "circle.grid.cross.up.fill"),
-                    selected: NCKeychain().mediaSortDate == "date",
-                    on: true,
-                    action: { _ in
-                        NCKeychain().mediaSortDate = "date"
-                        self.reloadDataSourceWithCompletion { _ in }
-                    }
-                )
-            )
-
-            actions.append(
-                NCMenuAction(
-                    title: NSLocalizedString("_media_by_created_date_", comment: ""),
-                    icon: utility.loadImage(named: "circle.grid.cross.down.fill"),
-                    selected: NCKeychain().mediaSortDate == "creationDate",
-                    on: true,
-                    action: { _ in
-                        NCKeychain().mediaSortDate = "creationDate"
-                        self.reloadDataSourceWithCompletion { _ in }
-                    }
-                )
-            )
-
-            actions.append(
-                NCMenuAction(
-                    title: NSLocalizedString("_media_by_upload_date_", comment: ""),
-                    icon: utility.loadImage(named: "circle.grid.cross.right.fill"),
-                    selected: NCKeychain().mediaSortDate == "uploadDate",
-                    on: true,
-                    action: { _ in
-                        NCKeychain().mediaSortDate = "uploadDate"
-                        self.reloadDataSourceWithCompletion { _ in }
-                    }
-                )
-            )
-
         } else {
 
             //