marinofaggiana 6 năm trước cách đây
mục cha
commit
6bc54754a5

+ 2 - 1
iOSClient/AppDelegate.h

@@ -39,6 +39,7 @@
 
 @class CCLoginWeb;
 @class CCMore;
+@class NCMedia;
 
 @interface AppDelegate : UIResponder <UIApplicationDelegate, BKPasscodeLockScreenManagerDelegate, BKPasscodeViewControllerDelegate, TWMessageBarStyleSheet, CCNetworkingDelegate>
 
@@ -112,7 +113,7 @@
 @property (nonatomic, strong) CCMain *activeMain;
 @property (nonatomic, strong) CCMain *homeMain;
 @property (nonatomic, strong) CCFavorites *activeFavorites;
-@property (nonatomic, strong) CCMedia *activeMedia;
+@property (nonatomic, strong) NCMedia *activeMedia;
 @property (nonatomic, retain) CCDetail *activeDetail;
 @property (nonatomic, retain) CCSettings *activeSettings;
 @property (nonatomic, retain) CCTransfers *activeTransfers;

+ 14 - 0
iOSClient/Database/NCManageDatabase.swift

@@ -1958,6 +1958,20 @@ class NCManageDatabase: NSObject {
         
         return tableMetadata.init(value: result)
     }
+   
+    @objc func getTablePhotos(predicate: NSPredicate) -> [tableMetadata]? {
+        
+        let realm = try! Realm()
+        realm.refresh()
+        
+        let results = realm.objects(tablePhotos.self).filter(predicate).sorted(byKeyPath: "date", ascending: false)
+        
+        if (results.count > 0) {
+            return Array(results.map { tableMetadata.init(value:$0) })
+        } else {
+            return nil
+        }
+    }
     
     @objc func createTablePhotos(_ metadatas: [tableMetadata], account: String) {
 

+ 3 - 3
iOSClient/Main/NCMainCommon.swift

@@ -958,7 +958,7 @@ class NCMainCommon: NSObject, PhotoEditorDelegate {
         }
         
         self.reloadDatasource(ServerUrl: serverUrl, fileID: nil, action: k_action_NULL)
-        self.appDelegate.activeMedia.reloadDatasource(nil, action: Int(k_action_NULL))
+        self.appDelegate.activeMedia.loadDatasource()
     }
     
     @objc func editPhoto(_ metadata: tableMetadata, viewController: UIViewController) {
@@ -1213,7 +1213,7 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
                     appDelegate.activeDetail.downloadPhotoBrowserSuccessFailure(metadata, selector: selector, errorCode: errorCode)
                 }
                 if appDelegate.activeMedia != nil {
-                    appDelegate.activeMedia.downloadFileSuccessFailure(metadata.fileName, fileID: metadata.fileID, serverUrl: serverUrl, selector: selector, errorMessage: errorMessage, errorCode: errorCode)
+                    //appDelegate.activeMedia.downloadFileSuccessFailure(metadata.fileName, fileID: metadata.fileID, serverUrl: serverUrl, selector: selector, errorMessage: errorMessage, errorCode: errorCode)
                 }
             }
             
@@ -1241,7 +1241,7 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
                     appDelegate.activeDetail.downloadPhotoBrowserSuccessFailure(metadata, selector: selector, errorCode: errorCode)
                 }
                 if appDelegate.activeMedia.view.window != nil {
-                    appDelegate.activeMedia.downloadFileSuccessFailure(metadata.fileName, fileID: metadata.fileID, serverUrl: serverUrl, selector: selector, errorMessage: errorMessage, errorCode: errorCode)
+                    //appDelegate.activeMedia.downloadFileSuccessFailure(metadata.fileName, fileID: metadata.fileID, serverUrl: serverUrl, selector: selector, errorMessage: errorMessage, errorCode: errorCode)
                 }
                 
                 NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, fileID: fileID, action: Int32(k_action_MOD))

+ 32 - 8
iOSClient/Media/NCMedia.swift

@@ -54,6 +54,12 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
 
     private let refreshControl = UIRefreshControl()
     
+    required init?(coder aDecoder: NSCoder) {
+        super.init(coder: aDecoder)
+
+        appDelegate.activeMedia = self
+    }
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         
@@ -303,33 +309,51 @@ class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDel
         actionSheet?.present(in: self, from: sender as! UIButton)
     }
     
-    // MARK: DATASOURCE
-    @objc func loadDatasource() {
+    func search() {
         
         if appDelegate.activeAccount.count == 0 {
             return
         }
         
         let startDirectory = NCManageDatabase.sharedInstance.getAccountStartDirectoryMediaTabView(CCUtility.getHomeServerUrlActiveUrl(appDelegate.activeUrl))
+
         //let date = Calendar.current.date(byAdding: .day, value: -30, to: Date())!
         
         let formatter = DateFormatter()
         formatter.dateFormat = "yyyy/MM/dd HH:mm"
         let date2 = formatter.date(from: "2019/01/29 00:00")!
 
-        
         OCNetworking.sharedManager()?.search(withAccount: appDelegate.activeAccount, fileName: "", serverUrl: startDirectory, contentType: ["image/%", "video/%"], lteDateLastModified: Date(), gteDateLastModified: date2, depth: "infinity", completion: { (account, metadatas, message, errorCode) in
             
             if errorCode == 0 && account == self.appDelegate.activeAccount {
                 NCManageDatabase.sharedInstance.createTablePhotos(metadatas as! [tableMetadata], account: account!)
                 
-                self.sectionDatasource = CCSectionMetadata.creataDataSourseSectionMetadata(metadatas, listProgressMetadata: nil, groupByField: "date", filterFileID: nil, filterTypeFileImage: self.filterTypeFileImage, filterTypeFileVideo: self.filterTypeFileVideo, activeAccount: account!)
-                self.collectionView.reloadData()
-
+                self.loadDatasource()
             }
+            
+            self.refreshControl.endRefreshing()
         })
-                
-        self.refreshControl.endRefreshing()
+    }
+    
+    // MARK: DATASOURCE
+    @objc func loadDatasource() {
+        
+        if appDelegate.activeAccount.count == 0 {
+            return
+        }
+        
+        DispatchQueue.global().async {
+            
+            if let metadatas = NCManageDatabase.sharedInstance.getTablePhotos(predicate: NSPredicate(format: "account == %@", self.appDelegate.activeAccount))  {
+                self.sectionDatasource = CCSectionMetadata.creataDataSourseSectionMetadata(metadatas, listProgressMetadata: nil, groupByField: "date", filterFileID: nil, filterTypeFileImage: self.filterTypeFileImage, filterTypeFileVideo: self.filterTypeFileVideo, activeAccount: self.appDelegate.activeAccount)
+            } else {
+                self.sectionDatasource = CCSectionDataSourceMetadata()
+            }
+        
+            DispatchQueue.main.async {
+                self.collectionView?.reloadData()
+            }
+        }
     }
     
     // MARK: COLLECTIONVIEW METHODS

+ 1 - 1
iOSClient/Networking/CCNetworking.m

@@ -1109,7 +1109,7 @@
         // Hardcoded for add new photo/video for tab Media view
         NSString *startDirectoryMediaTabView = [[NCManageDatabase sharedInstance] getAccountStartDirectoryMediaTabView:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
         if ([serverUrl containsString:startDirectoryMediaTabView] && ([metadata.typeFile isEqualToString:k_metadataTypeFile_image] || [metadata.typeFile isEqualToString:k_metadataTypeFile_video])) {
-            [appDelegate.activeMedia.addMetadatasFromUpload addObject:metadata];
+            //[appDelegate.activeMedia.addMetadatasFromUpload addObject:metadata];
         }
 #endif
         

+ 1 - 1
iOSClient/Networking/NCService.swift

@@ -245,7 +245,7 @@ class NCService: NSObject {
                 
                 // Call func thath required the userdID
                 self.appDelegate.activeFavorites.listingFavorites()
-                //self.appDelegate.activeMedia.searchPhotoVideo()
+                self.appDelegate.activeMedia.loadDatasource()
                 NCFunctionMain.sharedInstance.synchronizeOffline()
                 
                 DispatchQueue.global(qos: .default).async {