Sfoglia il codice sorgente

WIP - building initalsLabel

Bastian van de Wetering 6 anni fa
parent
commit
9bb5a22df6

+ 5 - 1
deltachat-ios.xcodeproj/project.pbxproj

@@ -95,6 +95,7 @@
 		AE851AC5227C755A00ED86F0 /* Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC4227C755A00ED86F0 /* Protocols.swift */; };
 		AE851AC7227C776400ED86F0 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC6227C776400ED86F0 /* Location.swift */; };
 		AE851AC9227C77CF00ED86F0 /* Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC8227C77CF00ED86F0 /* Media.swift */; };
+		AE851ACE227CA54400ED86F0 /* InitialsLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACD227CA54300ED86F0 /* InitialsLabel.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 */; };
@@ -285,6 +286,7 @@
 		AE851AC4227C755A00ED86F0 /* Protocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Protocols.swift; sourceTree = "<group>"; };
 		AE851AC6227C776400ED86F0 /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
 		AE851AC8227C77CF00ED86F0 /* Media.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = "<group>"; };
+		AE851ACD227CA54300ED86F0 /* InitialsLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsLabel.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>"; };
@@ -577,10 +579,10 @@
 		AE851AC0227C693B00ED86F0 /* Controller */ = {
 			isa = PBXGroup;
 			children = (
+				78E45E3D21D3D28C00D4B15E /* NavigationController.swift */,
 				785BE16721E247F1003BE98C /* MessageInfoViewController.swift */,
 				7A0052C71FBE6CB40048C3BF /* NewContactController.swift */,
 				AEE56D752253431E007DC082 /* AccountSetupController.swift */,
-				78E45E3D21D3D28C00D4B15E /* NavigationController.swift */,
 				AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */,
 				789E879521D6CB58003ED1C5 /* QrCodeReaderController.swift */,
 				7092474020B3869500AF8799 /* ContactProfileViewController.swift */,
@@ -627,6 +629,7 @@
 				78E45E3B21D3D03700D4B15E /* TextFieldTableViewCell.swift */,
 				789E879C21D6DF86003ED1C5 /* ProgressHud.swift */,
 				AE38B31722672DFC00EC37A1 /* ActionCell.swift */,
+				AE851ACD227CA54300ED86F0 /* InitialsLabel.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -985,6 +988,7 @@
 				7070FB5F20FF345F000DC258 /* dc_tools.c in Sources */,
 				7070FB8E20FF4118000DC258 /* dc_apeerstate.c in Sources */,
 				7A451DBE1FB4AD0700177250 /* Wrapper.swift in Sources */,
+				AE851ACE227CA54400ED86F0 /* InitialsLabel.swift in Sources */,
 				7070FB6420FF345F000DC258 /* dc_dehtml.c in Sources */,
 				70B8882E2091B8550074812E /* ContactCell.swift in Sources */,
 				7070FB8D20FF4118000DC258 /* dc_sqlite3.c in Sources */,

+ 123 - 105
deltachat-ios/Controller/ChatViewController.swift

@@ -40,8 +40,114 @@ class ChatViewController: MessagesViewController {
     }
   }
 
+	required init?(coder _: NSCoder) {
+		fatalError("init(coder:) has not been implemented")
+	}
+
+	override func viewDidLoad() {
+		messagesCollectionView.register(CustomCell.self)
+		super.viewDidLoad()
+		view.backgroundColor = DCColors.chatBackgroundColor
+
+
+		if !MRConfig.configured {
+			// TODO: display message about nothing being configured
+			return
+		}
+
+		let chat = MRChat(id: chatId)
+		updateTitleView(title: chat.name, subtitle: chat.subtitle)
+
+		if let image = chat.profileImage {
+			navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style: .done, target: self, action: #selector(chatProfilePressed))
+		} else {
+			navigationItem.rightBarButtonItem = UIBarButtonItem(title: chat.name, style: .done, target: self, action: #selector(chatProfilePressed))
+		}
+
+
+		configureMessageCollectionView()
+
+		if !disableWriting {
+			configureMessageInputBar()
+			messageInputBar.inputTextView.text = textDraft
+			messageInputBar.inputTextView.becomeFirstResponder()
+		}
+
+		loadFirstMessages()
+	}
+
+	override func viewWillAppear(_ animated: Bool) {
+		super.viewWillAppear(animated)
+		configureMessageMenu()
+
+		if #available(iOS 11.0, *) {
+			if disableWriting {
+				navigationController?.navigationBar.prefersLargeTitles = true
+			}
+		}
+
+		let nc = NotificationCenter.default
+		msgChangedObserver = nc.addObserver(
+			forName: dcNotificationChanged,
+			object: nil,
+			queue: OperationQueue.main
+		) { notification in
+			if let ui = notification.userInfo {
+				if self.disableWriting {
+					// always refresh, as we can't check currently
+					self.refreshMessages()
+				} else if let id = ui["message_id"] as? Int {
+					if id > 0 {
+						self.updateMessage(id)
+					}
+				}
+			}
+		}
+
+		incomingMsgObserver = nc.addObserver(
+			forName: dcNotificationIncoming,
+			object: nil, queue: OperationQueue.main
+		) { notification in
+			if let ui = notification.userInfo {
+				if self.chatId == ui["chat_id"] as! Int {
+					let id = ui["message_id"] as! Int
+					if id > 0 {
+						self.insertMessage(MRMessage(id: id))
+					}
+				}
+			}
+		}
+	}
+
+	override func viewWillDisappear(_ animated: Bool) {
+		super.viewWillDisappear(animated)
+
+		let cnt = Int(dc_get_fresh_msg_cnt(mailboxPointer, UInt32(chatId)))
+		logger.info("updating count for chat \(cnt)")
+		UIApplication.shared.applicationIconBadgeNumber = cnt
+
+		if #available(iOS 11.0, *) {
+			if disableWriting {
+				navigationController?.navigationBar.prefersLargeTitles = false
+			}
+		}
+	}
+
+	override func viewDidDisappear(_ animated: Bool) {
+		super.viewDidDisappear(animated)
+
+		setTextDraft()
+		let nc = NotificationCenter.default
+		if let msgChangedObserver = self.msgChangedObserver {
+			nc.removeObserver(msgChangedObserver)
+		}
+		if let incomingMsgObserver = self.incomingMsgObserver {
+			nc.removeObserver(incomingMsgObserver)
+		}
+	}
+
   @objc
-  func loadMoreMessages() {
+  private func loadMoreMessages() {
     DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 1) {
       DispatchQueue.main.async {
         self.messageList = self.getMessageIds(self.loadCount, from: self.messageList.count) + self.messageList
@@ -52,7 +158,7 @@ class ChatViewController: MessagesViewController {
   }
 
   @objc
-  func refreshMessages() {
+  private func refreshMessages() {
     DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 1) {
       DispatchQueue.main.async {
         self.messageList = self.getMessageIds(self.messageList.count)
@@ -65,7 +171,7 @@ class ChatViewController: MessagesViewController {
     }
   }
 
-  func loadFirstMessages() {
+  private func loadFirstMessages() {
     DispatchQueue.global(qos: .userInitiated).async {
       DispatchQueue.main.async {
         self.messageList = self.getMessageIds(self.loadCount)
@@ -76,7 +182,7 @@ class ChatViewController: MessagesViewController {
     }
   }
 
-  var textDraft: String? {
+  private var textDraft: String? {
     // FIXME: need to free pointer
     if let draft = dc_get_draft(mailboxPointer, UInt32(chatId)) {
       if let text = dc_msg_get_text(draft) {
@@ -88,7 +194,7 @@ class ChatViewController: MessagesViewController {
     return nil
   }
 
-  func getMessageIds(_ count: Int, from: Int? = nil) -> [MRMessage] {
+  private func getMessageIds(_ count: Int, from: Int? = nil) -> [MRMessage] {
     let cMessageIds = dc_get_chat_msgs(mailboxPointer, UInt32(chatId), 0, 0)
 
     let ids: [Int]
@@ -106,54 +212,9 @@ class ChatViewController: MessagesViewController {
     }
   }
 
-  required init?(coder _: NSCoder) {
-    fatalError("init(coder:) has not been implemented")
-  }
-
-  override func viewWillAppear(_ animated: Bool) {
-    super.viewWillAppear(animated)
-    configureMessageMenu()
 
-    if #available(iOS 11.0, *) {
-      if disableWriting {
-        navigationController?.navigationBar.prefersLargeTitles = true
-      }
-    }
 
-    let nc = NotificationCenter.default
-    msgChangedObserver = nc.addObserver(
-      forName: dcNotificationChanged,
-      object: nil,
-      queue: OperationQueue.main
-    ) { notification in
-      if let ui = notification.userInfo {
-        if self.disableWriting {
-          // always refresh, as we can't check currently
-          self.refreshMessages()
-        } else if let id = ui["message_id"] as? Int {
-          if id > 0 {
-            self.updateMessage(id)
-          }
-        }
-      }
-    }
-
-    incomingMsgObserver = nc.addObserver(
-      forName: dcNotificationIncoming,
-      object: nil, queue: OperationQueue.main
-    ) { notification in
-      if let ui = notification.userInfo {
-        if self.chatId == ui["chat_id"] as! Int {
-          let id = ui["message_id"] as! Int
-          if id > 0 {
-            self.insertMessage(MRMessage(id: id))
-          }
-        }
-      }
-    }
-  }
-
-  func setTextDraft() {
+  private func setTextDraft() {
     if let text = self.messageInputBar.inputTextView.text {
       let draft = dc_msg_new(mailboxPointer, DC_MSG_TEXT)
       dc_msg_set_text(draft, text.cString(using: .utf8))
@@ -164,32 +225,7 @@ class ChatViewController: MessagesViewController {
     }
   }
 
-  override func viewWillDisappear(_ animated: Bool) {
-    super.viewWillDisappear(animated)
 
-    let cnt = Int(dc_get_fresh_msg_cnt(mailboxPointer, UInt32(chatId)))
-    logger.info("updating count for chat \(cnt)")
-    UIApplication.shared.applicationIconBadgeNumber = cnt
-
-    if #available(iOS 11.0, *) {
-      if disableWriting {
-        navigationController?.navigationBar.prefersLargeTitles = false
-      }
-    }
-  }
-
-  override func viewDidDisappear(_ animated: Bool) {
-    super.viewDidDisappear(animated)
-
-    setTextDraft()
-    let nc = NotificationCenter.default
-    if let msgChangedObserver = self.msgChangedObserver {
-      nc.removeObserver(msgChangedObserver)
-    }
-    if let incomingMsgObserver = self.incomingMsgObserver {
-      nc.removeObserver(incomingMsgObserver)
-    }
-  }
 
   override var inputAccessoryView: UIView? {
     if disableWriting {
@@ -199,31 +235,9 @@ class ChatViewController: MessagesViewController {
     return messageInputBar
   }
 
-  override func viewDidLoad() {
-    messagesCollectionView.register(CustomCell.self)
-    super.viewDidLoad()
-    view.backgroundColor = DCColors.chatBackgroundColor
 
-    if !MRConfig.configured {
-      // TODO: display message about nothing being configured
-      return
-    }
-
-    let chat = MRChat(id: chatId)
-    updateTitleView(title: chat.name, subtitle: chat.subtitle)
-
-    configureMessageCollectionView()
-
-    if !disableWriting {
-      configureMessageInputBar()
-      messageInputBar.inputTextView.text = textDraft
-      messageInputBar.inputTextView.becomeFirstResponder()
-    }
-
-    loadFirstMessages()
-  }
 
-  func configureMessageMenu() {
+  private func configureMessageMenu() {
     var menuItems: [UIMenuItem]
 
     if disableWriting {
@@ -242,7 +256,7 @@ class ChatViewController: MessagesViewController {
     UIMenuController.shared.menuItems = menuItems
   }
 
-  func configureMessageCollectionView() {
+  private func configureMessageCollectionView() {
     messagesCollectionView.messagesDataSource = self
     messagesCollectionView.messageCellDelegate = self
 
@@ -275,7 +289,7 @@ class ChatViewController: MessagesViewController {
     messagesCollectionView.messagesDisplayDelegate = self
   }
 
-  func configureMessageInputBar() {
+  private func configureMessageInputBar() {
     messageInputBar.delegate = self
     messageInputBar.inputTextView.tintColor = DCColors.primary
     messageInputBar.sendButton.tintColor = DCColors.primary
@@ -301,17 +315,17 @@ class ChatViewController: MessagesViewController {
 
   private func configureInputBarItems() {
     messageInputBar.setLeftStackViewWidthConstant(to: 44, animated: false)
-    messageInputBar.setRightStackViewWidthConstant(to: 36, animated: false)
+    messageInputBar.setRightStackViewWidthConstant(to: 30, animated: false)
 
     let sendButtonImage = UIImage(named: "paper_plane")?.withRenderingMode(.alwaysTemplate)
     messageInputBar.sendButton.image = sendButtonImage
     messageInputBar.sendButton.tintColor = UIColor(white: 1, alpha: 1)
     messageInputBar.sendButton.backgroundColor = UIColor(white: 0.9, alpha: 1)
     messageInputBar.sendButton.contentEdgeInsets = UIEdgeInsets(top: 6, left: 0, bottom: 6, right: 0)
-    messageInputBar.sendButton.setSize(CGSize(width: 34, height: 34), animated: false)
+    messageInputBar.sendButton.setSize(CGSize(width: 30, height: 30), animated: false)
 
     messageInputBar.sendButton.title = nil
-    messageInputBar.sendButton.layer.cornerRadius = 18
+    messageInputBar.sendButton.layer.cornerRadius = 15
 
     messageInputBar.textViewPadding.right = -40
 
@@ -345,6 +359,10 @@ class ChatViewController: MessagesViewController {
       }
   }
 
+	@objc private func chatProfilePressed() {
+		print("Profile pressed")
+	}
+
   // MARK: - UICollectionViewDataSource
 
   public override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
@@ -666,7 +684,7 @@ extension ChatViewController: MessagesDisplayDelegate {
     }
   }
 
-  func configureAvatarView(_ avatarView: AvatarView, for message: MessageType, at indexPath: IndexPath, in _: MessagesCollectionView) {
+	func configureAvatarView(_ avatarView: AvatarView, for message: MessageType, at indexPath: IndexPath, in _: MessagesCollectionView) {
     let message = messageList[indexPath.section]
     let contact = message.fromContact
     let avatar = Avatar(image: contact.profileImage, initials: Utils.getInitials(inputName: contact.name))

+ 1 - 1
deltachat-ios/Controller/NewChatViewController.swift

@@ -271,7 +271,7 @@ class NewChatViewController: UITableViewController {
             })
         } else {
           let contactId = contactIds[row]
-         	self.coordinator?.showNewChat(contactId: contactId)
+         		self.coordinator?.showNewChat(contactId: contactId)
          }
       } else {
         showSettingsAlert()

+ 9 - 4
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -42,11 +42,12 @@ class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
 	}()
 
 	private lazy var mailboxController: UIViewController = {
-		let controller = ChatListController()
+		let controller = ChatViewController(chatId: Int(DC_CHAT_ID_DEADDROP), title: "Mailbox")
+		controller.disableWriting = true
 		let nav = NavigationController(rootViewController: controller)
 		let settingsImage = UIImage(named: "message")
 		nav.tabBarItem = UITabBarItem(title: "Mailbox", image: settingsImage, tag: 4)
-		let coordinator = ChatListCoordinator(navigationController: nav)
+		let coordinator = ChatViewCoordinator(navigationController: nav)
 		self.childCoordinators.append(coordinator)
 		controller.coordinator = coordinator
 		return nav
@@ -119,9 +120,13 @@ class ContactListCoordinator: Coordinator {
 
 class ChatViewCoordinator: Coordinator {
 	var rootViewController: UIViewController
+	let navigationController: UINavigationController
 
-	init(rootViewController: UIViewController) {
-		self.rootViewController = rootViewController
+	var childCoordinators:[Coordinator] = []
+
+	init(navigationController: UINavigationController) {
+		self.rootViewController = navigationController.viewControllers.first!
+		self.navigationController = navigationController
 	}
 }
 

+ 19 - 0
deltachat-ios/View/InitialsLabel.swift

@@ -0,0 +1,19 @@
+//
+//  InitialsLabel.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 03.05.19.
+//  Copyright © 2019 Jonas Reinsch. All rights reserved.
+//
+
+import UIKit
+
+class InitialsLabel: UILabel {
+
+	init(name: String, size: CGFloat, color: UIColor) {
+		self.text = name.i
+	}
+
+
+
+}