Эх сурвалжийг харах

#2221

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 жил өмнө
parent
commit
65eaab11bb

+ 31 - 9
iOSClient/Account Request/NCTalkAccounts.storyboard

@@ -4,6 +4,7 @@
     <dependencies>
         <deployment identifier="iOS"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
+        <capability name="Image references" minToolsVersion="12.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -48,26 +49,45 @@
                                             <rect key="frame" x="0.0" y="0.0" width="280" height="60"/>
                                             <autoresizingMask key="autoresizingMask"/>
                                             <subviews>
-                                                <label opaque="NO" userInteractionEnabled="NO" tag="10" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pWI-iZ-BTy" userLabel="User">
-                                                    <rect key="frame" x="10" y="21.666666666666668" width="260" height="17.000000000000004"/>
-                                                    <fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
+                                                <imageView clipsSubviews="YES" userInteractionEnabled="NO" tag="10" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="4cH-oC-YBd" userLabel="Avatar">
+                                                    <rect key="frame" x="0.0" y="15.999999999999998" width="30" height="28.666666666666664"/>
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="30" id="Efd-BU-u61"/>
+                                                        <constraint firstAttribute="width" constant="30" id="qFy-Tu-ov6"/>
+                                                    </constraints>
+                                                    <imageReference key="image" image="person.circle" catalog="system" variableValue="0.80000000000000004"/>
+                                                </imageView>
+                                                <label opaque="NO" userInteractionEnabled="NO" tag="20" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pWI-iZ-BTy" userLabel="User">
+                                                    <rect key="frame" x="40" y="20.333333333333336" width="220" height="19.333333333333336"/>
+                                                    <fontDescription key="fontDescription" type="boldSystem" pointSize="16"/>
                                                     <nil key="textColor"/>
                                                     <nil key="highlightedColor"/>
                                                 </label>
-                                                <label opaque="NO" userInteractionEnabled="NO" tag="20" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sWT-NJ-ihR" userLabel="Url">
-                                                    <rect key="frame" x="10" y="39.666666666666664" width="260" height="16"/>
+                                                <label opaque="NO" userInteractionEnabled="NO" tag="30" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sWT-NJ-ihR" userLabel="Url">
+                                                    <rect key="frame" x="40" y="40.666666666666664" width="220" height="16"/>
                                                     <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                                     <nil key="textColor"/>
                                                     <nil key="highlightedColor"/>
                                                 </label>
+                                                <imageView clipsSubviews="YES" userInteractionEnabled="NO" tag="40" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="chevron.right" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="x47-dQ-alI" userLabel="Active">
+                                                    <rect key="frame" x="265" y="24.666666666666671" width="15" height="11.333333333333329"/>
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="15" id="SXt-LG-c5N"/>
+                                                        <constraint firstAttribute="width" constant="15" id="vdZ-4R-gY5"/>
+                                                    </constraints>
+                                                </imageView>
                                             </subviews>
                                             <constraints>
-                                                <constraint firstItem="sWT-NJ-ihR" firstAttribute="leading" secondItem="IkA-cK-iZV" secondAttribute="leading" constant="10" id="ECI-2F-iyI"/>
+                                                <constraint firstItem="4cH-oC-YBd" firstAttribute="leading" secondItem="IkA-cK-iZV" secondAttribute="leading" id="3cz-yE-yoQ"/>
+                                                <constraint firstAttribute="trailing" secondItem="x47-dQ-alI" secondAttribute="trailing" id="Dna-rj-LLQ"/>
+                                                <constraint firstItem="x47-dQ-alI" firstAttribute="centerY" secondItem="IkA-cK-iZV" secondAttribute="centerY" id="Ghs-sZ-Bzf"/>
+                                                <constraint firstItem="sWT-NJ-ihR" firstAttribute="leading" secondItem="4cH-oC-YBd" secondAttribute="trailing" constant="10" id="MxV-Du-vUw"/>
+                                                <constraint firstItem="4cH-oC-YBd" firstAttribute="centerY" secondItem="IkA-cK-iZV" secondAttribute="centerY" id="WuT-iT-3xk"/>
                                                 <constraint firstItem="sWT-NJ-ihR" firstAttribute="top" secondItem="pWI-iZ-BTy" secondAttribute="bottom" constant="1" id="ZVm-u7-JGI"/>
-                                                <constraint firstItem="pWI-iZ-BTy" firstAttribute="leading" secondItem="IkA-cK-iZV" secondAttribute="leading" constant="10" id="auF-fg-pYj"/>
-                                                <constraint firstAttribute="trailing" secondItem="pWI-iZ-BTy" secondAttribute="trailing" constant="10" id="dE9-ok-ZJi"/>
-                                                <constraint firstAttribute="trailing" secondItem="sWT-NJ-ihR" secondAttribute="trailing" constant="10" id="g6m-x4-DDa"/>
+                                                <constraint firstItem="x47-dQ-alI" firstAttribute="leading" secondItem="pWI-iZ-BTy" secondAttribute="trailing" constant="5" id="e8E-uH-gvt"/>
                                                 <constraint firstItem="pWI-iZ-BTy" firstAttribute="centerY" secondItem="IkA-cK-iZV" secondAttribute="centerY" id="jUS-89-RRO"/>
+                                                <constraint firstItem="x47-dQ-alI" firstAttribute="leading" secondItem="sWT-NJ-ihR" secondAttribute="trailing" constant="5" id="lIk-Sj-EgC"/>
+                                                <constraint firstItem="pWI-iZ-BTy" firstAttribute="leading" secondItem="4cH-oC-YBd" secondAttribute="trailing" constant="10" id="mlI-8s-1Ae"/>
                                             </constraints>
                                         </tableViewCellContentView>
                                         <color key="backgroundColor" systemColor="secondarySystemGroupedBackgroundColor"/>
@@ -117,6 +137,8 @@
         </scene>
     </scenes>
     <resources>
+        <image name="chevron.right" catalog="system" width="97" height="128"/>
+        <image name="person.circle" catalog="system" width="128" height="123"/>
         <image name="xmark" width="24" height="24"/>
         <systemColor name="secondarySystemGroupedBackgroundColor">
             <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

+ 19 - 10
iOSClient/Account Request/NCTalkAccounts.swift

@@ -40,7 +40,7 @@ class NCTalkAccounts: UIViewController {
     @IBOutlet weak var tableView: UITableView!
     @IBOutlet weak var progressView: UIProgressView!
 
-    public var accounts: [[String: String]] = [[:]]
+    public var accounts: [dataAccountFile] = []
     public let heightCell: CGFloat = 60
     public var enableTimerProgress: Bool = true
     public var dismissDidEnterBackground: Bool = true
@@ -161,10 +161,9 @@ extension NCTalkAccounts: UITableViewDelegate {
 
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
 
-        if let account = accounts[indexPath.row].first {
-            dismiss(animated: true) {
-                self.delegate?.selected(url: account.key, user: account.value)
-            }
+        dismiss(animated: true) {
+            let account = self.accounts[indexPath.row]
+            self.delegate?.selected(url: account.url, user: account.user)
         }
     }
 }
@@ -180,17 +179,27 @@ extension NCTalkAccounts: UITableViewDataSource {
         let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
         cell.backgroundColor = tableView.backgroundColor
 
-        let userLabel = cell.viewWithTag(10) as? UILabel
-        let urlLabel = cell.viewWithTag(20) as? UILabel
+        let avatarImage = cell.viewWithTag(10) as? UIImageView
+        let userLabel = cell.viewWithTag(20) as? UILabel
+        let urlLabel = cell.viewWithTag(30) as? UILabel
 
         userLabel?.text = ""
         urlLabel?.text = ""
 
-        if let account = accounts[indexPath.row].first {
-            userLabel?.text = account.value.uppercased()
-            urlLabel?.text = (URL(string: account.key)?.host ?? "")
+        let account = accounts[indexPath.row]
+
+        if let avatarPath = account.avatar, let avatarImage = avatarImage {
+            do {
+                let data = try Data(contentsOf: URL(fileURLWithPath: avatarPath))
+                if let image = UIImage(data: data) {
+                    avatarImage.image = image
+                }
+            } catch { print("Error: \(error)") }
         }
 
+        userLabel?.text = account.user.uppercased()
+        urlLabel?.text = (URL(string: account.url)?.host ?? "")
+
         return cell
     }
 }

+ 8 - 6
iOSClient/Login/NCLogin.swift

@@ -419,13 +419,13 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
         }
     }
 
-    func readTalkAccounts() -> [[String:String]]? {
+    func readTalkAccounts() -> [dataAccountFile]? {
 
         guard let dirGroupTalk = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroupsTalk) else { return nil }
         let url = dirGroupTalk.appendingPathComponent(NCGlobal.shared.appDatabaseTalk + "/" + NCGlobal.shared.fileAccounts)
 
         if FileManager.default.fileExists(atPath: url.path) {
-            return NCUtility.shared.readAccountsFile(at: url)
+            return NCUtility.shared.readDataAccountFile(at: url)
         }
         return nil
     }
@@ -435,13 +435,15 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
         guard let dirGroupTalk = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroupsTalk) else { return nil }
         let url = dirGroupTalk.appendingPathComponent(NCGlobal.shared.appDatabaseTalk + "/" + NCGlobal.shared.fileAccounts)
 
-
         let tableAccount = NCManageDatabase.shared.getAllAccount()
-        var accounts = [[String:String]]()
+        var accounts = [dataAccountFile]()
         for account in tableAccount {
-            accounts.append([account.urlBase:account.user])
+            let userBaseUrl = account.user + "-" + (URL(string: account.urlBase)?.host ?? "")
+            let avatar = String(CCUtility.getDirectoryUserData()) + "/" +  userBaseUrl + "-\(account.user).png"
+            let userData = dataAccountFile(withUrl: account.urlBase, user: account.user, alias: account.alias, avatar: avatar)
+            accounts.append(userData)
         }
-        return NCUtility.shared.createAccountsFile(at: url, accounts: accounts)
+        return NCUtility.shared.createDataAccountFile(at: url, accounts: accounts)
     }
 }
 

+ 18 - 5
iOSClient/Utility/NCUtility.swift

@@ -1075,9 +1075,7 @@ class NCUtility: NSObject {
         return false
     }
 
-    //
-
-    @objc func createAccountsFile(at url: URL, accounts: [[String:String]]) -> Error? {
+    @objc func createDataAccountFile(at url: URL, accounts: [dataAccountFile]) -> Error? {
 
         do {
             let encode = try JSONEncoder().encode(accounts)
@@ -1088,14 +1086,29 @@ class NCUtility: NSObject {
         return nil
     }
 
-    @objc func readAccountsFile(at url: URL) -> [[String:String]]? {
+    @objc func readDataAccountFile(at url: URL) -> [dataAccountFile]? {
 
         do {
             let data = try Data(contentsOf: url)
-            let accounts: [[String:String]] = try JSONDecoder().decode([[String: String]].self, from: data)
+            let accounts: [dataAccountFile] = try JSONDecoder().decode([dataAccountFile].self, from: data)
             return accounts
         } catch {
             return nil
         }
     }
 }
+
+class dataAccountFile: NSObject, Codable {
+
+    @objc var url: String
+    @objc var user: String
+    @objc var alias: String?
+    @objc var avatar: String?
+
+    init(withUrl url: String, user: String, alias: String? = nil, avatar: String? = nil) {
+        self.url = url
+        self.user = user
+        self.alias = alias
+        self.avatar = avatar
+    }
+}