git.iko.soy/dashared/GDproject
on master help sign in
channels: attempt2
49bc15bDarya Rednikina
GDproject.xcodeproj/project.pbxproj+4
@@ -7,6 +7,7 @@
7 objects = {
7 objects = {
8
8
9/* Begin PBXBuildFile section */
9/* Begin PBXBuildFile section */
10+ 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */; };
10 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; };
11 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; };
11 123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; };
12 123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; };
12 124CC7032221C00C009DF531 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124CC7022221C00C009DF531 /* Model.swift */; };
13 124CC7032221C00C009DF531 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124CC7022221C00C009DF531 /* Model.swift */; };
@@ -72,6 +73,7 @@
72/* End PBXCopyFilesBuildPhase section */
73/* End PBXCopyFilesBuildPhase section */
73
74
74/* Begin PBXFileReference section */
75/* Begin PBXFileReference section */
76+ 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedChannelsList.swift; sourceTree = "<group>"; };
75 123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = "<group>"; };
77 123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = "<group>"; };
76 123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = "<group>"; };
78 123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = "<group>"; };
77 124CC7022221C00C009DF531 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
79 124CC7022221C00C009DF531 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
@@ -238,6 +240,7 @@
238 children = (
240 children = (
239 12D7D134221C42B700B35452 /* ChannelController.swift */,
241 12D7D134221C42B700B35452 /* ChannelController.swift */,
240 12D7D132221C321600B35452 /* ChannelListController.swift */,
242 12D7D132221C321600B35452 /* ChannelListController.swift */,
243+ 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */,
241 12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
244 12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
242 12E36DD022148122006FCDD7 /* FullPostController.swift */,
245 12E36DD022148122006FCDD7 /* FullPostController.swift */,
243 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
246 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
@@ -332,6 +335,7 @@
332 12D7D137221D78E800B35452 /* Channel.swift in Sources */,
335 12D7D137221D78E800B35452 /* Channel.swift in Sources */,
333 1291BE3622218DBF009D3F23 /* LogInCoordinator.swift in Sources */,
336 1291BE3622218DBF009D3F23 /* LogInCoordinator.swift in Sources */,
334 12E36DB922144016006FCDD7 /* User.swift in Sources */,
337 12E36DB922144016006FCDD7 /* User.swift in Sources */,
338+ 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */,
335 125BD5812217314A008A3575 /* NewsVC.swift in Sources */,
339 125BD5812217314A008A3575 /* NewsVC.swift in Sources */,
336 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
340 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
337 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
341 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
GDproject/Base.lproj/Main.storyboard+44
@@ -214,6 +214,50 @@
214 </objects>
214 </objects>
215 <point key="canvasLocation" x="2803" y="1756"/>
215 <point key="canvasLocation" x="2803" y="1756"/>
216 </scene>
216 </scene>
217+ <!--Simplified Channels List-->
218+ <scene sceneID="gAa-jy-vpG">
219+ <objects>
220+ <tableViewController storyboardIdentifier="SimplifiedChannelsList" id="pgD-Fz-bkD" customClass="SimplifiedChannelsList" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
221+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="Onz-Ne-JgO">
222+ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
223+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
224+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
225+ <prototypes>
226+ <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="cell" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="cell" textLabel="mZB-IA-VFq" detailTextLabel="6A8-yj-Eqe" style="IBUITableViewCellStyleSubtitle" id="6dT-km-gZC">
227+ <rect key="frame" x="0.0" y="28" width="375" height="44"/>
228+ <autoresizingMask key="autoresizingMask"/>
229+ <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="6dT-km-gZC" id="h7U-va-4PX">
230+ <rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
231+ <autoresizingMask key="autoresizingMask"/>
232+ <subviews>
233+ <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="mZB-IA-VFq">
234+ <rect key="frame" x="16" y="5" width="33.5" height="20.5"/>
235+ <autoresizingMask key="autoresizingMask"/>
236+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
237+ <nil key="textColor"/>
238+ <nil key="highlightedColor"/>
239+ </label>
240+ <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Subtitle" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="6A8-yj-Eqe">
241+ <rect key="frame" x="16" y="25.5" width="44" height="14.5"/>
242+ <autoresizingMask key="autoresizingMask"/>
243+ <fontDescription key="fontDescription" type="system" pointSize="12"/>
244+ <nil key="textColor"/>
245+ <nil key="highlightedColor"/>
246+ </label>
247+ </subviews>
248+ </tableViewCellContentView>
249+ </tableViewCell>
250+ </prototypes>
251+ <connections>
252+ <outlet property="dataSource" destination="pgD-Fz-bkD" id="V4y-ql-GOS"/>
253+ <outlet property="delegate" destination="pgD-Fz-bkD" id="Avz-4G-8j6"/>
254+ </connections>
255+ </tableView>
256+ </tableViewController>
257+ <placeholder placeholderIdentifier="IBFirstResponder" id="731-nV-bC3" userLabel="First Responder" sceneMemberID="firstResponder"/>
258+ </objects>
259+ <point key="canvasLocation" x="4445.6000000000004" y="-598.65067466266873"/>
260+ </scene>
217 <!--Channel List Controller-->
261 <!--Channel List Controller-->
218 <scene sceneID="4eb-Jz-gcx">
262 <scene sceneID="4eb-Jz-gcx">
219 <objects>
263 <objects>
GDproject/Constants.swift+2
@@ -44,3 +44,5 @@ let logInController = "LogInController"
44
44
45
45
46let profileViewController = "ProfileViewController"
46let profileViewController = "ProfileViewController"
47+
48+let simplifiedChannelsList = "SimplifiedChannelsList"
GDproject/Controller/ News and channels/ChannelController.swift+3−1
@@ -198,7 +198,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
198
198
199 func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
199 func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
200 if searchText.isEmpty {
200 if searchText.isEmpty {
201− switch activeDataSource{
201+ switch activeDataSource {
202 case .people:
202 case .people:
203 dataSourcePeople = fullPeople
203 dataSourcePeople = fullPeople
204 case .tags:
204 case .tags:
@@ -235,6 +235,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
235 dataSourceTags = fullTags
235 dataSourceTags = fullTags
236 dataSourcePeople = []
236 dataSourcePeople = []
237 }
237 }
238+ print("\(searchBar.selectedScopeButtonIndex)")
238 activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
239 activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
239 if (!(searchBar.text?.isEmpty ?? true))
240 if (!(searchBar.text?.isEmpty ?? true))
240 {
241 {
@@ -250,6 +251,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
250 dataSourceTags = channel!.tags
251 dataSourceTags = channel!.tags
251 dataSourcePeople = []
252 dataSourcePeople = []
252 }
253 }
254+ print(" not active \(searchBar.selectedScopeButtonIndex)")
253 activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
255 activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
254 tableView.reloadData()
256 tableView.reloadData()
255 }
257 }
GDproject/Controller/ News and channels/ChannelListController.swift+12−2
@@ -70,16 +70,25 @@ class ChannelListController: UITableViewController, DataDelegate {
70 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
70 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
71 }
71 }
72
72
73− override func viewWillAppear(_ animated: Bool)
73+ override func viewDidAppear(_ animated: Bool)
74 {
74 {
75− super.viewWillAppear(animated)
75+ super.viewDidAppear(animated)
76 searchController.isActive = false
76 searchController.isActive = false
77+ askForUpdates()
78+ }
79+
80+ private func askForUpdates(){
77 Model.channelsList { [weak self] (channels) in
81 Model.channelsList { [weak self] (channels) in
78 self?.dataSource = [ChannelListController.generalChannel] + channels
82 self?.dataSource = [ChannelListController.generalChannel] + channels
79 self?.toReload = true
83 self?.toReload = true
80 }
84 }
81 }
85 }
82
86
87+ override func viewWillAppear(_ animated: Bool) {
88+ super.viewWillAppear(true)
89+ askForUpdates()
90+ }
91+
83 @objc func addChannel()
92 @objc func addChannel()
84 {
93 {
85 // editing mode is on automatically
94 // editing mode is on automatically
@@ -157,6 +166,7 @@ class ChannelListController: UITableViewController, DataDelegate {
157 self?.tableView.deleteRows(at: [indexPath], with: .none)
166 self?.tableView.deleteRows(at: [indexPath], with: .none)
158 self?.tableView.endUpdates()
167 self?.tableView.endUpdates()
159 }
168 }
169+
160 deleteButton.backgroundColor = .red
170 deleteButton.backgroundColor = .red
161
171
162 return [editButton, deleteButton]
172 return [editButton, deleteButton]
GDproject/Controller/ News and channels/NewsController.swift+6−1
@@ -32,14 +32,19 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
32 }
32 }
33
33
34 var dictionary: [Int: Model.Users]? {
34 var dictionary: [Int: Model.Users]? {
35− didSet{
35+ didSet {
36
36
37 var newPosts: [Model.Posts] = []
37 var newPosts: [Model.Posts] = []
38
38
39 posts!.forEach({ (post) in
39 posts!.forEach({ (post) in
40+
40 newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: dictionary![post.authorId]!, date: post.updated, tags: post.tags))
41 newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: dictionary![post.authorId]!, date: post.updated, tags: post.tags))
42+
43+ post.tags.forEach { Model.Channels.fullTags.insert($0) }
44+
41 })
45 })
42
46
47+
43 news.dataSourse = newPosts
48 news.dataSourse = newPosts
44 tableView.reloadData()
49 tableView.reloadData()
45 }
50 }
GDproject/Controller/ News and channels/PostViewCell.swift+7−1
@@ -142,7 +142,13 @@ class PostViewCell: UITableViewCell
142 contentView.addSubview(mainView)
142 contentView.addSubview(mainView)
143 mainView.edgesToSuperview(excluding: [.top, .bottom])
143 mainView.edgesToSuperview(excluding: [.top, .bottom])
144 mainView.topToBottom(of: nameStackView, offset: 5)
144 mainView.topToBottom(of: nameStackView, offset: 5)
145+
146+ // TODO:- change!!!!!!!!!!!!
147+ if hashtags.isEmpty{
148+ mainView.height(0)
149+ } else {
145− mainView.height(30)
150+ mainView.height(30)
151+ }
146
152
147 let stackView = MyStackView(arrangedSubviews: views)
153 let stackView = MyStackView(arrangedSubviews: views)
148 stackView.isFull = full
154 stackView.isFull = full
GDproject/Controller/ News and channels/SimplifiedChannelsList.swiftnew file+81
@@ -0,0 +1,81 @@
1+//
2+// SimplifiedChannelsList.swift
3+// GDproject
4+//
5+// Created by cstore on 13/03/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+
10+/// class for ADDing person to existing (or new) channel: like playlist in itunes
11+import UIKit
12+
13+class SimplifiedChannelsList: UITableViewController {
14+
15+ var user: Model.Users?
16+
17+ var dataSource: [Model.Channels]?{
18+ didSet{
19+ tableView.reloadData()
20+ }
21+ }
22+
23+ override func viewDidLoad() {
24+ super.viewDidLoad()
25+ setUpNavigationButtons()
26+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
27+ }
28+
29+ override func viewWillAppear(_ animated: Bool) {
30+ Model.channelsList { [weak self] (channels) in
31+ self?.dataSource = channels
32+ }
33+ }
34+
35+ func setUpNavigationButtons(){
36+ navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelAction))
37+ }
38+
39+ func completedActions(with channel: Model.Channels){
40+ Model.updateChannel(with: channel)
41+ cancelAction()
42+ }
43+
44+ @objc func cancelAction(){
45+ let transition = CATransition()
46+ transition.duration = 0.5
47+ transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
48+ transition.type = CATransitionType.reveal
49+ transition.subtype = CATransitionSubtype.fromBottom
50+ navigationController?.view.layer.add(transition, forKey: nil)
51+ navigationController?.popViewController(animated: false)
52+ }
53+
54+ override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
55+ let viewHeader = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 30))
56+ return viewHeader
57+ }
58+
59+ override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
60+ return 30
61+ }
62+
63+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
64+ return dataSource?.count ?? 0
65+ }
66+
67+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
68+ var channel = dataSource![indexPath.row]
69+ channel.people.append(user!.id)
70+ completedActions(with: channel)
71+ }
72+
73+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
74+ let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
75+
76+ cell.textLabel?.text = dataSource![indexPath.row].name
77+ cell.detailTextLabel?.text = "\(dataSource![indexPath.row].id!)"
78+
79+ return cell
80+ }
81+}
GDproject/Controller/Profile/ProfileViewController.swift+20−5
@@ -47,6 +47,9 @@ class ProfileViewController: UIViewController
47 var user: Model.Users? {
47 var user: Model.Users? {
48 didSet {
48 didSet {
49 self.fill(with: user!)
49 self.fill(with: user!)
50+ Model.getPostsForUser(with: user!.id) { [weak self] (posts) in
51+ self?.dataSourse = posts
52+ }
50 navigationItem.title = "\(user?.id ?? 0)"
53 navigationItem.title = "\(user?.id ?? 0)"
51 }
54 }
52 }
55 }
@@ -108,9 +111,7 @@ class ProfileViewController: UIViewController
108 }
111 }
109 }
112 }
110
113
111− Model.getPostsForUser(with: id) { [weak self] (posts) in
114+ // requst for postsforuser was here. moved because of concrr
112− self?.dataSourse = posts
113− }
114 }
115 }
115
116
116 setUpNavigarionBar()
117 setUpNavigarionBar()
@@ -136,7 +137,21 @@ class ProfileViewController: UIViewController
136 // saved
137 // saved
137
138
138 let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
139 let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
139− let editAction = UIAlertAction(title: "Edit profile", style: .default)
140+ let channelAction = UIAlertAction(title: "Add to the channel", style: .default){
141+ [weak self] (_) in
142+
143+ let vc = self?.storyboard?.instantiateViewController(withIdentifier: simplifiedChannelsList) as! SimplifiedChannelsList
144+
145+ vc.user = self?.user!
146+
147+ let transition = CATransition()
148+ transition.duration = 0.5
149+ transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
150+ transition.type = CATransitionType.moveIn
151+ transition.subtype = CATransitionSubtype.fromTop
152+ self?.navigationController?.view.layer.add(transition, forKey: nil)
153+ self?.navigationController?.pushViewController(vc, animated: false)
154+ }
140 let settingsAction = UIAlertAction(title: "Setting", style: .default)
155 let settingsAction = UIAlertAction(title: "Setting", style: .default)
141 { [weak self] (_) in
156 { [weak self] (_) in
142
157
@@ -151,7 +166,7 @@ class ProfileViewController: UIViewController
151 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
166 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
152 }
167 }
153
168
154− optionMenu.addAction(editAction)
169+ optionMenu.addAction(channelAction)
155 optionMenu.addAction(settingsAction)
170 optionMenu.addAction(settingsAction)
156 optionMenu.addAction(copyLink)
171 optionMenu.addAction(copyLink)
157 optionMenu.addAction(logoutAction)
172 optionMenu.addAction(logoutAction)
GDproject/Simple model/Model.swift+10−7
@@ -124,18 +124,14 @@ class Model{
124
124
125 struct Channels: Codable {
125 struct Channels: Codable {
126
126
127+ static var fullTags = Set<String>()
128+ static var fullPeople = [Int:Users]()
129+
127 var people: [Int]
130 var people: [Int]
128 var name: String
131 var name: String
129 var id: Int?
132 var id: Int?
130 var tags: [String]
133 var tags: [String]
131
134
132− enum CodingKeys: String, CodingKey {
133− case people
134− case name
135− case id
136− case tags
137− }
138−
139 init(people: [Int], name: String, id: Int, tags: [String]) {
135 init(people: [Int], name: String, id: Int, tags: [String]) {
140 self.id = id
136 self.id = id
141 self.people = people
137 self.people = people
@@ -149,6 +145,13 @@ class Model{
149 self.name = name
145 self.name = name
150 }
146 }
151
147
148+ enum CodingKeys: String, CodingKey {
149+ case people
150+ case name
151+ case id
152+ case tags
153+ }
154+
152 func encode(to encoder: Encoder) throws {
155 func encode(to encoder: Encoder) throws {
153 var container = encoder.container(keyedBy: CodingKeys.self)
156 var container = encoder.container(keyedBy: CodingKeys.self)
154 try container.encode(people, forKey: .people)
157 try container.encode(people, forKey: .people)