@@ -16,6 +16,28 @@ struct ChannelData{
16// TODO: make search controller availiable
16// TODO: make search controller availiable
17class ChannelListController: UITableViewController, DataDelegate {
17class ChannelListController: UITableViewController, DataDelegate {
19+ // MARK:- filter search controller
21+ var filteredDataSource = [Channel]()
22+ var myProtocol: DataDelegate?
24+ var isFiltering: Bool {
25+ return searchController.isActive && !searchBarIsEmpty()
28+ func searchBarIsEmpty() -> Bool {
29+ return searchController.searchBar.text?.isEmpty ?? true
32+ func filterContentForSearchText(_ searchText: String, scope: String = "All")
34+ filteredDataSource = ChannelListController.dataSource.filter({(keys : Channel) -> Bool in
35+ return keys.title.lowercased().contains(searchText.lowercased())
38+ tableView.reloadData()
19 func passData(for row: Int, channel: Channel) {
41 func passData(for row: Int, channel: Channel) {
20 ChannelListController.dataSource[row].hashtags = channel.hashtags
42 ChannelListController.dataSource[row].hashtags = channel.hashtags
21 ChannelListController.dataSource[row].people = channel.people
43 ChannelListController.dataSource[row].people = channel.people
@@ -29,8 +51,8 @@ class ChannelListController: UITableViewController, DataDelegate {
29 super.viewDidLoad()
51 super.viewDidLoad()
30 setUpNavigationBar()
52 setUpNavigationBar()
31 navigationItem.title = "Channels"
53 navigationItem.title = "Channels"
32−
54+ searchController.obscuresBackgroundDuringPresentation = false
33− searchController.searchBar.placeholder = "Search anything"
55+ searchController.searchBar.placeholder = "Search channel"
34 navigationItem.searchController = searchController
56 navigationItem.searchController = searchController
@@ -48,7 +70,7 @@ class ChannelListController: UITableViewController, DataDelegate {
49 // insertion
71 // insertion
50 tableView.beginUpdates()
72 tableView.beginUpdates()
51− ChannelListController.dataSource.insert(Channel(title: "Untitled", subtitle: "No", hashtags: [], people: []), at: 0)
73+ ChannelListController.dataSource.insert(Channel(title: "Untitled", subtitle: "No", hashtags: [], people: [], posts: []), at: 0)
52 tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .none)
74 tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .none)
53 tableView.endUpdates()
75 tableView.endUpdates()
@@ -61,22 +83,37 @@ class ChannelListController: UITableViewController, DataDelegate {
63 static var dataSource : [Channel] = [
85 static var dataSource : [Channel] = [
64− Channel(title: "Title", subtitle: "subtitle", hashtags: ["# sad", "# happy"], people: ["Seva", "Andrey"]),
86+ Channel(title: "Title", subtitle: "subtitle", hashtags: ["# sad", "# happy"], people: ["Seva", "Andrey"], posts: [Post(dataArray: [.text("Le Lorem Ipsum est simplement du faux texte employé dans la composition et la mise en page avant impression. Le Lorem Ipsum est le faux texte standard.")], from: User(name: "vbogomazova", id: 2, fullName: "Богомазова Вероника Львовна"), date: "14.02.19 в 12:05")]),
65− Channel(title: "Title2", subtitle: "subtitle2", hashtags: ["# studyhard", "# university"], people: ["Pasha", "Olya", "Andrey", "Ilya"]),
87+ Channel(title: "Title2", subtitle: "subtitle2", hashtags: ["# studyhard", "# university"], people: ["Pasha", "Olya", "Andrey", "Ilya"], posts:
66− Channel(title: "Title3", subtitle: "subtitle3", hashtags: ["# lol", "# meme", "# hehe"], people: ["Superman"])
88+ [
89+ Post(dataArray: [.text("L'avantage du Lorem Ipsum sur un texte générique comme 'Du texte. Du texte. Du texte.' est qu'il possède une distribution de lettres plus ou moins normale.")], from: User(name: "vbogomazova", id: 2, fullName: "Богомазова Вероника Львовна"), date: "14.02.19 в 12:05"),
90+ Post(dataArray: [.text("par accident, souvent intentionnellement (histoire d'y rajouter de petits clins d'oeil, voire des phrases embarassantes).")], from: User(name: "vbogomazova", id: 2, fullName: "Богомазова Вероника Львовна"), date: "14.02.19 в 12:05")
92+ Channel(title: "Title3", subtitle: "subtitle3", hashtags: ["# lol", "# meme", "# hehe"], people: ["Superman"], posts: [Post(dataArray: [.text("Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen de polices de texte. Il n'a pas fait que survivre cinq siècles, mais s'est aussi adapté à la bureautique informatique, sans que son contenu n'en soit modifié.")], from: User(name: "vbogomazova", id: 2, fullName: "Богомазова Вероника Львовна"), date: "14.02.19 в 12:05")])
69 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
95 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
97+ return filteredDataSource.count
70− return ChannelListController.dataSource.count
99+ return ChannelListController.dataSource.count
73 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
103 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
75 let cell = tableView.dequeueReusableCell(withIdentifier: channelCellId, for: indexPath)
106 let cell = tableView.dequeueReusableCell(withIdentifier: channelCellId, for: indexPath)
76− cell.textLabel?.text = ChannelListController.dataSource[indexPath.row].title
77− cell.detailTextLabel?.text = ChannelListController.dataSource[indexPath.row].subtitle
110+ cell.textLabel?.text = filteredDataSource[indexPath.row].title
111+ cell.detailTextLabel?.text = filteredDataSource[indexPath.row].subtitle
113+ cell.textLabel?.text = ChannelListController.dataSource[indexPath.row].title
114+ cell.detailTextLabel?.text = ChannelListController.dataSource[indexPath.row].subtitle
80 return cell
117 return cell
@@ -109,4 +146,22 @@ class ChannelListController: UITableViewController, DataDelegate {
110 return [editButton, deleteButton]
147 return [editButton, deleteButton]
150+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
153+ navigationController?.popViewController(animated: true)
154+ myProtocol?.passData(for: 0, channel: filteredDataSource[indexPath.row])
156+ navigationController?.popViewController(animated: true)
157+ myProtocol?.passData(for: 0, channel: ChannelListController.dataSource[indexPath.row])
163+extension ChannelListController : UISearchResultsUpdating {
164+ func updateSearchResults(for searchController: UISearchController) {
165+ filterContentForSearchText(searchController.searchBar.text!)