Browse Source

added createContact to contactList

Bastian van de Wetering 6 years ago
parent
commit
5fa53c8671

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

@@ -54,6 +54,7 @@
 		AE851AC9227C77CF00ED86F0 /* Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC8227C77CF00ED86F0 /* Media.swift */; };
 		AE851ACE227CA54400ED86F0 /* InitialsBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACD227CA54300ED86F0 /* InitialsBadge.swift */; };
 		AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACF227DF50900ED86F0 /* GroupChatDetailViewController.swift */; };
+		AE9DAF0D22C1215D004C9591 /* EditContactController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9DAF0C22C1215D004C9591 /* EditContactController.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 */; };
@@ -135,6 +136,7 @@
 		AE851AC8227C77CF00ED86F0 /* Media.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = "<group>"; };
 		AE851ACD227CA54300ED86F0 /* InitialsBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsBadge.swift; sourceTree = "<group>"; };
 		AE851ACF227DF50900ED86F0 /* GroupChatDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupChatDetailViewController.swift; sourceTree = "<group>"; };
+		AE9DAF0C22C1215D004C9591 /* EditContactController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditContactController.swift; 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>"; };
 		AEACE2E21FB32B5C00DCDD78 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
@@ -294,6 +296,7 @@
 				AEE6EC472283045D00EDC689 /* EditSettingsController.swift */,
 				AE52EA1F229EB9F000C586C9 /* EditGroupViewController.swift */,
 				AE4AEE3422B1030D000AA495 /* PreviewController.swift */,
+				AE9DAF0C22C1215D004C9591 /* EditContactController.swift */,
 			);
 			path = Controller;
 			sourceTree = "<group>";
@@ -657,6 +660,7 @@
 				AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */,
 				7A451DB01FB1F84900177250 /* AppCoordinator.swift in Sources */,
 				AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */,
+				AE9DAF0D22C1215D004C9591 /* EditContactController.swift in Sources */,
 				785BE16821E247F1003BE98C /* MessageInfoViewController.swift in Sources */,
 				AE851AC5227C755A00ED86F0 /* Protocols.swift in Sources */,
 				AE728F15229D5C390047565B /* PhotoPickerAlertAction.swift in Sources */,

+ 23 - 0
deltachat-ios/Assets.xcassets/ic_add.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ic_add.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_add_2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_add_3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
deltachat-ios/Assets.xcassets/ic_add.imageset/ic_add.png


BIN
deltachat-ios/Assets.xcassets/ic_add.imageset/ic_add_2x.png


BIN
deltachat-ios/Assets.xcassets/ic_add.imageset/ic_add_3x.png


+ 11 - 0
deltachat-ios/Controller/ContactListController.swift

@@ -22,6 +22,11 @@ class ContactListController: UITableViewController {
 		return handler
 	}()
 
+	lazy var newContactButton: UIBarButtonItem = {
+		let button = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_add").withRenderingMode(.alwaysTemplate), style: .plain, target: self, action: #selector(newContactButtonPressed))
+		return button
+	}()
+
 	var deviceContactAccessGranted: Bool = false {
 		didSet {
 			tableView.reloadData()
@@ -36,6 +41,8 @@ class ContactListController: UITableViewController {
    // tableView.rowHeight = 80
     tableView.register(ContactCell.self, forCellReuseIdentifier: contactCellReuseIdentifier)
 		tableView.register(ActionCell.self, forCellReuseIdentifier: "actionCell")
+
+		navigationItem.rightBarButtonItem = newContactButton
   }
 
   private func getContactIds() {
@@ -141,6 +148,10 @@ class ContactListController: UITableViewController {
 		edit.backgroundColor = DCColors.primary
 		return [edit]
 	}
+
+	@objc func newContactButtonPressed() {
+		coordinator?.showNewContactController()
+	}
 }
 
 extension ContactListController: ContactListDelegate {

+ 43 - 0
deltachat-ios/Controller/EditContactController.swift

@@ -0,0 +1,43 @@
+//
+//  EditContactController.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 24.06.19.
+//  Copyright © 2019 Jonas Reinsch. All rights reserved.
+//
+
+import UIKit
+
+class EditContactController: NewContactController {
+
+	// for editing existing contacts (only
+	// the name may be edited, therefore disable
+	// the email field)
+	init(contactIdForUpdate: Int) {
+		super.init()
+		title = "Edit Contact"
+
+		let contact = MRContact(id: contactIdForUpdate)
+		nameCell.textField.text = contact.name
+		emailCell.textField.text = contact.email
+		emailCell.textField.isEnabled = false
+		emailCell.contentView.alpha = 0.3
+
+		model.name = contact.name
+		model.email = contact.email
+
+		if contactIsValid() {
+			doneButton?.isEnabled = true
+		}
+	}
+
+	required init?(coder _: NSCoder) {
+		fatalError("init(coder:) has not been implemented")
+	}
+
+	@objc override func saveContactButtonPressed() {
+		dc_create_contact(mailboxPointer, model.name, model.email)
+		coordinator?.navigateBack()
+	}
+
+}

+ 0 - 35
deltachat-ios/Controller/NewContactController.swift

@@ -8,39 +8,6 @@
 
 import UIKit
 
-class EditContactController: NewContactController {
-
-	// for editing existing contacts (only
-	// the name may be edited, therefore disable
-	// the email field)
-	init(contactIdForUpdate: Int) {
-		super.init()
-		title = "Edit Contact"
-
-		let contact = MRContact(id: contactIdForUpdate)
-		nameCell.textField.text = contact.name
-		emailCell.textField.text = contact.email
-		emailCell.textField.isEnabled = false
-		emailCell.contentView.alpha = 0.3
-
-		model.name = contact.name
-		model.email = contact.email
-
-		if contactIsValid() {
-			doneButton?.isEnabled = true
-		}
-	}
-
-	required init?(coder _: NSCoder) {
-		fatalError("init(coder:) has not been implemented")
-	}
-
-	@objc override func saveContactButtonPressed() {
-		dc_create_contact(mailboxPointer, model.name, model.email)
-		coordinator?.navigateBack()
-	}
-
-}
 
 class NewContactController: UITableViewController {
 
@@ -67,8 +34,6 @@ class NewContactController: UITableViewController {
 
   let cells: [UITableViewCell]
 
-
-
   // for creating a new contact
   init() {
     cells = [emailCell, nameCell]

+ 8 - 0
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -165,6 +165,14 @@ class ContactListCoordinator: Coordinator {
 		chatVC.coordinator = coordinator
 		navigationController.pushViewController(chatVC, animated: true)
 	}
+
+	func showNewContactController() {
+		let newContactController = NewContactController()
+		let coordinator = EditContactCoordinator(navigationController: navigationController)
+		childCoordinators.append(coordinator)
+		newContactController.coordinator = coordinator
+		navigationController.pushViewController(newContactController, animated: true)
+	}
 }
 
 // since mailbox and chatView -tab both use ChatViewController we want to be able to assign different functionality via coordinators -> therefore we override unneeded functions such as showChatDetail -> maybe find better solution in longterm