git.iko.soy/dashared/GDproject
on master help sign in
fixed news feed updates. added time for posts. have to detect correct time zone
78a2adeDarya Rednikina
GDproject/Controller/ News and channels/NewsController.swift+3
@@ -37,12 +37,14 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
37 })
37 })
38
38
39 news.dataSourse = newPosts
39 news.dataSourse = newPosts
40+ print("and heeeere in dict")
40 tableView.reloadData()
41 tableView.reloadData()
41 }
42 }
42 }
43 }
43
44
44 var channel: Channel?{
45 var channel: Channel?{
45 didSet{
46 didSet{
47+ print(channel!.posts.count)
46 navigationItem.title = channel?.title ?? ""
48 navigationItem.title = channel?.title ?? ""
47 }
49 }
48 }
50 }
@@ -90,6 +92,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
90 }
92 }
91
93
92 @objc func refreshPostsData( _ ff: UIRefreshControl){
94 @objc func refreshPostsData( _ ff: UIRefreshControl){
95+ print("I am here")
93 Model.getLast { [weak self] (tuple) in
96 Model.getLast { [weak self] (tuple) in
94 self?.channel = tuple.channel
97 self?.channel = tuple.channel
95 self?.dictionary = tuple.users
98 self?.dictionary = tuple.users
GDproject/Controller/ News and channels/NewsVC.swift+1
@@ -29,6 +29,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
29
29
30 var dataSourse: [Model.Posts] = []{
30 var dataSourse: [Model.Posts] = []{
31 didSet{
31 didSet{
32+ cellDataSourse = []
32 dataSourse.forEach { (item) in
33 dataSourse.forEach { (item) in
33 cellDataSourse.append(PostCellData(attributedData: PostCellData.create(with: item.body)))
34 cellDataSourse.append(PostCellData(attributedData: PostCellData.create(with: item.body)))
34 }
35 }
GDproject/Controller/ News and channels/PostViewCell.swift+5−3
@@ -31,7 +31,7 @@ class PostViewCell: UITableViewCell
31 return label
31 return label
32 }()
32 }()
33
33
34− let commentsLabel: UILabel = {
34+ let timeLabel: UILabel = {
35 let label = UILabel()
35 let label = UILabel()
36 label.font = UIFont.systemFont(ofSize: 12)
36 label.font = UIFont.systemFont(ofSize: 12)
37 label.textColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
37 label.textColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
@@ -84,6 +84,7 @@ class PostViewCell: UITableViewCell
84 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.lastName ?? "")", for: .normal)
84 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.lastName ?? "")", for: .normal)
85 nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
85 nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
86 fullNameLabel.text = "\(post.authorId)"
86 fullNameLabel.text = "\(post.authorId)"
87+
87 setUpInStackView(isFullVersoin)
88 setUpInStackView(isFullVersoin)
88 }
89 }
89
90
@@ -151,10 +152,11 @@ class PostViewCell: UITableViewCell
151
152
152 stackView.edgesToSuperview(excluding: [.top, .bottom], insets: .left(16) + .right(16))
153 stackView.edgesToSuperview(excluding: [.top, .bottom], insets: .left(16) + .right(16))
153
154
154− let commentsSharesStackView = UIStackView(arrangedSubviews: [ commentsLabel, shareButton])
155+ let commentsSharesStackView = UIStackView(arrangedSubviews: [ timeLabel, shareButton])
155 contentView.addSubview(commentsSharesStackView)
156 contentView.addSubview(commentsSharesStackView)
156
157
157− commentsLabel.text = "14.02.19 в 23:00"
158+ timeLabel.text = post!.convertDateFormatter()
159+
158 commentsSharesStackView.axis = .horizontal
160 commentsSharesStackView.axis = .horizontal
159 commentsSharesStackView.distribution = .equalSpacing
161 commentsSharesStackView.distribution = .equalSpacing
160 commentsSharesStackView.edgesToSuperview(excluding: .top, insets: .bottom(10) + .left(16) + .right(16))
162 commentsSharesStackView.edgesToSuperview(excluding: .top, insets: .bottom(10) + .left(16) + .right(16))
GDproject/Simple model/Model.swift+15
@@ -56,6 +56,21 @@ class Model{
56 self.user = user
56 self.user = user
57 self.updated = date
57 self.updated = date
58 }
58 }
59+
60+ func convertDateFormatter() -> String
61+ {
62+
63+ let dateFormatter = DateFormatter()
64+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format
65+ dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone!
66+ let date = dateFormatter.date(from: updated)
67+
68+ dateFormatter.dateFormat = "MMM d, yyyy HH:mm" ///this is what you want to convert format
69+ dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone!
70+ let timeStamp = dateFormatter.string(from: date!)
71+
72+ return timeStamp
73+ }
59 }
74 }
60
75
61 struct Users: Codable{
76 struct Users: Codable{