pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
changeset 1623 de640fc8295f
parent 1620 30a2dd92a5d2
child 1650 33eba5b4f5f5
     1.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Fri Feb 03 14:37:35 2017 +0100
     1.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Fri Feb 03 15:21:00 2017 +0100
     1.3 @@ -30,7 +30,7 @@
     1.4  
     1.5      override func viewDidLoad() {
     1.6          super.viewDidLoad()
     1.7 -        
     1.8 +
     1.9          title = "EmailList.title".localized
    1.10          UIHelper.emailListTableHeight(self.tableView)
    1.11          addSearchBar()
    1.12 @@ -38,7 +38,7 @@
    1.13  
    1.14      override func viewWillAppear(_ animated: Bool) {
    1.15          super.viewWillAppear(animated)
    1.16 -        
    1.17 +
    1.18          if MiscUtil.isUnitTest() {
    1.19              return
    1.20          }
    1.21 @@ -53,7 +53,7 @@
    1.22          super.viewWillDisappear(animated)
    1.23          MessageModelConfig.messageFolderDelegate = nil
    1.24      }
    1.25 -    
    1.26 +
    1.27      func initialConfig() {
    1.28          guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
    1.29              return
    1.30 @@ -66,7 +66,7 @@
    1.31              performSegue(withIdentifier:.segueAddNewAccount, sender: self)
    1.32          }
    1.33      }
    1.34 -    
    1.35 +
    1.36      func addSearchBar() {
    1.37          searchController.searchResultsUpdater = self
    1.38          searchController.dimsBackgroundDuringPresentation = false
    1.39 @@ -76,9 +76,9 @@
    1.40          tableView.setContentOffset(CGPoint(x: 0.0, y: 40.0), animated: false)
    1.41      }
    1.42  
    1.43 -    
    1.44 +
    1.45      @IBAction func showUnreadButtonTapped(_ sender: UIBarButtonItem) {}
    1.46 -    
    1.47 +
    1.48      func updateModel() {
    1.49          tableView.reloadData()
    1.50      }
    1.51 @@ -134,7 +134,7 @@
    1.52  
    1.53      override func tableView(_ tableView: UITableView, editActionsForRowAt
    1.54          indexPath: IndexPath)-> [UITableViewRowAction]? {
    1.55 -        
    1.56 +
    1.57          let cell = tableView.cellForRow(at: indexPath) as! EmailListViewCell
    1.58          if let email = cell.messageAt(indexPath: indexPath, config: config) {
    1.59              let flagAction = createFlagAction(message: email, cell: cell)
    1.60 @@ -148,8 +148,8 @@
    1.61      // MARK: - Misc
    1.62  
    1.63      func createRowAction(cell: EmailListViewCell,
    1.64 -        image: UIImage?, action: @escaping (UITableViewRowAction, IndexPath) -> Void,
    1.65 -        title: String) -> UITableViewRowAction {
    1.66 +                         image: UIImage?, action: @escaping (UITableViewRowAction, IndexPath) -> Void,
    1.67 +                         title: String) -> UITableViewRowAction {
    1.68          let rowAction = UITableViewRowAction(
    1.69              style: .normal, title: title, handler: action)
    1.70  
    1.71 @@ -189,7 +189,7 @@
    1.72              guard let message = cell.messageAt(indexPath: indexPath, config: self.config) else {
    1.73                  return
    1.74              }
    1.75 -            
    1.76 +
    1.77              message.imapFlags?.deleted = true
    1.78              message.save()
    1.79              self.tableView.reloadData()
    1.80 @@ -223,7 +223,7 @@
    1.81  
    1.82          return isReadAction
    1.83      }
    1.84 -    
    1.85 +
    1.86      func createMoreAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
    1.87          func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
    1.88              self.showMoreActionSheet(cell: cell)
    1.89 @@ -233,15 +233,15 @@
    1.90              cell: cell, image: UIImage(named: "swipe-more"), action: action,
    1.91              title: "\n\nMore".localized)
    1.92      }
    1.93 -    
    1.94 +
    1.95      // MARK: - Action Sheet
    1.96 -    
    1.97 +
    1.98      func showMoreActionSheet(cell: EmailListViewCell) {
    1.99          let alertControler = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
   1.100          alertControler.view.tintColor = .pEpGreen
   1.101          let cancelAction = createCancelAction()
   1.102          let replyAction = createReplyAction(cell: cell)
   1.103 -        let replyAllAction = createReplyAction(cell: cell)
   1.104 +        let replyAllAction = createReplyAllAction(cell: cell)
   1.105          let forwardAction = createForwardAction(cell: cell)
   1.106          let markAction = createMarkAction()
   1.107          alertControler.addAction(cancelAction)
   1.108 @@ -254,23 +254,23 @@
   1.109          }
   1.110          present(alertControler, animated: true, completion: nil)
   1.111      }
   1.112 -    
   1.113 +
   1.114      // MARK: - Action Sheet Actions
   1.115  
   1.116      func createCancelAction() -> UIAlertAction {
   1.117 -      return  UIAlertAction(title: "Cancel", style: .cancel) { (action) in}
   1.118 +        return  UIAlertAction(title: "Cancel", style: .cancel) { (action) in}
   1.119      }
   1.120 -    
   1.121 +
   1.122      func createReplyAction(cell: EmailListViewCell) ->  UIAlertAction {
   1.123          return UIAlertAction(title: "Reply", style: .default) { (action) in
   1.124 -           // self.performSegue(withIdentifier: self.segueCompose, sender: cell)
   1.125 +            // self.performSegue(withIdentifier: self.segueCompose, sender: cell)
   1.126              self.performSegue(withIdentifier: .segueCompose, sender: cell)
   1.127          }
   1.128      }
   1.129  
   1.130      func createReplyAllAction(cell: EmailListViewCell) ->  UIAlertAction {
   1.131 -        return UIAlertAction(title: "ReplyAll", style: .default) { (action) in
   1.132 -            self.performSegue(withIdentifier: .segueCompose, sender: cell)
   1.133 +        return UIAlertAction(title: "Reply All", style: .default) { (action) in
   1.134 +            self.performSegue(withIdentifier: .segueReplyAll, sender: cell)
   1.135          }
   1.136      }
   1.137  
   1.138 @@ -280,30 +280,30 @@
   1.139              self.performSegue(withIdentifier: .segueCompose, sender: cell)
   1.140          }
   1.141      }
   1.142 -    
   1.143 +
   1.144      func createMarkAction() -> UIAlertAction {
   1.145          return UIAlertAction(title: "Mark", style: .default) { (action) in
   1.146          }
   1.147      }
   1.148 -    
   1.149 +
   1.150      // MARK: - Content Search
   1.151 -    
   1.152 +
   1.153      func filterContentForSearchText(searchText: String) {
   1.154 -        
   1.155 +
   1.156      }
   1.157 - 
   1.158 +
   1.159      // MARK: - Actions
   1.160 -//    @IBAction func unwindToEmailList(for unwindSegue: UIStoryboardSegue) {
   1.161 -//        
   1.162 -//    }
   1.163 -   
   1.164 +    //    @IBAction func unwindToEmailList(for unwindSegue: UIStoryboardSegue) {
   1.165 +    //
   1.166 +    //    }
   1.167 +
   1.168  }
   1.169  
   1.170  extension EmailListViewController: UISearchResultsUpdating, UISearchControllerDelegate {
   1.171      public func updateSearchResults(for searchController: UISearchController) {
   1.172          filterContentForSearchText(searchText: searchController.searchBar.text!)
   1.173      }
   1.174 -    
   1.175 +
   1.176      func didDismissSearchController(_ searchController: UISearchController) {
   1.177      }
   1.178  }
   1.179 @@ -311,17 +311,18 @@
   1.180  // MARK: - Navigation
   1.181  
   1.182  extension EmailListViewController: SegueHandlerType {
   1.183 -    
   1.184 +
   1.185      // MARK: - SegueHandlerType
   1.186 -    
   1.187 +
   1.188      enum SegueIdentifier: String {
   1.189          case segueAddNewAccount
   1.190          case segueEditAccounts
   1.191          case segueShowEmail
   1.192          case segueCompose
   1.193 +        case segueReplyAll
   1.194          case noSegue
   1.195      }
   1.196 -    
   1.197 +
   1.198      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
   1.199          switch segueIdentifier(for: segue) {
   1.200          case .segueCompose:
   1.201 @@ -332,15 +333,26 @@
   1.202              //
   1.203              //                destination.originalMessage = draft
   1.204              //                destination.composeMode = .draft
   1.205 -        //            }
   1.206 +            //            }
   1.207 +            break
   1.208 +        case .segueReplyAll:
   1.209 +            if let nav = segue.destination as? UINavigationController,
   1.210 +                let destination = nav.topViewController as? ComposeTableViewController,
   1.211 +                let cell = sender as? EmailListViewCell,
   1.212 +                let indexPath = self.tableView.indexPath(for: cell),
   1.213 +                let email = cell.messageAt(indexPath: indexPath, config: config) {
   1.214 +                destination.composeMode = .replyAll
   1.215 +                destination.appConfig = config?.appConfig
   1.216 +                destination.originalMessage = email
   1.217 +            }
   1.218              break
   1.219          case .segueShowEmail:
   1.220              if let vc = segue.destination as? EmailViewController,
   1.221                  let cell = sender as? EmailListViewCell,
   1.222                  let indexPath = self.tableView.indexPath(for: cell),
   1.223                  let email = cell.messageAt(indexPath: indexPath, config: config) {
   1.224 -                    vc.appConfig = config?.appConfig
   1.225 -                    vc.message = email
   1.226 +                vc.appConfig = config?.appConfig
   1.227 +                vc.message = email
   1.228              }
   1.229              break
   1.230          default: ()