From da2801a3ab0e48d9669f55f2b1383a829888ca03 Mon Sep 17 00:00:00 2001
From: jakobsbode <jakobsbode@mi.fu-berlin.de>
Date: Fri, 14 Jul 2017 16:21:07 +0200
Subject: [PATCH] UI should be working

---
 .../FolderListViewController.swift            |  7 +++---
 enzevalos_iphone/FolderViewController.swift   | 22 +++++++++++--------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/enzevalos_iphone/FolderListViewController.swift b/enzevalos_iphone/FolderListViewController.swift
index 35456f1b..d88616a0 100644
--- a/enzevalos_iphone/FolderListViewController.swift
+++ b/enzevalos_iphone/FolderListViewController.swift
@@ -15,6 +15,7 @@ class FolderListViewController: UITableViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         self.navigationItem.title = folder.name
+        print("Hallo")
     }
     
     override func numberOfSections(in tableView: UITableView) -> Int {
@@ -28,7 +29,7 @@ class FolderListViewController: UITableViewController {
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         let cell = tableView.dequeueReusableCell(withIdentifier: "folderListCell") as! FolderListCell
         
-        let mail = folder.mailsOfFolder[indexPath.row]
+        let mail = folder.mailsOfFolder.sorted()[indexPath.row]
         
         cell.body.text = mail.body
         if let contact = mail.from.contact {
@@ -38,7 +39,7 @@ class FolderListViewController: UITableViewController {
             cell.from.text = mail.from.mailAddress
         }
         cell.subject.text = mail.subject
-        cell.date.text = mail.date.description
+        cell.date.text = mail.timeString
         
         if mail.isSecure {
             cell.secureImageView.image = IconsStyleKit.imageOfLetter
@@ -113,7 +114,7 @@ class FolderListViewController: UITableViewController {
     }
     
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
-        performSegue(withIdentifier: "readFolderMailSegue", sender: folder.mailsOfFolder[indexPath.row])
+        performSegue(withIdentifier: "readFolderMailSegue", sender: folder.mailsOfFolder.sorted()[indexPath.row])
     }
     
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
diff --git a/enzevalos_iphone/FolderViewController.swift b/enzevalos_iphone/FolderViewController.swift
index f902d662..73d404b5 100644
--- a/enzevalos_iphone/FolderViewController.swift
+++ b/enzevalos_iphone/FolderViewController.swift
@@ -33,6 +33,10 @@ class FolderViewController: UITableViewController {
             }
         }
     }
+    override func viewDidAppear(_ animated: Bool) {
+        super.viewDidAppear(animated)
+        tableView.reloadData()
+    }
     override func numberOfSections(in tableView: UITableView) -> Int {
         var count = 0
         
@@ -51,16 +55,16 @@ class FolderViewController: UITableViewController {
         return count
     }
     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        if section == 0 {
+        if sectionType(IndexPath.init(row: 0, section: section)) == .inbox {
            return 1
         }
-        if section == 2 {
-            return 7
+        if sectionType(IndexPath.init(row: 0, section: section)) == .folders {
+            return folders.count
         }
-        return folders.count <= 0 ? 0 : folders.count - 1
+        return getMails().count
     }
     override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-        if indexPath.section == 2 {
+        if sectionType(indexPath) == .mails {
             return 71
         }
         return 44
@@ -83,7 +87,7 @@ class FolderViewController: UITableViewController {
                     cell.from.text = mail.from.mailAddress
                 }
                 cell.subject.text = mail.subject
-                cell.date.text = mail.date.description
+                cell.date.text = mail.timeString
                 
                 if mail.isSecure {
                     cell.secureImageView.image = IconsStyleKit.imageOfLetter
@@ -91,12 +95,12 @@ class FolderViewController: UITableViewController {
                 else {
                     cell.secureImageView.image = IconsStyleKit.imageOfPostcard
                 }
-                if !mail.flag.contains(MCOMessageFlag.seen) {
+                if !mail.isRead {
                     cell.markImageView.image = "🔵".image()
                     cell.body.font = UIFont.boldSystemFont(ofSize: cell.body.font.pointSize)
                     cell.subject.font = UIFont.boldSystemFont(ofSize: cell.subject.font.pointSize)
                 }
-                if mail.flag.contains(MCOMessageFlag.answered) {
+                if mail.isAnwered {
                     cell.replyImageView.image = "↩️".image()
                 }
                 
@@ -195,7 +199,7 @@ class FolderViewController: UITableViewController {
     }
     func getMails() -> [PersistentMail] {
         if let folder = self.presentedFolder {
-            return folder.mailsOfFolder
+            return folder.mailsOfFolder.sorted()
         }
         return []
     }
-- 
GitLab