Browse Source

new view share

marinofaggiana 5 years ago
parent
commit
d9453366c3

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

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

BIN
iOSClient/Images.xcassets/shareAdd.imageset/shareAdd.pdf


+ 25 - 10
iOSClient/Share/NCShare.storyboard

@@ -99,20 +99,31 @@
                                         </constraints>
                                     </imageView>
                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Share link" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SQW-aQ-ydN">
-                                        <rect key="frame" x="53" y="75" width="286" height="18"/>
+                                        <rect key="frame" x="53" y="75" width="276" height="18"/>
                                         <fontDescription key="fontDescription" type="system" pointSize="15"/>
                                         <nil key="textColor"/>
                                         <nil key="highlightedColor"/>
                                     </label>
-                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Qek-aQ-NjE">
-                                        <rect key="frame" x="369" y="69" width="30" height="30"/>
+                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Qek-aQ-NjE" userLabel="ButtonMenu">
+                                        <rect key="frame" x="379" y="74" width="20" height="20"/>
                                         <constraints>
-                                            <constraint firstAttribute="width" constant="30" id="BAT-jK-rUt"/>
-                                            <constraint firstAttribute="height" constant="30" id="zc5-W6-SXG"/>
+                                            <constraint firstAttribute="width" constant="20" id="BAT-jK-rUt"/>
+                                            <constraint firstAttribute="height" constant="20" id="zc5-W6-SXG"/>
                                         </constraints>
-                                        <state key="normal" image="add"/>
+                                        <state key="normal" image="shareMenu"/>
                                         <connections>
-                                            <action selector="touchUpInsideAddShareLink:" destination="bgO-Rz-2M1" eventType="touchUpInside" id="hrJ-Bm-XgB"/>
+                                            <action selector="touchUpInsideButtonMenu:" destination="bgO-Rz-2M1" eventType="touchUpInside" id="ogE-7H-hMG"/>
+                                        </connections>
+                                    </button>
+                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cLd-wD-cSC" userLabel="ButtonCopy">
+                                        <rect key="frame" x="339" y="74" width="20" height="20"/>
+                                        <constraints>
+                                            <constraint firstAttribute="width" constant="20" id="Bzl-zW-yzd"/>
+                                            <constraint firstAttribute="height" constant="20" id="RIV-EC-kwC"/>
+                                        </constraints>
+                                        <state key="normal" image="shareCopy"/>
+                                        <connections>
+                                            <action selector="touchUpInsideButtonCopy:" destination="bgO-Rz-2M1" eventType="touchUpInside" id="ccu-6N-Tm4"/>
                                         </connections>
                                     </button>
                                 </subviews>
@@ -125,15 +136,17 @@
                                     <constraint firstItem="SQW-aQ-ydN" firstAttribute="centerY" secondItem="8Cj-cK-AKZ" secondAttribute="centerY" id="LtS-8d-L7a"/>
                                     <constraint firstItem="Qek-aQ-NjE" firstAttribute="centerY" secondItem="8Cj-cK-AKZ" secondAttribute="centerY" id="NYZ-hc-SBk"/>
                                     <constraint firstItem="SQW-aQ-ydN" firstAttribute="leading" secondItem="8Cj-cK-AKZ" secondAttribute="trailing" constant="8" id="Oby-Ea-MaC"/>
+                                    <constraint firstItem="cLd-wD-cSC" firstAttribute="leading" secondItem="SQW-aQ-ydN" secondAttribute="trailing" constant="10" id="PFh-qU-yXY"/>
                                     <constraint firstAttribute="bottom" secondItem="c94-b9-Sim" secondAttribute="bottom" id="Svm-RV-vnl"/>
-                                    <constraint firstItem="Qek-aQ-NjE" firstAttribute="leading" secondItem="SQW-aQ-ydN" secondAttribute="trailing" constant="30" id="UAz-au-krl"/>
                                     <constraint firstItem="8Cj-cK-AKZ" firstAttribute="leading" secondItem="X2m-IC-J1u" secondAttribute="leading" constant="5" id="WlZ-CY-x4s"/>
                                     <constraint firstAttribute="trailing" secondItem="f5j-bG-pbj" secondAttribute="trailing" constant="5" id="Yb4-KO-nwi"/>
+                                    <constraint firstItem="Qek-aQ-NjE" firstAttribute="leading" secondItem="cLd-wD-cSC" secondAttribute="trailing" constant="20" id="bSw-vM-d12"/>
                                     <constraint firstItem="iSO-mc-0TB" firstAttribute="leading" secondItem="X2m-IC-J1u" secondAttribute="leading" constant="5" id="d8E-WM-YfC"/>
                                     <constraint firstItem="iSO-mc-0TB" firstAttribute="top" secondItem="X2m-IC-J1u" secondAttribute="top" constant="20" id="jPM-Uo-0lS"/>
                                     <constraint firstAttribute="trailing" secondItem="Qek-aQ-NjE" secondAttribute="trailing" constant="5" id="puY-4D-ARy"/>
                                     <constraint firstItem="c94-b9-Sim" firstAttribute="leading" secondItem="X2m-IC-J1u" secondAttribute="leading" id="rvD-u3-Dug"/>
                                     <constraint firstItem="8Cj-cK-AKZ" firstAttribute="top" secondItem="iSO-mc-0TB" secondAttribute="bottom" constant="14" id="shO-sV-GWB"/>
+                                    <constraint firstItem="cLd-wD-cSC" firstAttribute="centerY" secondItem="8Cj-cK-AKZ" secondAttribute="centerY" id="xia-sb-RNk"/>
                                 </constraints>
                             </view>
                         </subviews>
@@ -147,7 +160,8 @@
                         <viewLayoutGuide key="safeArea" id="eAi-wv-a4Y"/>
                     </view>
                     <connections>
-                        <outlet property="addShareLinkButton" destination="Qek-aQ-NjE" id="SKs-18-AzY"/>
+                        <outlet property="buttonCopy" destination="cLd-wD-cSC" id="Sib-oL-uQx"/>
+                        <outlet property="buttonMenu" destination="Qek-aQ-NjE" id="xfp-a1-YDn"/>
                         <outlet property="returnSearchButton" destination="f5j-bG-pbj" id="Frk-T3-NV9"/>
                         <outlet property="searchField" destination="iSO-mc-0TB" id="1vY-Js-dGQ"/>
                         <outlet property="shareLinkImage" destination="8Cj-cK-AKZ" id="dIZ-nv-gyf"/>
@@ -162,7 +176,8 @@
         </scene>
     </scenes>
     <resources>
-        <image name="add" width="25" height="25"/>
         <image name="arrowRight" width="329" height="329"/>
+        <image name="shareCopy" width="329" height="329"/>
+        <image name="shareMenu" width="329" height="329"/>
     </resources>
 </document>

+ 41 - 20
iOSClient/Share/NCShare.swift

@@ -237,14 +237,14 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
     
     private var viewMenuShareLink: UIView?
     private var shareLinkMenuView: NCShareLinkMenuView?
-    private var sharesTable: [tableShare]?
 
     @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint!
     @IBOutlet weak var searchField: UITextField!
     @IBOutlet weak var returnSearchButton: UIButton!
     @IBOutlet weak var shareLinkImage: UIImageView!
     @IBOutlet weak var shareLinkLabel: UILabel!
-    @IBOutlet weak var addShareLinkButton: UIButton!
+    @IBOutlet weak var buttonCopy: UIButton!
+    @IBOutlet weak var buttonMenu: UIButton!
     @IBOutlet weak var tableView: UITableView!
     
     override func viewDidLoad() {
@@ -254,9 +254,8 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
         
         searchField.placeholder = NSLocalizedString("_shareLinksearch_placeholder_", comment: "")
         
-        returnSearchButton.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "arrowRight"), width: 40, height: 40, color: UIColor.gray), for: .normal)
+        returnSearchButton.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "arrowRight"), width: 100, height: 100, color: UIColor.gray), for: .normal)
         shareLinkLabel.text = NSLocalizedString("_share_link_", comment: "")
-        addShareLinkButton.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "add"), width: 40, height: 40, color: UIColor.gray), for: .normal)
         shareLinkImage.image = NCShareUtility.sharedInstance.createLinkAvatar()
         
         tableView.dataSource = self
@@ -264,28 +263,42 @@ class NCShare: UIViewController, UIGestureRecognizerDelegate, NCShareLinkCellDel
         tableView.allowsSelection = false
         
         tableView.register(UINib.init(nibName: "NCShareLinkCell", bundle: nil), forCellReuseIdentifier: "cellLink")
+        
+        reloadData()
     }
     
     override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
         viewMenuShareLink?.removeFromSuperview()
     }
     
-    @IBAction func touchUpInsideAddShareLink(_ sender: Any) {
+    @IBAction func touchUpInsideButtonCopy(_ sender: Any) {
+    }
+    
+    @IBAction func touchUpInsideButtonMenu(_ sender: Any) {
         
         let shares = NCManageDatabase.sharedInstance.getTableSharesV2(metadata: metadata!)
         if shares.firstShareLink != nil {
-            tapMenu(with: shares.firstShareLink!.idRemoteShared, sender: sender)
+            tapMenu(with: shares.firstShareLink!, sender: sender)
         } else {
-            tapMenu(with: 0, sender: sender)
+            tapMenu(with: nil, sender: sender)
         }
     }
     
-    func tapCopy(with idRemoteShared: Int, sender: Any) {
+    func tapCopy(with tableShare: tableShare?, sender: Any) {
         
     }
     
-    func tapMenu(with idRemoteShared: Int, sender: Any) {
-        NCShareUtility.sharedInstance.openViewMenuShareLink(view: self.view, height: height, idRemoteShared: idRemoteShared)
+    func tapMenu(with tableShare: tableShare?, sender: Any) {
+        NCShareUtility.sharedInstance.openViewMenuShareLink(view: self.view, height: height, tableShare: tableShare)
+    }
+    
+    func reloadData() {
+        let shares = NCManageDatabase.sharedInstance.getTableSharesV2(metadata: metadata!)
+        if shares.firstShareLink == nil {
+            buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareAdd"), width: 100, height: 100, color: UIColor.gray), for: .normal)
+        } else {
+            buttonMenu.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "shareMenu"), width: 100, height: 100, color: UIColor.gray), for: .normal)
+        }
     }
 }
 
@@ -321,7 +334,7 @@ extension NCShare: UITableViewDataSource {
         
         if tableShare.shareLink != "" {
             if let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell {
-                cell.idRemoteShared = tableShare.idRemoteShared
+                cell.tableShare = tableShare
                 cell.delegate = self
                 return cell
             }
@@ -335,7 +348,7 @@ class NCShareLinkCell: UITableViewCell {
     
     private let iconShare: CGFloat = 200
     
-    var idRemoteShared: Int = 0
+    var tableShare: tableShare?
     var delegate: NCShareLinkCellDelegate?
 
     @IBOutlet weak var imageItem: UIImageView!
@@ -353,20 +366,20 @@ class NCShareLinkCell: UITableViewCell {
     }
     
     @IBAction func touchUpInsideCopy(_ sender: Any) {
-        delegate?.tapCopy(with: idRemoteShared, sender: sender)
+        delegate?.tapCopy(with: tableShare, sender: sender)
     }
     
     @IBAction func touchUpInsideMenu(_ sender: Any) {
-        delegate?.tapMenu(with: idRemoteShared, sender: sender)
+        delegate?.tapMenu(with: tableShare, sender: sender)
     }
 }
 
 protocol NCShareLinkCellDelegate {
-    func tapCopy(with idRemoteShared: Int, sender: Any)
-    func tapMenu(with idRemoteShared: Int, sender: Any)
+    func tapCopy(with tableShare: tableShare?, sender: Any)
+    func tapMenu(with tableShare: tableShare?, sender: Any)
 }
 
-// MARK: - hareLinkMenuView
+// MARK: - ShareLinkMenuView
 
 class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate {
     
@@ -396,7 +409,7 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate {
     
     public let width: CGFloat = 250
     public let height: CGFloat = 470
-    public var idRemoteShared: Int = 0
+    public var tableShare: tableShare?
     public var viewWindow: UIView?
     
     override func awakeFromNib() {
@@ -437,8 +450,16 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate {
     func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
         return gestureRecognizer.view == touch.view
     }
+    
+    func loadData(_ tableShare: tableShare?) {
+        self.tableShare = tableShare
+    }
 }
 
+// --------------------------------------------------------------------------------------------
+// ===== Networking =====
+// --------------------------------------------------------------------------------------------
+
 class NCShareUtility: NSObject {
     @objc static let sharedInstance: NCShareUtility = {
         let instance = NCShareUtility()
@@ -460,7 +481,7 @@ class NCShareUtility: NSObject {
         return image
     }
     
-    func openViewMenuShareLink(view: UIView, height: CGFloat, idRemoteShared: Int) {
+    func openViewMenuShareLink(view: UIView, height: CGFloat, tableShare: tableShare?) {
         
         let globalPoint = view.superview?.convert(view.frame.origin, to: nil)
         
@@ -469,8 +490,8 @@ class NCShareUtility: NSObject {
         window.addSubview(viewWindow)
         
         let shareLinkMenuView = Bundle.main.loadNibNamed("NCShareLinkMenuView", owner: self, options: nil)?.first as? NCShareLinkMenuView
-        shareLinkMenuView?.idRemoteShared = idRemoteShared
         shareLinkMenuView?.addTap(view: viewWindow)
+        shareLinkMenuView?.loadData(tableShare)
         let shareLinkMenuViewX = view.bounds.width - (shareLinkMenuView?.frame.width)! - 40 + globalPoint!.x
         var shareLinkMenuViewY = height + 10 + globalPoint!.y
         if (view.bounds.height - (height + 10))  < shareLinkMenuView!.height {