pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
changeset 1242 4cecb482ae1c
parent 965 baea625419a9
child 1243 2a9465fd0bfc
equal deleted inserted replaced
971:7f3a8c5d7f05 1242:4cecb482ae1c
   218         indexPath: IndexPath)-> [UITableViewRowAction]? {
   218         indexPath: IndexPath)-> [UITableViewRowAction]? {
   219         let cell = tableView.cellForRow(at: indexPath) as! EmailListViewCell
   219         let cell = tableView.cellForRow(at: indexPath) as! EmailListViewCell
   220         if let email = messageAt(indexPath: indexPath) {
   220         if let email = messageAt(indexPath: indexPath) {
   221             let isFlagAction = createIsFlagAction(message: email, cell: cell)
   221             let isFlagAction = createIsFlagAction(message: email, cell: cell)
   222             let deleteAction = createDeleteAction(cell)
   222             let deleteAction = createDeleteAction(cell)
   223             let isReadAction = createIsReadAction(message: email, cell: cell)
   223             //let isReadAction = createIsReadAction(message: email, cell: cell)
   224             return [deleteAction,isFlagAction,isReadAction]
   224             let moreAction = createMoreAction(message: email, cell: cell)
       
   225             return [deleteAction,isFlagAction,moreAction]
   225         }
   226         }
   226         return nil
   227         return nil
   227     }
   228     }
   228 
   229 
   229     // MARK: - Misc
   230     // MARK: - Misc
   315         // TODO: IOS 222: Sync flags back to server
   316         // TODO: IOS 222: Sync flags back to server
   316     }
   317     }
   317 
   318 
   318     func createIsFlagAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
   319     func createIsFlagAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
   319         // preparing the title action to show when user swipe
   320         // preparing the title action to show when user swipe
   320         var localizedIsFlagTitle = " "
   321 //        var localizedIsFlagTitle = " "
   321         if (isImportant(message: message)) {
   322 //        if (isImportant(message: message)) {
   322             localizedIsFlagTitle = NSLocalizedString(
   323 //            localizedIsFlagTitle = NSLocalizedString(
   323                 "Unflag",
   324 //                "Unflag",
   324                 comment: "Unflag button title in swipe action on EmailListViewController")
   325 //                comment: "Unflag button title in swipe action on EmailListViewController")
   325         } else {
   326 //        } else {
   326             localizedIsFlagTitle = NSLocalizedString(
   327 //            localizedIsFlagTitle = NSLocalizedString(
   327                 "Flag",
   328 //                "Flag",
   328                 comment: "Flag button title in swipe action on EmailListViewController")
   329 //                comment: "Flag button title in swipe action on EmailListViewController")
   329         }
   330 //        }
   330 
   331 
   331         // preparing action to trigger when user swipe
   332         // preparing action to trigger when user swipe
   332         let isFlagCompletionHandler: (UITableViewRowAction, IndexPath) -> Void =
   333         let isFlagCompletionHandler: (UITableViewRowAction, IndexPath) -> Void =
   333             { (action, indexPath) in
   334             { (action, indexPath) in
   334                 if (self.isImportant(message: message)) {
   335                 if (self.isImportant(message: message)) {
   339                 }
   340                 }
   340                 self.syncFlagsToServer(message: message)
   341                 self.syncFlagsToServer(message: message)
   341                 self.tableView.reloadRows(at: [indexPath], with: .none)
   342                 self.tableView.reloadRows(at: [indexPath], with: .none)
   342         }
   343         }
   343         // creating the action
   344         // creating the action
   344         let isFlagAction = UITableViewRowAction(style: .default, title: localizedIsFlagTitle,
   345         let isFlagAction = UITableViewRowAction(style: .normal, title: "          ",
   345                                                 handler: isFlagCompletionHandler)
   346                                                 handler: isFlagCompletionHandler)
   346         // changing default action color
   347         // changing default action color
   347         isFlagAction.backgroundColor = UIColor.orange
   348         let swipeFlagImage = UIImage(named: "swipe-flag")
       
   349         let flagIconColor = UIColor(patternImage: swipeFlagImage!)
       
   350         isFlagAction.backgroundColor = flagIconColor
   348 
   351 
   349         return isFlagAction
   352         return isFlagAction
   350     }
   353     }
   351 
   354 
   352     func createDeleteAction (_ cell: EmailListViewCell) -> UITableViewRowAction {
   355     func createDeleteAction (_ cell: EmailListViewCell) -> UITableViewRowAction {
   353 
   356 
   354         // preparing the title action to show when user swipe
   357         // preparing the title action to show when user swipe
   355         let localizedDeleteTitle = NSLocalizedString(
       
   356             "Erase",
       
   357             comment: "Erase button title in swipe action on EmailListViewController")
       
   358 
   358 
   359         let deleteCompletionHandler: (UITableViewRowAction, IndexPath) -> Void =
   359         let deleteCompletionHandler: (UITableViewRowAction, IndexPath) -> Void =
   360             { (action, indexPath) in
   360             { (action, indexPath) in
   361                 let message = self.messageAt(indexPath: indexPath)
   361                 let message = self.messageAt(indexPath: indexPath)
   362                 message?.imapFlags?.deleted = true
   362                 message?.imapFlags?.deleted = true
   363                 self.syncFlagsToServer(message: message!)
   363                 self.syncFlagsToServer(message: message!)
   364         }
   364         }
   365 
   365 
   366         // creating the action
   366         // creating the action
   367         let deleteAction = UITableViewRowAction(style: .default, title: localizedDeleteTitle,
   367         let deleteAction = UITableViewRowAction(style: .normal, title: "          ",
   368                                                 handler: deleteCompletionHandler)
   368                                                 handler: deleteCompletionHandler)
       
   369         let swipeTrashImage = UIImage(named: "swipe-trash")
       
   370         let trashIconColor = UIColor(patternImage: swipeTrashImage!)
       
   371         deleteAction.backgroundColor = trashIconColor
   369         return deleteAction
   372         return deleteAction
   370     }
   373     }
   371 
   374 
   372     func createIsReadAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
   375     func createIsReadAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
   373         // preparing the title action to show when user swipe
   376         // preparing the title action to show when user swipe
   397                                                 handler: isReadCompletionHandler)
   400                                                 handler: isReadCompletionHandler)
   398         isReadAction.backgroundColor = UIColor.blue
   401         isReadAction.backgroundColor = UIColor.blue
   399 
   402 
   400         return isReadAction
   403         return isReadAction
   401     }
   404     }
       
   405     
       
   406     func createMoreAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
       
   407         let moreCompletitionHandler :(UITableViewRowAction, IndexPath) -> Void = {(action, indexPath) in
       
   408             self.showMoreActionSheet(cell: cell)
       
   409         }
       
   410         let moreAction = UITableViewRowAction(style: .normal, title: "          ", handler: moreCompletitionHandler)
       
   411         let swipeMoreImage = UIImage(named: "swipe-more")
       
   412         let moreIconColor = UIColor(patternImage: swipeMoreImage!)
       
   413         moreAction.backgroundColor = moreIconColor
       
   414         return moreAction
       
   415     }
       
   416     
       
   417     // MARK: - Action Sheet
       
   418     
       
   419     func showMoreActionSheet(cell: EmailListViewCell) {
       
   420         let alertControler = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
       
   421         let cancelAction = createCancelAction()
       
   422         let replyAction = createReplyAction(cell: cell)
       
   423         let forwardAction = createForwardAction(cell: cell)
       
   424         let markAction = createMarkAction()
       
   425         alertControler.addAction(cancelAction)
       
   426         alertControler.addAction(replyAction)
       
   427         alertControler.addAction(forwardAction)
       
   428         alertControler.addAction(markAction)
       
   429         present(alertControler, animated: true, completion: nil)
       
   430     }
       
   431     
       
   432     // MARK: - Action Sheet Actions
       
   433 
       
   434     func createCancelAction() -> UIAlertAction {
       
   435       return  UIAlertAction(title: "Cancel", style: .cancel) { (action) in}
       
   436     }
       
   437     
       
   438     func createReplyAction(cell: EmailListViewCell) ->  UIAlertAction {
       
   439         return UIAlertAction(title: "Reply", style: .default) { (action) in
       
   440             self.performSegue(withIdentifier: self.segueCompose, sender: cell)
       
   441         }
       
   442     }
       
   443     
       
   444     func createForwardAction(cell: EmailListViewCell) -> UIAlertAction {
       
   445         return UIAlertAction(title: "Forward", style: .default) { (action) in
       
   446             self.performSegue(withIdentifier: self.segueCompose, sender: cell)
       
   447         }
       
   448     }
       
   449     
       
   450     func createMarkAction() -> UIAlertAction {
       
   451         return UIAlertAction(title: "Mark", style: .default) { (action) in
       
   452         }
       
   453     }
   402 }
   454 }