still working on channels. coordination is improved. need to design channel card and get rid of previous editing mode

This commit is contained in:
Darya Rednikina 2019-03-20 17:19:13 +03:00
parent 32e1d267d1
commit e8b7ede593
5 changed files with 58 additions and 66 deletions

View File

@ -14,7 +14,7 @@ struct ChannelData{
}
// TODO: make search controller availiable
class ChannelListController: UITableViewController, DataDelegate {
class ChannelListController: UITableViewController {
// MARK: - Output -
var onChannelSelected: ((Model.Channels) -> Void)?
@ -22,7 +22,6 @@ class ChannelListController: UITableViewController, DataDelegate {
// MARK: - filter search controller
var filteredDataSource = [Model.Channels]()
var myProtocol: DataDelegate?
var displayingChannel: Model.Channels?
var toReload: Bool = false {
@ -97,7 +96,6 @@ class ChannelListController: UITableViewController, DataDelegate {
// editing mode is on automatically
let vc = storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
vc.index = 1
vc.myProtocol = self
vc.channel = Model.Channels(people: [], name: "Untitled", tags: [])
navigationController?.pushViewController(vc, animated: true)
}
@ -147,7 +145,6 @@ class ChannelListController: UITableViewController, DataDelegate {
let editButton = UITableViewRowAction(style: .normal, title: "Edit") { [weak self] (action, indexPath) in
let vc = self?.storyboard?.instantiateViewController(withIdentifier: channelControllerId) as! ChannelController
vc.index = indexPath.row
vc.myProtocol = self!
vc.channel = self?.dataSource[indexPath.row]
self?.navigationController?.pushViewController(vc, animated: true)
}
@ -159,11 +156,7 @@ class ChannelListController: UITableViewController, DataDelegate {
Model.channelsDelete(by: self!.dataSource[indexPath.row].id!, completion: {
print("хз что тут делать при успехе")
})
if (self!.dataSource[indexPath.row].id == self!.displayingChannel?.id ?? -1)
{
self?.myProtocol?.passData(for: 0, channel: self!.dataSource[0])
}
self?.tableView.beginUpdates()
self?.dataSource.remove(at: indexPath.row)
self?.tableView.deleteRows(at: [indexPath], with: .none)
@ -175,17 +168,12 @@ class ChannelListController: UITableViewController, DataDelegate {
return [editButton, deleteButton]
}
// TODO: remove popping
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if isFiltering {
//onChannelSelected?(filteredDataSource[indexPath.row])
myProtocol?.passData(for: 0, channel: filteredDataSource[indexPath.row])
navigationController?.popViewController(animated: true)
onChannelSelected?(filteredDataSource[indexPath.row])
} else {
myProtocol?.passData(for: 0, channel: dataSource[indexPath.row])
navigationController?.popViewController(animated: true)
//onChannelSelected?(ChannelListController.dataSource[indexPath.row])
onChannelSelected?(dataSource[indexPath.row])
}
}
}

View File

@ -22,9 +22,6 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
// Keep strong instance of the `NSTextStorage` subclass
let textStorage = MarklightTextStorage()
weak var parentVC: NewsController?
var myProtocol: NewPostDelegate?
static var draft: String = ""
static var hashTagsDraft: [String] = []
@ -219,7 +216,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
Model.createAndPublish(body: [Model.Attachments(markdown: textView!.text)], tags: tagsField.tags.map { $0.text })
// adding row to uiTableView after adding new post
// myProtocol?.addPost(post: p)
moveBackToParentVC()
moveBackToParentVC?()
// somewhere here i will be sending server notifications about new post arrival
}
@ -232,7 +229,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
_ in
NewPostViewController.draft = self?.textView.text ?? ""
NewPostViewController.hashTagsDraft = self?.tagsField.tags.map { $0.text } ?? []
self?.moveBackToParentVC()
self?.moveBackToParentVC?()
}
let deleteAction = UIAlertAction(title: "Delete draft", style: .destructive)
@ -241,7 +238,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
in
NewPostViewController.draft = ""
NewPostViewController.hashTagsDraft = []
self?.moveBackToParentVC()
self?.moveBackToParentVC?()
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
@ -258,16 +255,7 @@ class NewPostViewController: UIViewController, UITextViewDelegate {
actionSaveDraft()
}
func moveBackToParentVC(){
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.reveal
transition.subtype = CATransitionSubtype.fromBottom
navigationController?.view.layer.add(transition, forKey: nil)
navigationController?.popViewController(animated: false)
textView!.resignFirstResponder()
}
var moveBackToParentVC: (()->())?
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {

View File

@ -61,11 +61,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
}
}
var channel: Model.Channels? {
didSet {
navigationItem.title = channel?.name ?? ""
}
}
var channel: Model.Channels?
// MARK: - Output -
var onSelectChannel: (() -> Void)?
@ -144,6 +140,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
self?.posts = $0.posts
self?.dictionary = $0.users
self?.refreshContr.endRefreshing()
self?.changedChannelName?(channel.name)
}
} else {
@ -158,38 +155,11 @@ class NewsController: UIViewController, UISearchControllerDelegate, NewPostDeleg
}
func setUpNavigationItemsforPosts(){
navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:))),UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(self.showChannels(_:)))
]
tableView.delegate = news
tableView.dataSource = news
tableView.reloadData()
}
// MARK:- attempt with coordinator
@objc func showChannels(_ barItem: UIBarButtonItem){
let vc = UIStoryboard.makeChannelsListController()
vc.myProtocol = self
vc.displayingChannel = channel
self.navigationController?.pushViewController(vc, animated: true)
}
@objc func writePost(_ barItem: UIBarButtonItem)
{
let vc = storyboard?.instantiateViewController(withIdentifier: "NewPostViewController") as! NewPostViewController
vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Post", style: .plain, target: vc, action: #selector(vc.newPost))
vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close", style: .plain, target: vc, action: #selector(vc.closeView))
vc.myProtocol = self
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.moveIn
transition.subtype = CATransitionSubtype.fromTop
navigationController?.view.layer.add(transition, forKey: nil)
navigationController?.pushViewController(vc, animated: false)
}
// for animating the banner
var topConstraint: NSLayoutConstraint?

View File

@ -11,10 +11,12 @@ import UIKit
import Pulley
class ChannelsCoordinator: BaseCoordinator{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
private weak var navigationController: UINavigationController?
init(nc: UINavigationController) {
self.navigationController = nc
navigationController?.navigationItem.largeTitleDisplayMode = .always
}
override func start() {
@ -22,21 +24,63 @@ class ChannelsCoordinator: BaseCoordinator{
}
private func show() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let channels = storyboard.instantiateViewController(withIdentifier: channelListControllerId) as! ChannelListController
channels.onChannelSelected = { [weak self]
(channel) in
self?.navigationController?.pushViewController(self!.presentNewsController(with: channel), animated: true)
}
navigationController?.setViewControllers([channels,presentNewsController()], animated: false)
}
private func presentNewsController(with channel: Model.Channels? = nil) -> PulleyViewController {
let mainContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: newsController) as! NewsController
mainContentVC.channel = channel
let drawerContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DrawerContentViewController")
let pulleyDrawerVC = PulleyViewController(contentViewController: mainContentVC, drawerViewController: drawerContentVC)
pulleyDrawerVC.initialDrawerPosition = .collapsed
mainContentVC.changedChannelName = {
[weak pulleyDrawerVC] (title) in pulleyDrawerVC?.navigationItem.title = title
}
navigationController?.setViewControllers([channels,pulleyDrawerVC], animated: false)
pulleyDrawerVC.navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(writePost(_:)))
]
return pulleyDrawerVC
}
@objc private func writePost(_ barItem: UIBarButtonItem)
{
let vc = storyboard.instantiateViewController(withIdentifier: "NewPostViewController") as! NewPostViewController
vc.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Post", style: .plain, target: vc, action: #selector(vc.newPost))
vc.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Close", style: .plain, target: vc, action: #selector(vc.closeView))
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.moveIn
transition.subtype = CATransitionSubtype.fromTop
navigationController?.view.layer.add(transition, forKey: nil)
navigationController?.pushViewController(vc, animated: false)
vc.moveBackToParentVC = {
[weak self] in
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.reveal
transition.subtype = CATransitionSubtype.fromBottom
self?.navigationController?.view.layer.add(transition, forKey: nil)
self?.navigationController?.popViewController(animated: false)
}
}
}

View File

@ -26,10 +26,12 @@ class ProfileCoordinator: BaseCoordinator {
private func show() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let profile = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
profile.logOut = { [weak self] in
DataStorage.standard.setIsLoggedIn(value: false, with: 0)
self?.didEndSession?()
}
profile.onSettings = { [weak self, weak storyboard] in
let vc = storyboard?.instantiateViewController(withIdentifier: "SettingsViewController") as! SettingsViewController
self?.navigationController?.pushViewController(vc, animated: true)