Browse Source

Contact book implementation for sharing

TSI-amrutwaghmare 1 year ago
parent
commit
b575bf262e

+ 12 - 0
iOSClient/Images.xcassets/contact.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "contact.svg",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 7 - 0
iOSClient/Images.xcassets/contact.imageset/contact.svg

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>01_24px/icon/user_file/contacts/default</title>
+    <g id="icon/user_file/contacts/default" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <path d="M18,1.49999996 C19.5910715,1.49999996 20.9031887,2.75529333 20.994882,4.32441003 L21,4.49999996 L21,19.5 C21,21.0910715 19.7447067,22.4031887 18.1755899,22.494882 L18,22.5 L2.99999996,22.5 L2.99999996,1.49999996 L18,1.49999996 Z M18,2.99999996 L4.49999997,2.99999996 L4.49999997,21 L18,21 C18.8,21 19.4228373,20.4242215 19.4933442,19.6478323 L19.5,19.5 L19.5,4.49999996 C19.5,3.69999997 18.9242215,3.07716259 18.1478323,3.00665577 L18,2.99999996 Z M14,13.4 C14.75,13.4 15.3681641,13.9273438 15.5661011,14.6524414 L15.6,14.8 L15.75,15.5 L8.24999998,15.5 L8.34999998,14.8 C8.49062499,14.05 9.11464843,13.5197266 9.85128173,13.4563721 L9.99999999,13.45 L10.85,13.45 L12,14.6 L13.2,13.4 L14,13.4 Z M12,7.99999998 C13.15,7.99999998 14.1,8.84999999 14.1,10.1 C14.1,11.35 13.2,12.6 12,12.6 C10.8,12.6 9.89999999,11.35 9.89999999,10.1 C9.89999999,8.84999999 10.85,7.99999998 12,7.99999998 Z" id="Shape" fill="#000000"></path>
+    </g>
+</svg>

+ 23 - 12
iOSClient/Share/NCShare.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ts3-RO-A9l">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ts3-RO-A9l">
     <device id="retina5_5" orientation="portrait" appearance="light"/>
     <device id="retina5_5" orientation="portrait" appearance="light"/>
     <dependencies>
     <dependencies>
         <deployment identifier="iOS"/>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -31,7 +31,7 @@
                 <navigationController automaticallyAdjustsScrollViewInsets="NO" id="Ts3-RO-A9l" sceneMemberID="viewController">
                 <navigationController automaticallyAdjustsScrollViewInsets="NO" id="Ts3-RO-A9l" sceneMemberID="viewController">
                     <toolbarItems/>
                     <toolbarItems/>
                     <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="RCF-gN-HcM">
                     <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="RCF-gN-HcM">
-                        <rect key="frame" x="0.0" y="20" width="414" height="44"/>
+                        <rect key="frame" x="0.0" y="20" width="414" height="50"/>
                         <autoresizingMask key="autoresizingMask"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </navigationBar>
                     </navigationBar>
                     <nil name="viewControllers"/>
                     <nil name="viewControllers"/>
@@ -106,7 +106,7 @@
                                         </constraints>
                                         </constraints>
                                     </view>
                                     </view>
                                     <textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="iSO-mc-0TB">
                                     <textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="249" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" translatesAutoresizingMaskIntoConstraints="NO" id="iSO-mc-0TB">
-                                        <rect key="frame" x="5" y="95" width="389" height="30"/>
+                                        <rect key="frame" x="5" y="95" width="349" height="30"/>
                                         <constraints>
                                         <constraints>
                                             <constraint firstAttribute="height" constant="30" id="0aG-z9-fcy"/>
                                             <constraint firstAttribute="height" constant="30" id="0aG-z9-fcy"/>
                                         </constraints>
                                         </constraints>
@@ -116,15 +116,29 @@
                                             <action selector="searchFieldDidEndOnExitWithTextField:" destination="bgO-Rz-2M1" eventType="editingDidEndOnExit" id="xH6-YR-5W9"/>
                                             <action selector="searchFieldDidEndOnExitWithTextField:" destination="bgO-Rz-2M1" eventType="editingDidEndOnExit" id="xH6-YR-5W9"/>
                                         </connections>
                                         </connections>
                                     </textField>
                                     </textField>
+                                    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="GsB-jy-SBk">
+                                        <rect key="frame" x="364" y="95" width="30" height="30"/>
+                                        <constraints>
+                                            <constraint firstAttribute="width" secondItem="GsB-jy-SBk" secondAttribute="height" multiplier="1:1" id="5wC-Ir-Tuj"/>
+                                        </constraints>
+                                        <state key="normal" title="Button"/>
+                                        <buttonConfiguration key="configuration" style="plain" image="contact"/>
+                                        <connections>
+                                            <action selector="selectContactClicked:" destination="bgO-Rz-2M1" eventType="touchUpInside" id="TEM-Pg-YgB"/>
+                                        </connections>
+                                    </button>
                                 </subviews>
                                 </subviews>
                                 <constraints>
                                 <constraints>
                                     <constraint firstItem="oBQ-TP-qof" firstAttribute="top" secondItem="X2m-IC-J1u" secondAttribute="top" constant="10" id="09Y-bm-RvQ"/>
                                     <constraint firstItem="oBQ-TP-qof" firstAttribute="top" secondItem="X2m-IC-J1u" secondAttribute="top" constant="10" id="09Y-bm-RvQ"/>
+                                    <constraint firstAttribute="trailing" secondItem="GsB-jy-SBk" secondAttribute="trailing" constant="10" id="32l-QA-7ue"/>
                                     <constraint firstAttribute="trailing" secondItem="c94-b9-Sim" secondAttribute="trailing" id="BtN-cJ-TTc"/>
                                     <constraint firstAttribute="trailing" secondItem="c94-b9-Sim" secondAttribute="trailing" id="BtN-cJ-TTc"/>
                                     <constraint firstItem="c94-b9-Sim" firstAttribute="top" secondItem="iSO-mc-0TB" secondAttribute="bottom" constant="8" id="Co6-l6-HiT"/>
                                     <constraint firstItem="c94-b9-Sim" firstAttribute="top" secondItem="iSO-mc-0TB" secondAttribute="bottom" constant="8" id="Co6-l6-HiT"/>
+                                    <constraint firstItem="GsB-jy-SBk" firstAttribute="centerY" secondItem="iSO-mc-0TB" secondAttribute="centerY" id="Qe6-An-Hda"/>
                                     <constraint firstAttribute="bottom" secondItem="c94-b9-Sim" secondAttribute="bottom" id="Svm-RV-vnl"/>
                                     <constraint firstAttribute="bottom" secondItem="c94-b9-Sim" secondAttribute="bottom" id="Svm-RV-vnl"/>
-                                    <constraint firstAttribute="trailing" secondItem="iSO-mc-0TB" secondAttribute="trailing" constant="10" id="Vhu-GP-EJN"/>
                                     <constraint firstAttribute="trailing" secondItem="oBQ-TP-qof" secondAttribute="trailing" id="ZuM-2G-aoM"/>
                                     <constraint firstAttribute="trailing" secondItem="oBQ-TP-qof" secondAttribute="trailing" id="ZuM-2G-aoM"/>
+                                    <constraint firstItem="GsB-jy-SBk" firstAttribute="leading" secondItem="iSO-mc-0TB" secondAttribute="trailing" constant="10" id="cqh-P5-H1x"/>
                                     <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="leading" secondItem="X2m-IC-J1u" secondAttribute="leading" constant="5" id="d8E-WM-YfC"/>
+                                    <constraint firstItem="GsB-jy-SBk" firstAttribute="height" secondItem="iSO-mc-0TB" secondAttribute="height" id="doY-eV-FYw"/>
                                     <constraint firstItem="iSO-mc-0TB" firstAttribute="top" secondItem="X2m-IC-J1u" secondAttribute="top" constant="95" id="jPM-Uo-0lS"/>
                                     <constraint firstItem="iSO-mc-0TB" firstAttribute="top" secondItem="X2m-IC-J1u" secondAttribute="top" constant="95" id="jPM-Uo-0lS"/>
                                     <constraint firstItem="c94-b9-Sim" firstAttribute="leading" secondItem="X2m-IC-J1u" secondAttribute="leading" id="rvD-u3-Dug"/>
                                     <constraint firstItem="c94-b9-Sim" firstAttribute="leading" secondItem="X2m-IC-J1u" secondAttribute="leading" id="rvD-u3-Dug"/>
                                 </constraints>
                                 </constraints>
@@ -141,6 +155,7 @@
                         </constraints>
                         </constraints>
                     </view>
                     </view>
                     <connections>
                     <connections>
+                        <outlet property="btnContact" destination="GsB-jy-SBk" id="76u-5m-CTZ"/>
                         <outlet property="searchField" destination="iSO-mc-0TB" id="1vY-Js-dGQ"/>
                         <outlet property="searchField" destination="iSO-mc-0TB" id="1vY-Js-dGQ"/>
                         <outlet property="searchFieldTopConstraint" destination="jPM-Uo-0lS" id="yfd-cG-1mu"/>
                         <outlet property="searchFieldTopConstraint" destination="jPM-Uo-0lS" id="yfd-cG-1mu"/>
                         <outlet property="sharedWithYouByImage" destination="fKv-xM-rVY" id="EJ0-sV-By8"/>
                         <outlet property="sharedWithYouByImage" destination="fKv-xM-rVY" id="EJ0-sV-By8"/>
@@ -281,18 +296,14 @@
             <point key="canvasLocation" x="3510" y="-169"/>
             <point key="canvasLocation" x="3510" y="-169"/>
         </scene>
         </scene>
     </scenes>
     </scenes>
-    <designables>
-        <designable name="KHG-xj-wfG">
-            <size key="intrinsicContentSize" width="37.333333333333336" height="18"/>
-        </designable>
-    </designables>
     <resources>
     <resources>
+        <image name="contact" width="24" height="24"/>
         <image name="note.text" width="24" height="24"/>
         <image name="note.text" width="24" height="24"/>
         <systemColor name="labelColor">
         <systemColor name="labelColor">
-            <color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+            <color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
         </systemColor>
         </systemColor>
         <systemColor name="secondarySystemBackgroundColor">
         <systemColor name="secondarySystemBackgroundColor">
-            <color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+            <color red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
         </systemColor>
         </systemColor>
         <systemColor name="systemBackgroundColor">
         <systemColor name="systemBackgroundColor">
             <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
             <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

+ 51 - 0
iOSClient/Share/NCShare.swift

@@ -28,6 +28,7 @@ import Parchment
 import DropDown
 import DropDown
 import NextcloudKit
 import NextcloudKit
 import MarqueeLabel
 import MarqueeLabel
+import ContactsUI
 
 
 class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent {
 class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent {
 
 
@@ -42,6 +43,7 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
     var textField: UITextField? { searchField }
     var textField: UITextField? { searchField }
 
 
     @IBOutlet weak var tableView: UITableView!
     @IBOutlet weak var tableView: UITableView!
+    @IBOutlet weak var btnContact: UIButton!
 
 
     weak var appDelegate = UIApplication.shared.delegate as? AppDelegate
     weak var appDelegate = UIApplication.shared.delegate as? AppDelegate
 
 
@@ -103,6 +105,13 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
             let isVisible = (self.navigationController?.topViewController as? NCSharePaging)?.page == .sharing
             let isVisible = (self.navigationController?.topViewController as? NCSharePaging)?.page == .sharing
             networking?.readShare(showLoadingIndicator: isVisible)
             networking?.readShare(showLoadingIndicator: isVisible)
         }
         }
+
+        btnContact.layer.cornerRadius = 5
+        btnContact.layer.masksToBounds = true
+        btnContact.layer.borderWidth = 1
+        btnContact.layer.borderColor = UIColor.gray.cgColor
+        btnContact.tintColor = .gray
+        btnContact.setImage(NCUtility.shared.loadImage(named: "contact", color: .gray, size: 24), for: .normal)
     }
     }
 
 
     func makeNewLinkShare() {
     func makeNewLinkShare() {
@@ -208,6 +217,14 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent
         self.present(UIAlertController.password(titleKey: "_enforce_password_protection_", completion: completion), animated: true)
         self.present(UIAlertController.password(titleKey: "_enforce_password_protection_", completion: completion), animated: true)
     }
     }
 
 
+    @IBAction func selectContactClicked(_ sender: Any) {
+        let cnPicker = CNContactPickerViewController()
+        cnPicker.delegate = self
+        cnPicker.displayedPropertyKeys = [CNContactEmailAddressesKey]
+        cnPicker.predicateForEnablingContact = NSPredicate(format: "emailAddresses.@count > 0")
+        cnPicker.predicateForSelectionOfProperty = NSPredicate(format: "emailAddresses.@count > 0")
+        self.present(cnPicker, animated: true)
+    }
     // MARK: - NCShareNetworkingDelegate
     // MARK: - NCShareNetworkingDelegate
 
 
     func readShareCompleted() {
     func readShareCompleted() {
@@ -362,3 +379,37 @@ extension NCShare: UITableViewDataSource {
         return UITableViewCell()
         return UITableViewCell()
     }
     }
 }
 }
+
+
+//MARK: CNContactPickerDelegate
+extension NCShare: CNContactPickerDelegate {
+    func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
+        if  contact.emailAddresses.count > 1 {
+            showEmailList(arrEmail: contact.emailAddresses.map({$0.value as String}))
+        } else if let email = contact.emailAddresses.first?.value as? String {
+            textField?.text = email
+            networking?.getSharees(searchString: email)
+        }
+    }
+    
+    func showEmailList(arrEmail: [String]) {
+        var actions = [NCMenuAction]()
+        for email in arrEmail {
+            actions.append(
+                NCMenuAction(
+                    title: email,
+                    icon: NCUtility.shared.loadImage(named: "email"),
+                    selected: false,
+                    on: false,
+                    action: { _ in
+                        self.textField?.text = email
+                        self.networking?.getSharees(searchString: email)
+                    }
+                )
+            )
+        }
+        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+            self.presentMenu(with: actions)
+        }
+    }
+}