marinofaggiana 6 年 前
コミット
ea91d9bfe4

+ 1 - 1
iOSClient/CCGlobal.h

@@ -82,7 +82,7 @@
 
 // Database Realm
 #define k_databaseDefault                               @"nextcloud.realm"
-#define k_databaseSchemaVersion                         47
+#define k_databaseSchemaVersion                         48
 
 // Intro selector
 #define k_intro_login                                   0

+ 1 - 1
iOSClient/Database/NCDatabase.swift

@@ -38,7 +38,7 @@ class tableAccount: Object {
     @objc dynamic var autoUploadVideo: Bool = false
     @objc dynamic var autoUploadWWAnPhoto: Bool = false
     @objc dynamic var autoUploadWWAnVideo: Bool = false
-    @objc dynamic var businessSize: Double = 0
+    @objc dynamic var businessSize: String = ""
     @objc dynamic var businessType = ""
     @objc dynamic var dateSearchContentTypeImageVideo = NSDate.distantPast
     @objc dynamic var city = ""

+ 15 - 2
iOSClient/Database/NCManageDatabase.swift

@@ -203,6 +203,19 @@ class NCManageDatabase: NSObject {
         }
     }
     
+    @objc func updateAccount(_ account: tableAccount) {
+        
+        let realm = try! Realm()
+        
+        do {
+            try realm.write {
+                realm.add(account, update: true)
+            }
+        } catch let error {
+            print("[LOG] Could not write to database: ", error)
+        }
+    }
+    
     @objc func deleteAccount(_ account: String) {
         
         let realm = try! Realm()
@@ -232,7 +245,7 @@ class NCManageDatabase: NSObject {
             return nil
         }
         
-        return result
+        return tableAccount.init(value: result)
     }
 
     @objc func getAccounts() -> [String]? {
@@ -449,7 +462,7 @@ class NCManageDatabase: NSObject {
                 result.webpage = userProfile.webpage
                 
                 if HCProperties {
-                    result.businessSize = Double(userProfile.businessSize)
+                    result.businessSize = userProfile.businessSize
                     result.businessType = userProfile.businessType
                     result.city = userProfile.city
                     result.country = userProfile.country

+ 34 - 3
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -3122,9 +3122,40 @@
                 if ([data valueForKey:@"displayname"] && ![[data valueForKey:@"displayname"] isKindOfClass:[NSNull class]])
                     userProfile.displayName = [data valueForKey:@"displayname"];
                 
-                if ([data valueForKey:@"businesssize"] && ![[data valueForKey:@"businesssize"] isKindOfClass:[NSNull class]])
-                    userProfile.businessSize = [[data valueForKey:@"businesssize"] integerValue];
-                
+                if ([data valueForKey:@"businesssize"] && ![[data valueForKey:@"businesssize"] isKindOfClass:[NSNull class]]) {
+                    switch ([[data valueForKey:@"businesssize"] integerValue]) {
+                        case 1:
+                            userProfile.businessSize = @"1-4";
+                            break;
+                        case 5:
+                            userProfile.businessSize = @"5-9";
+                            break;
+                        case 10:
+                            userProfile.businessSize = @"10-19";
+                            break;
+                        case 20:
+                            userProfile.businessSize = @"20-49";
+                            break;
+                        case 50:
+                            userProfile.businessSize = @"50-99";
+                            break;
+                        case 100:
+                            userProfile.businessSize = @"100-249";
+                            break;
+                        case 250:
+                            userProfile.businessSize = @"250-499";
+                            break;
+                        case 500:
+                            userProfile.businessSize = @"500-999";
+                            break;
+                        case 1000:
+                            userProfile.businessSize = @"1000+";
+                            break;
+                        default:
+                            break;
+                    }
+                }
+               
                 if ([data valueForKey:@"businesstype"] && ![[data valueForKey:@"businesstype"] isKindOfClass:[NSNull class]])
                     userProfile.businessType = [data valueForKey:@"businesstype"];
                 

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCUserProfile.h

@@ -29,7 +29,7 @@
 @property BOOL enabled;
 
 @property (nonatomic, strong) NSString *address;
-@property NSInteger businessSize;
+@property (nonatomic, strong) NSString *businessSize;
 @property (nonatomic, strong) NSString *businessType;
 @property (nonatomic, strong) NSString *city;
 @property (nonatomic, strong) NSString *company;

+ 1 - 0
iOSClient/Library/OCCommunicationLib/OCUserProfile.m

@@ -32,6 +32,7 @@
     self.id = @"";
     
     self.address = @"";
+    self.businessSize = @"";
     self.businessType = @"";
     self.city = @"";
     self.company = @"";

+ 11 - 1
iOSClient/Networking/OCNetworking.m

@@ -2002,7 +2002,17 @@
     // Create JSON
     NSMutableDictionary *dataDic = [NSMutableDictionary new];
     if (address) [dataDic setValue:address forKey:@"address"];
-    if (businesssize) [dataDic setValue:businesssize forKey:@"businesssize"];
+    if (businesssize) {
+        if ([businesssize isEqualToString:@"1-4"]) { [dataDic setValue:[NSNumber numberWithInt:1] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"5-9"]) { [dataDic setValue:[NSNumber numberWithInt:5] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"10-19"]) { [dataDic setValue:[NSNumber numberWithInt:10] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"20-49"]) { [dataDic setValue:[NSNumber numberWithInt:20] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"50-99"]) { [dataDic setValue:[NSNumber numberWithInt:50] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"100-249"]) { [dataDic setValue:[NSNumber numberWithInt:100] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"250-499"]) { [dataDic setValue:[NSNumber numberWithInt:250] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"500-999"]) { [dataDic setValue:[NSNumber numberWithInt:500] forKey:@"businesssize"]; }
+        else if ([businesssize isEqualToString:@"1000+"]) { [dataDic setValue:[NSNumber numberWithInt:1000] forKey:@"businesssize"]; }
+    }
     if (businesstype) [dataDic setValue:businesstype forKey:@"businesstype"];
     if (city) [dataDic setValue:city forKey:@"city"];
     if (company) [dataDic setValue:company forKey:@"company"];

+ 1 - 31
iOSClient/Settings/CCManageAccount.m

@@ -250,37 +250,7 @@
         [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
         [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
         [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"users"] width:50 height:50 color:[NCBrandColor sharedInstance].icon] forKey:@"imageView.image"];
-        switch ((int)tableAccount.businessSize) {
-            case 1:
-                row.value = @"1-4";
-                break;
-            case 5:
-                row.value = @"5-9";
-                break;
-            case 10:
-                row.value = @"10-19";
-                break;
-            case 20:
-                row.value = @"20-49";
-                break;
-            case 50:
-                row.value = @"50-99";
-                break;
-            case 100:
-                row.value = @"100-249";
-                break;
-            case 250:
-                row.value = @"250-499";
-                break;
-            case 500:
-                row.value = @"500-999";
-                break;
-            case 1000:
-                row.value = @"1000+";
-                break;
-            default:
-                row.value = @"";
-        }
+        row.value = tableAccount.businessSize;
         [section addFormRow:row];
         
         // Role

+ 67 - 37
iOSClient/Settings/HCEditProfile.swift

@@ -151,18 +151,7 @@ class HCEditProfile: XLFormViewController {
         row.cellConfig["detailTextLabel.font"] = UIFont.systemFont(ofSize: 15.0)
         row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "users"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
         row.selectorOptions = ["1-4", "5-9", "10-19", "20-49", "50-99", "100-249", "250-499", "500-999", "1000+"];
-        switch tableAccount?.businessSize {
-        case 1: row.value = "1-4"
-        case 5: row.value = "5-9"
-        case 10: row.value = "10-19"
-        case 20: row.value = "20-49"
-        case 50: row.value = "50-99"
-        case 100: row.value = "100-249"
-        case 250: row.value = "250-499"
-        case 500: row.value = "500-999"
-        case 1000: row.value = "1000+"
-        default: row.value = ""
-        }
+        row.value = tableAccount?.businessSize;
         section.addFormRow(row)
         
         row = XLFormRowDescriptor(tag: "userrole", rowType: XLFormRowDescriptorTypeSelectorPickerView, title: NSLocalizedString("_user_role_", comment: ""))
@@ -190,6 +179,7 @@ class HCEditProfile: XLFormViewController {
     
     override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
         super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
+        
     }
     
     // MARK: - View Life Cycle
@@ -224,10 +214,33 @@ class HCEditProfile: XLFormViewController {
         
         NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: 0)
         
-        tableAccount?.displayName = self.form.formRow(withTag: "userfullname")!.value as! String
-        tableAccount?.address = self.form.formRow(withTag: "useraddress")!.value as! String
-        tableAccount?.city = self.form.formRow(withTag: "usercity")!.value as! String
-        tableAccount?.zip = self.form.formRow(withTag: "userzip")!.value as! String
+        // Full name
+        if self.form.formRow(withTag: "userfullname")?.value == nil {
+            tableAccount?.displayName = ""
+        } else {
+            tableAccount?.displayName = self.form.formRow(withTag: "userfullname")?.value as! String
+        }
+
+        // Address
+        if self.form.formRow(withTag: "useraddress")?.value == nil {
+            tableAccount?.address = ""
+        } else {
+            tableAccount?.address = self.form.formRow(withTag: "useraddress")?.value as! String
+        }
+        
+        // City
+        if self.form.formRow(withTag: "usercity")?.value == nil {
+            tableAccount?.city = ""
+        } else {
+            tableAccount?.city = self.form.formRow(withTag: "usercity")?.value as! String
+        }
+        
+        // Zip
+        if self.form.formRow(withTag: "userzip")?.value == nil {
+            tableAccount?.zip = ""
+        } else {
+            tableAccount?.zip = self.form.formRow(withTag: "userzip")?.value as! String
+        }
         
         let countryNameRow = self.form.formRow(withTag: "usercountry")!.value as? String
         for localeCode in NSLocale.isoCountryCodes {
@@ -238,26 +251,43 @@ class HCEditProfile: XLFormViewController {
             }
         }
         
-        tableAccount?.phone = self.form.formRow(withTag: "userphone")!.value as! String
-        tableAccount?.email = self.form.formRow(withTag: "useremail")!.value as! String
-        tableAccount?.webpage = self.form.formRow(withTag: "userweb")!.value as! String
-        tableAccount?.twitter = self.form.formRow(withTag: "usertwitter")!.value as! String
-        tableAccount?.company = self.form.formRow(withTag: "usercompany")!.value as! String
-        
-        let businesssizeRow = self.form.formRow(withTag: "userbusinesssize")!.value as! String
-        switch businesssizeRow {
-        case "1-4": tableAccount?.businessSize = 1
-        case "5-9": tableAccount?.businessSize = 5
-        case "10-19": tableAccount?.businessSize = 10
-        case "20-49": tableAccount?.businessSize = 20
-        case "50-99": tableAccount?.businessSize = 50
-        case "100-249": tableAccount?.businessSize = 100
-        case "250-499": tableAccount?.businessSize = 250
-        case "500-999": tableAccount?.businessSize = 500
-        case "1000+": tableAccount?.businessSize = 1000
-        default: break
+        // Phone
+        if self.form.formRow(withTag: "userphone")?.value == nil {
+            tableAccount?.phone = ""
+        } else {
+            tableAccount?.phone = self.form.formRow(withTag: "userphone")?.value as! String
         }
         
+        // Email
+        if self.form.formRow(withTag: "useremail")?.value == nil {
+            tableAccount?.email = ""
+        } else {
+            tableAccount?.email = self.form.formRow(withTag: "useremail")?.value as! String
+        }
+        
+        // Web
+        if self.form.formRow(withTag: "userweb")?.value == nil {
+            tableAccount?.webpage = ""
+        } else {
+            tableAccount?.webpage = self.form.formRow(withTag: "userweb")?.value as! String
+        }
+        
+        // Twitter
+        if self.form.formRow(withTag: "usertwitter")?.value == nil {
+            tableAccount?.twitter = ""
+        } else {
+            tableAccount?.twitter = self.form.formRow(withTag: "usertwitter")?.value as! String
+        }
+        
+        // Company
+        if self.form.formRow(withTag: "usercompany")?.value == nil {
+            tableAccount?.company = ""
+        } else {
+            tableAccount?.company = self.form.formRow(withTag: "usercompany")?.value as! String
+        }
+        
+        tableAccount?.businessSize = self.form.formRow(withTag: "userbusinesssize")!.value as! String
+       
         let roleRow = self.form.formRow(withTag: "userrole")!.value as! String
         switch roleRow {
         case NSLocalizedString("_user_owner_", comment: ""): tableAccount?.role = "owner"
@@ -267,11 +297,11 @@ class HCEditProfile: XLFormViewController {
         }
         
         let businesstypeArray = self.form.formRow(withTag: "userbusinesstype")!.value
-        tableAccount?.businessType =  (businesstypeArray as! [String]).joined(separator: ",")
+        tableAccount?.businessType = (businesstypeArray as! [String]).joined(separator: ",")
         
-        OCNetworking.sharedManager()?.putHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, address: tableAccount?.address, businesssize: String(describing: tableAccount?.businessSize), businesstype: tableAccount?.businessType, city: tableAccount?.city, company: tableAccount?.company, country: tableAccount?.country, displayname: tableAccount?.displayName, email: tableAccount?.email, phone: tableAccount?.phone, role_: tableAccount?.role, twitter: tableAccount?.twitter, website: tableAccount?.webpage, zip: tableAccount?.zip, completion: { (account, message, errorCode) in
+        OCNetworking.sharedManager()?.putHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, address: tableAccount?.address, businesssize: tableAccount?.businessSize, businesstype: tableAccount?.businessType, city: tableAccount?.city, company: tableAccount?.company, country: tableAccount?.country, displayname: tableAccount?.displayName, email: tableAccount?.email, phone: tableAccount?.phone, role_: tableAccount?.role, twitter: tableAccount?.twitter, website: tableAccount?.webpage, zip: tableAccount?.zip, completion: { (account, message, errorCode) in
             if errorCode == 0 && account == self.appDelegate.activeAccount {
-//                _ = NCManageDatabase.sharedInstance.updateAccount(self.tableAccount!)
+                NCManageDatabase.sharedInstance.updateAccount(self.tableAccount!)
                 self.navigationController?.popViewController(animated: true)
                 self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
             } else if errorCode != 0 {