diff --git a/GDproject.xcodeproj/project.pbxproj b/GDproject.xcodeproj/project.pbxproj index 7bf9107..f5e6326 100644 --- a/GDproject.xcodeproj/project.pbxproj +++ b/GDproject.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */; }; 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; }; 123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; }; 124CC7032221C00C009DF531 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124CC7022221C00C009DF531 /* Model.swift */; }; @@ -72,6 +73,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedChannelsList.swift; sourceTree = ""; }; 123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = ""; }; 123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = ""; }; 124CC7022221C00C009DF531 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; @@ -238,6 +240,7 @@ children = ( 12D7D134221C42B700B35452 /* ChannelController.swift */, 12D7D132221C321600B35452 /* ChannelListController.swift */, + 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */, 12E36DC922144635006FCDD7 /* NewPostViewController.swift */, 12E36DD022148122006FCDD7 /* FullPostController.swift */, 12E36D9D221424EA006FCDD7 /* NewsController.swift */, @@ -332,6 +335,7 @@ 12D7D137221D78E800B35452 /* Channel.swift in Sources */, 1291BE3622218DBF009D3F23 /* LogInCoordinator.swift in Sources */, 12E36DB922144016006FCDD7 /* User.swift in Sources */, + 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */, 125BD5812217314A008A3575 /* NewsVC.swift in Sources */, 12E36DB72214400A006FCDD7 /* Post.swift in Sources */, 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */, diff --git a/GDproject/Base.lproj/Main.storyboard b/GDproject/Base.lproj/Main.storyboard index e451d31..03e97fa 100644 --- a/GDproject/Base.lproj/Main.storyboard +++ b/GDproject/Base.lproj/Main.storyboard @@ -214,6 +214,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GDproject/Constants.swift b/GDproject/Constants.swift index 59afd69..1a937f7 100644 --- a/GDproject/Constants.swift +++ b/GDproject/Constants.swift @@ -44,3 +44,5 @@ let logInController = "LogInController" let profileViewController = "ProfileViewController" + +let simplifiedChannelsList = "SimplifiedChannelsList" diff --git a/GDproject/Controller/ News and channels/ChannelController.swift b/GDproject/Controller/ News and channels/ChannelController.swift index d877bd5..7481041 100644 --- a/GDproject/Controller/ News and channels/ChannelController.swift +++ b/GDproject/Controller/ News and channels/ChannelController.swift @@ -198,7 +198,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { if searchText.isEmpty { - switch activeDataSource{ + switch activeDataSource { case .people: dataSourcePeople = fullPeople case .tags: @@ -235,6 +235,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS dataSourceTags = fullTags dataSourcePeople = [] } + print("\(searchBar.selectedScopeButtonIndex)") activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags if (!(searchBar.text?.isEmpty ?? true)) { @@ -250,6 +251,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS dataSourceTags = channel!.tags dataSourcePeople = [] } + print(" not active \(searchBar.selectedScopeButtonIndex)") activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags tableView.reloadData() } diff --git a/GDproject/Controller/ News and channels/ChannelListController.swift b/GDproject/Controller/ News and channels/ChannelListController.swift index 0778f28..70a5ab9 100644 --- a/GDproject/Controller/ News and channels/ChannelListController.swift +++ b/GDproject/Controller/ News and channels/ChannelListController.swift @@ -70,16 +70,25 @@ class ChannelListController: UITableViewController, DataDelegate { navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))] } - override func viewWillAppear(_ animated: Bool) + override func viewDidAppear(_ animated: Bool) { - super.viewWillAppear(animated) + super.viewDidAppear(animated) searchController.isActive = false + askForUpdates() + } + + private func askForUpdates(){ Model.channelsList { [weak self] (channels) in self?.dataSource = [ChannelListController.generalChannel] + channels self?.toReload = true } } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(true) + askForUpdates() + } + @objc func addChannel() { // editing mode is on automatically @@ -157,6 +166,7 @@ class ChannelListController: UITableViewController, DataDelegate { self?.tableView.deleteRows(at: [indexPath], with: .none) self?.tableView.endUpdates() } + deleteButton.backgroundColor = .red return [editButton, deleteButton] diff --git a/GDproject/Controller/ News and channels/NewsController.swift b/GDproject/Controller/ News and channels/NewsController.swift index 6ccf44b..c3d9dc5 100644 --- a/GDproject/Controller/ News and channels/NewsController.swift +++ b/GDproject/Controller/ News and channels/NewsController.swift @@ -32,14 +32,19 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost } var dictionary: [Int: Model.Users]? { - didSet{ + didSet { var newPosts: [Model.Posts] = [] posts!.forEach({ (post) in + newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: dictionary![post.authorId]!, date: post.updated, tags: post.tags)) + + post.tags.forEach { Model.Channels.fullTags.insert($0) } + }) + news.dataSourse = newPosts tableView.reloadData() } diff --git a/GDproject/Controller/ News and channels/PostViewCell.swift b/GDproject/Controller/ News and channels/PostViewCell.swift index 002ddac..5f47bd5 100644 --- a/GDproject/Controller/ News and channels/PostViewCell.swift +++ b/GDproject/Controller/ News and channels/PostViewCell.swift @@ -142,7 +142,13 @@ class PostViewCell: UITableViewCell contentView.addSubview(mainView) mainView.edgesToSuperview(excluding: [.top, .bottom]) mainView.topToBottom(of: nameStackView, offset: 5) - mainView.height(30) + + // TODO:- change!!!!!!!!!!!! + if hashtags.isEmpty{ + mainView.height(0) + } else { + mainView.height(30) + } let stackView = MyStackView(arrangedSubviews: views) stackView.isFull = full diff --git a/GDproject/Controller/ News and channels/SimplifiedChannelsList.swift b/GDproject/Controller/ News and channels/SimplifiedChannelsList.swift new file mode 100644 index 0000000..ba93d12 --- /dev/null +++ b/GDproject/Controller/ News and channels/SimplifiedChannelsList.swift @@ -0,0 +1,81 @@ +// +// SimplifiedChannelsList.swift +// GDproject +// +// Created by cstore on 13/03/2019. +// Copyright © 2019 drHSE. All rights reserved. +// + + +/// class for ADDing person to existing (or new) channel: like playlist in itunes +import UIKit + +class SimplifiedChannelsList: UITableViewController { + + var user: Model.Users? + + var dataSource: [Model.Channels]?{ + didSet{ + tableView.reloadData() + } + } + + override func viewDidLoad() { + super.viewDidLoad() + setUpNavigationButtons() + tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") + } + + override func viewWillAppear(_ animated: Bool) { + Model.channelsList { [weak self] (channels) in + self?.dataSource = channels + } + } + + func setUpNavigationButtons(){ + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelAction)) + } + + func completedActions(with channel: Model.Channels){ + Model.updateChannel(with: channel) + cancelAction() + } + + @objc func cancelAction(){ + 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) + } + + override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + let viewHeader = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30)) + return viewHeader + } + + override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return 30 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return dataSource?.count ?? 0 + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + var channel = dataSource![indexPath.row] + channel.people.append(user!.id) + completedActions(with: channel) + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) + + cell.textLabel?.text = dataSource![indexPath.row].name + cell.detailTextLabel?.text = "\(dataSource![indexPath.row].id!)" + + return cell + } +} diff --git a/GDproject/Controller/Profile/ProfileViewController.swift b/GDproject/Controller/Profile/ProfileViewController.swift index a42c06b..f4ce699 100644 --- a/GDproject/Controller/Profile/ProfileViewController.swift +++ b/GDproject/Controller/Profile/ProfileViewController.swift @@ -47,6 +47,9 @@ class ProfileViewController: UIViewController var user: Model.Users? { didSet { self.fill(with: user!) + Model.getPostsForUser(with: user!.id) { [weak self] (posts) in + self?.dataSourse = posts + } navigationItem.title = "\(user?.id ?? 0)" } } @@ -108,9 +111,7 @@ class ProfileViewController: UIViewController } } - Model.getPostsForUser(with: id) { [weak self] (posts) in - self?.dataSourse = posts - } + // requst for postsforuser was here. moved because of concrr } setUpNavigarionBar() @@ -136,7 +137,21 @@ class ProfileViewController: UIViewController // saved let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - let editAction = UIAlertAction(title: "Edit profile", style: .default) + let channelAction = UIAlertAction(title: "Add to the channel", style: .default){ + [weak self] (_) in + + let vc = self?.storyboard?.instantiateViewController(withIdentifier: simplifiedChannelsList) as! SimplifiedChannelsList + + vc.user = self?.user! + + let transition = CATransition() + transition.duration = 0.5 + transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut) + transition.type = CATransitionType.moveIn + transition.subtype = CATransitionSubtype.fromTop + self?.navigationController?.view.layer.add(transition, forKey: nil) + self?.navigationController?.pushViewController(vc, animated: false) + } let settingsAction = UIAlertAction(title: "Setting", style: .default) { [weak self] (_) in @@ -151,7 +166,7 @@ class ProfileViewController: UIViewController DataStorage.standard.setIsLoggedIn(value: false, with: 0) } - optionMenu.addAction(editAction) + optionMenu.addAction(channelAction) optionMenu.addAction(settingsAction) optionMenu.addAction(copyLink) optionMenu.addAction(logoutAction) diff --git a/GDproject/Simple model/Model.swift b/GDproject/Simple model/Model.swift index ac92641..e168060 100644 --- a/GDproject/Simple model/Model.swift +++ b/GDproject/Simple model/Model.swift @@ -124,18 +124,14 @@ class Model{ struct Channels: Codable { + static var fullTags = Set() + static var fullPeople = [Int:Users]() + var people: [Int] var name: String var id: Int? var tags: [String] - enum CodingKeys: String, CodingKey { - case people - case name - case id - case tags - } - init(people: [Int], name: String, id: Int, tags: [String]) { self.id = id self.people = people @@ -149,6 +145,13 @@ class Model{ self.name = name } + enum CodingKeys: String, CodingKey { + case people + case name + case id + case tags + } + func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(people, forKey: .people)