pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
changeset 2369 6ab35cb4c20f
parent 2363 e969a926d09b
child 2404 092e3013db61
     1.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Mon Jul 03 12:55:04 2017 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Mon Jul 03 17:53:59 2017 +0200
     1.3 @@ -20,7 +20,7 @@
     1.4      let imageProvider = IdentityImageProvider()
     1.5  }
     1.6  
     1.7 -class EmailListViewController: UITableViewController, FilterUpdateProtocol {
     1.8 +class EmailListViewController: UITableViewController {
     1.9      struct UIState {
    1.10          var isSynching: Bool = false
    1.11      }
    1.12 @@ -72,7 +72,7 @@
    1.13              fol.updateLastLookAt()
    1.14          }
    1.15  
    1.16 -        viewModel = EmailListViewModel(config: config)
    1.17 +        viewModel = EmailListViewModel(config: config, delegate: self)
    1.18          MessageModelConfig.messageFolderDelegate = self
    1.19          
    1.20      }
    1.21 @@ -118,13 +118,13 @@
    1.22                  vm.filterEnabled = false
    1.23                  textFilterButton.title = ""
    1.24                  enableFilterButton.image = UIImage(named: "unread-icon")
    1.25 -                updateFilter(filter: Filter.unified())
    1.26 +                vm.updateFilter(filter: Filter.unified())
    1.27              } else {
    1.28                  vm.filterEnabled = true
    1.29                  textFilterButton.title = "Filter by: unread"
    1.30                  enableFilterButton.image = UIImage(named: "unread-icon-active")
    1.31                  if config != nil {
    1.32 -                    updateFilter(filter: Filter.unread())
    1.33 +                    vm.updateFilter(filter: Filter.unread())
    1.34                  }
    1.35              }
    1.36              self.textFilterButton.isEnabled = vm.filterEnabled
    1.37 @@ -133,11 +133,6 @@
    1.38  
    1.39      }
    1.40  
    1.41 -    func updateFilter(filter: Filter) {
    1.42 -        config?.folder?.updateFilter(filter: filter)
    1.43 -        self.tableView.reloadData()
    1.44 -    }
    1.45 -
    1.46      // MARK: - UI State
    1.47  
    1.48      func updateUI() {
    1.49 @@ -330,33 +325,19 @@
    1.50          }
    1.51      }
    1.52  
    1.53 -    // MARK: - Content Search
    1.54 -
    1.55 -    func filterContentForSearchText(searchText: String? = nil, clear: Bool) {
    1.56 -        if clear {
    1.57 -            updateFilter(filter: Filter.unified())
    1.58 -        } else {
    1.59 -            if let text = searchText, text != "" {
    1.60 -                let f = Filter.search(subject: text)
    1.61 -                if let vm = viewModel, vm.filterEnabled {
    1.62 -                    f.and(filter: Filter.unread())
    1.63 -                    updateFilter(filter: f)
    1.64 -                }
    1.65 -                if config != nil {
    1.66 -                    updateFilter(filter: f)
    1.67 -                }
    1.68 -            }
    1.69 -        }
    1.70 -    }
    1.71  }
    1.72  
    1.73  extension EmailListViewController: UISearchResultsUpdating, UISearchControllerDelegate {
    1.74      public func updateSearchResults(for searchController: UISearchController) {
    1.75 -        filterContentForSearchText(searchText: searchController.searchBar.text!, clear: false)
    1.76 +        if let vm = viewModel {
    1.77 +            vm.filterContentForSearchText(searchText: searchController.searchBar.text!, clear: false)
    1.78 +        }
    1.79      }
    1.80  
    1.81      func didDismissSearchController(_ searchController: UISearchController) {
    1.82 -        filterContentForSearchText(clear: true)
    1.83 +        if let vm = viewModel {
    1.84 +            vm.filterContentForSearchText(clear: true)
    1.85 +        }
    1.86      }
    1.87  }
    1.88  
    1.89 @@ -413,7 +394,7 @@
    1.90              break
    1.91          case .segueFilter:
    1.92              if let destiny = segue.destination as? FilterTableViewController {
    1.93 -                destiny.filterDelegate = self
    1.94 +                destiny.filterDelegate = self.viewModel
    1.95                  destiny.inFolder = false
    1.96                  destiny.filterEnabled = self.config?.folder?.filter as! Filter?
    1.97                  destiny.hidesBottomBarWhenPushed = true
    1.98 @@ -484,3 +465,9 @@
    1.99          }
   1.100      }
   1.101  }
   1.102 +
   1.103 +extension EmailListViewController: tableViewUpdate {
   1.104 +    func updateView() {
   1.105 +        self.tableView.reloadData()
   1.106 +    }
   1.107 +}