Browse Source

Add request account

marinofaggiana 4 years ago
parent
commit
af6846e0b9

+ 1 - 1
iOSClient/AppDelegate.swift

@@ -618,7 +618,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                
                 vcAccountRequest.accounts = accounts
                 
-                let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: 360)
+                let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: 310)
                 popup.backgroundAlpha = 0.8
                              
                 UIApplication.shared.keyWindow?.rootViewController?.present(popup, animated: true)

+ 1 - 1
iOSClient/Data/NCManageDatabase.swift

@@ -376,7 +376,7 @@ class NCManageDatabase: NSObject {
         
         let realm = try! Realm()
         
-        let results = realm.objects(tableAccount.self)
+        let results = realm.objects(tableAccount.self).sorted(byKeyPath: "active", ascending: false)
         
         return Array(results.map { tableAccount.init(value:$0) })
     }

+ 15 - 0
iOSClient/Images.xcassets/check.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "filename" : "check.svg",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

+ 1 - 0
iOSClient/Images.xcassets/check.imageset/check.svg

@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" /></svg>

+ 64 - 21
iOSClient/Main/Account Request/NCAccountRequest.storyboard

@@ -1,10 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="V0q-CP-xMJ">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="V0q-CP-xMJ">
     <device id="retina6_1" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
-        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
@@ -13,8 +12,12 @@
         <scene sceneID="L90-uG-f4z">
             <objects>
                 <viewController id="V0q-CP-xMJ" customClass="NCAccountRequest" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
+                    <layoutGuides>
+                        <viewControllerLayoutGuide type="top" id="4vK-ua-S0e"/>
+                        <viewControllerLayoutGuide type="bottom" id="hTI-Bw-Fws"/>
+                    </layoutGuides>
                     <view key="view" contentMode="scaleToFill" id="gzh-6E-hc4">
-                        <rect key="frame" x="0.0" y="0.0" width="300" height="400"/>
+                        <rect key="frame" x="0.0" y="0.0" width="300" height="350"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ouH-gK-Guv" userLabel="Separator">
@@ -31,7 +34,7 @@
                                 <nil key="highlightedColor"/>
                             </label>
                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="W5y-aT-UlI">
-                                <rect key="frame" x="100" y="333" width="100" height="30"/>
+                                <rect key="frame" x="100" y="308" width="100" height="30"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="30" id="APQ-0x-b1G"/>
                                     <constraint firstAttribute="width" constant="100" id="Amv-Gj-xDj"/>
@@ -43,44 +46,84 @@
                                 </connections>
                             </button>
                             <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Pdo-MB-AhU">
-                                <rect key="frame" x="10" y="113" width="280" height="200"/>
+                                <rect key="frame" x="10" y="113" width="280" height="180"/>
                                 <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                                 <constraints>
-                                    <constraint firstAttribute="height" constant="200" id="ZUy-pC-C0i"/>
+                                    <constraint firstAttribute="height" constant="180" id="ZUy-pC-C0i"/>
                                 </constraints>
+                                <prototypes>
+                                    <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="cell" rowHeight="43.5" id="Q4K-la-J3W">
+                                        <rect key="frame" x="0.0" y="28" width="280" height="43.5"/>
+                                        <autoresizingMask key="autoresizingMask"/>
+                                        <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Q4K-la-J3W" id="IkA-cK-iZV">
+                                            <rect key="frame" x="0.0" y="0.0" width="280" height="43.5"/>
+                                            <autoresizingMask key="autoresizingMask"/>
+                                            <subviews>
+                                                <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="5" y="7" width="30" height="30"/>
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="30" id="Efd-BU-u61"/>
+                                                        <constraint firstAttribute="width" constant="30" id="qFy-Tu-ov6"/>
+                                                    </constraints>
+                                                </imageView>
+                                                <label opaque="NO" userInteractionEnabled="NO" tag="20" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pWI-iZ-BTy" userLabel="Account">
+                                                    <rect key="frame" x="40" y="14.5" width="210" height="14.5"/>
+                                                    <fontDescription key="fontDescription" type="system" pointSize="12"/>
+                                                    <nil key="textColor"/>
+                                                    <nil key="highlightedColor"/>
+                                                </label>
+                                                <imageView clipsSubviews="YES" userInteractionEnabled="NO" tag="30" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="x47-dQ-alI" userLabel="Active">
+                                                    <rect key="frame" x="255" y="12" width="20" height="20"/>
+                                                    <constraints>
+                                                        <constraint firstAttribute="height" constant="20" id="SXt-LG-c5N"/>
+                                                        <constraint firstAttribute="width" constant="20" id="vdZ-4R-gY5"/>
+                                                    </constraints>
+                                                </imageView>
+                                            </subviews>
+                                            <constraints>
+                                                <constraint firstItem="4cH-oC-YBd" firstAttribute="leading" secondItem="IkA-cK-iZV" secondAttribute="leading" constant="5" id="3cz-yE-yoQ"/>
+                                                <constraint firstAttribute="trailing" secondItem="x47-dQ-alI" secondAttribute="trailing" constant="5" id="Dna-rj-LLQ"/>
+                                                <constraint firstItem="x47-dQ-alI" firstAttribute="centerY" secondItem="IkA-cK-iZV" secondAttribute="centerY" id="Ghs-sZ-Bzf"/>
+                                                <constraint firstItem="pWI-iZ-BTy" firstAttribute="centerY" secondItem="IkA-cK-iZV" secondAttribute="centerY" id="TaB-23-hA1"/>
+                                                <constraint firstItem="4cH-oC-YBd" firstAttribute="centerY" secondItem="IkA-cK-iZV" secondAttribute="centerY" id="WuT-iT-3xk"/>
+                                                <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="leading" secondItem="4cH-oC-YBd" secondAttribute="trailing" constant="5" id="mlI-8s-1Ae"/>
+                                            </constraints>
+                                        </tableViewCellContentView>
+                                    </tableViewCell>
+                                </prototypes>
                                 <connections>
                                     <outlet property="dataSource" destination="V0q-CP-xMJ" id="xmA-NY-Eyz"/>
                                     <outlet property="delegate" destination="V0q-CP-xMJ" id="j64-3x-N2u"/>
                                 </connections>
                             </tableView>
                             <progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="e8R-j7-ObS">
-                                <rect key="frame" x="0.0" y="398" width="300" height="2"/>
+                                <rect key="frame" x="0.0" y="348" width="300" height="2"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="2" id="G3U-2x-imL"/>
                                 </constraints>
                             </progressView>
                         </subviews>
-                        <viewLayoutGuide key="safeArea" id="1c1-7Q-WMG"/>
                         <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                         <constraints>
-                            <constraint firstItem="e8R-j7-ObS" firstAttribute="leading" secondItem="1c1-7Q-WMG" secondAttribute="leading" id="1gS-Ca-1Ov"/>
-                            <constraint firstItem="1c1-7Q-WMG" firstAttribute="trailing" secondItem="Pdo-MB-AhU" secondAttribute="trailing" constant="10" id="819-yV-vz7"/>
-                            <constraint firstItem="ouH-gK-Guv" firstAttribute="leading" secondItem="1c1-7Q-WMG" secondAttribute="leading" id="A6T-ed-97T"/>
-                            <constraint firstItem="1c1-7Q-WMG" firstAttribute="bottom" secondItem="e8R-j7-ObS" secondAttribute="bottom" id="Cko-PC-TiW"/>
-                            <constraint firstItem="1c1-7Q-WMG" firstAttribute="trailing" secondItem="nZr-nE-ths" secondAttribute="trailing" constant="20" id="DPW-MV-oKc"/>
+                            <constraint firstItem="e8R-j7-ObS" firstAttribute="leading" secondItem="gzh-6E-hc4" secondAttribute="leading" id="1gS-Ca-1Ov"/>
+                            <constraint firstAttribute="trailing" secondItem="Pdo-MB-AhU" secondAttribute="trailing" constant="10" id="819-yV-vz7"/>
+                            <constraint firstItem="ouH-gK-Guv" firstAttribute="leading" secondItem="gzh-6E-hc4" secondAttribute="leading" id="A6T-ed-97T"/>
+                            <constraint firstItem="hTI-Bw-Fws" firstAttribute="top" secondItem="e8R-j7-ObS" secondAttribute="bottom" id="Cko-PC-TiW"/>
+                            <constraint firstAttribute="trailing" secondItem="nZr-nE-ths" secondAttribute="trailing" constant="20" id="DPW-MV-oKc"/>
                             <constraint firstItem="Pdo-MB-AhU" firstAttribute="top" secondItem="ouH-gK-Guv" secondAttribute="bottom" constant="10" id="HnJ-03-7W5"/>
-                            <constraint firstItem="nZr-nE-ths" firstAttribute="leading" secondItem="1c1-7Q-WMG" secondAttribute="leading" constant="20" id="SI9-xL-6s8"/>
-                            <constraint firstItem="Pdo-MB-AhU" firstAttribute="leading" secondItem="1c1-7Q-WMG" secondAttribute="leading" constant="10" id="Y5n-ju-hts"/>
-                            <constraint firstItem="1c1-7Q-WMG" firstAttribute="trailing" secondItem="e8R-j7-ObS" secondAttribute="trailing" id="chh-t9-vJN"/>
-                            <constraint firstItem="W5y-aT-UlI" firstAttribute="centerX" secondItem="1c1-7Q-WMG" secondAttribute="centerX" id="nhM-cg-paa"/>
-                            <constraint firstItem="nZr-nE-ths" firstAttribute="top" secondItem="1c1-7Q-WMG" secondAttribute="top" constant="20" id="oyJ-sj-j5N"/>
-                            <constraint firstItem="W5y-aT-UlI" firstAttribute="top" secondItem="Pdo-MB-AhU" secondAttribute="bottom" constant="20" id="pfI-HG-ci4"/>
-                            <constraint firstItem="1c1-7Q-WMG" firstAttribute="trailing" secondItem="ouH-gK-Guv" secondAttribute="trailing" id="r1N-R6-iZg"/>
+                            <constraint firstItem="nZr-nE-ths" firstAttribute="leading" secondItem="gzh-6E-hc4" secondAttribute="leading" constant="20" id="SI9-xL-6s8"/>
+                            <constraint firstItem="Pdo-MB-AhU" firstAttribute="leading" secondItem="gzh-6E-hc4" secondAttribute="leading" constant="10" id="Y5n-ju-hts"/>
+                            <constraint firstAttribute="trailing" secondItem="e8R-j7-ObS" secondAttribute="trailing" id="chh-t9-vJN"/>
+                            <constraint firstItem="W5y-aT-UlI" firstAttribute="centerX" secondItem="gzh-6E-hc4" secondAttribute="centerX" id="nhM-cg-paa"/>
+                            <constraint firstItem="nZr-nE-ths" firstAttribute="top" secondItem="4vK-ua-S0e" secondAttribute="bottom" constant="20" id="oyJ-sj-j5N"/>
+                            <constraint firstItem="W5y-aT-UlI" firstAttribute="top" secondItem="Pdo-MB-AhU" secondAttribute="bottom" constant="15" id="pfI-HG-ci4"/>
+                            <constraint firstAttribute="trailing" secondItem="ouH-gK-Guv" secondAttribute="trailing" id="r1N-R6-iZg"/>
                             <constraint firstItem="ouH-gK-Guv" firstAttribute="top" secondItem="nZr-nE-ths" secondAttribute="bottom" constant="20" id="yuT-iN-zVv"/>
                         </constraints>
                     </view>
                     <navigationItem key="navigationItem" id="Zon-2j-rsc"/>
-                    <size key="freeformSize" width="300" height="400"/>
+                    <size key="freeformSize" width="300" height="350"/>
                     <connections>
                         <outlet property="okButton" destination="W5y-aT-UlI" id="59a-ck-kGF"/>
                         <outlet property="progressView" destination="e8R-j7-ObS" id="2gM-MB-IhE"/>

+ 67 - 7
iOSClient/Main/Account Request/NCAccountRequest.swift

@@ -35,6 +35,7 @@ class NCAccountRequest: UIViewController {
     
     private var timer: Timer?
     private var time: Float = 0
+    private let secondsAutoDismiss: Float = 3
     
     // MARK: - Life Cycle
     
@@ -43,6 +44,8 @@ class NCAccountRequest: UIViewController {
         
         titleLabel.text = NSLocalizedString("_account_request_", comment: "")
         
+        tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1))
+
         okButton.setTitle(NSLocalizedString("_ok_", comment: ""), for: .normal)
         okButton.setTitleColor(NCBrandColor.shared.brandText, for: .normal)
         okButton.layer.cornerRadius = 15
@@ -66,11 +69,15 @@ class NCAccountRequest: UIViewController {
     
     override func viewWillDisappear(_ animated: Bool) {
         super.viewWillDisappear(animated)
+        
+        timer?.invalidate()
     }
-     
+
     // MARK: - Progress
     
     @objc func startTimer() {
+        time = 0
+        timer?.invalidate()
         timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(updateProgress), userInfo: nil, repeats: true)
     }
     
@@ -78,11 +85,10 @@ class NCAccountRequest: UIViewController {
         
         time += 0.1
         
-        if time >= 3 {
-            timer?.invalidate()
+        if time >= secondsAutoDismiss {
             dismiss(animated: true)
         } else {
-            progressView.progress = 1 - (time / 3)
+            progressView.progress = 1 - (time / secondsAutoDismiss)
         }
     }
     
@@ -95,14 +101,68 @@ class NCAccountRequest: UIViewController {
 
 extension NCAccountRequest: UITableViewDelegate {
     
+    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
+        timer?.invalidate()
+        progressView.progress = 1
+    }
+    
+    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
+        if decelerate {
+            startTimer()
+        }
+    }
+    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
+        startTimer()
+    }
 }
 
 extension NCAccountRequest: UITableViewDataSource {
+    
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        0
+        return accounts.count
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        return UITableViewCell()
-    }    
+       
+        let account = accounts[indexPath.row]
+        var avatar = UIImage(named: "avatarCredentials")
+        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
+        cell.tintColor = NCBrandColor.shared.customer
+       
+        let avatarImage = cell.viewWithTag(10) as? UIImageView
+        let accountLabel = cell.viewWithTag(20) as? UILabel
+        let activeImage = cell.viewWithTag(30) as? UIImageView
+        
+        avatarImage?.image = UIImage(named: "avatarCredentials")
+        avatarImage?.image = UIImage(named: "avatarCredentials")
+        
+        var fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(account.user, urlBase: account.urlBase) + "-" + account.user
+        fileNamePath = fileNamePath + ".png"
+
+        if var userImage = UIImage(contentsOfFile: fileNamePath) {
+            userImage = userImage.resizeImage(size: CGSize(width: 50, height: 50), isAspectRation: true)!
+            let userImageView = UIImageView(image: userImage)
+            userImageView.avatar(roundness: 2, borderWidth: 1, borderColor: NCBrandColor.shared.avatarBorder, backgroundColor: .clear)
+            UIGraphicsBeginImageContext(userImageView.bounds.size)
+            userImageView.layer.render(in: UIGraphicsGetCurrentContext()!)
+            if let newAvatar = UIGraphicsGetImageFromCurrentImageContext() {
+                avatar = newAvatar
+            }
+            UIGraphicsEndImageContext()
+        }
+        
+        avatarImage?.image = avatar
+        accountLabel?.text = account.user + " " + (URL(string: account.urlBase)?.host ?? "")
+        if account.active {
+            activeImage?.image = UIImage(named: "check")
+        } else {
+            activeImage?.image = nil
+        }
+
+        return cell
+    }
+    
+    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        dismiss(animated: true)
+    }
 }