Ver Fonte

New offline interface

Marino Faggiana há 8 anos atrás
pai
commit
82f874f42c

+ 1 - 1
iOSClient/AppDelegate.m

@@ -362,7 +362,7 @@
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
         
         NSLog(@"[LOG] read file Offline");
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"readFileOffline" object:nil];
+        [[CCOfflineFileFolder sharedOfflineFileFolder] readFileOffline];
         
         NSLog(@"[LOG] read folder offline");
         [[CCOfflineFileFolder sharedOfflineFileFolder] readFolderOffline];

+ 4 - 3
iOSClient/FileSystem/CCCoreData.h

@@ -158,7 +158,6 @@
 // ===== LocalFile =====
 
 + (void)addLocalFile:(CCMetadata *)metadata activeAccount:(NSString *)activeAccount;
-+ (void)addOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount;
 
 + (void)deleteLocalFileWithPredicate:(NSPredicate *)predicate;
 + (void)removeOfflineFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount;
@@ -166,11 +165,13 @@
 + (void)renameLocalFileWithFileID:(NSString *)fileID fileNameTo:(NSString *)fileNameTo fileNamePrintTo:(NSString *)fileNamePrintTo activeAccount:(NSString *)activeAccount;
 + (void)updateLocalFileModel:(CCMetadata *)metadata activeAccount:(NSString *)activeAccount;
 
-+ (BOOL)isOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount;
-
 + (TableLocalFile *)getLocalFileWithFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount;
 + (NSArray *)getTableLocalFileWithPredicate:(NSPredicate *)predicate;
 
++ (void)addOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount;
++ (BOOL)isOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount;
++ (NSArray *)getOfflineLocalFileActiveAccount:(NSString *)activeAccount directoryUser:(NSString *)directoryUser;
+
 + (NSArray *)getGeoInformationLocalFromFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount;
 + (void)setGeoInformationLocalFromFileID:(NSString *)fileID exifDate:(NSDate *)exifDate exifLatitude:(NSString *)exifLatitude exifLongitude:(NSString *)exifLongitude activeAccount:(NSString *)activeAccount;
 + (void)setGeoInformationLocalNull;

+ 47 - 21
iOSClient/FileSystem/CCCoreData.m

@@ -1256,18 +1256,6 @@
     }];
 }
 
-+ (void)addOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount
-{
-    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
-        
-        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount];
-        TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate inContext:localContext];
-    
-        if (record)
-            record.offline = [NSNumber numberWithBool:YES];
-    }];
-}
-
 + (void)deleteLocalFileWithPredicate:(NSPredicate *)predicate
 {
     [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
@@ -1324,15 +1312,6 @@
     }];
 }
 
-+ (BOOL)isOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount
-{
-    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (offline == 1) AND (account == %@)", fileID, activeAccount];
-    TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate];
-    
-    if (record) return YES;
-    else return NO;
-}
-
 + (TableLocalFile *)getLocalFileWithFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount
 {
     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount];
@@ -1381,6 +1360,53 @@
     return [TableLocalFile MR_findAllWithPredicate:predicate];
 }
 
++ (void)addOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount
+{
+    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
+        
+        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount];
+        TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate inContext:localContext];
+        
+        if (record)
+            record.offline = [NSNumber numberWithBool:YES];
+    }];
+}
+
++ (BOOL)isOffline:(NSString *)fileID activeAccount:(NSString *)activeAccount
+{
+    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (offline == 1) AND (account == %@)", fileID, activeAccount];
+    TableLocalFile *record = [TableLocalFile MR_findFirstWithPredicate:predicate];
+    
+    if (record) return YES;
+    else return NO;
+}
+
++ (NSArray *)getOfflineLocalFileActiveAccount:(NSString *)activeAccount directoryUser:(NSString *)directoryUser
+{
+    NSMutableArray *metadatas = [NSMutableArray new];
+    NSArray *files = [self getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (offline == 1)", activeAccount] controlZombie:YES activeAccount:activeAccount directoryUser:directoryUser];
+    
+    for (TableLocalFile *file in files) {
+        
+        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", file.fileID, activeAccount];
+        CCMetadata *metadata = [self getMetadataWithPreficate:predicate context:nil];
+        
+        if (metadata) {
+            
+            // verify if is not on directory offline
+            
+            NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(directoryID == %@) AND (offline == 1) AND (account == %@)", metadata.directoryID, activeAccount];
+            
+            TableDirectory *directory = [TableDirectory MR_findFirstWithPredicate:predicate];
+            
+            if (!directory)
+                [metadatas addObject:metadata];
+        }
+    }
+
+    return metadatas;
+}
+
 + (NSArray *)getGeoInformationLocalFromFileID:(NSString *)fileID activeAccount:(NSString *)activeAccount
 {
     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, activeAccount];

+ 2 - 0
iOSClient/Offline/CCOfflineFileFolder.h

@@ -36,6 +36,8 @@
 - (void)readFolderOffline;
 - (void)addOfflineFolder:(NSString *)serverUrl;
 
+- (void)readFileOffline;
+
 - (void)verifyChangeMedatas:(NSArray *)allRecordMetadatas serverUrl:(NSString *)serverUrl directoryID:(NSString *)directoryID account:(NSString *)account offline:(BOOL)offline;
 
 - (BOOL)offlineFolderAnimationDirectory:(NSArray *)directory callViewController:(BOOL)callViewController;

+ 87 - 35
iOSClient/Offline/CCOfflineFileFolder.m

@@ -108,9 +108,38 @@
     NSLog(@"[LOG] Read offline directory : %@", serverUrl);
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Read Folder offline =====
-#pragma --------------------------------------------------------------------------------------------
+// Graphics Animation Offline Folders
+//
+// User return BOOL animation for 1 directory only
+//
+
+- (BOOL)offlineFolderAnimationDirectory:(NSArray *)directory callViewController:(BOOL)callViewController
+{
+    BOOL animation = NO;
+    NSMutableOrderedSet *serversUrlInDownload = [[NSMutableOrderedSet alloc] init];
+    
+    NSMutableArray *metadatasNet = [app verifyExistsInQueuesDownloadSelector:selectorDownloadOffline];
+    
+    for (CCMetadataNet *metadataNet in metadatasNet)
+        [serversUrlInDownload addObject:metadataNet.serverUrl];
+    
+    /* Animation ON/OFF */
+    
+    for (NSString *serverUrl in directory) {
+        
+        animation = [serversUrlInDownload containsObject:serverUrl];
+        
+        if (callViewController) {
+            
+            NSString *serverUrlOffline = [CCUtility deletingLastPathComponentFromServerUrl:serverUrl];
+            CCMain *viewController = [app.listMainVC objectForKey:serverUrlOffline];
+            if (viewController)
+                [viewController offlineFolderGraphicsServerUrl:serverUrl animation:animation];
+        }
+    }
+    
+    return animation;
+}
 
 - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
@@ -237,6 +266,61 @@
     });
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Read File Offline =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)readFileOffline
+{
+    if (app.activeAccount == nil || [CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud] == nil)
+        return;
+        
+    NSArray *metadatas = [CCCoreData getOfflineLocalFileActiveAccount:app.activeAccount directoryUser:app.directoryUser];
+    
+    for (CCMetadata *metadata in metadatas) {
+        
+        NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
+        if (serverUrl == nil) continue;
+        
+        CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
+        
+        metadataNet.action = actionReadFile;
+        metadataNet.fileID = metadata.fileID;
+        metadataNet.fileName = metadata.fileName;
+        metadataNet.fileNamePrint = metadata.fileNamePrint;
+        metadataNet.serverUrl = serverUrl;
+        metadataNet.selector = selectorReadFileOffline;
+        metadataNet.priority = NSOperationQueuePriorityVeryLow;
+        
+        [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
+    }
+}
+
+- (void)readFileFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
+{
+    // verify active user
+    TableAccount *recordAccount = [CCCoreData getActiveAccount];
+    
+    // File not present, remove it
+    if (errorCode == 404 && [recordAccount.account isEqualToString:metadataNet.account]) {
+        [CCCoreData deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", metadataNet.account, metadataNet.fileID]];
+        [CCCoreData deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", metadataNet.account, metadataNet.fileID]];
+    }
+}
+
+- (void)readFileSuccess:(CCMetadataNet *)metadataNet metadata:(CCMetadata *)metadata
+{
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+        
+        [self verifyChangeMedatas:[[NSArray alloc] initWithObjects:metadata, nil] serverUrl:metadataNet.serverUrl directoryID:metadataNet.directoryID account:app.activeAccount offline:NO];
+    });
+}
+
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Verify Metadatas =====
+#pragma --------------------------------------------------------------------------------------------
+
+
 // MULTI THREAD
 - (void)verifyChangeMedatas:(NSArray *)allRecordMetadatas serverUrl:(NSString *)serverUrl directoryID:(NSString *)directoryID account:(NSString *)account offline:(BOOL)offline
 {
@@ -354,37 +438,5 @@
     });
 }
 
-// Graphics Animation Offline Folders
-//
-// User return BOOL animation for 1 directory only
-//
-
-- (BOOL)offlineFolderAnimationDirectory:(NSArray *)directory callViewController:(BOOL)callViewController
-{
-    BOOL animation = NO;
-    NSMutableOrderedSet *serversUrlInDownload = [[NSMutableOrderedSet alloc] init];
-    
-    NSMutableArray *metadatasNet = [app verifyExistsInQueuesDownloadSelector:selectorDownloadOffline];
-    
-    for (CCMetadataNet *metadataNet in metadatasNet)
-        [serversUrlInDownload addObject:metadataNet.serverUrl];
-    
-    /* Animation ON/OFF */
-    
-    for (NSString *serverUrl in directory) {
-        
-        animation = [serversUrlInDownload containsObject:serverUrl];
-        
-        if (callViewController) {
-            
-            NSString *serverUrlOffline = [CCUtility deletingLastPathComponentFromServerUrl:serverUrl];
-            CCMain *viewController = [app.listMainVC objectForKey:serverUrlOffline];
-            if (viewController)
-                [viewController offlineFolderGraphicsServerUrl:serverUrl animation:animation];
-        }
-    }
-    
-    return animation;
-}
 
 @end