浏览代码

add new contact/new chat screen

Jonas Reinsch 7 年之前
父节点
当前提交
8f0881680f

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

@@ -8,6 +8,7 @@
 
 /* Begin PBXBuildFile section */
 		7A0052A11FBC50C40048C3BF /* CredentialsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0052A01FBC50C40048C3BF /* CredentialsController.swift */; };
+		7A0052C81FBE6CB40048C3BF /* NewContactController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A0052C71FBE6CB40048C3BF /* NewContactController.swift */; };
 		7A451D941FB1B1DB00177250 /* wrapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 7A451D921FB1B1DB00177250 /* wrapper.c */; };
 		7A451DAE1FB1F5A200177250 /* libetpan-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A451DA71FB1F4BF00177250 /* libetpan-ios.a */; };
 		7A451DB01FB1F84900177250 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A451DAF1FB1F84900177250 /* AppCoordinator.swift */; };
@@ -96,6 +97,7 @@
 /* Begin PBXFileReference section */
 		6241BE1534A653E79AD5D01D /* Pods_deltachat_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_deltachat_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		7A0052A01FBC50C40048C3BF /* CredentialsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CredentialsController.swift; sourceTree = "<group>"; };
+		7A0052C71FBE6CB40048C3BF /* NewContactController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewContactController.swift; sourceTree = "<group>"; };
 		7A451D921FB1B1DB00177250 /* wrapper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = wrapper.c; sourceTree = "<group>"; };
 		7A451D931FB1B1DB00177250 /* wrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wrapper.h; sourceTree = "<group>"; };
 		7A451D9A1FB1F4BF00177250 /* libetpan.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = libetpan.xcodeproj; path = "deltachat-ios/libraries/libetpan/build-mac/libetpan.xcodeproj"; sourceTree = "<group>"; };
@@ -339,6 +341,7 @@
 				7A451DBD1FB4AD0700177250 /* Wrapper.swift */,
 				AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */,
 				7A0052A01FBC50C40048C3BF /* CredentialsController.swift */,
+				7A0052C71FBE6CB40048C3BF /* NewContactController.swift */,
 				AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */,
 				AEACE2E01FB3271700DCDD78 /* SampleData.swift */,
 				AEACE2E21FB32B5C00DCDD78 /* Constants.swift */,
@@ -614,6 +617,7 @@
 				7A9FB5551FB08557001FEA36 /* mrstock.c in Sources */,
 				7A9FB53B1FB08557001FEA36 /* mrchatlist.c in Sources */,
 				AE0D26FD1FB1FE88002FAFCE /* ChatListController.swift in Sources */,
+				7A0052C81FBE6CB40048C3BF /* NewContactController.swift in Sources */,
 				7A9FB54E1FB08557001FEA36 /* mrparam.c in Sources */,
 				AEACE2DD1FB323CA00DCDD78 /* ChatViewController.swift in Sources */,
 				7A7923741FB0A2C800BC2DE5 /* symmetric.c in Sources */,

+ 9 - 2
deltachat-ios/ChatListController.swift

@@ -8,8 +8,6 @@
 
 import UIKit
 
-
-
 class ChatListController: UIViewController {
     var chatList:MRChatList?
 
@@ -76,6 +74,15 @@ class ChatListController: UIViewController {
         chatTable.dataSource = chatTableDataSource
         chatTableDelegate.chatPresenter = self
         chatTable.delegate = chatTableDelegate
+        
+        let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(ChatListController.addChat))
+        navigationItem.rightBarButtonItem = addButton
+    }
+    
+    @objc func addChat() {
+        let ncc = NewContactController()
+        let nav = UINavigationController(rootViewController: ncc)
+        present(nav, animated: true, completion: nil)
     }
     
     override func didReceiveMemoryWarning() {

+ 77 - 1
deltachat-ios/NewContactController.swift

@@ -6,4 +6,80 @@
 //  Copyright © 2017 Jonas Reinsch. All rights reserved.
 //
 
-import Foundation
+import UIKit
+
+class NewContactController: UITableViewController {
+    let nameCell = TextFieldCell.makeNameCell()
+    let emailCell = TextFieldCell.makeEmailCell()
+    var doneButton:UIBarButtonItem?
+    
+    var model:(name:String, email:String) = ("", "") {
+        didSet {
+            if (Utils.isValid(model.email) && !model.name.isEmpty) {
+                doneButton?.isEnabled = true
+            } else {
+                doneButton?.isEnabled = false
+            }
+        }
+    }
+    
+    let cells:[UITableViewCell]
+    
+    init() {
+        cells = [nameCell, emailCell]
+        
+        super.init(style: .grouped)
+        doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(NewContactController.saveContactButtonPressed))
+        doneButton?.isEnabled = false
+        navigationItem.rightBarButtonItem = doneButton
+        
+        nameCell.textField.addTarget(self, action: #selector(NewContactController.nameTextChanged), for: UIControlEvents.editingChanged)
+        emailCell.textField.addTarget(self, action: #selector(NewContactController.emailTextChanged), for: UIControlEvents.editingChanged)
+    }
+    
+    @objc func emailTextChanged() {
+        let emailText = emailCell.textField.text ?? ""
+        
+        model.email = emailText
+    }
+    
+    @objc func nameTextChanged() {
+        let nameText = nameCell.textField.text ?? ""
+        
+        model.name = nameText
+    }
+    
+    @objc func saveContactButtonPressed() {
+        dismiss(animated: true) {
+            let contactId = mrmailbox_create_contact(mailboxPointer, self.model.name, self.model.email)
+            let _ = mrmailbox_create_chat_by_contact_id(mailboxPointer, contactId)
+        }
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        
+        title = "New Contact"
+        navigationController?.navigationBar.prefersLargeTitles = true
+    }
+    
+    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        return cells.count
+    }
+    
+    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        let row = indexPath.row
+        
+        return cells[row]
+    }
+    
+    override func didReceiveMemoryWarning() {
+        super.didReceiveMemoryWarning()
+        // Dispose of any resources that can be recreated.
+    }
+}
+