Forráskód Böngészése

Integrated DeviceContactHandler into NewChatViewController - added NSContactsUsageDescription to request addressbook access

Bastian van de Wetering 6 éve
szülő
commit
b59ad2cfec

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -91,6 +91,7 @@
 		AE0D26FD1FB1FE88002FAFCE /* ChatListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */; };
 		AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B31722672DFC00EC37A1 /* ActionCell.swift */; };
 		AE38B31A2267328200EC37A1 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B3192267328200EC37A1 /* Colors.swift */; };
+		AE8519EA2272FDCA00ED86F0 /* DeviceContactsHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8519E92272FDCA00ED86F0 /* DeviceContactsHandler.swift */; };
 		AEACE2DD1FB323CA00DCDD78 /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */; };
 		AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DE1FB3246400DCDD78 /* Message.swift */; };
 		AEACE2E31FB32B5C00DCDD78 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E21FB32B5C00DCDD78 /* Constants.swift */; };
@@ -267,6 +268,7 @@
 		AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListController.swift; sourceTree = "<group>"; };
 		AE38B31722672DFC00EC37A1 /* ActionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCell.swift; sourceTree = "<group>"; };
 		AE38B3192267328200EC37A1 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
+		AE8519E92272FDCA00ED86F0 /* DeviceContactsHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceContactsHandler.swift; sourceTree = "<group>"; };
 		AEA9CC2F22522DA20061D113 /* librpgp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = librpgp.h; sourceTree = "<group>"; };
 		AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
 		AEACE2DE1FB3246400DCDD78 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
@@ -474,6 +476,7 @@
 				AEE56D7C2253ADB4007DC082 /* HudHandler.swift */,
 				AE38B31722672DFC00EC37A1 /* ActionCell.swift */,
 				AE38B3192267328200EC37A1 /* Colors.swift */,
+				AE8519E92272FDCA00ED86F0 /* DeviceContactsHandler.swift */,
 			);
 			path = "deltachat-ios";
 			sourceTree = "<group>";
@@ -813,6 +816,7 @@
 				7070FB8F20FF4118000DC258 /* dc_loginparam.c in Sources */,
 				7AE0A5491FC42F65005ECB4B /* NewChatViewController.swift in Sources */,
 				78E45E3A21D3CFBC00D4B15E /* SettingsController.swift in Sources */,
+				AE8519EA2272FDCA00ED86F0 /* DeviceContactsHandler.swift in Sources */,
 				78ED838321D5379000243125 /* TextFieldCell.swift in Sources */,
 				78E45E3C21D3D03700D4B15E /* TextFieldTableViewCell.swift in Sources */,
 				7070FB7220FF345F000DC258 /* dc_key.c in Sources */,

+ 0 - 8
deltachat-ios/AppCoordinator.swift

@@ -33,12 +33,4 @@ class AppCoordinator: Coordinator {
     let chatNavigationController = UINavigationController(rootViewController: chatListController)
     baseController.present(chatNavigationController, animated: false, completion: nil)
   }
-
-  /*
-   func setupAccountSetup() {
-     let accountSetupController = AccountSetupController()
-     let accountSetupNavigationController = UINavigationController(rootViewController: accountSetupController)
-     baseController.present(accountSetupNavigationController, animated: false, completion: nil)
-   }
-   */
 }

+ 2 - 0
deltachat-ios/Info.plist

@@ -30,6 +30,8 @@
 	<string>Allowing access to the microphone lets you record audio.</string>
 	<key>NSPhotoLibraryUsageDescription</key>
 	<string>Allowing access to the photo library allows you to upload images from it.</string>
+	<key>NSContactsUsageDescription</key>
+	<string>Allowing access to your address book lets you chat with contacts from your device</string>
 	<key>UIBackgroundModes</key>
 	<array>
 		<string>fetch</string>

+ 46 - 0
deltachat-ios/NewChatViewController.swift

@@ -8,6 +8,7 @@
 
 import ALCameraViewController
 import UIKit
+import Contacts
 
 protocol ChatDisplayer: class {
   func displayNewChat(contactId: Int)
@@ -21,6 +22,9 @@ class NewChatViewController: UITableViewController {
   var syncObserver: Any?
   var hud: ProgressHud?
 
+	let deviceContactHandler = DeviceContactsHandler()
+
+
   override func viewDidLoad() {
     super.viewDidLoad()
 
@@ -35,6 +39,8 @@ class NewChatViewController: UITableViewController {
   override func viewDidAppear(_ animated: Bool) {
     super.viewDidAppear(animated)
 
+		let contacts = deviceContactHandler.requestDeviceContacts(delegate: self)
+
     contactIds = Utils.getContactIds()
     tableView.reloadData()
 
@@ -222,3 +228,43 @@ extension NewChatViewController: QrCodeReaderDelegate {
     dc_lot_unref(check)
   }
 }
+
+extension NewChatViewController: DeviceContactsDelegate {
+	func setContacts(contacts: [DeviceContact]) {
+		print(contacts)
+	}
+
+	func accessDenied() {
+		
+	}
+
+	func requestAccess() {
+		// ignore for now
+	}
+
+
+
+	private func showSettingsAlert(_ completionHandler: @escaping (_ accessGranted: Bool) -> Void) {
+		let alert = UIAlertController(title: nil, message: "This app requires access to Contacts to proceed. Would you like to open settings and grant permission to contacts?", preferredStyle: .alert)
+		alert.addAction(UIAlertAction(title: "Open Settings", style: .default) { action in
+			completionHandler(false)
+			UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
+		})
+		alert.addAction(UIAlertAction(title: "Cancel", style: .cancel) { action in
+			completionHandler(false)
+		})
+		present(alert, animated: true)
+	}
+}
+
+protocol DeviceContactsDelegate {
+	func setContacts(contacts: [DeviceContact])
+	func accessDenied()
+	func requestAccess()
+}
+
+/*
+To Chat
+
+
+*/

+ 13 - 9
deltachat-ios/TopViews/ChatListController.swift

@@ -22,16 +22,7 @@ class ChatListController: UIViewController {
 
   var newButton: UIBarButtonItem!
 
-  func getChatList() {
-    guard let chatlistPointer = dc_get_chatlist(mailboxPointer, DC_GCL_NO_SPECIALS, nil, 0) else {
-      fatalError("chatlistPointer was nil")
-    }
-    // ownership of chatlistPointer transferred here to ChatList object
-    chatList = MRChatList(chatListPointer: chatlistPointer)
 
-    chatTableDataSource.chatList = chatList
-    chatTable.reloadData()
-  }
 
   override func viewWillAppear(_ animated: Bool) {
     super.viewWillAppear(animated)
@@ -117,6 +108,17 @@ class ChatListController: UIViewController {
     let nav = UINavigationController(rootViewController: ncv)
     present(nav, animated: true, completion: nil)
   }
+
+	func getChatList() {
+		guard let chatlistPointer = dc_get_chatlist(mailboxPointer, DC_GCL_NO_SPECIALS, nil, 0) else {
+			fatalError("chatlistPointer was nil")
+		}
+		// ownership of chatlistPointer transferred here to ChatList object
+		chatList = MRChatList(chatListPointer: chatlistPointer)
+
+		chatTableDataSource.chatList = chatList
+		chatTable.reloadData()
+	}
 }
 
 extension ChatListController: ChatPresenter {
@@ -195,6 +197,8 @@ class ChatTableDataSource: NSObject, UITableViewDataSource {
     cell.emailLabel.text = result
     return cell
   }
+
+
 }
 
 protocol ChatPresenter: class {