git.iko.soy/dashared/GDproject
on master help sign in
still working on channels. coordination is improved. need to design channel card and get rid of previous editing mode
e8b7edeDarya Rednikina
GDproject/Controller/ News and channels/ChannelListController.swift+4−16
@@ -14,7 +14,7 @@ struct ChannelData{
14}
14}
15
15
16// TODO: make search controller availiable
16// TODO: make search controller availiable
17−class ChannelListController: UITableViewController, DataDelegate {
17+class ChannelListController: UITableViewController {
18
18
19 // MARK: - Output -
19 // MARK: - Output -
20 var onChannelSelected: ((Model.Channels) -> Void)?
20 var onChannelSelected: ((Model.Channels) -> Void)?
@@ -22,7 +22,6 @@ class ChannelListController: UITableViewController, DataDelegate {
22 // MARK: - filter search controller
22 // MARK: - filter search controller
23 var filteredDataSource = [Model.Channels]()
23 var filteredDataSource = [Model.Channels]()
24
24
25− var myProtocol: DataDelegate?
26 var displayingChannel: Model.Channels?
25 var displayingChannel: Model.Channels?
27
26
28 var toReload: Bool = false {
27 var toReload: Bool = false {
@@ -97,7 +96,6 @@ class ChannelListController: UITableViewController, DataDelegate {
97 // editing mode is on automatically
96 // editing mode is on automatically
98 let vc = storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
97 let vc = storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
99 vc.index = 1
98 vc.index = 1
100− vc.myProtocol = self
101 vc.channel = Model.Channels(people: [], name: "Untitled", tags: [])
99 vc.channel = Model.Channels(people: [], name: "Untitled", tags: [])
102 navigationController?.pushViewController(vc, animated: true)
100 navigationController?.pushViewController(vc, animated: true)
103 }
101 }
@@ -147,7 +145,6 @@ class ChannelListController: UITableViewController, DataDelegate {
147 let editButton = UITableViewRowAction(style: .normal, title: "Edit") { [weak self] (action, indexPath) in
145 let editButton = UITableViewRowAction(style: .normal, title: "Edit") { [weak self] (action, indexPath) in
148 let vc = self?.storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
146 let vc = self?.storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
149 vc.index = indexPath.row
147 vc.index = indexPath.row
150− vc.myProtocol = self!
151 vc.channel = self?.dataSource[indexPath.row]
148 vc.channel = self?.dataSource[indexPath.row]
152 self?.navigationController?.pushViewController(vc, animated: true)
149 self?.navigationController?.pushViewController(vc, animated: true)
153 }
150 }
@@ -159,11 +156,7 @@ class ChannelListController: UITableViewController, DataDelegate {
159 Model.channelsDelete(by: self!.dataSource[indexPath.row].id!, completion: {
156 Model.channelsDelete(by: self!.dataSource[indexPath.row].id!, completion: {
160 print("хз что тут делать при успехе")
157 print("хз что тут делать при успехе")
161 })
158 })
162−
159+
163− if (self!.dataSource[indexPath.row].id == self!.displayingChannel?.id ?? -1)
164− {
165− self?.myProtocol?.passData(for: 0, channel: self!.dataSource[0])
166− }
167 self?.tableView.beginUpdates()
160 self?.tableView.beginUpdates()
168 self?.dataSource.remove(at: indexPath.row)
161 self?.dataSource.remove(at: indexPath.row)
169 self?.tableView.deleteRows(at: [indexPath], with: .none)
162 self?.tableView.deleteRows(at: [indexPath], with: .none)
@@ -175,17 +168,12 @@ class ChannelListController: UITableViewController, DataDelegate {
175 return [editButton, deleteButton]
168 return [editButton, deleteButton]
176 }
169 }
177
170
178− // TODO: remove popping
179 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
171 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
180 {
172 {
181 if isFiltering {
173 if isFiltering {
182− //onChannelSelected?(filteredDataSource[indexPath.row])
174+ onChannelSelected?(filteredDataSource[indexPath.row])
183− myProtocol?.passData(for: 0, channel: filteredDataSource[indexPath.row])
184− navigationController?.popViewController(animated: true)
185 } else {
175 } else {
186− myProtocol?.passData(for: 0, channel: dataSource[indexPath.row])
187− navigationController?.popViewController(animated: true)
188− //onChannelSelected?(ChannelListController.dataSource[indexPath.row])
176+ onChannelSelected?(dataSource[indexPath.row])
189 }
177 }
190 }
178 }
191}
179}
GDproject/Controller/ News and channels/NewPostViewController.swift+4−16
@@ -22,9 +22,6 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
22 // Keep strong instance of the `NSTextStorage` subclass
22 // Keep strong instance of the `NSTextStorage` subclass
23 let textStorage = MarklightTextStorage()
23 let textStorage = MarklightTextStorage()
24
24
25− weak var parentVC: NewsController?
26− var myProtocol: NewPostDelegate?
27−
28 static var draft: String = ""
25 static var draft: String = ""
29 static var hashTagsDraft: [String] = []
26 static var hashTagsDraft: [String] = []
30
27
@@ -219,7 +216,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
219 Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: tagsField.tags.map { $0.text })
216 Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: tagsField.tags.map { $0.text })
220 // adding row to uiTableView after adding new post
217 // adding row to uiTableView after adding new post
221 // myProtocol?.addPost(post: p)
218 // myProtocol?.addPost(post: p)
222− moveBackToParentVC()
219+ moveBackToParentVC?()
223 // somewhere here i will be sending server notifications about new post arrival
220 // somewhere here i will be sending server notifications about new post arrival
224 }
221 }
225
222
@@ -232,7 +229,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
232 _ in
229 _ in
233 NewPostViewController.draft = self?.textView.text ?? ""
230 NewPostViewController.draft = self?.textView.text ?? ""
234 NewPostViewController.hashTagsDraft = self?.tagsField.tags.map { $0.text } ?? []
231 NewPostViewController.hashTagsDraft = self?.tagsField.tags.map { $0.text } ?? []
235− self?.moveBackToParentVC()
232+ self?.moveBackToParentVC?()
236 }
233 }
237
234
238 let deleteAction = UIAlertAction(title: "Delete draft", style: .destructive)
235 let deleteAction = UIAlertAction(title: "Delete draft", style: .destructive)
@@ -241,7 +238,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
241 in
238 in
242 NewPostViewController.draft = ""
239 NewPostViewController.draft = ""
243 NewPostViewController.hashTagsDraft = []
240 NewPostViewController.hashTagsDraft = []
244− self?.moveBackToParentVC()
241+ self?.moveBackToParentVC?()
245 }
242 }
246
243
247 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
244 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
@@ -258,16 +255,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
258 actionSaveDraft()
255 actionSaveDraft()
259 }
256 }
260
257
261− func moveBackToParentVC(){
258+ var moveBackToParentVC: (()->())?
262− let transition = CATransition()
263− transition.duration = 0.5
264− transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
265− transition.type = CATransitionType.reveal
266− transition.subtype = CATransitionSubtype.fromBottom
267− navigationController?.view.layer.add(transition, forKey: nil)
268− navigationController?.popViewController(animated: false)
269− textView!.resignFirstResponder()
270− }
271
259
272
260
273 func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
261 func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
GDproject/Controller/ News and channels/NewsController.swift+2−32
@@ -61,11 +61,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
61 }
61 }
62 }
62 }
63
63
64− var channel: Model.Channels? {
64+ var channel: Model.Channels?
65− didSet {
66− navigationItem.title = channel?.name ?? ""
67− }
68− }
69
65
70 // MARK: - Output -
66 // MARK: - Output -
71 var onSelectChannel: (() -> Void)?
67 var onSelectChannel: (() -> Void)?
@@ -144,6 +140,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
144 self?.posts = $0.posts
140 self?.posts = $0.posts
145 self?.dictionary = $0.users
141 self?.dictionary = $0.users
146 self?.refreshContr.endRefreshing()
142 self?.refreshContr.endRefreshing()
143+ self?.changedChannelName?(channel.name)
147 }
144 }
148
145
149 } else {
146 } else {
@@ -158,38 +155,11 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
158 }
155 }
159
156
160 func setUpNavigationItemsforPosts(){
157 func setUpNavigationItemsforPosts(){
161− navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))
162− ]
163 tableView.delegate = news
158 tableView.delegate = news
164 tableView.dataSource = news
159 tableView.dataSource = news
165 tableView.reloadData()
160 tableView.reloadData()
166 }
161 }
167
162
168− // MARK:- attempt with coordinator
169− @objc func showChannels(_ barItem: UIBarButtonItem){
170− let vc = UIStoryboard.makeChannelsListController()
171− vc.myProtocol = self
172− vc.displayingChannel = channel
173− self.navigationController?.pushViewController(vc, animated: true)
174− }
175−
176− @objc func writePost(_ barItem: UIBarButtonItem)
177− {
178− let vc = storyboard?.instantiateViewController(withIdentifier: "NewPostViewController") as! NewPostViewController
179−
180− vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Post", style: .plain, target: vc, action: #selector(vc.newPost))
181− vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close", style: .plain, target: vc, action: #selector(vc.closeView))
182−
183− vc.myProtocol = self
184−
185− let transition = CATransition()
186− transition.duration = 0.5
187− transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
188− transition.type = CATransitionType.moveIn
189− transition.subtype = CATransitionSubtype.fromTop
190− navigationController?.view.layer.add(transition, forKey: nil)
191− navigationController?.pushViewController(vc, animated: false)
192− }
193
163
194 // for animating the banner
164 // for animating the banner
195 var topConstraint: NSLayoutConstraint?
165 var topConstraint: NSLayoutConstraint?
GDproject/Controller/Coordinators/ChannelsCoordinator.swift+46−2
@@ -11,10 +11,12 @@ import UIKit
11import Pulley
11import Pulley
12
12
13class ChannelsCoordinator: BaseCoordinator{
13class ChannelsCoordinator: BaseCoordinator{
14+ let storyboard = UIStoryboard(name: "Main", bundle: nil)
14 private weak var navigationController: UINavigationController?
15 private weak var navigationController: UINavigationController?
15
16
16 init(nc: UINavigationController) {
17 init(nc: UINavigationController) {
17 self.navigationController = nc
18 self.navigationController = nc
19+ navigationController?.navigationItem.largeTitleDisplayMode = .always
18 }
20 }
19
21
20 override func start() {
22 override func start() {
@@ -22,21 +24,63 @@ class ChannelsCoordinator: BaseCoordinator{
22 }
24 }
23
25
24 private func show() {
26 private func show() {
25− let storyboard = UIStoryboard(name: "Main", bundle: nil)
26
27
27 let channels = storyboard.instantiateViewController(withIdentifier: channelListControllerId) as! ChannelListController
28 let channels = storyboard.instantiateViewController(withIdentifier: channelListControllerId) as! ChannelListController
28
29
30+ channels.onChannelSelected = { [weak self]
31+ (channel) in
32+ self?.navigationController?.pushViewController(self!.presentNewsController(with: channel), animated: true)
33+ }
34+ navigationController?.setViewControllers([channels,presentNewsController()], animated: false)
35+ }
36+
37+ private func presentNewsController(with channel: Model.Channels? = nil) -> PulleyViewController {
38+
29 let mainContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: newsController) as! NewsController
39 let mainContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: newsController) as! NewsController
40+ mainContentVC.channel = channel
30
41
31 let drawerContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DrawerContentViewController")
42 let drawerContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DrawerContentViewController")
32
43
33 let pulleyDrawerVC = PulleyViewController(contentViewController: mainContentVC, drawerViewController: drawerContentVC)
44 let pulleyDrawerVC = PulleyViewController(contentViewController: mainContentVC, drawerViewController: drawerContentVC)
34
45
35 pulleyDrawerVC.initialDrawerPosition = .collapsed
46 pulleyDrawerVC.initialDrawerPosition = .collapsed
47+
48+
36 mainContentVC.changedChannelName = {
49 mainContentVC.changedChannelName = {
37 [weak pulleyDrawerVC] (title) in pulleyDrawerVC?.navigationItem.title = title
50 [weak pulleyDrawerVC] (title) in pulleyDrawerVC?.navigationItem.title = title
38 }
51 }
39
52
40− navigationController?.setViewControllers([channels,pulleyDrawerVC], animated: false)
53+ pulleyDrawerVC.navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(writePost(_:)))
54+ ]
55+
56+ return pulleyDrawerVC
57+ }
58+
59+ @objc private func writePost(_ barItem: UIBarButtonItem)
60+ {
61+ let vc = storyboard.instantiateViewController(withIdentifier: "NewPostViewController") as! NewPostViewController
62+
63+ vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Post", style: .plain, target: vc, action: #selector(vc.newPost))
64+ vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close", style: .plain, target: vc, action: #selector(vc.closeView))
65+
66+ let transition = CATransition()
67+ transition.duration = 0.5
68+ transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
69+ transition.type = CATransitionType.moveIn
70+ transition.subtype = CATransitionSubtype.fromTop
71+ navigationController?.view.layer.add(transition, forKey: nil)
72+ navigationController?.pushViewController(vc, animated: false)
73+
74+ vc.moveBackToParentVC = {
75+ [weak self] in
76+
77+ let transition = CATransition()
78+ transition.duration = 0.5
79+ transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
80+ transition.type = CATransitionType.reveal
81+ transition.subtype = CATransitionSubtype.fromBottom
82+ self?.navigationController?.view.layer.add(transition, forKey: nil)
83+ self?.navigationController?.popViewController(animated: false)
84+ }
41 }
85 }
42}
86}
GDproject/Controller/Coordinators/ProfileCoordinator.swift+2
@@ -26,10 +26,12 @@ class ProfileCoordinator: BaseCoordinator {
26 private func show() {
26 private func show() {
27 let storyboard = UIStoryboard(name: "Main", bundle: nil)
27 let storyboard = UIStoryboard(name: "Main", bundle: nil)
28 let profile = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
28 let profile = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
29+
29 profile.logOut = { [weak self] in
30 profile.logOut = { [weak self] in
30 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
31 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
31 self?.didEndSession?()
32 self?.didEndSession?()
32 }
33 }
34+
33 profile.onSettings = { [weak self, weak storyboard] in
35 profile.onSettings = { [weak self, weak storyboard] in
34 let vc = storyboard?.instantiateViewController(withIdentifier: "SettingsViewController") as! SettingsViewController
36 let vc = storyboard?.instantiateViewController(withIdentifier: "SettingsViewController") as! SettingsViewController
35 self?.navigationController?.pushViewController(vc, animated: true)
37 self?.navigationController?.pushViewController(vc, animated: true)