pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
changeset 3266 72d4c077ec46
parent 3226 9295883a4519
child 3272 f65c21439f43
equal deleted inserted replaced
3265:e97dad3351d9 3266:72d4c077ec46
   383 
   383 
   384 // MARK: - TableViewCell Actions
   384 // MARK: - TableViewCell Actions
   385 
   385 
   386 extension EmailListViewController {
   386 extension EmailListViewController {
   387     private func createRowAction(image: UIImage?,
   387     private func createRowAction(image: UIImage?,
   388                                  action: @escaping (UITableViewRowAction, IndexPath) -> Void,
   388                                  action: @escaping (UITableViewRowAction, IndexPath) -> Void
   389                                  title: String) -> UITableViewRowAction {
   389         ) -> UITableViewRowAction {
   390         let rowAction = UITableViewRowAction(style: .normal, title: title, handler: action)
   390         let rowAction = UITableViewRowAction(style: .normal, title: nil, handler: action)
   391         if let theImage = image {
   391         if let theImage = image {
   392             let iconColor = UIColor(patternImage: theImage)
   392             let iconColor = UIColor(patternImage: theImage)
   393             rowAction.backgroundColor = iconColor
   393             rowAction.backgroundColor = iconColor
   394         }
   394         }
   395         return rowAction
   395         return rowAction
   409             tableView.beginUpdates()
   409             tableView.beginUpdates()
   410             tableView.setEditing(false, animated: true)
   410             tableView.setEditing(false, animated: true)
   411             tableView.reloadRows(at: [indexPath], with: .none)
   411             tableView.reloadRows(at: [indexPath], with: .none)
   412             tableView.endUpdates()
   412             tableView.endUpdates()
   413         }
   413         }
   414         let title: String
   414         return createRowAction(image: UIImage(named: "swipe-flag"), action: action)
   415         if row.isFlagged{
       
   416             let unflagString = NSLocalizedString("Unflag", comment: "Message action (on swipe)")
       
   417             title = "\n\n\(unflagString)"
       
   418         } else {
       
   419             let flagString = NSLocalizedString("Flag", comment: "Message action (on swipe)")
       
   420             title = "\n\n\(flagString)"
       
   421         }
       
   422         return createRowAction(image: UIImage(named: "swipe-flag"), action: action, title: title)
       
   423     }
   415     }
   424     
   416     
   425     func createDeleteAction(forCellAt indexPath: IndexPath) -> UITableViewRowAction? {
   417     func createDeleteAction(forCellAt indexPath: IndexPath) -> UITableViewRowAction? {
   426         func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
   418         func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
   427             tableView.beginUpdates()
   419             tableView.beginUpdates()
   428             model?.delete(forIndexPath: indexPath) // mark for deletion/trash
   420             model?.delete(forIndexPath: indexPath) // mark for deletion/trash
   429             tableView.deleteRows(at: [indexPath], with: .none)
   421             tableView.deleteRows(at: [indexPath], with: .none)
   430             tableView.endUpdates()
   422             tableView.endUpdates()
   431         }
   423         }
   432         
   424 
   433         let title = NSLocalizedString("Delete", comment: "Message action (on swipe)")
   425         return createRowAction(image: UIImage(named: "swipe-trash"), action: action)
   434         return createRowAction(image: UIImage(named: "swipe-trash"), action: action,
       
   435                                title: "\n\n\(title)")
       
   436     }
   426     }
   437     
   427     
   438     func createMoreAction(forCellAt indexPath: IndexPath) -> UITableViewRowAction? {
   428     func createMoreAction(forCellAt indexPath: IndexPath) -> UITableViewRowAction? {
   439         func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
   429         func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
   440             self.showMoreActionSheet(forRowAt: indexPath)
   430             self.showMoreActionSheet(forRowAt: indexPath)
   441         }
   431         }
   442         
   432 
   443         let title = NSLocalizedString("More", comment: "Message action (on swipe)")
       
   444         return createRowAction(image: UIImage(named: "swipe-more"),
   433         return createRowAction(image: UIImage(named: "swipe-more"),
   445                                action: action,
   434                                action: action)
   446                                title: "\n\n\(title)")
       
   447     }
   435     }
   448 }
   436 }
   449 
   437 
   450 // MARK: - SegueHandlerType
   438 // MARK: - SegueHandlerType
   451 
   439