git.iko.soy/dashared/GDproject
on master help sign in
channels: attempt2
commit49bc15b3b20291d78b08b46f0ff63af446ec261b authorDarya Rednikina <rednikina.com@yandex.ru> dateWed 13 Mar 2019, 19:09 (8 years ago) parent333da26
10 files changed+189−17
GDproject.xcodeproj/project.pbxproj+4 GDproject/Base.lproj/Main.storyboard+44 GDproject/Constants.swift+2 GDproject/Controller/ News and channels/ChannelController.swift+3−1 GDproject/Controller/ News and channels/ChannelListController.swift+12−2 GDproject/Controller/ News and channels/NewsController.swift+6−1 GDproject/Controller/ News and channels/PostViewCell.swift+7−1 GDproject/Controller/ News and channels/SimplifiedChannelsList.swift+81 GDproject/Controller/Profile/ProfileViewController.swift+20−5 GDproject/Simple model/Model.swift+10−7
GDproject.xcodeproj/project.pbxproj+4
@@ -7,6 +7,7 @@
77 objects = {
88
99/* Begin PBXBuildFile section */
10+ 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */; };
1011 123E37A5221F1B3200F6E42A /* LogInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A4221F1B3200F6E42A /* LogInViewController.swift */; };
1112 123E37A7221F1DD700F6E42A /* MainController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 123E37A6221F1DD700F6E42A /* MainController.swift */; };
1213 124CC7032221C00C009DF531 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124CC7022221C00C009DF531 /* Model.swift */; };
@@ -72,6 +73,7 @@
7273/* End PBXCopyFilesBuildPhase section */
7374
7475/* Begin PBXFileReference section */
76+ 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedChannelsList.swift; sourceTree = "<group>"; };
7577 123E37A4221F1B3200F6E42A /* LogInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInViewController.swift; sourceTree = "<group>"; };
7678 123E37A6221F1DD700F6E42A /* MainController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainController.swift; sourceTree = "<group>"; };
7779 124CC7022221C00C009DF531 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
@@ -238,6 +240,7 @@
238240 children = (
239241 12D7D134221C42B700B35452 /* ChannelController.swift */,
240242 12D7D132221C321600B35452 /* ChannelListController.swift */,
243+ 1210A0BA223940310080686D /* SimplifiedChannelsList.swift */,
241244 12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
242245 12E36DD022148122006FCDD7 /* FullPostController.swift */,
243246 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
@@ -332,6 +335,7 @@
332335 12D7D137221D78E800B35452 /* Channel.swift in Sources */,
333336 1291BE3622218DBF009D3F23 /* LogInCoordinator.swift in Sources */,
334337 12E36DB922144016006FCDD7 /* User.swift in Sources */,
338+ 1210A0BB223940310080686D /* SimplifiedChannelsList.swift in Sources */,
335339 125BD5812217314A008A3575 /* NewsVC.swift in Sources */,
336340 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
337341 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
GDproject/Base.lproj/Main.storyboard+44
@@ -214,6 +214,50 @@
214214 </objects>
215215 <point key="canvasLocation" x="2803" y="1756"/>
216216 </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>
217261 <!--Channel List Controller-->
218262 <scene sceneID="4eb-Jz-gcx">
219263 <objects>
GDproject/Constants.swift+2
@@ -44,3 +44,5 @@ let logInController = "LogInController"
4444
4545
4646let 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
198198
199199 func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
200200 if searchText.isEmpty {
201− switch activeDataSource{
201+ switch activeDataSource {
202202 case .people:
203203 dataSourcePeople = fullPeople
204204 case .tags:
@@ -235,6 +235,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
235235 dataSourceTags = fullTags
236236 dataSourcePeople = []
237237 }
238+ print("\(searchBar.selectedScopeButtonIndex)")
238239 activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
239240 if (!(searchBar.text?.isEmpty ?? true))
240241 {
@@ -250,6 +251,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
250251 dataSourceTags = channel!.tags
251252 dataSourcePeople = []
252253 }
254+ print(" not active \(searchBar.selectedScopeButtonIndex)")
253255 activeDataSource = searchBar.selectedScopeButtonIndex == 0 ? .people : .tags
254256 tableView.reloadData()
255257 }
GDproject/Controller/ News and channels/ChannelListController.swift+12−2
@@ -70,16 +70,25 @@ class ChannelListController: UITableViewController, DataDelegate {
7070 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
7171 }
7272
73− override func viewWillAppear(_ animated: Bool)
73+ override func viewDidAppear(_ animated: Bool)
7474 {
75− super.viewWillAppear(animated)
75+ super.viewDidAppear(animated)
7676 searchController.isActive = false
77+ askForUpdates()
78+ }
79+
80+ private func askForUpdates(){
7781 Model.channelsList { [weak self] (channels) in
7882 self?.dataSource = [ChannelListController.generalChannel] + channels
7983 self?.toReload = true
8084 }
8185 }
8286
87+ override func viewWillAppear(_ animated: Bool) {
88+ super.viewWillAppear(true)
89+ askForUpdates()
90+ }
91+
8392 @objc func addChannel()
8493 {
8594 // editing mode is on automatically
@@ -157,6 +166,7 @@ class ChannelListController: UITableViewController, DataDelegate {
157166 self?.tableView.deleteRows(at: [indexPath], with: .none)
158167 self?.tableView.endUpdates()
159168 }
169+
160170 deleteButton.backgroundColor = .red
161171
162172 return [editButton, deleteButton]
GDproject/Controller/ News and channels/NewsController.swift+6−1
@@ -32,14 +32,19 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
3232 }
3333
3434 var dictionary: [Int: Model.Users]? {
35− didSet{
35+ didSet {
3636
3737 var newPosts: [Model.Posts] = []
3838
3939 posts!.forEach({ (post) in
40+
4041 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+
4145 })
4246
47+
4348 news.dataSourse = newPosts
4449 tableView.reloadData()
4550 }
GDproject/Controller/ News and channels/PostViewCell.swift+7−1
@@ -142,7 +142,13 @@ class PostViewCell: UITableViewCell
142142 contentView.addSubview(mainView)
143143 mainView.edgesToSuperview(excluding: [.top, .bottom])
144144 mainView.topToBottom(of: nameStackView, offset: 5)
145− mainView.height(30)
145+
146+ // TODO:- change!!!!!!!!!!!!
147+ if hashtags.isEmpty{
148+ mainView.height(0)
149+ } else {
150+ mainView.height(30)
151+ }
146152
147153 let stackView = MyStackView(arrangedSubviews: views)
148154 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
4747 var user: Model.Users? {
4848 didSet {
4949 self.fill(with: user!)
50+ Model.getPostsForUser(with: user!.id) { [weak self] (posts) in
51+ self?.dataSourse = posts
52+ }
5053 navigationItem.title = "\(user?.id ?? 0)"
5154 }
5255 }
@@ -108,9 +111,7 @@ class ProfileViewController: UIViewController
108111 }
109112 }
110113
111− Model.getPostsForUser(with: id) { [weak self] (posts) in
112− self?.dataSourse = posts
113− }
114+ // requst for postsforuser was here. moved because of concrr
114115 }
115116
116117 setUpNavigarionBar()
@@ -136,7 +137,21 @@ class ProfileViewController: UIViewController
136137 // saved
137138
138139 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+ }
140155 let settingsAction = UIAlertAction(title: "Setting", style: .default)
141156 { [weak self] (_) in
142157
@@ -151,7 +166,7 @@ class ProfileViewController: UIViewController
151166 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
152167 }
153168
154− optionMenu.addAction(editAction)
169+ optionMenu.addAction(channelAction)
155170 optionMenu.addAction(settingsAction)
156171 optionMenu.addAction(copyLink)
157172 optionMenu.addAction(logoutAction)
GDproject/Simple model/Model.swift+10−7
@@ -124,18 +124,14 @@ class Model{
124124
125125 struct Channels: Codable {
126126
127+ static var fullTags = Set<String>()
128+ static var fullPeople = [Int:Users]()
129+
127130 var people: [Int]
128131 var name: String
129132 var id: Int?
130133 var tags: [String]
131134
132− enum CodingKeys: String, CodingKey {
133− case people
134− case name
135− case id
136− case tags
137− }
138−
139135 init(people: [Int], name: String, id: Int, tags: [String]) {
140136 self.id = id
141137 self.people = people
@@ -149,6 +145,13 @@ class Model{
149145 self.name = name
150146 }
151147
148+ enum CodingKeys: String, CodingKey {
149+ case people
150+ case name
151+ case id
152+ case tags
153+ }
154+
152155 func encode(to encoder: Encoder) throws {
153156 var container = encoder.container(keyedBy: CodingKeys.self)
154157 try container.encode(people, forKey: .people)