pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
changeset 3369 e99419ad3c71
parent 3368 e79ab6166c5b
child 3419 f4c5d2ec661f
     1.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Tue Nov 07 12:59:41 2017 +0100
     1.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Tue Nov 07 15:08:22 2017 +0100
     1.3 @@ -255,18 +255,18 @@
     1.4      func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
     1.5          if indexPath.section == 0 {
     1.6              let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
     1.7 -                //self.viewModel.delete(section: indexPath.section, cell: indexPath.row)
     1.8 +                self.deleteAction(forCellAt: indexPath)
     1.9              }
    1.10              configure(action: deleteAction, with: .trash)
    1.11  
    1.12              let flagAction = SwipeAction(style: .default, title: "Flag") { action, indexPath in
    1.13 -                //self.viewModel.delete(section: indexPath.section, cell: indexPath.row)
    1.14 +                self.flagAction(forCellAt: indexPath)
    1.15              }
    1.16              flagAction.hidesWhenSelected = true
    1.17              configure(action: flagAction, with: .flag)
    1.18  
    1.19              let moreAction = SwipeAction(style: .default, title: "More") { action, indexPath in
    1.20 -                //self.viewModel.delete(section: indexPath.section, cell: indexPath.row)
    1.21 +                self.moreAction(forCellAt: indexPath)
    1.22              }
    1.23              moreAction.hidesWhenSelected = true
    1.24              configure(action: moreAction, with: .more)
    1.25 @@ -298,17 +298,6 @@
    1.26              action.transitionDelegate = ScaleTransition.default
    1.27          }
    1.28      }
    1.29 -
    1.30 -    override func tableView(_ tableView: UITableView, editActionsForRowAt
    1.31 -        indexPath: IndexPath)-> [UITableViewRowAction]? {
    1.32 -        guard let flagAction = createFlagAction(forCellAt: indexPath),
    1.33 -            let deleteAction = createDeleteAction(forCellAt: indexPath),
    1.34 -            let moreAction = createMoreAction(forCellAt: indexPath) else {
    1.35 -                Log.shared.errorAndCrash(component: #function, errorString: "Error creating action.")
    1.36 -                return nil
    1.37 -        }
    1.38 -        return [deleteAction, flagAction, moreAction]
    1.39 -    }
    1.40      
    1.41      override func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    1.42          cancelOperation(for: indexPath)
    1.43 @@ -462,43 +451,28 @@
    1.44          return rowAction
    1.45      }
    1.46      
    1.47 -    func createFlagAction(forCellAt indexPath: IndexPath) -> UITableViewRowAction? {
    1.48 +    func flagAction(forCellAt indexPath: IndexPath) {
    1.49          guard let row = model?.row(for: indexPath) else {
    1.50              Log.shared.errorAndCrash(component: #function, errorString: "No data for indexPath!")
    1.51 -            return nil
    1.52 +            return
    1.53          }
    1.54 -        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
    1.55 -            if row.isFlagged {
    1.56 -                model?.unsetFlagged(forIndexPath: indexPath)
    1.57 -            } else {
    1.58 -                model?.setFlagged(forIndexPath: indexPath)
    1.59 -            }
    1.60 -            tableView.beginUpdates()
    1.61 -            tableView.setEditing(false, animated: true)
    1.62 -            tableView.reloadRows(at: [indexPath], with: .none)
    1.63 -            tableView.endUpdates()
    1.64 +        if row.isFlagged {
    1.65 +            model?.unsetFlagged(forIndexPath: indexPath)
    1.66 +        } else {
    1.67 +            model?.setFlagged(forIndexPath: indexPath)
    1.68          }
    1.69 -        return createRowAction(image: UIImage(named: "swipe-flag"), action: action)
    1.70 +        tableView.beginUpdates()
    1.71 +        tableView.setEditing(false, animated: true)
    1.72 +        tableView.reloadRows(at: [indexPath], with: .none)
    1.73 +        tableView.endUpdates()
    1.74      }
    1.75      
    1.76 -    func createDeleteAction(forCellAt indexPath: IndexPath) -> UITableViewRowAction? {
    1.77 -        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
    1.78 -            tableView.beginUpdates()
    1.79 -            model?.delete(forIndexPath: indexPath) // mark for deletion/trash
    1.80 -            tableView.deleteRows(at: [indexPath], with: .none)
    1.81 -            tableView.endUpdates()
    1.82 -        }
    1.83 -
    1.84 -        return createRowAction(image: UIImage(named: "swipe-trash"), action: action)
    1.85 +    func deleteAction(forCellAt indexPath: IndexPath) {
    1.86 +        model?.delete(forIndexPath: indexPath) // mark for deletion/trash
    1.87      }
    1.88      
    1.89 -    func createMoreAction(forCellAt indexPath: IndexPath) -> UITableViewRowAction? {
    1.90 -        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
    1.91 -            self.showMoreActionSheet(forRowAt: indexPath)
    1.92 -        }
    1.93 -
    1.94 -        return createRowAction(image: UIImage(named: "swipe-more"),
    1.95 -                               action: action)
    1.96 +    func moreAction(forCellAt indexPath: IndexPath) {
    1.97 +        self.showMoreActionSheet(forRowAt: indexPath)
    1.98      }
    1.99  }
   1.100