Marino Faggiana 8 жил өмнө
parent
commit
3beb040d43

+ 1 - 1
Libraries external/OCCommunicationLib/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -307,7 +307,7 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     
     NSMutableURLRequest *request = [self requestWithMethod:_requestMethod path:serverFilePath parameters:nil];
     
-    NSString *body = [NSString stringWithFormat:@"<?xml version=\"1.0\"?><d:propertyupdate xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\"><d:set><d:prop><oc:favorite>%d</oc:favorite></d:prop></d:set></d:propertyupdate>", [NSNumber numberWithBool:favorite]];
+    NSString *body = [NSString stringWithFormat:@"<?xml version=\"1.0\"?><d:propertyupdate xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\"><d:set><d:prop><oc:favorite>%i</oc:favorite></d:prop></d:set></d:propertyupdate>", (favorite ? 1 : 0)];
                       
     [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
     

+ 4 - 0
iOSClient/Actions/CCActions.swift

@@ -357,6 +357,7 @@ class CCActions: NSObject {
         metadataNet.fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: serverUrl, activeUrl: appDelegate.activeUrl)
         metadataNet.fileNameLocal = metadata.fileID
         metadataNet.fileNamePrint = metadata.fileNamePrint
+        metadataNet.metadata = metadata
         metadataNet.options = "m"
         metadataNet.priority = Operation.QueuePriority.low.rawValue
         metadataNet.selector = selectorDownloadThumbnail;
@@ -388,6 +389,7 @@ class CCActions: NSObject {
         metadataNet.delegate = delegate
         metadataNet.fileID = metadata.fileID
         metadataNet.fileName = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: serverUrl, activeUrl: appDelegate.activeUrl)
+        metadataNet.metadata = metadata
         metadataNet.options = "\(favorite)"
         metadataNet.priority = Operation.QueuePriority.normal.rawValue
         metadataNet.selector = selectorAddFavorite
@@ -403,6 +405,8 @@ class CCActions: NSObject {
     
     func settingFavoriteFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger) {
         
+        appDelegate.messageNotification("_favorite_", description: message as String, visible: true, delay:TimeInterval(k_dismissAfterSecond), type:TWMessageBarMessageType.error)
+
         metadataNet.delegate?.settingFavoriteFailure(metadataNet, message: message, errorCode: errorCode)
     }
 

+ 1 - 0
iOSClient/CCImages.h

@@ -80,6 +80,7 @@
 #define image_actionSheetReload                 @"reloadNextcloud"
 #define image_actionSheetOpenIn                 @"openInNextcloud"
 #define image_actionSheetOffline                @"actionSheetOffline"
+#define image_actionSheetFavorite               @"actionSheetFavorite"
 #define image_actionSheetLocal                  @"localStorageNextcloud"
 #define image_directory                         @"directory"
 #define image_directorycriptata                 @"directorycriptata"

+ 1 - 0
iOSClient/FileSystem/CCCoreData.h

@@ -108,6 +108,7 @@
 + (void)moveMetadata:(NSString *)fileName directoryID:(NSString *)directoryID directoryIDTo:(NSString *)directoryIDTo activeAccount:(NSString *)activeAccount;
 + (void)updateMetadata:(CCMetadata *)metadata predicate:(NSPredicate *)predicate activeAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl context:(NSManagedObjectContext *)context;
 + (void)setMetadataSession:(NSString *)session sessionError:(NSString *)sessionError sessionSelector:(NSString *)sessionSelector sessionSelectorPost:(NSString *)sessionSelectorPost sessionTaskIdentifier:(NSInteger)sessionTaskIdentifier sessionTaskIdentifierPlist:(NSInteger)sessionTaskIdentifierPlist predicate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context;
++ (void)SetMetadataFavoriteFileID:(NSString *)fileID favorite:(BOOL)favorite activeAccount:(NSString *)activeAccount context:(NSManagedObjectContext *)context;
 
 + (NSArray *)getTableMetadataWithPredicate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context;
 + (NSArray *)getTableMetadataWithPredicate:(NSPredicate *)predicate fieldOrder:(NSString *)fieldOrder ascending:(BOOL)ascending;

+ 14 - 0
iOSClient/FileSystem/CCCoreData.m

@@ -713,6 +713,20 @@
     [context MR_saveToPersistentStoreAndWait];
 }
 
++ (void)SetMetadataFavoriteFileID:(NSString *)fileID favorite:(BOOL)favorite activeAccount:(NSString *)activeAccount context:(NSManagedObjectContext *)context
+{
+    if (context == nil)
+        context = [NSManagedObjectContext MR_defaultContext];
+    
+    TableMetadata *tableMetadata = [TableMetadata MR_findFirstWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (fileID == %@)", activeAccount, fileID] inContext:context];
+    
+    if (tableMetadata) {
+        tableMetadata.favorite = [NSNumber numberWithBool:favorite];
+        
+        [context MR_saveToPersistentStoreAndWait];
+    }
+}
+
 + (CCMetadata *)getMetadataWithPreficate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context
 {
     if (context == nil)

+ 23 - 0
iOSClient/Images.xcassets/actionSheetFavorite.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "actionSheet.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "actionSheet@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "actionSheet@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
iOSClient/Images.xcassets/actionSheetFavorite.imageset/actionSheet.png


BIN
iOSClient/Images.xcassets/actionSheetFavorite.imageset/actionSheet@2x.png


BIN
iOSClient/Images.xcassets/actionSheetFavorite.imageset/actionSheet@3x.png


+ 23 - 0
iOSClient/Images.xcassets/tabBarFavorite.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "tabBarFavorite.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "tabBarFavorite@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "tabBarFavorite@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
iOSClient/Images.xcassets/tabBarFavorite.imageset/tabBarFavorite.png


BIN
iOSClient/Images.xcassets/tabBarFavorite.imageset/tabBarFavorite@2x.png


BIN
iOSClient/Images.xcassets/tabBarFavorite.imageset/tabBarFavorite@3x.png


+ 28 - 14
iOSClient/Main/CCMain.m

@@ -43,7 +43,7 @@
 #define alertRename 3
 #define alertOfflineFolder 4
 
-@interface CCMain () <CCActionsDeleteDelegate, CCActionsRenameDelegate, CCActionsSearchDelegate, CCActionsDownloadThumbnailDelegate>
+@interface CCMain () <CCActionsDeleteDelegate, CCActionsRenameDelegate, CCActionsSearchDelegate, CCActionsDownloadThumbnailDelegate, CCActionsSettingFavoriteDelegate>
 {
     CCMetadata *_metadataSegue;
     CCMetadata *_metadata;
@@ -2929,22 +2929,27 @@
 #pragma mark ===== Favorite =====
 #pragma --------------------------------------------------------------------------------------------
 
+- (void)settingFavoriteSuccess:(CCMetadataNet *)metadataNet
+{
+    [CCCoreData SetMetadataFavoriteFileID:metadataNet.fileID favorite:[metadataNet.options boolValue] activeAccount:app.activeAccount context:nil];
+    _dateReadDataSource = nil;
+    [self reloadDatasource:metadataNet.serverUrl fileID:metadataNet.fileID selector:metadataNet.selector];
+}
+
+- (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
+{
+}
+
 - (void)addFavorite:(CCMetadata *)metadata
 {
     NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
     
     [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorAddFavorite selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
-    
-    NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
-    if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
 }
 
 - (void)removeFavorite:(CCMetadata *)metadata
 {
-    //[CCCoreData setOfflineLocalFileID:metadata.fileID offline:NO activeAccount:app.activeAccount];
-    
-    //NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
-    //if (indexPath) [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
+    [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -4063,7 +4068,7 @@
     
     NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
     
-    NSString *titoloCriptaDecripta, *titoloOffline, *titoloLock, *titleOfflineFolder;
+    NSString *titoloCriptaDecripta, *titoloOffline, *titoloLock, *titleOfflineFolder, *titleFavorite;
     BOOL offlineFolder = NO;
     
     if (_metadata.cryptated) titoloCriptaDecripta = [NSString stringWithFormat:NSLocalizedString(@"_decrypt_", nil)];
@@ -4080,6 +4085,14 @@
         
     } else titleOfflineFolder = [NSString stringWithFormat:NSLocalizedString(@"_add_offline_", nil)];
     
+    if (_metadata.favorite) {
+        
+        titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_remove_favorites_", nil)];
+    } else {
+        
+        titleFavorite = [NSString stringWithFormat:NSLocalizedString(@"_add_favorites_", nil)];
+    }
+    
     if (_metadata.directory) {
         // calcolo lockServerUrl
         NSString *lockServerUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:_metadata.fileNameData];
@@ -4425,8 +4438,8 @@
         
         if (!_metadata.cryptated) {
             
-            [actionSheet addButtonWithTitle:@"favorite"
-                                      image:[UIImage imageNamed:image_actionSheetOffline]
+            [actionSheet addButtonWithTitle:titleFavorite
+                                      image:[UIImage imageNamed:image_actionSheetFavorite]
                             backgroundColor:[UIColor whiteColor]
                                      height: 50.0
                                        type:AHKActionSheetButtonTypeDefault
@@ -4435,9 +4448,10 @@
                                         // close swipe
                                         [self setEditing:NO animated:YES];
                                         
-                                        
-                                        [self addFavorite:_metadata];
-                                        
+                                        if (_metadata.favorite)
+                                            [self  removeFavorite:_metadata];
+                                        else
+                                            [self addFavorite:_metadata];
                                     }];
         }
 

+ 5 - 0
iOSClient/Networking/OCNetworking.h

@@ -107,6 +107,11 @@
 - (void)searchSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas;
 - (void)searchFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
+// Favorite
+
+- (void)settingFavoriteSuccess:(CCMetadataNet *)metadataNet;
+- (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
+
 // HUD
 - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
 

+ 6 - 3
iOSClient/Networking/OCNetworking.m

@@ -461,7 +461,10 @@
     [communication setCredentialsWithUser:_activeUser andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
         
-    [communication settingFavoriteServer:_activeUrl andFileOrFolderPath:_metadataNet.fileName favorite:YES withUserSessionToken:nil onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer, NSString *token) {
+    [communication settingFavoriteServer:_activeUrl andFileOrFolderPath:_metadataNet.fileName favorite:[_metadataNet.options boolValue] withUserSessionToken:nil onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer, NSString *token) {
+        
+        if ([self.delegate respondsToSelector:@selector(settingFavoriteSuccess:)])
+            [self.delegate settingFavoriteSuccess:_metadataNet];
         
         [self complete];
         
@@ -471,8 +474,8 @@
         if (errorCode == 0)
             errorCode = error.code;
         
-        //if ([self.delegate respondsToSelector:@selector(searchFailure:message:errorCode:)])
-        //    [self.delegate searchFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
+        if ([self.delegate respondsToSelector:@selector(settingFavoriteFailure:message:errorCode:)])
+            [self.delegate settingFavoriteFailure:_metadataNet message:[error.userInfo valueForKey:@"NSLocalizedDescription"] errorCode:errorCode];
         
         // Request trusted certificated
         if ([error code] == NSURLErrorServerCertificateUntrusted)

+ 1 - 0
iOSClient/en.lproj/Localizable.strings

@@ -58,6 +58,7 @@
 "_postpone_"                = "Postpone";
 "_remove_"                  = "Remove";
 "_file_not_found_"          = "File not found";
+"_favorite_"                = "Favorite";
 
 // App