Browse Source

NKShareAccounts

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
0904094a6d

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -4278,7 +4278,7 @@
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/nextcloud/NextcloudKit";
 			requirement = {
-				branch = develop;
+				branch = shareAccounts;
 				kind = branch;
 			};
 		};

+ 1 - 1
iOSClient/Account Request/NCShareAccounts.swift

@@ -39,7 +39,7 @@ class NCShareAccounts: UIViewController {
     @IBOutlet weak var tableView: UITableView!
     @IBOutlet weak var progressView: UIProgressView!
 
-    public var accounts: [NKDataAccountFile] = []
+    public var accounts: [NKShareAccounts.DataAccounts] = []
     public let heightCell: CGFloat = 60
     public var enableTimerProgress: Bool = true
     public var dismissDidEnterBackground: Bool = true

+ 4 - 4
iOSClient/AppDelegate.swift

@@ -632,7 +632,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         try? FileManager.default.createDirectory(at: dirGroupApps.appendingPathComponent(NCGlobal.shared.directoryNextcloudAccounts), withIntermediateDirectories: true)
         let url = dirGroupApps.appendingPathComponent(NCGlobal.shared.directoryNextcloudAccounts + "/" + NCGlobal.shared.fileShareAccounts)
         let tableAccount = NCManageDatabase.shared.getAllAccount()
-        var accounts = [NKDataAccountFile]()
+        var accounts = [NKShareAccounts.DataAccounts]()
         for account in tableAccount {
             let alias = account.alias.isEmpty ? account.displayName : account.alias
             let userBaseUrl = account.user + "-" + (URL(string: account.urlBase)?.host ?? "")
@@ -641,12 +641,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             let toPathAvatar = (dirGroupApps.appendingPathComponent(NCGlobal.shared.directoryNextcloudAccounts + "/" + avatarFileName)).path
             if FileManager.default.fileExists(atPath: atPathAvatar) {
                 NCUtilityFileSystem.shared.copyFile(atPath: atPathAvatar, toPath: toPathAvatar)
-                accounts.append(NKDataAccountFile(withUrl: account.urlBase, user: account.user, alias: alias, avatar: toPathAvatar))
+                accounts.append(NKShareAccounts.DataAccounts(withUrl: account.urlBase, user: account.user, alias: alias, avatar: toPathAvatar))
             } else {
-                accounts.append(NKDataAccountFile(withUrl: account.urlBase, user: account.user, alias: alias))
+                accounts.append(NKShareAccounts.DataAccounts(withUrl: account.urlBase, user: account.user, alias: alias))
             }
         }
-        return NKAccountFile().putShareAccounts(at: url, app: NCGlobal.shared.appScheme, dataAccounts: accounts)
+        return NKShareAccounts().putShareAccounts(at: url, app: NCGlobal.shared.appScheme, dataAccounts: accounts)
     }
 
     // MARK: - Account Request

+ 5 - 5
iOSClient/Login/NCLogin.swift

@@ -42,7 +42,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
     private var activeTextfieldDiff: CGFloat = 0
     private var activeTextField = UITextField()
 
-    private var shareAccounts: [NKDataAccountFile]?
+    private var shareAccounts: [NKShareAccounts.DataAccounts]?
 
     // MARK: - View Life Cycle
 
@@ -117,12 +117,12 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
 
         if NCBrandOptions.shared.use_GroupApps, let dirGroupApps = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroupApps) {
             let url = dirGroupApps.appendingPathComponent(NCGlobal.shared.directoryNextcloudAccounts + "/" + NCGlobal.shared.fileShareAccounts)
-            if FileManager.default.fileExists(atPath: url.path), let shareAccounts = NKAccountFile().getShareAccount(at: url, application: UIApplication.shared) {
-                var accountTemp = [NKDataAccountFile]()
+            if FileManager.default.fileExists(atPath: url.path), let shareAccounts = NKShareAccounts().getShareAccount(at: url, application: UIApplication.shared) {
+                var accountTemp = [NKShareAccounts.DataAccounts]()
                 for shareAccount in shareAccounts {
-                    // if NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "urlBase == %@ AND user == %@", shareAccount.url, shareAccount.user)) == nil {
+                    if NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "urlBase == %@ AND user == %@", shareAccount.url, shareAccount.user)) == nil {
                         accountTemp.append(shareAccount)
-                    // }
+                    }
                 }
                 if !accountTemp.isEmpty {
                     self.shareAccounts = accountTemp

+ 0 - 77
iOSClient/Networking/NCNetworking.swift

@@ -1559,83 +1559,6 @@ import Photos
     }
 }
 
-// MARK: - *** TEST ***
-
-    public class NKAccountFile: NSObject {
-
-        struct Account: Codable {
-            let url: String
-            let user: String
-            let alias: String?
-            let avatar: String?
-        }
-
-        struct Apps: Codable {
-            let apps: [String: [Account]]?
-        }
-
-        @objc func putShareAccounts(at url: URL, app: String, dataAccounts: [NKDataAccountFile]) -> Error? {
-
-            var apps: [String : [Account]] = [:]
-            var accounts: [Account] = []
-
-            for dataAccount in dataAccounts {
-                let account = Account(url: dataAccount.url, user: dataAccount.user, alias: dataAccount.alias, avatar: dataAccount.avatar)
-                accounts.append(account)
-            }
-            apps[app] = accounts
-
-            // Decode
-            do {
-                let data = try Data(contentsOf: url)
-                let json = try JSONDecoder().decode(Apps.self, from: data)
-                if let appsDecoder = json.apps {
-                    let otherApps = appsDecoder.filter({ $0.key != app })
-                    apps.merge(otherApps){(current, _) in current}
-                }
-            } catch { }
-
-            // Encode
-            do {
-                let data = try JSONEncoder().encode(Apps(apps: apps))
-                try data.write(to: url)
-                data.printJson()
-            } catch let error {
-                return error
-            }
-            return nil
-        }
-
-        @objc func getShareAccount(at url: URL, application: UIApplication?) -> [NKDataAccountFile]? {
-
-            var dataAccounts: [NKDataAccountFile] = []
-
-            do {
-                let data = try Data(contentsOf: url)
-                let json = try JSONDecoder().decode(Apps.self, from: data)
-                if let appsDecoder = json.apps {
-                    for appDecoder in appsDecoder {
-                        let app = appDecoder.key
-                        let accounts = appDecoder.value
-                        if let url = URL(string: app + "://"), let application = application, application.canOpenURL(url) {
-                            for account in accounts {
-                                if dataAccounts.first(where: { $0.url == account.url && $0.user == account.user }) == nil {
-                                    let account = NKDataAccountFile(withUrl: account.url, user: account.user, alias: account.alias, avatar: account.avatar)
-                                    dataAccounts.append(account)
-                                }
-                            }
-                        }
-                    }
-                }
-            } catch { }
-
-            return dataAccounts.isEmpty ? nil : dataAccounts
-        }
-    }
-
-    
-
-
 extension Array where Element == URLQueryItem {
     subscript(name: String) -> URLQueryItem? {
         first(where: { $0.name == name })