git.iko.soy/dashared/GDproject
on master help sign in
Fixed a few bags. Added styling to a chat/gropu chat
0722718Darya Rednikina
GDproject/Controller/ News and channels/ChannelViewController.swift+2−1
@@ -72,7 +72,8 @@ class ChannelViewController: UITableViewController, UpdatableName, UpdatableChan
72 // nou
72 // nou
73 }
73 }
74
74
75− @objc func showPreview(){
75+ @objc func showPreview()
76+ {
76 if let channel = channel {
77 if let channel = channel {
77 onShowingPreview?(channel)
78 onShowingPreview?(channel)
78 }
79 }
GDproject/Controller/ News and channels/NewsVC.swift+1
@@ -42,6 +42,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
42 }
42 }
43
43
44 (viewController as? NewsController)?.tableView.reloadData()
44 (viewController as? NewsController)?.tableView.reloadData()
45+ (viewController as? ProfileViewController)?.tableView.reloadData()
45 }
46 }
46 }
47 }
47
48
GDproject/Controller/Coordinators/MessagesCoordinator.swift+13−3
@@ -33,9 +33,19 @@ class MessagesCoordinator: BaseCoordinator {
33
33
34 let newVC = self.storyboard.instantiateViewController(withIdentifier: peopleToWriteVC) as! PeopleToWriteViewController
34 let newVC = self.storyboard.instantiateViewController(withIdentifier: peopleToWriteVC) as! PeopleToWriteViewController
35
35
36−// newVC.whatToDoWithSelection = {
36+ newVC.whatToDoWithSelection = { [weak newVC, weak self] in
37−//
37+ newVC?.navigationController?.popViewController(animated: true)
38+
39+ var group = Model.Group(users: $0, name: "Untitled", id: 0)
40+ Model.createGroupChat(from: group, completion:
41+ { [weak self] id in
42+
43+ let newVC1 = DialogViewController()
44+ group.id = id
45+ newVC1.dialog = Model.Dialog.groupChat(Model.GroupChat(group: group))
46+ self?.navigationController?.pushViewController(newVC1, animated: true)
47+ })
38−// }
48+ }
39
49
40 vc?.navigationController?.pushViewController(newVC, animated: true)
50 vc?.navigationController?.pushViewController(newVC, animated: true)
41 }
51 }
GDproject/Controller/Messages/Dialog/DialogCell.swift+51−15
@@ -27,20 +27,15 @@ class DialogCell: UITableViewCell {
27 onUserDisplay?(id)
27 onUserDisplay?(id)
28 }
28 }
29 }
29 }
30− var onUserDisplay: ((Int)->())?
31
30
32− let fullNameLabel: UILabel = {
31+ var onUserDisplay: ((Int)->())?
33− let label = UILabel()
32+
34− label.textColor = #colorLiteral(red: 0.3333333433, green: 0.3333333433, blue: 0.3333333433, alpha: 1)
35− label.text = "Богомазова Вероника Львовна"
36− label.font = UIFont.systemFont(ofSize: 12)
37− return label
38− }()
39
33
40 let timeLabel: UILabel = {
34 let timeLabel: UILabel = {
41 let label = UILabel()
35 let label = UILabel()
42− label.font = UIFont.systemFont(ofSize: 12)
36+ label.font = UIFont.systemFont(ofSize: 9)
37+ label.textAlignment = NSTextAlignment.right
43− label.textColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
38+ label.textColor = #colorLiteral(red: 0.4352941176, green: 0.4431372549, blue: 0.4745098039, alpha: 1)
44 return label
39 return label
45 }()
40 }()
46
41
@@ -49,6 +44,7 @@ class DialogCell: UITableViewCell {
49 let textView = UITextView()
44 let textView = UITextView()
50 textView.isScrollEnabled = false
45 textView.isScrollEnabled = false
51 textView.isEditable = false
46 textView.isEditable = false
47+ textView.sizeToFit()
52
48
53 if isSelectable {
49 if isSelectable {
54 textView.isSelectable = true
50 textView.isSelectable = true
@@ -76,18 +72,58 @@ class DialogCell: UITableViewCell {
76 }
72 }
77 }
73 }
78
74
75+ var textView: UITextView!
76+
79− func fill(with markdownText: NSAttributedString, byUser: Model.Users)
77+ func fill(with markdownText: NSAttributedString, byUser: Model.Users, when: String)
80 {
78 {
79+ let myId = DataStorage.standard.getUserId()
81 // important
80 // important
82 contentView.subviews.forEach({ $0.removeFromSuperview() })
81 contentView.subviews.forEach({ $0.removeFromSuperview() })
83
82
84 self.user = byUser
83 self.user = byUser
85− let textView = createTextView(with: markdownText, true)
84+ textView = createTextView(with: markdownText, true)
85+ textView.layer.cornerRadius = 10
86+ textView.clipsToBounds = true
86
87
87− self.contentView.addSubview(nameLabel)
88 self.contentView.addSubview(textView)
88 self.contentView.addSubview(textView)
89+ self.contentView.addSubview(timeLabel)
90+
91+ timeLabel.text = when.getDate()
92+ textView.width(min: 50, max: self.contentView.bounds.width-70, priority: .required, isActive: true)
93+
94+ if myId == byUser.id
95+ {
96+ layoutMyMessage()
97+ } else {
98+ layOutOtherMessage()
99+ }
100+ }
101+
102+ func layOutOtherMessage(){
103+ self.contentView.addSubview(nameLabel)
104+
105+ nameLabel.setTitle(user!.fullName(), for: .normal)
106+
89− nameLabel.edgesToSuperview(excluding: .bottom, insets: .top(8) + .left(8))
107+ nameLabel.edgesToSuperview(excluding: .bottom, insets: .top(4) + .left(8))
90− textView.edgesToSuperview(excluding: .top, insets: .right(8) + .left(8) + .bottom(8))
108+ textView.edgesToSuperview(excluding: [.top, .right] , insets: .left(8) + .bottom(20))
91 textView.topToBottom(of: nameLabel)
109 textView.topToBottom(of: nameLabel)
110+
111+ textView.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
112+ textView.textColor = .white
113+ timeLabel.edgesToSuperview(excluding: .top, insets: .right(70) + .left(4))
114+ timeLabel.topToBottom(of: textView, offset: 4)
115+ timeLabel.textAlignment = .left
116+ }
117+
118+ func layoutMyMessage()
119+ {
120+ textView.edgesToSuperview(excluding: .left, insets: .right(8) + .bottom(20) + .top(4))
121+ textView.backgroundColor = UIColor(red:0.08, green:0.49, blue:0.98, alpha:1.0)
122+ textView.textColor = .white
123+ timeLabel.edgesToSuperview(excluding: .top, insets: .left(70) + .right(4))
124+ timeLabel.topToBottom(of: textView, offset: 4)
92 }
125 }
93}
126}
127+
128+
129+
GDproject/Controller/Messages/Dialog/DialogViewController.swift+45−11
@@ -8,6 +8,7 @@
8
8
9import UIKit
9import UIKit
10import TinyConstraints
10import TinyConstraints
11+import Marklight
11
12
12protocol UpdatableGroup:class {
13protocol UpdatableGroup:class {
13 func updateGroup(with group: Model.Group)
14 func updateGroup(with group: Model.Group)
@@ -46,7 +47,6 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
46
47
47 var cellData: [PostCellData] = [] {
48 var cellData: [PostCellData] = [] {
48 didSet {
49 didSet {
49− print(cellData)
50 tableView.reloadData()
50 tableView.reloadData()
51 }
51 }
52 }
52 }
@@ -63,10 +63,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
63 tabBarController?.tabBar.isHidden = true
63 tabBarController?.tabBar.isHidden = true
64 navigationItem.largeTitleDisplayMode = .never
64 navigationItem.largeTitleDisplayMode = .never
65
65
66+ tableView.keyboardDismissMode = .onDrag
67+ tableView.separatorStyle = .none
66 tableView.register(DialogCell.self, forCellReuseIdentifier: cellId)
68 tableView.register(DialogCell.self, forCellReuseIdentifier: cellId)
67 tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
69 tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
68 tableView.contentInsetAdjustmentBehavior = .never
70 tableView.contentInsetAdjustmentBehavior = .never
69− tableView.contentOffset = CGPoint(x: 0, y: -30)
71+ tableView.contentOffset = CGPoint(x: 0, y: 30)
70
72
71 if let groupChat = groupChat {
73 if let groupChat = groupChat {
72 setTitleForGroup(groupChat: groupChat)
74 setTitleForGroup(groupChat: groupChat)
@@ -77,15 +79,33 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
77
79
78 var messageSendView: UIView = {
80 var messageSendView: UIView = {
79 let view = UIView()
81 let view = UIView()
80− view.backgroundColor = .red
82+ view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
81 return view
83 return view
82 }()
84 }()
83
85
84− var messageTextView: UITextView = {
86+ var messageTextView: UITextView =
87+ {
88+ let textStorage = MarklightTextStorage()
89+ textStorage.marklightTextProcessor.codeColor = UIColor.orange
90+ textStorage.marklightTextProcessor.quoteColor = UIColor.darkGray
91+ textStorage.marklightTextProcessor.syntaxColor = UIColor.blue
92+ textStorage.marklightTextProcessor.codeFontName = "Courier"
93+ textStorage.marklightTextProcessor.fontTextStyle = UIFont.TextStyle.subheadline.rawValue
94+ textStorage.marklightTextProcessor.hideSyntax = false
95+
96+ let layoutManager = NSLayoutManager()
97+
98+ // Assign the `UITextView`'s `NSLayoutManager` to the `NSTextStorage` subclass
99+ //textStorage.addLayoutManager(textView.layoutManager)
100+ textStorage.addLayoutManager(layoutManager)
101+
102+ let textContainer = NSTextContainer()
103+ layoutManager.addTextContainer(textContainer)
104+
85− let textView = UITextView()
105+ let textView = UITextView(frame: CGRect.zero, textContainer: textContainer)
86 textView.isEditable = true
106 textView.isEditable = true
87 textView.isScrollEnabled = true
107 textView.isScrollEnabled = true
88− textView.backgroundColor = .green
108+ textView.backgroundColor = .white
89 return textView
109 return textView
90 }()
110 }()
91
111
@@ -101,7 +121,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
101 {
121 {
102 var destination: Model.MessageDestination?
122 var destination: Model.MessageDestination?
103
123
104− if let group = groupChat{
124+ if let group = groupChat {
105 destination = Model.MessageDestination.groupChatDestination(group.group.id)
125 destination = Model.MessageDestination.groupChatDestination(group.group.id)
106 } else if let user = userChat {
126 } else if let user = userChat {
107 destination = Model.MessageDestination.userChatDestination(user.user)
127 destination = Model.MessageDestination.userChatDestination(user.user)
@@ -111,10 +131,17 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
111 {
131 {
112 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
132 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
113 self.getMessages(for: self.dialog!)
133 self.getMessages(for: self.dialog!)
134+ self.messageTextView.text = ""
114 }
135 }
115 }
136 }
116 }
137 }
117
138
139+ var lineView: UIView = {
140+ let view = UIView()
141+ view.backgroundColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
142+ return view
143+ }()
144+
118 var bottomConstraint: NSLayoutConstraint!
145 var bottomConstraint: NSLayoutConstraint!
119
146
120 func setConstraints(){
147 func setConstraints(){
@@ -123,17 +150,21 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
123
150
124 messageSendView.addSubview(messageTextView)
151 messageSendView.addSubview(messageTextView)
125 messageSendView.addSubview(sendButton)
152 messageSendView.addSubview(sendButton)
153+ messageSendView.addSubview(lineView)
126
154
127 messageSendView.edgesToSuperview(excluding: [.top,.bottom])
155 messageSendView.edgesToSuperview(excluding: [.top,.bottom])
128
156
129 bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
157 bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
130 view.addConstraint(bottomConstraint)
158 view.addConstraint(bottomConstraint)
131
159
132− messageSendView.height(40)
160+ messageSendView.height(60)
133
161
134 sendButton.edgesToSuperview(excluding: .left)
162 sendButton.edgesToSuperview(excluding: .left)
135 sendButton.width(60)
163 sendButton.width(60)
136
164
165+ lineView.edgesToSuperview(excluding: .bottom)
166+ lineView.height(0.5)
167+
137 messageTextView.edgesToSuperview(excluding: .right)
168 messageTextView.edgesToSuperview(excluding: .right)
138 messageTextView.rightToLeft(of: sendButton)
169 messageTextView.rightToLeft(of: sendButton)
139
170
@@ -167,11 +198,11 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
167 }
198 }
168
199
169 func setTitleForChat(userChat: Model.UserChat){
200 func setTitleForChat(userChat: Model.UserChat){
170− navigationItem.title = "🌌 \(users![userChat.user]!.fullName())"
201+ navigationItem.title = "👤 \(users![userChat.user]!.fullName())"
171 }
202 }
172
203
173 func setTitleForGroup(groupChat: Model.GroupChat){
204 func setTitleForGroup(groupChat: Model.GroupChat){
174− navigationItem.title = "🌌 \(groupChat.group.id) \(groupChat.group.name)"
205+ navigationItem.title = "\(groupChat.group.name)"
175 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
206 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
176 }
207 }
177
208
@@ -215,6 +246,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
215 }
246 }
216
247
217 func getMessages(for dialog: Model.Dialog){
248 func getMessages(for dialog: Model.Dialog){
249+ print("Here")
218 switch dialog {
250 switch dialog {
219 case .groupChat(let groupChat):
251 case .groupChat(let groupChat):
220 Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
252 Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
@@ -235,10 +267,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
235
267
236 //In cellForRowAtIndexPath
268 //In cellForRowAtIndexPath
237 cell.transform = CGAffineTransform(scaleX: 1, y: -1)
269 cell.transform = CGAffineTransform(scaleX: 1, y: -1)
270+ cell.selectionStyle = .none
271+
238
272
239 if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
273 if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
240 {
274 {
241− cell.fill(with: cellData[indexPath.row].attributedData, byUser: user)
275+ cell.fill(with: cellData[indexPath.row].attributedData, byUser: user, when: (currentMessagesInChat?[indexPath.row].time)!)
242 }
276 }
243
277
244 return cell
278 return cell
GDproject/Controller/Messages/MessagesViewController.swift+1−1
@@ -70,7 +70,7 @@ class MessagesViewController: UITableViewController {
70
70
71 case .groupChat(let group):
71 case .groupChat(let group):
72 cell.textLabel?.text = group.group.name
72 cell.textLabel?.text = group.group.name
73− cell.detailTextLabel?.text = group.lastMessage.body.markdown
73+ cell.detailTextLabel?.text = group.lastMessage!.body.markdown
74 case .userChat(let userChat):
74 case .userChat(let userChat):
75 cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())"
75 cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())"
76 cell.detailTextLabel?.text = userChat.lastMessage.body.markdown
76 cell.detailTextLabel?.text = userChat.lastMessage.body.markdown
GDproject/Controller/Profile/ProfileViewController.swift+28−28
@@ -38,7 +38,8 @@ class ProfileViewController: UIViewController
38
38
39 var protoDictionary: [Int: UIImage] = [9: #imageLiteral(resourceName: "9"), 5051: #imageLiteral(resourceName: "5051"), 69: #imageLiteral(resourceName: "69"), 42: #imageLiteral(resourceName: "42")]
39 var protoDictionary: [Int: UIImage] = [9: #imageLiteral(resourceName: "9"), 5051: #imageLiteral(resourceName: "5051"), 69: #imageLiteral(resourceName: "69"), 42: #imageLiteral(resourceName: "42")]
40
40
41− func fill(with user: Model.Users){
41+ func fill(with user: Model.Users)
42+ {
42 self.facultyLabel.text = "Студент: Факультет Компьютерных Наук"
43 self.facultyLabel.text = "Студент: Факультет Компьютерных Наук"
43 self.nameLabel.text = "\(user.firstName) \(user.middleName)"
44 self.nameLabel.text = "\(user.firstName) \(user.middleName)"
44 self.surnameLabel.text = "\(user.lastName)"
45 self.surnameLabel.text = "\(user.lastName)"
@@ -54,36 +55,38 @@ class ProfileViewController: UIViewController
54 var user: Model.Users? {
55 var user: Model.Users? {
55 didSet {
56 didSet {
56 self.fill(with: user!)
57 self.fill(with: user!)
57− Model.getPostsForUser(with: user!.id) { [weak self] (posts) in
58− self?.dataSourse = posts
59− }
60 navigationItem.title = "\(user!.firstName) \(user!.lastName)"
58 navigationItem.title = "\(user!.firstName) \(user!.lastName)"
61 }
59 }
62 }
60 }
63
61
64− var basicInfo = BasicInfoController()
62+ var channel: Model.Channels? {
65− var posts = NewsVC()
63+ didSet {
64+ self.update()
65+ }
66+ }
66
67
67− var dataSourse: [Model.Posts]?{
68+ func update()
68− didSet{
69+ {
69−
70+ Model.getAnonymousChannel(by: channel!) { [unowned self] in
70− var newPosts: [Model.Posts] = []
71+ self.posts.dataSourse = $0.posts
71−
72+ self.posts.dictionary = $0.users
72− dataSourse?.forEach({ (post) in
73+ self.user = $0.users[self.idProfile!]
73− newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: user!, date: post.updated, tags: post.tags))
74− })
75−
76− self.posts.dataSourse = newPosts
77− tableView.reloadData()
78 }
74 }
79 }
75 }
80
76
77+ var basicInfo = BasicInfoController()
78+ var posts = NewsVC()
79+
81 override func viewDidLoad()
80 override func viewDidLoad()
82 {
81 {
83 super.viewDidLoad()
82 super.viewDidLoad()
84− print("hell")
83+ if idProfile == nil {
84+ idProfile = DataStorage.standard.getUserId()
85+ }
86+
85 posts.viewController = self
87 posts.viewController = self
86 posts.type = .NONE
88 posts.type = .NONE
89+ posts.currChannel = channel
87
90
88 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
91 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
89
92
@@ -100,23 +103,20 @@ class ProfileViewController: UIViewController
100 tableView.reloadData()
103 tableView.reloadData()
101 }
104 }
102
105
103− var idProfile: Int?
106+ var idProfile: Int? {
107+ didSet {
108+ channel = Model.Channels(people: [idProfile!], name: "", id: 0, tags: [])
109+ }
110+ }
104
111
105 override func viewWillAppear(_ animated: Bool) {
112 override func viewWillAppear(_ animated: Bool) {
106
113
107 if idProfile == nil {
114 if idProfile == nil {
108 idProfile = DataStorage.standard.getUserId()
115 idProfile = DataStorage.standard.getUserId()
109 }
116 }
117+ user = Model.Channels.fullPeopleDict[idProfile!]
110
118
111− if let id = idProfile {
119+ update()
112− if let user = Model.idUser[id] {
113− self.user = user
114− } else {
115− Model.getUsers(for: [id]) { [weak self] (dic) in
116− self?.user = dic[id]
117− }
118− }
119− }
120
120
121 setUpNavigarionBar()
121 setUpNavigarionBar()
122 }
122 }
GDproject/Extentions.swift+17
@@ -60,3 +60,20 @@ extension UIStoryboard {
60 return UIStoryboard.userEdit.instantiateViewController(withIdentifier: logInController) as! LogInViewController
60 return UIStoryboard.userEdit.instantiateViewController(withIdentifier: logInController) as! LogInViewController
61 }
61 }
62}
62}
63+
64+
65+extension String {
66+ func getDate() -> String
67+ {
68+ let dateFormatter = DateFormatter()
69+ dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format
70+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
71+ let date = dateFormatter.date(from: self)
72+
73+ dateFormatter.dateFormat = "MMM d, yyyy HH:mm" ///this is what you want to convert format
74+ dateFormatter.timeZone = NSTimeZone.local
75+ let timeStamp = dateFormatter.string(from: date!)
76+
77+ return timeStamp
78+ }
79+}
GDproject/Simple model/Model.swift+7−1
@@ -611,7 +611,13 @@ class Model{
611
611
612 struct GroupChat: Codable {
612 struct GroupChat: Codable {
613 var group: Group
613 var group: Group
614− var lastMessage: LastMessage
614+ var lastMessage: LastMessage?
615+
616+
617+ init(group: Group, lastMessage: LastMessage? = nil) {
618+ self.group = group
619+ self.lastMessage = lastMessage
620+ }
615 }
621 }
616
622
617 struct UserChat: Codable {
623 struct UserChat: Codable {