git.iko.soy/dashared/GDproject
on master help sign in
full post view and slight modifications
973f0edDarya Rednikina
GDproject.xcodeproj/project.pbxproj+4
@@ -26,6 +26,7 @@
26 12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DC922144635006FCDD7 /* NewPostViewController.swift */; };
26 12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DC922144635006FCDD7 /* NewPostViewController.swift */; };
27 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCB22144725006FCDD7 /* PostViewCell.swift */; };
27 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCB22144725006FCDD7 /* PostViewCell.swift */; };
28 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCD22144756006FCDD7 /* Constants.swift */; };
28 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCD22144756006FCDD7 /* Constants.swift */; };
29+ 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DD022148122006FCDD7 /* FullPostController.swift */; };
29/* End PBXBuildFile section */
30/* End PBXBuildFile section */
30
31
31/* Begin PBXCopyFilesBuildPhase section */
32/* Begin PBXCopyFilesBuildPhase section */
@@ -64,6 +65,7 @@
64 12E36DC922144635006FCDD7 /* NewPostViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewPostViewController.swift; sourceTree = "<group>"; };
65 12E36DC922144635006FCDD7 /* NewPostViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewPostViewController.swift; sourceTree = "<group>"; };
65 12E36DCB22144725006FCDD7 /* PostViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewCell.swift; sourceTree = "<group>"; };
66 12E36DCB22144725006FCDD7 /* PostViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewCell.swift; sourceTree = "<group>"; };
66 12E36DCD22144756006FCDD7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
67 12E36DCD22144756006FCDD7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
68+ 12E36DD022148122006FCDD7 /* FullPostController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullPostController.swift; sourceTree = "<group>"; };
67/* End PBXFileReference section */
69/* End PBXFileReference section */
68
70
69/* Begin PBXFrameworksBuildPhase section */
71/* Begin PBXFrameworksBuildPhase section */
@@ -135,6 +137,7 @@
135 12E36DCF22145923006FCDD7 /* Controller */ = {
137 12E36DCF22145923006FCDD7 /* Controller */ = {
136 isa = PBXGroup;
138 isa = PBXGroup;
137 children = (
139 children = (
140+ 12E36DD022148122006FCDD7 /* FullPostController.swift */,
138 12E36DC522144266006FCDD7 /* HeaderNewsChannels.swift */,
141 12E36DC522144266006FCDD7 /* HeaderNewsChannels.swift */,
139 12E36DC722144374006FCDD7 /* ChannelsController.swift */,
142 12E36DC722144374006FCDD7 /* ChannelsController.swift */,
140 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
143 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
@@ -223,6 +226,7 @@
223 12E36D9E221424EA006FCDD7 /* NewsController.swift in Sources */,
226 12E36D9E221424EA006FCDD7 /* NewsController.swift in Sources */,
224 12E36DC622144266006FCDD7 /* HeaderNewsChannels.swift in Sources */,
227 12E36DC622144266006FCDD7 /* HeaderNewsChannels.swift in Sources */,
225 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */,
228 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */,
229+ 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */,
226 12E36D9C221424EA006FCDD7 /* AppDelegate.swift in Sources */,
230 12E36D9C221424EA006FCDD7 /* AppDelegate.swift in Sources */,
227 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */,
231 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */,
228 );
232 );
GDproject/Base.lproj/Main.storyboard+18
@@ -72,6 +72,24 @@
72 </objects>
72 </objects>
73 <point key="canvasLocation" x="1773" y="132"/>
73 <point key="canvasLocation" x="1773" y="132"/>
74 </scene>
74 </scene>
75+ <!--Full Post Controller-->
76+ <scene sceneID="nNH-1Q-jks">
77+ <objects>
78+ <tableViewController storyboardIdentifier="FullPostController" id="tcM-Fs-WJr" customClass="FullPostController" customModule="GDproject" customModuleProvider="target" sceneMemberID="viewController">
79+ <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="dmU-W2-lq6">
80+ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
81+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
82+ <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
83+ <connections>
84+ <outlet property="dataSource" destination="tcM-Fs-WJr" id="Xvi-Mj-Id2"/>
85+ <outlet property="delegate" destination="tcM-Fs-WJr" id="190-Q0-2bn"/>
86+ </connections>
87+ </tableView>
88+ </tableViewController>
89+ <placeholder placeholderIdentifier="IBFirstResponder" id="CP8-RO-wn0" userLabel="First Responder" sceneMemberID="firstResponder"/>
90+ </objects>
91+ <point key="canvasLocation" x="2506" y="130"/>
92+ </scene>
75 <!--Navigation Controller-->
93 <!--Navigation Controller-->
76 <scene sceneID="RSd-UJ-34B">
94 <scene sceneID="RSd-UJ-34B">
77 <objects>
95 <objects>
GDproject/Constants.swift+2
@@ -10,3 +10,5 @@
10let postCellId = "PostCell"
10let postCellId = "PostCell"
11// constant for segmented controll in NewsController.swift and ChannelsController.swift
11// constant for segmented controll in NewsController.swift and ChannelsController.swift
12let headerNewsChannelsVC = "HeaderSegmentedControll"
12let headerNewsChannelsVC = "HeaderSegmentedControll"
13+// for transitioning to full post view
14+let fullPostControllerId = "FullPostController"
GDproject/Controller/FullPostController.swiftnew file+49
@@ -0,0 +1,49 @@
1+//
2+// FullPostViewController.swift
3+// GDproject
4+//
5+// Created by cstore on 13/02/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class FullPostController: UITableViewController {
12+
13+ var post: Post?
14+
15+ override func viewDidLoad() {
16+ super.viewDidLoad()
17+
18+ tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
19+ }
20+
21+ // MARK: - Table view data source
22+
23+ override func numberOfSections(in tableView: UITableView) -> Int {
24+ // #warning Incomplete implementation, return the number of sections
25+ return 2
26+ }
27+
28+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
29+ {
30+ switch section {
31+ case 0:
32+ return 1
33+ case 1:
34+ return post?.comments.count ?? 0
35+ default:
36+ return 0
37+ }
38+ }
39+
40+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
41+ {
42+ // TODO: make different cells for sections with switch
43+
44+ let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
45+
46+ cell.fill(with: post!.dataArray, true)
47+ return cell
48+ }
49+}
GDproject/Controller/NewsController.swift+8−2
@@ -69,7 +69,13 @@ class NewsController: UIViewController
69
69
70// MARK:- tableView delegate
70// MARK:- tableView delegate
71extension NewsController: UITableViewDelegate{
71extension NewsController: UITableViewDelegate{
72−
72+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
73+ {
74+ let vc = storyboard!.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
75+
76+ vc.post = dataSourse[indexPath.row]
77+ navigationController!.pushViewController(vc, animated: true)
78+ }
73}
79}
74
80
75// MARK:- tableView dataSourse
81// MARK:- tableView dataSourse
@@ -82,7 +88,7 @@ extension NewsController: UITableViewDataSource
82 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
88 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
83 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
89 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
84
90
85− cell.fill(with: dataSourse[indexPath.row].dataArray)
91+ cell.fill(with: dataSourse[indexPath.row].dataArray, false)
86 return cell
92 return cell
87 }
93 }
88
94
GDproject/Controller/PostViewCell.swift+6−4
@@ -58,7 +58,7 @@ class PostViewCell: UITableViewCell
58 var views: [UIView] = []
58 var views: [UIView] = []
59 var data : [UIImage] = []
59 var data : [UIImage] = []
60
60
61− func fill(with info: [Media])
61+ func fill(with info: [Media], _ isFullVersoin: Bool)
62 {
62 {
63 // important
63 // important
64 contentView.subviews.forEach({ $0.removeFromSuperview() })
64 contentView.subviews.forEach({ $0.removeFromSuperview() })
@@ -77,10 +77,10 @@ class PostViewCell: UITableViewCell
77 break
77 break
78 }
78 }
79 }
79 }
80− setUpInStackView()
80+ setUpInStackView(isFullVersoin)
81 }
81 }
82
82
83− func setUpInStackView(){
83+ func setUpInStackView(_ full : Bool){
84 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
84 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
85 nameStackView.axis = .vertical
85 nameStackView.axis = .vertical
86 contentView.addSubview(nameStackView)
86 contentView.addSubview(nameStackView)
@@ -90,7 +90,9 @@ class PostViewCell: UITableViewCell
90 let stackView = UIStackView(arrangedSubviews: views)
90 let stackView = UIStackView(arrangedSubviews: views)
91 stackView.axis = .vertical
91 stackView.axis = .vertical
92 contentView.addSubview(stackView)
92 contentView.addSubview(stackView)
93+ if !full {
93− stackView.height(300, relation: .equalOrLess, isActive: true)
94+ stackView.height(300, relation: .equalOrLess, isActive: true)
95+ }
94 stackView.topToBottom(of: nameStackView)
96 stackView.topToBottom(of: nameStackView)
95 stackView.edgesToSuperview(excluding: .top, insets: .bottom(8) + .left(16) + .right(16))
97 stackView.edgesToSuperview(excluding: .top, insets: .bottom(8) + .left(16) + .right(16))
96 }
98 }
GDproject/Simple model/Post.swift+9−1
@@ -13,12 +13,14 @@ struct Post {
13 var dataArray: [Media]
13 var dataArray: [Media]
14 var fromUser: User
14 var fromUser: User
15 var atDate: String
15 var atDate: String
16+ var comments: [Comment]
16
17
17− init(dataArray: [Media], from: User, date: String)
18+ init(dataArray: [Media], from: User, date: String, comments: [Comment] = [])
18 {
19 {
19 self.dataArray = dataArray
20 self.dataArray = dataArray
20 fromUser = from
21 fromUser = from
21 atDate = date
22 atDate = date
23+ self.comments = comments
22 }
24 }
23}
25}
24
26
@@ -28,3 +30,9 @@ enum Media{
28 case image([UIImage])
30 case image([UIImage])
29 case quote
31 case quote
30}
32}
33+
34+struct Comment {
35+ var from: User
36+ var atTime: String
37+ var withData: String
38+}