git.iko.soy/dashared/GDproject
on master help sign in
closes: #9. decreased number of requests
1400778Darya Rednikina
GDproject/Controller/ News and channels/FullPostController.swift+1−1
@@ -94,7 +94,7 @@ class FullPostController: UITableViewController {
94 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
94 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
95
95
96
96
97− cell.fill(with: post!.body, true, post: post!)
97+ cell.fill(with: PostCellData.create(with: post!.body), true, post: post!)
98 cell.selectionStyle = .none
98 cell.selectionStyle = .none
99 return cell
99 return cell
100 }
100 }
GDproject/Controller/ News and channels/NewsVC.swift+27−2
@@ -7,10 +7,35 @@
7//
7//
8
8
9import UIKit
9import UIKit
10+import MarkdownKit
11+
12+struct PostCellData{
13+ var attributedData = NSAttributedString()
14+
15+ static func create(with attachments: [Model.Attachments]) -> NSAttributedString{
16+ var markdown = ""
17+
18+ attachments.forEach { (attachment) in markdown.append(attachment.markdown) }
19+
20+ let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
21+ markdownParser.enabledElements = .disabledAutomaticLink
22+ markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
23+
24+ return markdownParser.parse(markdown)
25+ }
26+}
10
27
11class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
28class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
12
29
13− var dataSourse: [Model.Posts] = []
30+ var dataSourse: [Model.Posts] = []{
31+ didSet{
32+ dataSourse.forEach { (item) in
33+ cellDataSourse.append(PostCellData(attributedData: PostCellData.create(with: item.body)))
34+ }
35+ }
36+ }
37+
38+ var cellDataSourse: [PostCellData] = []
14
39
15 var type: HeaderType = .NONE
40 var type: HeaderType = .NONE
16
41
@@ -37,7 +62,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
37 {
62 {
38 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
63 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
39
64
40− cell.fill(with: dataSourse[indexPath.row].body, false, post: dataSourse[indexPath.row])
65+ cell.fill(with: cellDataSourse[indexPath.row].attributedData, false, post: dataSourse[indexPath.row])
41
66
42 switch type {
67 switch type {
43 case .NEWS:
68 case .NEWS:
GDproject/Controller/ News and channels/PostViewCell.swift+5−12
@@ -53,13 +53,8 @@ class PostViewCell: UITableViewCell
53 fatalError("init(coder:) has not been implemented")
53 fatalError("init(coder:) has not been implemented")
54 }
54 }
55
55
56− func createTextView(with text: String, _ isSelectable: Bool) -> UITextView
56+ func createTextView(with text: NSAttributedString, _ isSelectable: Bool) -> UITextView
57 {
57 {
58− let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
59− let markdown = text
60− markdownParser.enabledElements = .disabledAutomaticLink
61− markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
62−
63 let textView = UITextView()
58 let textView = UITextView()
64 textView.isScrollEnabled = false
59 textView.isScrollEnabled = false
65 textView.isEditable = false
60 textView.isEditable = false
@@ -69,24 +64,22 @@ class PostViewCell: UITableViewCell
69 } else {
64 } else {
70 textView.isUserInteractionEnabled = false
65 textView.isUserInteractionEnabled = false
71 }
66 }
67+
72− textView.attributedText = markdownParser.parse(markdown)
68+ textView.attributedText = text
73 return textView
69 return textView
74 }
70 }
75
71
76 var views: [UIView] = []
72 var views: [UIView] = []
77 var post: Model.Posts?
73 var post: Model.Posts?
78
74
79− func fill(with info: [Model.Attachments], _ isFullVersoin: Bool, post: Model.Posts)
75+ func fill(with info: NSAttributedString, _ isFullVersoin: Bool, post: Model.Posts)
80 {
76 {
81 self.post = post
77 self.post = post
82 // important
78 // important
83 contentView.subviews.forEach({ $0.removeFromSuperview() })
79 contentView.subviews.forEach({ $0.removeFromSuperview() })
84
80
85 views = []
81 views = []
86− for attachment in info
87− {
88− views.append(createTextView(with: attachment.markdown, isFullVersoin))
82+ views.append(createTextView(with: info, isFullVersoin))
89− }
90
83
91 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.lastName ?? "")", for: .normal)
84 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.lastName ?? "")", for: .normal)
92 nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
85 nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
GDproject/Simple model/Model.swift+1
@@ -135,6 +135,7 @@ class Model{
135 guard let newQueery = try? decoder.decode(QueryPosts.self, from: json) else { print("no")
135 guard let newQueery = try? decoder.decode(QueryPosts.self, from: json) else { print("no")
136 return }
136 return }
137
137
138+ idUser = newQueery.users
138 completion((newQueery.users, Channel(title: "# General", subtitle: "No subtitle", hashtags: ["ПИ"], people: ["No"], posts: newQueery.posts)))
139 completion((newQueery.users, Channel(title: "# General", subtitle: "No subtitle", hashtags: ["ПИ"], people: ["No"], posts: newQueery.posts)))
139 }
140 }
140 }
141 }