pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
changeset 2344 544503156670
parent 2325 cf0e71c1ef72
child 2345 4dd2c835d36f
     1.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Tue Jun 27 09:54:24 2017 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Tue Jun 27 15:13:24 2017 +0200
     1.3 @@ -25,6 +25,7 @@
     1.4          var isSynching: Bool = false
     1.5      }
     1.6  
     1.7 +    var viewModel = EmailListViewModel()
     1.8      var config: EmailListConfig?
     1.9      var state = UIState()
    1.10      let searchController = UISearchController(searchResultsController: nil)
    1.11 @@ -158,6 +159,7 @@
    1.12                              cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    1.13          let cell = tableView.dequeueReusableCell(
    1.14              withIdentifier: "EmailListViewCell", for: indexPath) as! EmailListViewCell
    1.15 +        //mantener el configure cell para tal de no generar un vm para celdas
    1.16          if let message = cell.configureCell(config: config, indexPath: indexPath) {
    1.17              associate(message: message, toCell: cell)
    1.18          }
    1.19 @@ -310,7 +312,6 @@
    1.20  
    1.21      func createForwardAction(cell: EmailListViewCell) -> UIAlertAction {
    1.22          return UIAlertAction(title: "Forward", style: .default) { (action) in
    1.23 -            //self.performSegue(withIdentifier: self.segueCompose, sender: cell)
    1.24              self.performSegue(withIdentifier: .segueForward, sender: cell)
    1.25          }
    1.26      }
    1.27 @@ -322,18 +323,31 @@
    1.28  
    1.29      // MARK: - Content Search
    1.30  
    1.31 -    func filterContentForSearchText(searchText: String) {
    1.32 -
    1.33 +    func filterContentForSearchText(searchText: String? = nil, clear: Bool) {
    1.34 +        if clear {
    1.35 +            updateFilter(filter: Filter.unified())
    1.36 +        } else {
    1.37 +            if let text = searchText, text != "" {
    1.38 +                let f = Filter.search(subject: text)
    1.39 +                if filterEnabled {
    1.40 +                    f.and(filter: Filter.unread())
    1.41 +                    updateFilter(filter: f)
    1.42 +                }
    1.43 +                if config != nil {
    1.44 +                    updateFilter(filter: f)
    1.45 +                }
    1.46 +            }
    1.47 +        }
    1.48      }
    1.49 -
    1.50  }
    1.51  
    1.52  extension EmailListViewController: UISearchResultsUpdating, UISearchControllerDelegate {
    1.53      public func updateSearchResults(for searchController: UISearchController) {
    1.54 -        filterContentForSearchText(searchText: searchController.searchBar.text!)
    1.55 +        filterContentForSearchText(searchText: searchController.searchBar.text!, clear: false)
    1.56      }
    1.57  
    1.58      func didDismissSearchController(_ searchController: UISearchController) {
    1.59 +        filterContentForSearchText(clear: true)
    1.60      }
    1.61  }
    1.62