diff --git a/enzevalos_iphone.xcodeproj/project.pbxproj b/enzevalos_iphone.xcodeproj/project.pbxproj index 8a821a953c9c8096520480470556a01f3be20c3b..8f1a882a32a762e839c6faf69ac3db340ddb49bc 100644 --- a/enzevalos_iphone.xcodeproj/project.pbxproj +++ b/enzevalos_iphone.xcodeproj/project.pbxproj @@ -267,6 +267,7 @@ A1EB05761D9567F2008659C1 /* read */, A1EB05751D956748008659C1 /* send */, A13526781D955BDF00D3BFE1 /* AppDelegate.swift */, + A1EB05871D956879008659C1 /* AddressHandler.swift */, A1EB059B1D956957008659C1 /* NSDateCompare.swift */, A1EB05911D95692A008659C1 /* MailObject.swift */, A1EB059D1D956963008659C1 /* EnzevalosContact.swift */, @@ -309,7 +310,6 @@ A1EB057D1D956848008659C1 /* VENDataDelegate.swift */, A1EB05811D95685B008659C1 /* CollectionDataDelegate.swift */, A1EB05831D956867008659C1 /* TableViewDataDelegate.swift */, - A1EB05871D956879008659C1 /* AddressHandler.swift */, A1EB05791D956829008659C1 /* ContactCell.swift */, A1EB05851D956872008659C1 /* FrequentCell.swift */, A1EB05891D956890008659C1 /* ContactCell.xib */, @@ -324,8 +324,8 @@ A1EB058F1D956923008659C1 /* ReadViewController.swift */, F12041FA1DA3FBF7002E4940 /* ListViewController.swift */, F12041FC1DA409A5002E4940 /* ListViewCell.swift */, - A1EB05931D956931008659C1 /* InboxCellDelegator.swift */, F12060811DA552FC00F6EF37 /* MailHandlerDelegator.swift */, + A1EB05931D956931008659C1 /* InboxCellDelegator.swift */, A1EB05951D956939008659C1 /* InboxTableViewCell.swift */, A1EB05971D956947008659C1 /* InboxViewController.swift */, F120607F1DA540FE00F6EF37 /* RefreshControlExtension.swift */, diff --git a/enzevalos_iphone/EnzevalosContact.swift b/enzevalos_iphone/EnzevalosContact.swift index 932f500386fae5b5bdcc01d76abf1886136c9a76..a20ed432d259efa29b4eb0d3d17341daa28d947a 100644 --- a/enzevalos_iphone/EnzevalosContact.swift +++ b/enzevalos_iphone/EnzevalosContact.swift @@ -27,9 +27,9 @@ class EnzevalosContact: Comparable { } func ==(lhs: EnzevalosContact, rhs: EnzevalosContact) -> Bool { - return lhs.mails.maxElement()!.time == rhs.mails.maxElement()!.time + return lhs.mails.first!.time == rhs.mails.first!.time } func <(lhs: EnzevalosContact, rhs: EnzevalosContact) -> Bool { - return lhs.mails.maxElement()!.time > rhs.mails.maxElement()!.time -} \ No newline at end of file + return lhs.mails.first!.time > rhs.mails.first!.time +} diff --git a/enzevalos_iphone/InboxTableViewCell.swift b/enzevalos_iphone/InboxTableViewCell.swift index bc5098e01f5a47cd789f5ed7cd28fafab0531caf..a4e03e9bc986735c5cee31ddcfaca122a6e9c833 100644 --- a/enzevalos_iphone/InboxTableViewCell.swift +++ b/enzevalos_iphone/InboxTableViewCell.swift @@ -46,9 +46,9 @@ class InboxTableViewCell: UITableViewCell { var enzContact: EnzevalosContact? { didSet { if let con = enzContact { - self.firstMail = con.mails.last + self.firstMail = con.mails.first if con.mails.count > 1 { - self.secondMail = con.mails[con.mails.endIndex - 2] + self.secondMail = con.mails[1] } self.contact = con.contact } diff --git a/enzevalos_iphone/InboxTableViewCell.xib b/enzevalos_iphone/InboxTableViewCell.xib index e8472f1465f3676b507323255c8dd9703aa7fb27..5c8354e2441f0c5cf9b602d642baf713912642a0 100644 --- a/enzevalos_iphone/InboxTableViewCell.xib +++ b/enzevalos_iphone/InboxTableViewCell.xib @@ -13,9 +13,15 @@ <rect key="frame" x="0.0" y="0.0" width="400" height="130"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="CFu-ns-kay" id="iQP-01-jFC" userLabel="Container"> - <frame key="frameInset" width="400" height="129.5"/> + <frame key="frameInset" width="400" height="129"/> <autoresizingMask key="autoresizingMask"/> <subviews> + <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="uDO-9h-a86" userLabel="Icon View"> + <constraints> + <constraint firstAttribute="width" constant="30" id="Zf5-eH-DtF"/> + <constraint firstAttribute="height" constant="30" id="n7I-Eu-a0k"/> + </constraints> + </imageView> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="WNp-Ty-Hv1"> <constraints> <constraint firstAttribute="height" constant="70" id="Bei-PK-STi"/> @@ -94,12 +100,6 @@ <action selector="firstButtonPressed:" destination="CFu-ns-kay" eventType="touchUpInside" id="YFb-kT-nNt"/> </connections> </button> - <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="uDO-9h-a86" userLabel="Icon View"> - <constraints> - <constraint firstAttribute="width" constant="30" id="Zf5-eH-DtF"/> - <constraint firstAttribute="height" constant="30" id="n7I-Eu-a0k"/> - </constraints> - </imageView> </subviews> <constraints> <constraint firstItem="Woe-Z6-TzX" firstAttribute="leading" secondItem="6Ac-fp-DaH" secondAttribute="trailing" constant="-498" id="1Xo-Rd-5M9"/> diff --git a/enzevalos_iphone/InboxViewController.swift b/enzevalos_iphone/InboxViewController.swift index 5bc57981176df9d008e016b18f6add2ae5d84288..8ccc775ce8d92fc1d9b12a81a69bbed1150e7c03 100644 --- a/enzevalos_iphone/InboxViewController.swift +++ b/enzevalos_iphone/InboxViewController.swift @@ -14,13 +14,11 @@ class InboxViewController : UITableViewController, InboxCellDelegator, MailHandl var contacts: [EnzevalosContact] = [] { didSet { self.contacts.sortInPlace() - dispatch_async(dispatch_get_main_queue(), { () -> Void in - self.tableView.reloadData() - print("Refreshed TableView") - }) + self.tableView.reloadData() } } - let mailHandler = MailHandler() + +let mailHandler = MailHandler() @IBOutlet weak var lastUpdateButton: UIBarButtonItem! var lastUpdateLabel = UILabel(frame: CGRectZero) @@ -34,9 +32,9 @@ class InboxViewController : UITableViewController, InboxCellDelegator, MailHandl var lastUpdate: NSDate? func addNewMail(mail: Mail) { - var isAdded = false for contact in contacts { for address in contact.contact.emailAddresses { + print("addr: \(address.value) sender: \(mail.sender?.mailbox)") if address.value as? String == mail.sender?.mailbox { // Kontakt existiert bereits if !contact.mails.contains(mail) { @@ -74,7 +72,7 @@ class InboxViewController : UITableViewController, InboxCellDelegator, MailHandl tableView.sectionFooterHeight = 0 self.refreshControl?.addTarget(self, action: #selector(InboxViewController.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged) -// self.refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh") + self.refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh") lastUpdateLabel.sizeToFit() lastUpdateLabel.backgroundColor = UIColor.clearColor() @@ -92,7 +90,6 @@ class InboxViewController : UITableViewController, InboxCellDelegator, MailHandl } func refresh(refreshControl: UIRefreshControl) { - print("refresh") lastUpdateText = "Updating..." self.mailHandler.recieve() } @@ -102,6 +99,8 @@ class InboxViewController : UITableViewController, InboxCellDelegator, MailHandl lastUpdate = NSDate() rc.endRefreshing() lastUpdateText = "Just refreshed" + self.contacts.sortInPlace() + self.tableView.reloadData() } } diff --git a/enzevalos_iphone/MailHandler.swift b/enzevalos_iphone/MailHandler.swift index d1a5f5c82253068e9853dfde789aeb38936ba8ac..21229a5f34212fd1a56996b1651549b75a69ac55 100644 --- a/enzevalos_iphone/MailHandler.swift +++ b/enzevalos_iphone/MailHandler.swift @@ -105,9 +105,9 @@ class MailHandler { if UInt64(message.uid) > biggest { biggest = UInt64(message.uid) } + dispatch_group_enter(dispatchGroup) let op = self.IMAPSession!.fetchMessageByUIDOperationWithFolder(folder, uid: message.uid) op.start { (err, data) -> Void in - dispatch_group_enter(dispatchGroup) let msgParser = MCOMessageParser(data: data) let html: String = msgParser.plainTextBodyRendering() var rec: [MCOAddress] = [] @@ -118,17 +118,17 @@ class MailHandler { rec.append(r as! MCOAddress) } } - let mail = Mail(uid: message.uid, sender: header.from, receivers: rec, time: header.date, received: true, subject: "UID: \(message.uid) \(header.subject)", body: html, isEncrypted: false, isVerified: false, trouble: false, isUnread: !messageRead) - + let mail = Mail(uid: message.uid, sender: header.from, receivers: rec, time: header.date, received: true, subject: header.subject, body: html, isEncrypted: false, isVerified: false, trouble: false, isUnread: !messageRead) + self.delegate?.addNewMail(mail) + dispatch_group_leave(dispatchGroup) } self.lastUID = biggest - - dispatch_group_notify(dispatchGroup, dispatch_get_main_queue()) { - print("All Done!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - self.delegate?.getMailCompleted() - } + } + dispatch_group_notify(dispatchGroup, dispatch_get_main_queue()) { + self.delegate?.getMailCompleted() + self.IMAPSession?.disconnectOperation().start({_ in }) } } } diff --git a/enzevalos_iphone/MailObject.swift b/enzevalos_iphone/MailObject.swift index 4983209264e9844c873925384db4dcca8b67ff18..6cc5c514323fa8bf999700207b5f182fa47bfded 100644 --- a/enzevalos_iphone/MailObject.swift +++ b/enzevalos_iphone/MailObject.swift @@ -80,5 +80,5 @@ func ==(lhs: Mail, rhs: Mail) -> Bool { } func <(lhs: Mail, rhs: Mail) -> Bool { - return lhs.time < rhs.time + return lhs.time > rhs.time }