فهرست منبع

name can be changed with contacts now

Jonas Reinsch 7 سال پیش
والد
کامیت
ca4962de4a
2فایلهای تغییر یافته به همراه43 افزوده شده و 6 حذف شده
  1. 13 0
      deltachat-ios/NewChatViewController.swift
  2. 30 6
      deltachat-ios/NewContactController.swift

+ 13 - 0
deltachat-ios/NewChatViewController.swift

@@ -65,6 +65,7 @@ class NewChatViewController: UITableViewController {
             cell.textLabel?.text = "New Contact"
             cell.textLabel?.textColor = self.view.tintColor
 
+
             return cell
         }
         if row == 1 {
@@ -88,6 +89,8 @@ class NewChatViewController: UITableViewController {
             cell = UITableViewCell(style: .value1, reuseIdentifier: "contactCell")
         }
         
+        cell.accessoryType = .detailDisclosureButton
+        
         let contactRow = row - 2
 
         let contact = MRContact(id: contactIds[contactRow])
@@ -118,6 +121,16 @@ class NewChatViewController: UITableViewController {
             }
         }
     }
+    
+    override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
+        let row = indexPath.row
+        if row > 1 {
+            let contactIndex = row - 2
+            let contactId = contactIds[contactIndex]
+            let newContactController = NewContactController(contactIdForUpdate: contactId)
+            navigationController?.pushViewController(newContactController, animated: true)
+        }
+    }
 
 
     /*

+ 30 - 6
deltachat-ios/NewContactController.swift

@@ -14,9 +14,13 @@ class NewContactController: UITableViewController {
     var doneButton:UIBarButtonItem?
     var cancelButton:UIBarButtonItem?
     
+    func contactIsValid() -> Bool {
+        return (Utils.isValid(model.email) && !model.name.isEmpty)
+    }
+    
     var model:(name:String, email:String) = ("", "") {
         didSet {
-            if (Utils.isValid(model.email) && !model.name.isEmpty) {
+            if contactIsValid() {
                 doneButton?.isEnabled = true
             } else {
                 doneButton?.isEnabled = false
@@ -26,10 +30,33 @@ class NewContactController: UITableViewController {
     
     let cells:[UITableViewCell]
     
+    // for editing existing contacts (only
+    // the name may be edited, therefore disable
+    // the email field)
+    convenience init(contactIdForUpdate: Int) {
+        self.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
+        }
+    }
+    
+    // for creating a new contact
     init() {
         cells = [nameCell, emailCell]
-        
+
         super.init(style: .grouped)
+        title = "New Contact"
         doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(NewContactController.saveContactButtonPressed))
         doneButton?.isEnabled = false
         navigationItem.rightBarButtonItem = doneButton
@@ -54,10 +81,8 @@ class NewContactController: UITableViewController {
     }
     
     @objc func saveContactButtonPressed() {
-        let contactId = mrmailbox_create_contact(mailboxPointer, self.model.name, self.model.email)
+        mrmailbox_create_contact(mailboxPointer, self.model.name, self.model.email)
         navigationController?.popViewController(animated: true)
-        
-        
     }
     
     @objc func cancelButtonPressed() {
@@ -71,7 +96,6 @@ class NewContactController: UITableViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         
-        title = "New Contact"
         navigationController?.navigationBar.prefersLargeTitles = true
     }