git.iko.soy/dashared/GDproject
on master help sign in
slightly impoved channels. only animation in uisearchbar is left
13f2878Darya Rednikina
GDproject.xcodeproj/project.pbxproj+4−8
@@ -14,8 +14,7 @@
14 125BD5812217314A008A3575 /* NewsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125BD5802217314A008A3575 /* NewsVC.swift */; };
14 125BD5812217314A008A3575 /* NewsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125BD5802217314A008A3575 /* NewsVC.swift */; };
15 1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1288B5CD221F1158002BE6B1 /* DataStorage.swift */; };
15 1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1288B5CD221F1158002BE6B1 /* DataStorage.swift */; };
16 1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */; };
16 1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */; };
17− 1291BE2F222152E1009D3F23 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE2E222152E1009D3F23 /* TabBarController.swift */; };
17+ 1291BE342221569B009D3F23 /* TabbarCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */; };
18− 1291BE312221530D009D3F23 /* TabbarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1291BE302221530D009D3F23 /* TabbarView.swift */; };
19 12D7D133221C321600B35452 /* ChannelListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D132221C321600B35452 /* ChannelListController.swift */; };
18 12D7D133221C321600B35452 /* ChannelListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D132221C321600B35452 /* ChannelListController.swift */; };
20 12D7D135221C42B700B35452 /* ChannelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D134221C42B700B35452 /* ChannelController.swift */; };
19 12D7D135221C42B700B35452 /* ChannelController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D134221C42B700B35452 /* ChannelController.swift */; };
21 12D7D137221D78E800B35452 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D136221D78E800B35452 /* Channel.swift */; };
20 12D7D137221D78E800B35452 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D7D136221D78E800B35452 /* Channel.swift */; };
@@ -74,8 +73,7 @@
74 125BD5802217314A008A3575 /* NewsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsVC.swift; sourceTree = "<group>"; };
73 125BD5802217314A008A3575 /* NewsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsVC.swift; sourceTree = "<group>"; };
75 1288B5CD221F1158002BE6B1 /* DataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStorage.swift; sourceTree = "<group>"; };
74 1288B5CD221F1158002BE6B1 /* DataStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStorage.swift; sourceTree = "<group>"; };
76 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelsCoordinator.swift; sourceTree = "<group>"; };
75 1291BE2C2221312C009D3F23 /* ChannelsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelsCoordinator.swift; sourceTree = "<group>"; };
77− 1291BE2E222152E1009D3F23 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = "<group>"; };
78− 1291BE302221530D009D3F23 /* TabbarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabbarView.swift; sourceTree = "<group>"; };
76+ 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabbarCoordinator.swift; sourceTree = "<group>"; };
79 12D7D132221C321600B35452 /* ChannelListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelListController.swift; sourceTree = "<group>"; };
77 12D7D132221C321600B35452 /* ChannelListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelListController.swift; sourceTree = "<group>"; };
80 12D7D134221C42B700B35452 /* ChannelController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelController.swift; sourceTree = "<group>"; };
78 12D7D134221C42B700B35452 /* ChannelController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelController.swift; sourceTree = "<group>"; };
81 12D7D136221D78E800B35452 /* Channel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Channel.swift; sourceTree = "<group>"; };
79 12D7D136221D78E800B35452 /* Channel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Channel.swift; sourceTree = "<group>"; };
@@ -137,8 +135,7 @@
137 1291BE32222154C3009D3F23 /* Coordinator tab bar? */ = {
135 1291BE32222154C3009D3F23 /* Coordinator tab bar? */ = {
138 isa = PBXGroup;
136 isa = PBXGroup;
139 children = (
137 children = (
140− 1291BE2E222152E1009D3F23 /* TabBarController.swift */,
138+ 1291BE332221569B009D3F23 /* TabbarCoordinator.swift */,
141− 1291BE302221530D009D3F23 /* TabbarView.swift */,
142 );
139 );
143 path = "Coordinator tab bar?";
140 path = "Coordinator tab bar?";
144 sourceTree = "<group>";
141 sourceTree = "<group>";
@@ -319,14 +316,13 @@
319 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */,
316 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */,
320 125BD57F22171D73008A3575 /* Extentions.swift in Sources */,
317 125BD57F22171D73008A3575 /* Extentions.swift in Sources */,
321 12D7D133221C321600B35452 /* ChannelListController.swift in Sources */,
318 12D7D133221C321600B35452 /* ChannelListController.swift in Sources */,
322− 1291BE312221530D009D3F23 /* TabbarView.swift in Sources */,
319+ 1291BE342221569B009D3F23 /* TabbarCoordinator.swift in Sources */,
323 1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */,
320 1291BE2D2221312D009D3F23 /* ChannelsCoordinator.swift in Sources */,
324 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */,
321 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */,
325 1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */,
322 1288B5CE221F1158002BE6B1 /* DataStorage.swift in Sources */,
326 125BD57D22171D2A008A3575 /* ProfileViewController.swift in Sources */,
323 125BD57D22171D2A008A3575 /* ProfileViewController.swift in Sources */,
327 12DB7FDB2218590C0096878E /* InfoCell.swift in Sources */,
324 12DB7FDB2218590C0096878E /* InfoCell.swift in Sources */,
328 12DB7FD922181E660096878E /* BasicInfoCell.swift in Sources */,
325 12DB7FD922181E660096878E /* BasicInfoCell.swift in Sources */,
329− 1291BE2F222152E1009D3F23 /* TabBarController.swift in Sources */,
330 12D7D135221C42B700B35452 /* ChannelController.swift in Sources */,
326 12D7D135221C42B700B35452 /* ChannelController.swift in Sources */,
331 12E36D9C221424EA006FCDD7 /* AppDelegate.swift in Sources */,
327 12E36D9C221424EA006FCDD7 /* AppDelegate.swift in Sources */,
332 12DB7FD722181CD20096878E /* BasicInfoController.swift in Sources */,
328 12DB7FD722181CD20096878E /* BasicInfoController.swift in Sources */,
GDproject/Base.lproj/Main.storyboard+2−2
@@ -407,7 +407,7 @@
407 <!--Posts-->
407 <!--Posts-->
408 <scene sceneID="RSd-UJ-34B">
408 <scene sceneID="RSd-UJ-34B">
409 <objects>
409 <objects>
410− <navigationController automaticallyAdjustsScrollViewInsets="NO" id="NuV-ZG-ld2" sceneMemberID="viewController">
410+ <navigationController storyboardIdentifier="navChannels" automaticallyAdjustsScrollViewInsets="NO" id="NuV-ZG-ld2" sceneMemberID="viewController">
411 <tabBarItem key="tabBarItem" title="Posts" id="dH2-sL-YsR"/>
411 <tabBarItem key="tabBarItem" title="Posts" id="dH2-sL-YsR"/>
412 <toolbarItems/>
412 <toolbarItems/>
413 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="6qB-3A-tuL">
413 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="6qB-3A-tuL">
@@ -446,7 +446,7 @@
446 <!--Profile-->
446 <!--Profile-->
447 <scene sceneID="dJj-Hp-Wa9">
447 <scene sceneID="dJj-Hp-Wa9">
448 <objects>
448 <objects>
449− <navigationController automaticallyAdjustsScrollViewInsets="NO" id="tae-5q-wvT" sceneMemberID="viewController">
449+ <navigationController storyboardIdentifier="navPosts" automaticallyAdjustsScrollViewInsets="NO" id="tae-5q-wvT" sceneMemberID="viewController">
450 <tabBarItem key="tabBarItem" title="Profile" id="lYy-LQ-AcR"/>
450 <tabBarItem key="tabBarItem" title="Profile" id="lYy-LQ-AcR"/>
451 <toolbarItems/>
451 <toolbarItems/>
452 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="q3a-ph-c8V">
452 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" largeTitles="YES" id="q3a-ph-c8V">
GDproject/Controller/ News and channels/ChannelListController.swift+20−7
@@ -23,6 +23,7 @@ class ChannelListController: UITableViewController, DataDelegate {
23 var filteredDataSource = [Channel]()
23 var filteredDataSource = [Channel]()
24
24
25 var myProtocol: DataDelegate?
25 var myProtocol: DataDelegate?
26+ var displayingChannel: Channel?
26
27
27 var isFiltering: Bool {
28 var isFiltering: Bool {
28 return searchController.isActive && !searchBarIsEmpty()
29 return searchController.isActive && !searchBarIsEmpty()
@@ -51,18 +52,22 @@ class ChannelListController: UITableViewController, DataDelegate {
51 super.viewDidLoad()
52 super.viewDidLoad()
52 setUpNavigationBar()
53 setUpNavigationBar()
53 navigationItem.title = "Channels"
54 navigationItem.title = "Channels"
55+ searchController.searchResultsUpdater = self
54 searchController.obscuresBackgroundDuringPresentation = false
56 searchController.obscuresBackgroundDuringPresentation = false
55 searchController.searchBar.placeholder = "Search channel"
57 searchController.searchBar.placeholder = "Search channel"
56 navigationItem.searchController = searchController
58 navigationItem.searchController = searchController
59+ definesPresentationContext = true
57 }
60 }
58
61
59 func setUpNavigationBar(){
62 func setUpNavigationBar(){
63+ navigationController?.navigationItem.largeTitleDisplayMode = .always
60 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
64 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
61 }
65 }
62
66
63 override func viewWillAppear(_ animated: Bool)
67 override func viewWillAppear(_ animated: Bool)
64 {
68 {
65 super.viewWillAppear(animated)
69 super.viewWillAppear(animated)
70+ searchController.isActive = false
66 tableView.reloadData()
71 tableView.reloadData()
67 }
72 }
68
73
@@ -70,15 +75,15 @@ class ChannelListController: UITableViewController, DataDelegate {
70 {
75 {
71 // insertion
76 // insertion
72 tableView.beginUpdates()
77 tableView.beginUpdates()
73− ChannelListController.dataSource.insert(Channel(title: "Untitled", subtitle: "No", hashtags: [], people: [], posts: []), at: 0)
78+ ChannelListController.dataSource.insert(Channel(title: "Untitled", subtitle: "No", hashtags: [], people: [], posts: []), at: 1)
74− tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .none)
79+ tableView.insertRows(at: [IndexPath(row: 1, section: 0)], with: .none)
75 tableView.endUpdates()
80 tableView.endUpdates()
76
81
77− // editing mode is one automatically
82+ // editing mode is on automatically
78 let vc = storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
83 let vc = storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
79− vc.index = 0
84+ vc.index = 1
80 vc.myProtocol = self
85 vc.myProtocol = self
81− vc.channel = ChannelListController.dataSource[0]
86+ vc.channel = ChannelListController.dataSource[1]
82 navigationController?.pushViewController(vc, animated: true)
87 navigationController?.pushViewController(vc, animated: true)
83 }
88 }
84
89
@@ -142,6 +147,10 @@ class ChannelListController: UITableViewController, DataDelegate {
142
147
143
148
144 let deleteButton = UITableViewRowAction(style: .normal, title: "Delete") { [weak self] (action, indexPath) in
149 let deleteButton = UITableViewRowAction(style: .normal, title: "Delete") { [weak self] (action, indexPath) in
150+ if (ChannelListController.dataSource[indexPath.row] == self!.displayingChannel!)
151+ {
152+ self?.myProtocol?.passData(for: 0, channel: ChannelListController.dataSource[0])
153+ }
145 self?.tableView.beginUpdates()
154 self?.tableView.beginUpdates()
146 ChannelListController.dataSource.remove(at: indexPath.row)
155 ChannelListController.dataSource.remove(at: indexPath.row)
147 self?.tableView.deleteRows(at: [indexPath], with: .none)
156 self?.tableView.deleteRows(at: [indexPath], with: .none)
@@ -157,9 +166,13 @@ class ChannelListController: UITableViewController, DataDelegate {
157 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
166 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
158 {
167 {
159 if isFiltering {
168 if isFiltering {
160− onChannelSelected?(filteredDataSource[indexPath.row])
169+ //onChannelSelected?(filteredDataSource[indexPath.row])
170+ myProtocol?.passData(for: 0, channel: filteredDataSource[indexPath.row])
171+ navigationController?.popViewController(animated: true)
161 } else {
172 } else {
173+ myProtocol?.passData(for: 0, channel: ChannelListController.dataSource[indexPath.row])
174+ navigationController?.popViewController(animated: true)
162− onChannelSelected?(ChannelListController.dataSource[indexPath.row])
175+ //onChannelSelected?(ChannelListController.dataSource[indexPath.row])
163 }
176 }
164 }
177 }
165}
178}
GDproject/Controller/ News and channels/ChannelsCoordinator.swift+3−1
@@ -42,8 +42,10 @@ final class ChannelsCoordinator{
42 controller.onSelectChannel = { [weak self] in
42 controller.onSelectChannel = { [weak self] in
43 self?.showListOfChannels()
43 self?.showListOfChannels()
44 }
44 }
45+ navigationController?.setViewControllers([controller], animated: false)
45− navigationController?.pushViewController(controller, animated: false)
46+ //navigationController?.pushViewController(controller, animated: false)
46 }
47 }
48+
47 // MARK:- update only viewControllers which are depandable on chosen channel
49 // MARK:- update only viewControllers which are depandable on chosen channel
48 private func updateInterfaces() {
50 private func updateInterfaces() {
49 navigationController?.viewControllers.forEach {
51 navigationController?.viewControllers.forEach {
GDproject/Controller/ News and channels/NewsController.swift+20−108
@@ -19,8 +19,12 @@ protocol NewPostDelegate {
19
19
20// MARK:- Controller with posts and channels availiable.
20// MARK:- Controller with posts and channels availiable.
21// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
21// Search is availiable within every table (posts and channels). Has button-functionality for boths post and chnnels
22−class NewsController: UITableViewController, UISearchControllerDelegate, NewPostDelegate, UpdateableWithChannel
22+class NewsController: UITableViewController, UISearchControllerDelegate, NewPostDelegate, UpdateableWithChannel, DataDelegate
23{
23{
24+ func passData(for row: Int, channel: Channel) {
25+ self.channel = channel
26+ }
27+
24 var channel: Channel?{
28 var channel: Channel?{
25 didSet{
29 didSet{
26 news.dataSourse = channel?.posts ?? []
30 news.dataSourse = channel?.posts ?? []
@@ -35,120 +39,34 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
35 news.dataSourse.insert(post, at: 0)
39 news.dataSourse.insert(post, at: 0)
36 }
40 }
37
41
38− var array = ["Faculty 1", "Faculty 2","Faculty 3","Faculty 4","Faculty 5","Faculty 6","Faculty 7","Faculty 8","Faculty 9","Faculty 10","Faculty 11","Faculty 12","Faculty 13","Faculty 14","Faculty 15","Faculty 16","Faculty 17","Faculty 18"]
39−
40− override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
41− return array.count
42− }
43−
44−
45− override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
46− let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
47−
48− cell.textLabel?.text = array[indexPath.row]
49− return cell
50− }
51−
52− func presentSearchController(_ searchController: UISearchController) {
53− print("here")
54− setUpTableView()
55− displayTableView() //setup
56− // this is 0.3
57− animateTable(some: true)
58− }
59−
60− func willDismissSearchController(_ searchController: UISearchController) {
61− dismissTable()
62− }
63−
64− //@IBOutlet weak var tableView: UITableView!
65−
66 var searchController = UISearchController(searchResultsController: nil)
42 var searchController = UISearchController(searchResultsController: nil)
67
43
68−
69 var news = NewsVC()
44 var news = NewsVC()
70
45
71 override func viewDidLoad()
46 override func viewDidLoad()
72 {
47 {
73 super.viewDidLoad()
48 super.viewDidLoad()
74−
75− //view.backgroundColor = .white
76 channel = ChannelListController.dataSource[0]
49 channel = ChannelListController.dataSource[0]
77
50
78− view.addSubview(label)
79− //label.horizontalToSuperview(insets: .left(30) + .right(30))
80− //label.verticalToSuperview()
81−
82 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
51 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
83 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
52 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
84
53
85 searchController.delegate = self
54 searchController.delegate = self
86 searchController.obscuresBackgroundDuringPresentation = false
55 searchController.obscuresBackgroundDuringPresentation = false
56+ navigationItem.searchController = searchController
57+ definesPresentationContext = true
58+ searchController.searchBar.placeholder = "Search anything"
87
59
88 news.dataSourse = channel!.posts
60 news.dataSourse = channel!.posts
89 news.viewController = self
61 news.viewController = self
90
62
91−
92− tableView.delegate = news
93− tableView.dataSource = news
94− tableView.reloadData()
95−
96 news.type = .NONE
63 news.type = .NONE
97
64
98 setUpNavigationItemsforPosts()
65 setUpNavigationItemsforPosts()
99− searchController.searchBar.placeholder = "Search anything"
66+
100−
101− navigationItem.searchController = searchController
102− definesPresentationContext = true
103−
104− setUpBanner()
67+ //setUpBanner()
105− }
106−
107−
108− var facultyTableView = UITableView()
109−
110− func setUpTableView()
111− {
112− facultyTableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
113− facultyTableView.delegate = self
114− facultyTableView.dataSource = self
115− let screenSize: CGRect = UIScreen.main.bounds
116−
117− let screenWidth = screenSize.width
118− let screenHeight = screenSize.height
119− facultyTableView.frame = CGRect(x: 0, y: 0, width: Int(screenWidth), height: Int(screenHeight))
120− }
121−
122− func displayTableView(){
123−
124− // the most important line
125− facultyTableView.translatesAutoresizingMaskIntoConstraints = false
126− facultyTableView.backgroundColor = UIColor(white: 1, alpha: 1)
127− view.addSubview(facultyTableView)
128−
129− facultyTableView.isHidden = true
130−
131− // now
132− constrain(facultyTableView, view){
133− tableView, view in
134−
135− tableView.top == view.safeAreaLayoutGuide.top
136− tableView.left == view.left
137− tableView.right == view.right
138− tableView.bottom == view.safeAreaLayoutGuide.bottom
139− }
140−
141 }
68 }
142
69
143− // animation of the table cells
144− func animateTable(some: Bool){
145− self.facultyTableView.reloadData()
146− self.facultyTableView.isHidden = false
147− }
148−
149− func dismissTable() {
150− self.facultyTableView.isHidden = true
151− }
152
70
153 let label : UILabel = {
71 let label : UILabel = {
154 let label = UILabel()
72 let label = UILabel()
@@ -162,22 +80,14 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
162
80
163 override func viewWillAppear(_ animated: Bool) {
81 override func viewWillAppear(_ animated: Bool) {
164 super.viewWillAppear(animated)
82 super.viewWillAppear(animated)
165− print("hello")
83+ searchController.isActive = false
166− navigationController?.navigationBar.prefersLargeTitles = true
84+ // TODO:- display something if no posts are availiable
167− if channel!.posts.isEmpty {
168− //tableView.isHidden = true
169− label.isHidden = false
170− } else {
171− label.isHidden = true
172− tableView.isHidden = false
173− tableView.reloadData()
85+ tableView.reloadData()
174− }
175 }
86 }
176
87
177 func setUpNavigationItemsforPosts(){
88 func setUpNavigationItemsforPosts(){
178− navigationItem.rightBarButtonItems = [
179− UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),
180− UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))]
89+ navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))
90+ ]
181 tableView.delegate = news
91 tableView.delegate = news
182 tableView.dataSource = news
92 tableView.dataSource = news
183 tableView.reloadData()
93 tableView.reloadData()
@@ -185,7 +95,10 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
185
95
186 // MARK:- attempt with coordinator
96 // MARK:- attempt with coordinator
187 @objc func showChannels(_ barItem: UIBarButtonItem){
97 @objc func showChannels(_ barItem: UIBarButtonItem){
188− onSelectChannel?()
98+ let vc = UIStoryboard.makeChannelsListController()
99+ vc.myProtocol = self
100+ vc.displayingChannel = channel
101+ self.navigationController?.pushViewController(vc, animated: true)
189 }
102 }
190
103
191 @objc func writePost(_ barItem: UIBarButtonItem)
104 @objc func writePost(_ barItem: UIBarButtonItem)
@@ -206,8 +119,6 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
206 navigationController?.pushViewController(vc, animated: false)
119 navigationController?.pushViewController(vc, animated: false)
207 }
120 }
208
121
209−
210−
211 // for animating the banner
122 // for animating the banner
212 var topConstraint: NSLayoutConstraint?
123 var topConstraint: NSLayoutConstraint?
213
124
@@ -227,6 +138,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
227 return label
138 return label
228 }()
139 }()
229
140
141+ // MARK:- banner
230 private func setUpBanner()
142 private func setUpBanner()
231 {
143 {
232 view.addSubview(bannerView)
144 view.addSubview(bannerView)
GDproject/Controller/ News and channels/NewsVC.swift+10−44
@@ -17,63 +17,29 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
17 var viewController: UIViewController?
17 var viewController: UIViewController?
18
18
19 func numberOfSections(in tableView: UITableView) -> Int {
19 func numberOfSections(in tableView: UITableView) -> Int {
20− return 2
20+ return 1
21 }
21 }
22
22
23 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
23 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
24 {
24 {
25 tableView.deselectRow(at: indexPath, animated: true)
25 tableView.deselectRow(at: indexPath, animated: true)
26+ let vc = viewController!.storyboard!.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
26
27
27− if indexPath.section == 1 && type == .NEWS || type == .NONE {
28− let vc = viewController!.storyboard!.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
29−
30− vc.post = dataSourse[indexPath.row]
28+ vc.post = dataSourse[indexPath.row]
31− viewController!.navigationController!.pushViewController(vc, animated: true)
32− }
33− else if indexPath.section == 0 && type == .NEWS{
34− let vc = viewController!.storyboard!.instantiateViewController(withIdentifier: channelListControllerId) as! ChannelListController
35− //vc.myProtocol = viewController as? NewsController
36− viewController!.navigationController!.pushViewController(vc, animated: true)
29+ viewController!.navigationController!.pushViewController(vc, animated: true)
37− }
38 }
30 }
39
31
40 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
32 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
41− switch type {
42− case .NONE:
43− return dataSourse.count
33+ return dataSourse.count
44− default:
45− switch section {
46− case 0:
47− return 1
48− default:
49− return dataSourse.count
50− }
51− }
52 }
34 }
53
35
54 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
36 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
55 {
37 {
56− switch type {
57− case .NONE:
58− let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
38+ let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
59−
39+
60− cell.fill(with: dataSourse[indexPath.row].dataArray, false, post: dataSourse[indexPath.row])
61− cell.selectionStyle = .none
62− return cell
63− default:
64− switch indexPath.section {
65− case 0:
66− let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
67− cell.textLabel?.text = "List of channels"
68− return cell
69− default:
70− let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
71−
72− cell.fill(with: dataSourse[indexPath.row].dataArray, false, post: dataSourse[indexPath.row])
40+ cell.fill(with: dataSourse[indexPath.row].dataArray, false, post: dataSourse[indexPath.row])
73− cell.selectionStyle = .none
41+ cell.selectionStyle = .none
74− return cell
42+ return cell
75− }
76− }
77 }
43 }
78
44
79 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
45 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
GDproject/Controller/Coordinator tab bar?/TabBarController.swiftdeleted−28
@@ -1,28 +0,0 @@
1−import UIKit
2−
3−final class TabbarController: UITabBarController, UITabBarControllerDelegate, TabbarView {
4−
5− var onItemFlowSelect: ((UINavigationController) -> ())?
6− var onSettingsFlowSelect: ((UINavigationController) -> ())?
7− var onViewDidLoad: ((UINavigationController) -> ())?
8−
9− override func viewDidLoad() {
10− super.viewDidLoad()
11−
12− delegate = self
13− if let controller = customizableViewControllers?.first as? UINavigationController {
14− onViewDidLoad?(controller)
15− }
16− }
17−
18− func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
19− guard let controller = viewControllers?[selectedIndex] as? UINavigationController else { return }
20−
21− if selectedIndex == 0 {
22− onItemFlowSelect?(controller)
23− }
24− else if selectedIndex == 1 {
25− onSettingsFlowSelect?(controller)
26− }
27− }
28−}
GDproject/Controller/Coordinator tab bar?/TabbarCoordinator.swiftnew file+13
@@ -0,0 +1,13 @@
1+import UIKit
2+
3+class TabbarCoordinator{
4+ var window: UIWindow!
5+
6+ func start(){
7+ window.rootViewController = UIStoryboard.tabBarController()
8+ }
9+
10+ init(window: UIWindow) {
11+ self.window = window
12+ }
13+}
GDproject/Controller/Coordinator tab bar?/TabbarView.swiftdeleted−7
@@ -1,7 +0,0 @@
1−import UIKit
2−
3−protocol TabbarView: class {
4− var onItemFlowSelect: ((UINavigationController) -> ())? { get set }
5− var onSettingsFlowSelect: ((UINavigationController) -> ())? { get set }
6− var onViewDidLoad: ((UINavigationController) -> ())? { get set }
7−}
GDproject/Extentions.swift+8
@@ -47,4 +47,12 @@ extension UIStoryboard {
47 class func makeNewsController() -> NewsController {
47 class func makeNewsController() -> NewsController {
48 return UIStoryboard.userEdit.instantiateViewController(withIdentifier: newsController) as! NewsController
48 return UIStoryboard.userEdit.instantiateViewController(withIdentifier: newsController) as! NewsController
49 }
49 }
50+
51+ class func tabBarController() -> UITabBarController{
52+ return UIStoryboard.userEdit.instantiateViewController(withIdentifier: "TabBar") as! UITabBarController
53+ }
54+
55+ class func navChannels() ->UINavigationController{
56+ return UIStoryboard.userEdit.instantiateViewController(withIdentifier: "navChannels") as! UINavigationController
57+ }
50}
58}
GDproject/Simple model/Channel.swift+8−1
@@ -8,7 +8,14 @@
8
8
9import Foundation
9import Foundation
10
10
11−class Channel {
11+class Channel: Equatable {
12+ static func == (lhs: Channel, rhs: Channel) -> Bool {
13+ return (lhs.title == rhs.title &&
14+ lhs.subtitle == rhs.subtitle &&
15+ lhs.people == rhs.people &&
16+ lhs.hashtags == rhs.hashtags)
17+ }
18+
12 var title = String()
19 var title = String()
13 var subtitle = String()
20 var subtitle = String()
14
21
GDproject/Supporting files/AppDelegate.swift+10−5
@@ -12,19 +12,24 @@ import UIKit
12class AppDelegate: UIResponder, UIApplicationDelegate {
12class AppDelegate: UIResponder, UIApplicationDelegate {
13
13
14 var coordinator: ChannelsCoordinator!
14 var coordinator: ChannelsCoordinator!
15+ var tabCoordinator: TabbarCoordinator!
16+
15 var window: UIWindow?
17 var window: UIWindow?
16− var rootController: UINavigationController {
18+ var rootController: UINavigationController? {
17− return self.window!.rootViewController as! UINavigationController
19+ return self.window!.rootViewController as? UINavigationController
18 }
20 }
19
21
20 private func makeCoordinator(with: UINavigationController) -> ChannelsCoordinator {
22 private func makeCoordinator(with: UINavigationController) -> ChannelsCoordinator {
21− return ChannelsCoordinator(currentChannel: Channel(title: "example", subtitle: "ex", hashtags: ["none"], people: ["none"], posts: []), navigationController: rootController)
23+ return ChannelsCoordinator(currentChannel: Channel(title: "example", subtitle: "ex", hashtags: ["none"], people: ["none"], posts: []), navigationController: with)
22 }
24 }
23
25
24 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
26 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
25 {
27 {
26− coordinator = makeCoordinator(with: rootController)
28+
27− coordinator.start()
29+ // TODO:- determine what to do here: log in or tabbar
30+ tabCoordinator = TabbarCoordinator(window: window!)
31+ tabCoordinator.start()
32+
28 return true
33 return true
29 }
34 }
30
35