merge IOS-1713
authorXavier Algarra <xavier@pep-project.org>
Tue, 06 Aug 2019 16:37:52 +0200
changeset 9565463e0faf5c5e
parent 9564 a9bb4767c249
parent 9563 f70767c9062b
child 9567 f5166670bdbe
child 9569 b59c1853367b
child 9573 25f3a6133bbc
child 9586 21ba58ea92fa
merge IOS-1713
     1.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewCell.swift	Tue Aug 06 16:37:23 2019 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewCell.swift	Tue Aug 06 16:37:52 2019 +0200
     1.3 @@ -38,6 +38,15 @@
     1.4  
     1.5      private var viewModel: MessageViewModel?
     1.6  
     1.7 +    /**
     1.8 +     Original selection background color
     1.9 +     - Note: When a cell is selected in edit mode the background color must be the same as
    1.10 +     unselected.
    1.11 +     For that reason we need to store the original selected background color to avoid loosing it
    1.12 +     if we need it in the future.
    1.13 +     */
    1.14 +    private var originalBackgroundSelectionColor: UIColor?
    1.15 +
    1.16      private var hasAttachment:Bool = false {
    1.17          didSet {
    1.18              if hasAttachment {
    1.19 @@ -72,6 +81,7 @@
    1.20  
    1.21      override func awakeFromNib() {
    1.22          super.awakeFromNib()
    1.23 +        originalBackgroundSelectionColor = selectedBackgroundView?.backgroundColor
    1.24          contactImageView.applyContactImageCornerRadius()
    1.25          resetToDefault()
    1.26      }
    1.27 @@ -220,10 +230,28 @@
    1.28          dateLabel.font = font
    1.29      }
    1.30  
    1.31 -    /**
    1.32 -     - Returns: " " (a space) instead of an empty String, otherwise the original String
    1.33 -     unchanged.
    1.34 -     */
    1.35 +
    1.36 +    /// This method highlights the cell that is being pressed.
    1.37 +    /// - Note: We only accept this if the cell is not in edit mode.
    1.38 +    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
    1.39 +        if !isEditing {
    1.40 +            super.setHighlighted(highlighted, animated: animated)
    1.41 +        }
    1.42 +    }
    1.43 +
    1.44 +    override func setSelected(_ selected: Bool, animated: Bool) {
    1.45 +        super.setSelected(selected, animated: false)
    1.46 +        let viewForHighlight = UIView()
    1.47 +        self.selectedBackgroundView = viewForHighlight
    1.48 +        if self.isEditing {
    1.49 +            viewForHighlight.backgroundColor = UIColor.clear
    1.50 +        } else {
    1.51 +            viewForHighlight.backgroundColor = originalBackgroundSelectionColor
    1.52 +        }
    1.53 +    }
    1.54 +
    1.55 +    /// - Returns: " " (a space) instead of an empty String, otherwise the original String
    1.56 +    /// unchanged.
    1.57      private func atLeastOneSpace(possiblyEmptyString: String) -> String {
    1.58          if possiblyEmptyString == "" {
    1.59              return " "
     2.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Tue Aug 06 16:37:23 2019 +0200
     2.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Tue Aug 06 16:37:52 2019 +0200
     2.3 @@ -20,6 +20,8 @@
     2.4      }
     2.5  
     2.6      public static let storyboardId = "EmailListViewController"
     2.7 +    /// This is used to handle the selection row when it recives an update
     2.8 +    /// and also when swipeCellAction is performed to store from which cell the action is done.
     2.9      private var lastSelectedIndexPath: IndexPath?
    2.10  
    2.11      let searchController = UISearchController(searchResultsController: nil)
    2.12 @@ -80,7 +82,7 @@
    2.13      }
    2.14  
    2.15      override func viewWillDisappear(_ animated: Bool) {
    2.16 -        guard let isIphone = splitViewController?.isCollapsed, let last = lastSelectedIndexPath else {
    2.17 +        guard let isIphone = splitViewController?.isCollapsed else {
    2.18              return
    2.19          }
    2.20          if !isIphone {
    2.21 @@ -427,12 +429,6 @@
    2.22          }
    2.23      }
    2.24  
    2.25 -    private func resetSelectionIfNeeded(for indexPath: IndexPath) {
    2.26 -        if lastSelectedIndexPath == indexPath {
    2.27 -            resetSelection()
    2.28 -        }
    2.29 -    }
    2.30 -
    2.31      private func resetSelection() {
    2.32          tableView.selectRow(at: lastSelectedIndexPath, animated: false, scrollPosition: .none)
    2.33      }
    2.34 @@ -499,11 +495,6 @@
    2.35  
    2.36      override func tableView(_ tableView: UITableView,
    2.37                              cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    2.38 -        if lastSelectedIndexPath == indexPath {
    2.39 -            defer {
    2.40 -                tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
    2.41 -            }
    2.42 -        }
    2.43  
    2.44          let cell = tableView.dequeueReusableCell(withIdentifier: EmailListViewCell.storyboardId,
    2.45                                                   for: indexPath)
    2.46 @@ -518,6 +509,11 @@
    2.47              Log.shared.errorAndCrash("dequeued wrong cell")
    2.48          }
    2.49  
    2.50 +        //restores selection state for updated or replaced cells.
    2.51 +        if lastSelectedIndexPath == indexPath {
    2.52 +            tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
    2.53 +        }
    2.54 +
    2.55          return cell
    2.56      }
    2.57  
    2.58 @@ -800,7 +796,7 @@
    2.59      }
    2.60  
    2.61      func emailListViewModel(viewModel: EmailListViewModel, didInsertDataAt indexPaths: [IndexPath]) {
    2.62 -        lastSelectedIndexPath = tableView.indexPathForSelectedRow
    2.63 +        lastSelectedIndexPath = nil
    2.64          tableView.insertRows(at: indexPaths, with: .automatic)
    2.65      }
    2.66  
    2.67 @@ -818,14 +814,9 @@
    2.68              showNoMessageSelectedIfNeeded()
    2.69          }
    2.70      }
    2.71 -    //!!!: comented code probably not needed anymore. if something strange appears, check this.
    2.72 -    //!!!: the reselection of the cell is performed in the cell for row. 
    2.73      func emailListViewModel(viewModel: EmailListViewModel, didUpdateDataAt indexPaths: [IndexPath]) {
    2.74          lastSelectedIndexPath = tableView.indexPathForSelectedRow
    2.75          tableView.reloadRows(at: indexPaths, with: .none)
    2.76 -//        for indexPath in indexPaths {
    2.77 -//            resetSelectionIfNeeded(for: indexPath)
    2.78 -//        }
    2.79      }
    2.80  
    2.81      func emailListViewModel(viewModel: EmailListViewModel, didMoveData atIndexPath: IndexPath, toIndexPath: IndexPath) {
    2.82 @@ -1140,8 +1131,6 @@
    2.83                  return
    2.84              }
    2.85              vC.appConfig = appConfig
    2.86 -            //!!!: was commented. Is this dead code? if so, rm!
    2.87 -            //vC.hidesBottomBarWhenPushed = true
    2.88              break
    2.89          case .segueShowMoveToFolder:
    2.90              var selectedRows: [IndexPath] = []