Browse Source

new view share

marinofaggiana 5 years ago
parent
commit
c488dd52b5

+ 8 - 0
iOSClient/Share/NCShare.swift

@@ -159,6 +159,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
     func updateShareWithError(idRemoteShared: Int) { }
 }
 
+// MARK: - UITableViewDelegate
+
 extension NCShare: UITableViewDelegate {
     
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
@@ -166,6 +168,8 @@ extension NCShare: UITableViewDelegate {
     }
 }
 
+// MARK: - UITableViewDataSource
+
 extension NCShare: UITableViewDataSource {
     
     func numberOfSections(in tableView: UITableView) -> Int {
@@ -215,6 +219,8 @@ extension NCShare: UITableViewDataSource {
     }
 }
 
+// MARK: - NCShareLinkCell
+
 class NCShareLinkCell: UITableViewCell {
     
     @IBOutlet weak var imageItem: UIImageView!
@@ -250,6 +256,8 @@ protocol NCShareLinkCellDelegate {
     func tapMenu(with tableShare: tableShare?, sender: Any)
 }
 
+// MARK: - NCShareUserCell
+
 class NCShareUserCell: UITableViewCell {
     
     @IBOutlet weak var imageItem: UIImageView!

+ 1 - 1
iOSClient/Share/NCShareCommon.swift

@@ -103,7 +103,7 @@ class NCShareCommon: NSObject {
         shareUserMenuView.viewWindow = viewWindow
         shareUserMenuView.reloadData(idRemoteShared: tableShare?.idRemoteShared ?? 0)
         let shareUserMenuViewX = view.bounds.width/2 - shareUserMenuView.frame.width/2 + globalPoint!.x
-        let shareUserMenuViewY = globalPoint!.y + 10
+        let shareUserMenuViewY = globalPoint!.y + 100
         
         shareUserMenuView.frame = CGRect(x: shareUserMenuViewX, y: shareUserMenuViewY, width: shareUserMenuView.width, height: shareUserMenuView.height)
         viewWindow.addSubview(shareUserMenuView)

+ 5 - 2
iOSClient/Share/NCShareLinkMenuView.swift

@@ -148,6 +148,8 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         }
     }
     
+    // MARK: - IBAction
+
     // Allow editing
     @IBAction func switchAllowEditingChanged(sender: UISwitch) {
         
@@ -244,7 +246,7 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         networking.share(metadata: metadata!, password: "", permission: 1, hideDownload: false)
     }
     
-    // delegate networking
+    // MARK: - Delegate networking
     
     func readShareCompleted(errorCode: Int) {
         reloadData(idRemoteShared: tableShare?.idRemoteShared ?? 0)
@@ -264,7 +266,8 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         reloadData(idRemoteShared: idRemoteShared)
     }
     
-    // delegate/appearance calendar
+    // MARK: - Delegate calendar
+    
     func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
         
         if monthPosition == .previous || monthPosition == .next {

+ 79 - 1
iOSClient/Share/NCShareUserMenuView.swift

@@ -114,7 +114,49 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         }
     }
     
-    // delegate networking
+    // MARK: - IBAction
+
+    // Set expiration date
+    @IBAction func switchSetExpirationDate(sender: UISwitch) {
+        
+        guard let tableShare = self.tableShare else { return }
+        
+        if sender.isOn {
+            fieldSetExpirationDate.isEnabled = true
+            fieldSetExpirationDate(sender: fieldSetExpirationDate)
+        } else {
+            let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
+            networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: 0, note: nil, expirationTime: "", hideDownload: tableShare.hideDownload)
+        }
+    }
+    
+    @IBAction func fieldSetExpirationDate(sender: UITextField) {
+        
+        let calendar = NCShareCommon.sharedInstance.openCalendar(view: self, width: width, height: height)
+        calendar.calendarView.delegate = self
+        viewWindowCalendar = calendar.viewWindow
+    }
+    
+    // Note to recipient
+    @IBAction func fieldNoteToRecipientDidEndOnExit(textField: UITextField) {
+        
+        guard let tableShare = self.tableShare else { return }
+        if fieldNoteToRecipient.text == nil { return }
+        
+        let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
+        networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: 0, note: fieldNoteToRecipient.text, expirationTime: nil, hideDownload: tableShare.hideDownload)
+    }
+    
+    // Unshare
+    @IBAction func buttonUnshare(sender: UIButton) {
+        
+        guard let tableShare = self.tableShare else { return }
+        let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
+        
+        networking.unShare(idRemoteShared: tableShare.idRemoteShared)
+    }
+    
+    // MARK: - Delegate networking
     
     func readShareCompleted(errorCode: Int) {
         reloadData(idRemoteShared: tableShare?.idRemoteShared ?? 0)
@@ -133,4 +175,40 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
     func updateShareWithError(idRemoteShared: Int) {
         reloadData(idRemoteShared: idRemoteShared)
     }
+    
+    // MARK: - Delegate calendar
+
+    func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
+        
+        if monthPosition == .previous || monthPosition == .next {
+            calendar.setCurrentPage(date, animated: true)
+        } else {
+            let dateFormatter = DateFormatter()
+            dateFormatter.formatterBehavior = .behavior10_4
+            dateFormatter.dateStyle = .medium
+            fieldSetExpirationDate.text = dateFormatter.string(from:date)
+            fieldSetExpirationDate.endEditing(true)
+            
+            viewWindowCalendar?.removeFromSuperview()
+            
+            guard let tableShare = self.tableShare else { return }
+            
+            let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
+            dateFormatter.dateFormat = "YYYY-MM-dd"
+            let expirationTime = dateFormatter.string(from: date)
+            networking.updateShare(idRemoteShared: tableShare.idRemoteShared, password: nil, permission: 0, note: nil, expirationTime: expirationTime, hideDownload: tableShare.hideDownload)
+        }
+    }
+    
+    func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
+        return date > Date()
+    }
+    
+    func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, titleDefaultColorFor date: Date) -> UIColor? {
+        if date > Date() {
+            return UIColor(red: 60/255, green: 60/255, blue: 60/255, alpha: 1)
+        } else {
+            return UIColor(red: 190/255, green: 190/255, blue: 190/255, alpha: 1)
+        }
+    }
 }

+ 12 - 0
iOSClient/Share/NCShareUserMenuView.xib

@@ -29,6 +29,9 @@
                 </label>
                 <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="dB8-1M-WZr">
                     <rect key="frame" x="10" y="61" width="51" height="31"/>
+                    <connections>
+                        <action selector="switchSetExpirationDateWithSender:" destination="iN0-l3-epB" eventType="valueChanged" id="A9c-YF-bXd"/>
+                    </connections>
                 </switch>
                 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Set expiration date" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qll-9F-4DA">
                     <rect key="frame" x="70" y="69" width="240" height="15"/>
@@ -47,6 +50,9 @@
                     <nil key="textColor"/>
                     <fontDescription key="fontDescription" type="system" pointSize="13"/>
                     <textInputTraits key="textInputTraits"/>
+                    <connections>
+                        <action selector="fieldSetExpirationDateWithSender:" destination="iN0-l3-epB" eventType="editingDidEndOnExit" id="WdF-Ie-Di0"/>
+                    </connections>
                 </textField>
                 <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="file_txt" translatesAutoresizingMaskIntoConstraints="NO" id="F4T-wQ-tBU">
                     <rect key="frame" x="13" y="144" width="25" height="25"/>
@@ -69,6 +75,9 @@
                     <nil key="textColor"/>
                     <fontDescription key="fontDescription" type="system" pointSize="14"/>
                     <textInputTraits key="textInputTraits"/>
+                    <connections>
+                        <action selector="fieldNoteToRecipientDidEndOnExitWithTextField:" destination="iN0-l3-epB" eventType="editingDidEndOnExit" id="q1P-u7-EBw"/>
+                    </connections>
                 </textField>
                 <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="trash" translatesAutoresizingMaskIntoConstraints="NO" id="hr8-Qe-xD0" userLabel="Image Delete Share Link">
                     <rect key="frame" x="13" y="224" width="25" height="25"/>
@@ -91,6 +100,9 @@
                     <constraints>
                         <constraint firstAttribute="height" constant="25" id="fWP-XF-kQx"/>
                     </constraints>
+                    <connections>
+                        <action selector="buttonUnshareWithSender:" destination="iN0-l3-epB" eventType="touchUpInside" id="Nky-nT-rCz"/>
+                    </connections>
                 </button>
             </subviews>
             <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>