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
commite8b7ede59391935337fa521952a8c4856f5d22ee authorDarya Rednikina <rednikina.com@yandex.ru> dateWed 20 Mar 2019, 17:19 (8 years ago) parent32e1d26
5 files changed+58−66
GDproject/Controller/ News and channels/ChannelListController.swift+4−16 GDproject/Controller/ News and channels/NewPostViewController.swift+4−16 GDproject/Controller/ News and channels/NewsController.swift+2−32 GDproject/Controller/Coordinators/ChannelsCoordinator.swift+46−2 GDproject/Controller/Coordinators/ProfileCoordinator.swift+2
GDproject/Controller/ News and channels/ChannelListController.swift+4−16
@@ -14,7 +14,7 @@ struct ChannelData{
1414}
1515
1616// TODO: make search controller availiable
17−class ChannelListController: UITableViewController, DataDelegate {
17+class ChannelListController: UITableViewController {
1818
1919 // MARK: - Output -
2020 var onChannelSelected: ((Model.Channels) -> Void)?
@@ -22,7 +22,6 @@ class ChannelListController: UITableViewController, DataDelegate {
2222 // MARK: - filter search controller
2323 var filteredDataSource = [Model.Channels]()
2424
25− var myProtocol: DataDelegate?
2625 var displayingChannel: Model.Channels?
2726
2827 var toReload: Bool = false {
@@ -97,7 +96,6 @@ class ChannelListController: UITableViewController, DataDelegate {
9796 // editing mode is on automatically
9897 let vc = storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
9998 vc.index = 1
100− vc.myProtocol = self
10199 vc.channel = Model.Channels(people: [], name: "Untitled", tags: [])
102100 navigationController?.pushViewController(vc, animated: true)
103101 }
@@ -147,7 +145,6 @@ class ChannelListController: UITableViewController, DataDelegate {
147145 let editButton = UITableViewRowAction(style: .normal, title: "Edit") { [weak self] (action, indexPath) in
148146 let vc = self?.storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
149147 vc.index = indexPath.row
150− vc.myProtocol = self!
151148 vc.channel = self?.dataSource[indexPath.row]
152149 self?.navigationController?.pushViewController(vc, animated: true)
153150 }
@@ -159,11 +156,7 @@ class ChannelListController: UITableViewController, DataDelegate {
159156 Model.channelsDelete(by: self!.dataSource[indexPath.row].id!, completion: {
160157 print("хз что тут делать при успехе")
161158 })
162−
163− if (self!.dataSource[indexPath.row].id == self!.displayingChannel?.id ?? -1)
164− {
165− self?.myProtocol?.passData(for: 0, channel: self!.dataSource[0])
166− }
159+
167160 self?.tableView.beginUpdates()
168161 self?.dataSource.remove(at: indexPath.row)
169162 self?.tableView.deleteRows(at: [indexPath], with: .none)
@@ -175,17 +168,12 @@ class ChannelListController: UITableViewController, DataDelegate {
175168 return [editButton, deleteButton]
176169 }
177170
178− // TODO: remove popping
179171 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
180172 {
181173 if isFiltering {
182− //onChannelSelected?(filteredDataSource[indexPath.row])
183− myProtocol?.passData(for: 0, channel: filteredDataSource[indexPath.row])
184− navigationController?.popViewController(animated: true)
174+ onChannelSelected?(filteredDataSource[indexPath.row])
185175 } 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])
189177 }
190178 }
191179}
GDproject/Controller/ News and channels/NewPostViewController.swift+4−16
@@ -22,9 +22,6 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
2222 // Keep strong instance of the `NSTextStorage` subclass
2323 let textStorage = MarklightTextStorage()
2424
25− weak var parentVC: NewsController?
26− var myProtocol: NewPostDelegate?
27−
2825 static var draft: String = ""
2926 static var hashTagsDraft: [String] = []
3027
@@ -219,7 +216,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
219216 Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: tagsField.tags.map { $0.text })
220217 // adding row to uiTableView after adding new post
221218 // myProtocol?.addPost(post: p)
222− moveBackToParentVC()
219+ moveBackToParentVC?()
223220 // somewhere here i will be sending server notifications about new post arrival
224221 }
225222
@@ -232,7 +229,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
232229 _ in
233230 NewPostViewController.draft = self?.textView.text ?? ""
234231 NewPostViewController.hashTagsDraft = self?.tagsField.tags.map { $0.text } ?? []
235− self?.moveBackToParentVC()
232+ self?.moveBackToParentVC?()
236233 }
237234
238235 let deleteAction = UIAlertAction(title: "Delete draft", style: .destructive)
@@ -241,7 +238,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
241238 in
242239 NewPostViewController.draft = ""
243240 NewPostViewController.hashTagsDraft = []
244− self?.moveBackToParentVC()
241+ self?.moveBackToParentVC?()
245242 }
246243
247244 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
@@ -258,16 +255,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
258255 actionSaveDraft()
259256 }
260257
261− func 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− }
258+ var moveBackToParentVC: (()->())?
271259
272260
273261 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
6161 }
6262 }
6363
64− var channel: Model.Channels? {
65− didSet {
66− navigationItem.title = channel?.name ?? ""
67− }
68− }
64+ var channel: Model.Channels?
6965
7066 // MARK: - Output -
7167 var onSelectChannel: (() -> Void)?
@@ -144,6 +140,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
144140 self?.posts = $0.posts
145141 self?.dictionary = $0.users
146142 self?.refreshContr.endRefreshing()
143+ self?.changedChannelName?(channel.name)
147144 }
148145
149146 } else {
@@ -158,38 +155,11 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
158155 }
159156
160157 func setUpNavigationItemsforPosts(){
161− navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))
162− ]
163158 tableView.delegate = news
164159 tableView.dataSource = news
165160 tableView.reloadData()
166161 }
167162
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− }
193163
194164 // for animating the banner
195165 var topConstraint: NSLayoutConstraint?
GDproject/Controller/Coordinators/ChannelsCoordinator.swift+46−2
@@ -11,10 +11,12 @@ import UIKit
1111import Pulley
1212
1313class ChannelsCoordinator: BaseCoordinator{
14+ let storyboard = UIStoryboard(name: "Main", bundle: nil)
1415 private weak var navigationController: UINavigationController?
1516
1617 init(nc: UINavigationController) {
1718 self.navigationController = nc
19+ navigationController?.navigationItem.largeTitleDisplayMode = .always
1820 }
1921
2022 override func start() {
@@ -22,21 +24,63 @@ class ChannelsCoordinator: BaseCoordinator{
2224 }
2325
2426 private func show() {
25− let storyboard = UIStoryboard(name: "Main", bundle: nil)
2627
2728 let channels = storyboard.instantiateViewController(withIdentifier: channelListControllerId) as! ChannelListController
2829
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+
2939 let mainContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: newsController) as! NewsController
40+ mainContentVC.channel = channel
3041
3142 let drawerContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DrawerContentViewController")
3243
3344 let pulleyDrawerVC = PulleyViewController(contentViewController: mainContentVC, drawerViewController: drawerContentVC)
3445
3546 pulleyDrawerVC.initialDrawerPosition = .collapsed
47+
48+
3649 mainContentVC.changedChannelName = {
3750 [weak pulleyDrawerVC] (title) in pulleyDrawerVC?.navigationItem.title = title
3851 }
3952
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+ }
4185 }
4286}
GDproject/Controller/Coordinators/ProfileCoordinator.swift+2
@@ -26,10 +26,12 @@ class ProfileCoordinator: BaseCoordinator {
2626 private func show() {
2727 let storyboard = UIStoryboard(name: "Main", bundle: nil)
2828 let profile = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
29+
2930 profile.logOut = { [weak self] in
3031 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
3132 self?.didEndSession?()
3233 }
34+
3335 profile.onSettings = { [weak self, weak storyboard] in
3436 let vc = storyboard?.instantiateViewController(withIdentifier: "SettingsViewController") as! SettingsViewController
3537 self?.navigationController?.pushViewController(vc, animated: true)