mirror of
https://github.com/dashared/GDproject.git
synced 2024-11-25 11:43:58 +03:00
closes: #9. decreased number of requests
This commit is contained in:
parent
658140bf7d
commit
1400778675
@ -94,7 +94,7 @@ class FullPostController: UITableViewController {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
|
||||
|
||||
|
||||
cell.fill(with: post!.body, true, post: post!)
|
||||
cell.fill(with: PostCellData.create(with: post!.body), true, post: post!)
|
||||
cell.selectionStyle = .none
|
||||
return cell
|
||||
}
|
||||
|
@ -7,10 +7,35 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MarkdownKit
|
||||
|
||||
struct PostCellData{
|
||||
var attributedData = NSAttributedString()
|
||||
|
||||
static func create(with attachments: [Model.Attachments]) -> NSAttributedString{
|
||||
var markdown = ""
|
||||
|
||||
attachments.forEach { (attachment) in markdown.append(attachment.markdown) }
|
||||
|
||||
let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
|
||||
markdownParser.enabledElements = .disabledAutomaticLink
|
||||
markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
|
||||
|
||||
return markdownParser.parse(markdown)
|
||||
}
|
||||
}
|
||||
|
||||
class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
|
||||
|
||||
var dataSourse: [Model.Posts] = []
|
||||
var dataSourse: [Model.Posts] = []{
|
||||
didSet{
|
||||
dataSourse.forEach { (item) in
|
||||
cellDataSourse.append(PostCellData(attributedData: PostCellData.create(with: item.body)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cellDataSourse: [PostCellData] = []
|
||||
|
||||
var type: HeaderType = .NONE
|
||||
|
||||
@ -37,7 +62,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
|
||||
{
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
|
||||
|
||||
cell.fill(with: dataSourse[indexPath.row].body, false, post: dataSourse[indexPath.row])
|
||||
cell.fill(with: cellDataSourse[indexPath.row].attributedData, false, post: dataSourse[indexPath.row])
|
||||
|
||||
switch type {
|
||||
case .NEWS:
|
||||
|
@ -53,13 +53,8 @@ class PostViewCell: UITableViewCell
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func createTextView(with text: String, _ isSelectable: Bool) -> UITextView
|
||||
func createTextView(with text: NSAttributedString, _ isSelectable: Bool) -> UITextView
|
||||
{
|
||||
let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
|
||||
let markdown = text
|
||||
markdownParser.enabledElements = .disabledAutomaticLink
|
||||
markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
|
||||
|
||||
let textView = UITextView()
|
||||
textView.isScrollEnabled = false
|
||||
textView.isEditable = false
|
||||
@ -69,24 +64,22 @@ class PostViewCell: UITableViewCell
|
||||
} else {
|
||||
textView.isUserInteractionEnabled = false
|
||||
}
|
||||
textView.attributedText = markdownParser.parse(markdown)
|
||||
|
||||
textView.attributedText = text
|
||||
return textView
|
||||
}
|
||||
|
||||
var views: [UIView] = []
|
||||
var post: Model.Posts?
|
||||
|
||||
func fill(with info: [Model.Attachments], _ isFullVersoin: Bool, post: Model.Posts)
|
||||
func fill(with info: NSAttributedString, _ isFullVersoin: Bool, post: Model.Posts)
|
||||
{
|
||||
self.post = post
|
||||
// important
|
||||
contentView.subviews.forEach({ $0.removeFromSuperview() })
|
||||
|
||||
views = []
|
||||
for attachment in info
|
||||
{
|
||||
views.append(createTextView(with: attachment.markdown, isFullVersoin))
|
||||
}
|
||||
views.append(createTextView(with: info, isFullVersoin))
|
||||
|
||||
nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.lastName ?? "")", for: .normal)
|
||||
nameLabel.addTarget(self, action: #selector(displayProfile), for: .touchUpInside)
|
||||
|
@ -135,6 +135,7 @@ class Model{
|
||||
guard let newQueery = try? decoder.decode(QueryPosts.self, from: json) else { print("no")
|
||||
return }
|
||||
|
||||
idUser = newQueery.users
|
||||
completion((newQueery.users, Channel(title: "# General", subtitle: "No subtitle", hashtags: ["ПИ"], people: ["No"], posts: newQueery.posts)))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user