Browse Source

Fix share permission safe area

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
37e425504d

+ 0 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -65,7 +65,6 @@
 		AF93471D27E2361E002537EE /* NCShareAdvancePermissionFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF93471827E2361E002537EE /* NCShareAdvancePermissionFooter.swift */; };
 		AF93474C27E34120002537EE /* NCUtility+Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF93474B27E34120002537EE /* NCUtility+Image.swift */; };
 		AF93474E27E3F212002537EE /* NCShareNewUserAddComment.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF93474D27E3F211002537EE /* NCShareNewUserAddComment.swift */; };
-		AF93475027E46B2E002537EE /* XibView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF93474F27E46B2E002537EE /* XibView.swift */; };
 		AF935067276B84E700BD078F /* NCMenu+FloatingPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF935066276B84E700BD078F /* NCMenu+FloatingPanel.swift */; };
 		AFA2AC8527849604008E1EA7 /* NCActivityCommentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA2AC8427849604008E1EA7 /* NCActivityCommentView.swift */; };
 		AFD33240276A02C100F5AE02 /* UIApplication+Orientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFD3323F276A02C000F5AE02 /* UIApplication+Orientation.swift */; };
@@ -520,7 +519,6 @@
 		AF93471827E2361E002537EE /* NCShareAdvancePermissionFooter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCShareAdvancePermissionFooter.swift; sourceTree = "<group>"; };
 		AF93474B27E34120002537EE /* NCUtility+Image.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCUtility+Image.swift"; sourceTree = "<group>"; };
 		AF93474D27E3F211002537EE /* NCShareNewUserAddComment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCShareNewUserAddComment.swift; sourceTree = "<group>"; };
-		AF93474F27E46B2E002537EE /* XibView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XibView.swift; sourceTree = "<group>"; };
 		AF935066276B84E700BD078F /* NCMenu+FloatingPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMenu+FloatingPanel.swift"; sourceTree = "<group>"; };
 		AFA2AC8427849604008E1EA7 /* NCActivityCommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityCommentView.swift; sourceTree = "<group>"; };
 		AFD3323F276A02C000F5AE02 /* UIApplication+Orientation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+Orientation.swift"; sourceTree = "<group>"; };
@@ -1075,7 +1073,6 @@
 				AF93471427E2361E002537EE /* NCShareAdvancePermissionFooter.xib */,
 				AF93474D27E3F211002537EE /* NCShareNewUserAddComment.swift */,
 				AF93471527E2361E002537EE /* NCShareAdvancePermissionHeader.swift */,
-				AF93474F27E46B2E002537EE /* XibView.swift */,
 				AF93471727E2361E002537EE /* NCShareAdvancePermissionHeader.xib */,
 			);
 			path = Advanced;
@@ -2559,7 +2556,6 @@
 				F78A18B623CDD07D00F681F3 /* NCViewerRichWorkspaceWebView.swift in Sources */,
 				AFA2AC8527849604008E1EA7 /* NCActivityCommentView.swift in Sources */,
 				F716B75F26F09DF600D37EFC /* NCKTVHTTPCache.swift in Sources */,
-				AF93475027E46B2E002537EE /* XibView.swift in Sources */,
 				AF36077127BFA4E8001A243D /* ParallelWorker.swift in Sources */,
 				F75A9EE623796C6F0044CFCE /* NCNetworking.swift in Sources */,
 				F758B460212C56A400515F55 /* NCScan.swift in Sources */,

+ 28 - 11
iOSClient/Share/Advanced/NCShareAdvancePermission.swift

@@ -31,7 +31,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
         defer { navigationController?.popViewController(animated: true) }
         guard shouldSave else { return }
         if NCManageDatabase.shared.getTableShare(account: share.account, idShare: share.idShare) == nil {
-            networking?.createShare(option: share, metadata: metadata)
+            networking?.createShare(option: share)
         } else {
             networking?.updateShare(option: share)
         }
@@ -76,7 +76,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg
         tableView.tableHeaderView = headerView
         headerView.translatesAutoresizingMaskIntoConstraints = false
         headerView.heightAnchor.constraint(equalToConstant: 200).isActive = true
-        headerView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
+        headerView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor).isActive = true
     }
 
     override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
@@ -392,20 +392,15 @@ open class DatePickerTableViewCell: UITableViewCell {
         }
         accessoryView = textField
 
-        let toolbar = UIToolbar()
-        toolbar.sizeToFit()
-        let doneButton = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: .done) {
+        let toolbar = UIToolbar.toolbar {
             self.resignFirstResponder()
-            share.expirationDate = self.picker.date as NSDate
+            share.expirationDate = nil
             self.onReload?()
-        }
-        let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
-        let cancelButton = UIBarButtonItem(title: NSLocalizedString("_clear_", comment: ""), style: .plain) {
+        } completion: {
             self.resignFirstResponder()
-            share.expirationDate = nil
+            share.expirationDate = self.picker.date as NSDate
             self.onReload?()
         }
-        toolbar.setItems([cancelButton, spaceButton, doneButton], animated: false)
 
         textField.inputAccessoryView = toolbar
         textField.inputView = picker
@@ -419,3 +414,25 @@ open class DatePickerTableViewCell: UITableViewCell {
         fatalError("init(coder:) has not been implemented")
     }
 }
+
+extension UIToolbar {
+    static func toolbar(onClear: (() -> Void)?, completion: @escaping () -> Void) -> UIToolbar {
+        let toolbar = UIToolbar()
+        toolbar.sizeToFit()
+        var buttons: [UIBarButtonItem] = []
+        let doneButton = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: .done) {
+            completion()
+        }
+        buttons.append(doneButton)
+
+        if let onClear = onClear {
+            let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
+            let clearButton = UIBarButtonItem(title: NSLocalizedString("_clear_", comment: ""), style: .plain) {
+                onClear()
+            }
+            buttons.append(contentsOf: [spaceButton, clearButton])
+        }
+        toolbar.setItems(buttons, animated: false)
+        return toolbar
+    }
+}

+ 3 - 3
iOSClient/Share/Advanced/NCShareAdvancePermissionHeader.xib

@@ -51,14 +51,14 @@
             <viewLayoutGuide key="safeArea" id="KLE-vd-Dsn"/>
             <constraints>
                 <constraint firstAttribute="trailing" secondItem="VaC-Fz-kHk" secondAttribute="trailing" constant="15" id="Ebg-3T-03W"/>
-                <constraint firstItem="Dkw-QP-be6" firstAttribute="leading" secondItem="wbW-yR-MZC" secondAttribute="leading" constant="16" id="KPc-al-RWN"/>
+                <constraint firstItem="Dkw-QP-be6" firstAttribute="leading" secondItem="KLE-vd-Dsn" secondAttribute="leading" constant="16" id="KPc-al-RWN"/>
                 <constraint firstItem="KLE-vd-Dsn" firstAttribute="top" secondItem="cki-Ql-o1I" secondAttribute="top" id="KsC-jf-M6F"/>
-                <constraint firstItem="bm4-az-bTg" firstAttribute="leading" secondItem="wbW-yR-MZC" secondAttribute="leading" constant="16" id="NgP-e4-owx"/>
+                <constraint firstItem="bm4-az-bTg" firstAttribute="leading" secondItem="KLE-vd-Dsn" secondAttribute="leading" constant="16" id="NgP-e4-owx"/>
                 <constraint firstItem="pu4-Nd-M08" firstAttribute="centerY" secondItem="bm4-az-bTg" secondAttribute="centerY" id="Pt7-LW-9Yv"/>
                 <constraint firstItem="pu4-Nd-M08" firstAttribute="leading" secondItem="bm4-az-bTg" secondAttribute="trailing" constant="8" id="TXl-5L-34h"/>
                 <constraint firstAttribute="trailing" secondItem="cki-Ql-o1I" secondAttribute="trailing" id="Wdl-Rb-Pjy"/>
                 <constraint firstItem="VaC-Fz-kHk" firstAttribute="leading" secondItem="pu4-Nd-M08" secondAttribute="leading" id="Ycb-wy-uL6"/>
-                <constraint firstItem="cki-Ql-o1I" firstAttribute="leading" secondItem="wbW-yR-MZC" secondAttribute="leading" id="ZlH-LU-x2x"/>
+                <constraint firstItem="cki-Ql-o1I" firstAttribute="leading" secondItem="KLE-vd-Dsn" secondAttribute="leading" id="ZlH-LU-x2x"/>
                 <constraint firstItem="Dkw-QP-be6" firstAttribute="centerY" secondItem="cki-Ql-o1I" secondAttribute="centerY" id="dME-jJ-PwO"/>
                 <constraint firstAttribute="trailing" secondItem="pu4-Nd-M08" secondAttribute="trailing" constant="15" id="rFa-oW-WgO"/>
                 <constraint firstItem="bm4-az-bTg" firstAttribute="top" secondItem="cki-Ql-o1I" secondAttribute="bottom" constant="5" id="tUq-fs-PhE"/>

+ 13 - 7
iOSClient/Share/Advanced/NCShareNewUserAddComment.swift

@@ -11,13 +11,14 @@ import UIKit
 import NCCommunication
 import SVGKit
 
-class NCShareNewUserAddComment: UIViewController, UITextViewDelegate, NCShareDetail {
+class NCShareNewUserAddComment: UIViewController, NCShareDetail {
 
     @IBOutlet weak var headerContainerView: UIView!
     @IBOutlet weak var sharingLabel: UILabel!
     @IBOutlet weak var sharingNote: UILabel!
     @IBOutlet weak var noteTextField: UITextView!
 
+    let contentInsets: CGFloat = 16
     var onDismiss: (() -> Void)?
 
     public var share: TableShareable!
@@ -40,13 +41,18 @@ class NCShareNewUserAddComment: UIViewController, UITextViewDelegate, NCShareDet
         sharingLabel.text = NSLocalizedString("_sharing_", comment: "")
         sharingNote.text = NSLocalizedString("_share_note_recipient_", comment: "")
 
+        noteTextField.textContainerInset = UIEdgeInsets(top: contentInsets, left: contentInsets, bottom: contentInsets, right: contentInsets)
         noteTextField.text = share.note
-        noteTextField.delegate = self
-    }
-
-    func textViewDidEndEditing(_ textView: UITextView) {
-        print(#function)
-//        share.note = noteTextField.text
+        let toolbar = UIToolbar.toolbar {
+            self.noteTextField.resignFirstResponder()
+            self.noteTextField.text = ""
+            self.share.note = ""
+        } completion: {
+            self.noteTextField.resignFirstResponder()
+            self.share.note = self.noteTextField.text
+        }
+
+        noteTextField.inputAccessoryView = toolbar
     }
 
     override func viewWillDisappear(_ animated: Bool) {

+ 23 - 25
iOSClient/Share/NCShare.storyboard

@@ -173,27 +173,22 @@
                                         <color key="textColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
                                         <nil key="highlightedColor"/>
                                     </label>
-                                    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hgf-O1-P97">
-                                        <rect key="frame" x="16" y="90.333333333333286" width="382" height="409.66666666666674"/>
-                                        <subviews>
-                                            <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" canCancelContentTouches="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="VT0-1l-5HI">
-                                                <rect key="frame" x="16" y="16" width="350" height="377.66666666666669"/>
-                                                <color key="textColor" systemColor="labelColor"/>
-                                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
-                                                <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
-                                                <connections>
-                                                    <outlet property="delegate" destination="VvU-6J-pzy" id="cAt-UZ-6KT"/>
-                                                </connections>
-                                            </textView>
-                                        </subviews>
-                                        <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
-                                        <constraints>
-                                            <constraint firstItem="VT0-1l-5HI" firstAttribute="top" secondItem="hgf-O1-P97" secondAttribute="top" constant="16" id="cc9-jI-nSo"/>
-                                            <constraint firstItem="VT0-1l-5HI" firstAttribute="centerX" secondItem="hgf-O1-P97" secondAttribute="centerX" id="cj9-1W-zVt"/>
-                                            <constraint firstItem="VT0-1l-5HI" firstAttribute="leading" secondItem="hgf-O1-P97" secondAttribute="leading" constant="16" id="gE6-6y-BzR"/>
-                                            <constraint firstItem="VT0-1l-5HI" firstAttribute="centerY" secondItem="hgf-O1-P97" secondAttribute="centerY" id="u80-BU-AcP"/>
-                                        </constraints>
-                                    </view>
+                                    <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" canCancelContentTouches="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="VT0-1l-5HI">
+                                        <rect key="frame" x="16" y="106.33333333333329" width="382" height="377.66666666666674"/>
+                                        <color key="backgroundColor" systemColor="secondarySystemBackgroundColor"/>
+                                        <inset key="scrollIndicatorInsets" minX="0.0" minY="0.0" maxX="10" maxY="0.0"/>
+                                        <color key="textColor" systemColor="labelColor"/>
+                                        <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                        <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
+                                        <userDefinedRuntimeAttributes>
+                                            <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                                <integer key="value" value="10"/>
+                                            </userDefinedRuntimeAttribute>
+                                        </userDefinedRuntimeAttributes>
+                                        <connections>
+                                            <outlet property="delegate" destination="VvU-6J-pzy" id="cAt-UZ-6KT"/>
+                                        </connections>
+                                    </textView>
                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Sharing" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vkm-Pe-6qd">
                                         <rect key="frame" x="16.000000000000004" y="24" width="61.333333333333343" height="20.333333333333329"/>
                                         <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="17"/>
@@ -203,14 +198,14 @@
                                 </subviews>
                                 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                 <constraints>
-                                    <constraint firstAttribute="trailing" secondItem="hgf-O1-P97" secondAttribute="trailing" constant="16" id="3wR-ue-mj3"/>
                                     <constraint firstItem="3yF-lL-GwU" firstAttribute="leading" secondItem="YMG-hf-HEX" secondAttribute="leading" constant="16" id="3yQ-Gl-Co9"/>
                                     <constraint firstItem="vkm-Pe-6qd" firstAttribute="leading" secondItem="YMG-hf-HEX" secondAttribute="leading" constant="16" id="Auk-mC-Mie"/>
+                                    <constraint firstItem="VT0-1l-5HI" firstAttribute="top" secondItem="3yF-lL-GwU" secondAttribute="bottom" constant="31.999999999999972" id="EpF-os-G1u"/>
+                                    <constraint firstAttribute="bottom" secondItem="VT0-1l-5HI" secondAttribute="bottom" constant="52" id="FYk-Lv-5f6"/>
                                     <constraint firstItem="vkm-Pe-6qd" firstAttribute="top" secondItem="YMG-hf-HEX" secondAttribute="top" constant="24" id="L0w-Cz-uK2"/>
-                                    <constraint firstItem="hgf-O1-P97" firstAttribute="leading" secondItem="YMG-hf-HEX" secondAttribute="leading" constant="16" id="lWp-4v-Apf"/>
-                                    <constraint firstAttribute="bottom" secondItem="hgf-O1-P97" secondAttribute="bottom" constant="36" id="ozS-dU-DSE"/>
+                                    <constraint firstAttribute="trailing" secondItem="VT0-1l-5HI" secondAttribute="trailing" constant="16" id="TgX-1J-iTO"/>
+                                    <constraint firstItem="VT0-1l-5HI" firstAttribute="leading" secondItem="YMG-hf-HEX" secondAttribute="leading" constant="16" id="gEq-qv-UTR"/>
                                     <constraint firstItem="3yF-lL-GwU" firstAttribute="top" secondItem="vkm-Pe-6qd" secondAttribute="bottom" constant="12" id="qtk-si-To3"/>
-                                    <constraint firstItem="hgf-O1-P97" firstAttribute="top" secondItem="3yF-lL-GwU" secondAttribute="bottom" constant="16" id="wXC-X4-cnJ"/>
                                 </constraints>
                             </view>
                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qVy-Qr-W7j">
@@ -284,6 +279,9 @@
         <systemColor name="labelColor">
             <color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
         </systemColor>
+        <systemColor name="secondarySystemBackgroundColor">
+            <color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+        </systemColor>
         <systemColor name="systemBackgroundColor">
             <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
         </systemColor>

+ 4 - 16
iOSClient/Share/NCShareNetworking.swift

@@ -62,23 +62,11 @@ class NCShareNetworking: NSObject {
             self.delegate?.readShareCompleted()
         }
     }
-
-    func createShareLink(password: String?) {
-        NCUtility.shared.startActivityIndicator(backgroundView: view, blurEffect: false)
-        let filenamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: urlBase, account: metadata.account)!
-        NCCommunication.shared.createShareLink(path: filenamePath, password: password) { account, share, errorCode, errorDescription in
-            NCUtility.shared.stopActivityIndicator()
-            if errorCode == 0 && share != nil {
-                NCManageDatabase.shared.addShare(urlBase: self.urlBase, account: self.metadata.account, shares: [share!])
-                self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: self.metadata.account)
-            } else if errorCode != 0 {
-                NCContentPresenter.shared.messageNotification("_share_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorInternalError)
-            }
-            self.delegate?.shareCompleted()
-        }
-    }
     
-    func createShare(option: TableShareable, metadata: tableMetadata) {
+    func createShare(option: TableShareable) {
+        // NOTE: Permissions don't work for file drop!
+        // https://github.com/nextcloud/server/issues/17504
+
         NCUtility.shared.startActivityIndicator(backgroundView: view, blurEffect: false)
         let filenamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: urlBase, account: metadata.account)!
         let permission = max(1, metadata.sharePermissionsCollaborationServices & option.permissions)