git.iko.soy/dashared/GDproject
on master help sign in
Fixed a few bags. Added styling to a chat/gropu chat
commit0722718f1e9362210a2208d06133a67366b71abe authorDarya Rednikina <rednikina.com@yandex.ru> dateTue 7 May 2019, 23:16 (7 years ago) parent4acfa6e
9 files changed+165−60
GDproject/Controller/ News and channels/ChannelViewController.swift+2−1 GDproject/Controller/ News and channels/NewsVC.swift+1 GDproject/Controller/Coordinators/MessagesCoordinator.swift+13−3 GDproject/Controller/Messages/Dialog/DialogCell.swift+51−15 GDproject/Controller/Messages/Dialog/DialogViewController.swift+45−11 GDproject/Controller/Messages/MessagesViewController.swift+1−1 GDproject/Controller/Profile/ProfileViewController.swift+28−28 GDproject/Extentions.swift+17 GDproject/Simple model/Model.swift+7−1
GDproject/Controller/ News and channels/ChannelViewController.swift+2−1
@@ -72,7 +72,8 @@ class ChannelViewController: UITableViewController, UpdatableName, UpdatableChan
7272 // nou
7373 }
7474
75− @objc func showPreview(){
75+ @objc func showPreview()
76+ {
7677 if let channel = channel {
7778 onShowingPreview?(channel)
7879 }
GDproject/Controller/ News and channels/NewsVC.swift+1
@@ -42,6 +42,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
4242 }
4343
4444 (viewController as? NewsController)?.tableView.reloadData()
45+ (viewController as? ProfileViewController)?.tableView.reloadData()
4546 }
4647 }
4748
GDproject/Controller/Coordinators/MessagesCoordinator.swift+13−3
@@ -33,9 +33,19 @@ class MessagesCoordinator: BaseCoordinator {
3333
3434 let newVC = self.storyboard.instantiateViewController(withIdentifier: peopleToWriteVC) as! PeopleToWriteViewController
3535
36−// newVC.whatToDoWithSelection = {
37−//
38−// }
36+ newVC.whatToDoWithSelection = { [weak newVC, weak self] in
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+ })
48+ }
3949
4050 vc?.navigationController?.pushViewController(newVC, animated: true)
4151 }
GDproject/Controller/Messages/Dialog/DialogCell.swift+51−15
@@ -27,20 +27,15 @@ class DialogCell: UITableViewCell {
2727 onUserDisplay?(id)
2828 }
2929 }
30− var onUserDisplay: ((Int)->())?
3130
32− let fullNameLabel: UILabel = {
33− let label = UILabel()
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− }()
31+ var onUserDisplay: ((Int)->())?
32+
3933
4034 let timeLabel: UILabel = {
4135 let label = UILabel()
42− label.font = UIFont.systemFont(ofSize: 12)
43− label.textColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
36+ label.font = UIFont.systemFont(ofSize: 9)
37+ label.textAlignment = NSTextAlignment.right
38+ label.textColor = #colorLiteral(red: 0.4352941176, green: 0.4431372549, blue: 0.4745098039, alpha: 1)
4439 return label
4540 }()
4641
@@ -49,6 +44,7 @@ class DialogCell: UITableViewCell {
4944 let textView = UITextView()
5045 textView.isScrollEnabled = false
5146 textView.isEditable = false
47+ textView.sizeToFit()
5248
5349 if isSelectable {
5450 textView.isSelectable = true
@@ -76,18 +72,58 @@ class DialogCell: UITableViewCell {
7672 }
7773 }
7874
79− func fill(with markdownText: NSAttributedString, byUser: Model.Users)
75+ var textView: UITextView!
76+
77+ func fill(with markdownText: NSAttributedString, byUser: Model.Users, when: String)
8078 {
79+ let myId = DataStorage.standard.getUserId()
8180 // important
8281 contentView.subviews.forEach({ $0.removeFromSuperview() })
8382
8483 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
8687
87− self.contentView.addSubview(nameLabel)
8888 self.contentView.addSubview(textView)
89− nameLabel.edgesToSuperview(excluding: .bottom, insets: .top(8) + .left(8))
90− textView.edgesToSuperview(excluding: .top, insets: .right(8) + .left(8) + .bottom(8))
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+
107+ nameLabel.edgesToSuperview(excluding: .bottom, insets: .top(4) + .left(8))
108+ textView.edgesToSuperview(excluding: [.top, .right] , insets: .left(8) + .bottom(20))
91109 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)
92125 }
93126}
127+
128+
129+
GDproject/Controller/Messages/Dialog/DialogViewController.swift+45−11
@@ -8,6 +8,7 @@
88
99import UIKit
1010import TinyConstraints
11+import Marklight
1112
1213protocol UpdatableGroup:class {
1314 func updateGroup(with group: Model.Group)
@@ -46,7 +47,6 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
4647
4748 var cellData: [PostCellData] = [] {
4849 didSet {
49− print(cellData)
5050 tableView.reloadData()
5151 }
5252 }
@@ -63,10 +63,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
6363 tabBarController?.tabBar.isHidden = true
6464 navigationItem.largeTitleDisplayMode = .never
6565
66+ tableView.keyboardDismissMode = .onDrag
67+ tableView.separatorStyle = .none
6668 tableView.register(DialogCell.self, forCellReuseIdentifier: cellId)
6769 tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
6870 tableView.contentInsetAdjustmentBehavior = .never
69− tableView.contentOffset = CGPoint(x: 0, y: -30)
71+ tableView.contentOffset = CGPoint(x: 0, y: 30)
7072
7173 if let groupChat = groupChat {
7274 setTitleForGroup(groupChat: groupChat)
@@ -77,15 +79,33 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
7779
7880 var messageSendView: UIView = {
7981 let view = UIView()
80− view.backgroundColor = .red
82+ view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
8183 return view
8284 }()
8385
84− var messageTextView: UITextView = {
85− let textView = 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+
105+ let textView = UITextView(frame: CGRect.zero, textContainer: textContainer)
86106 textView.isEditable = true
87107 textView.isScrollEnabled = true
88− textView.backgroundColor = .green
108+ textView.backgroundColor = .white
89109 return textView
90110 }()
91111
@@ -101,7 +121,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
101121 {
102122 var destination: Model.MessageDestination?
103123
104− if let group = groupChat{
124+ if let group = groupChat {
105125 destination = Model.MessageDestination.groupChatDestination(group.group.id)
106126 } else if let user = userChat {
107127 destination = Model.MessageDestination.userChatDestination(user.user)
@@ -111,10 +131,17 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
111131 {
112132 Model.sendMessage(message: Model.SendMessage(body: Model.Attachments(markdown: messageTextView.text), destination: destination)) { [unowned self] in
113133 self.getMessages(for: self.dialog!)
134+ self.messageTextView.text = ""
114135 }
115136 }
116137 }
117138
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+
118145 var bottomConstraint: NSLayoutConstraint!
119146
120147 func setConstraints(){
@@ -123,17 +150,21 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
123150
124151 messageSendView.addSubview(messageTextView)
125152 messageSendView.addSubview(sendButton)
153+ messageSendView.addSubview(lineView)
126154
127155 messageSendView.edgesToSuperview(excluding: [.top,.bottom])
128156
129157 bottomConstraint = NSLayoutConstraint(item: messageSendView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
130158 view.addConstraint(bottomConstraint)
131159
132− messageSendView.height(40)
160+ messageSendView.height(60)
133161
134162 sendButton.edgesToSuperview(excluding: .left)
135163 sendButton.width(60)
136164
165+ lineView.edgesToSuperview(excluding: .bottom)
166+ lineView.height(0.5)
167+
137168 messageTextView.edgesToSuperview(excluding: .right)
138169 messageTextView.rightToLeft(of: sendButton)
139170
@@ -167,11 +198,11 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
167198 }
168199
169200 func setTitleForChat(userChat: Model.UserChat){
170− navigationItem.title = "🌌 \(users![userChat.user]!.fullName())"
201+ navigationItem.title = "👤 \(users![userChat.user]!.fullName())"
171202 }
172203
173204 func setTitleForGroup(groupChat: Model.GroupChat){
174− navigationItem.title = "🌌 \(groupChat.group.id) \(groupChat.group.name)"
205+ navigationItem.title = "\(groupChat.group.name)"
175206 navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Info", style: .plain, target: self, action: #selector(moveToInfoVC))
176207 }
177208
@@ -215,6 +246,7 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
215246 }
216247
217248 func getMessages(for dialog: Model.Dialog){
249+ print("Here")
218250 switch dialog {
219251 case .groupChat(let groupChat):
220252 Model.getMessagesFor(typeOfChat: Model.Dialog.groupChat(groupChat), chat: groupChat.group.id)
@@ -235,10 +267,12 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
235267
236268 //In cellForRowAtIndexPath
237269 cell.transform = CGAffineTransform(scaleX: 1, y: -1)
270+ cell.selectionStyle = .none
271+
238272
239273 if let author = currentMessagesInChat?[indexPath.row].author, let user = users?[author]
240274 {
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)!)
242276 }
243277
244278 return cell
GDproject/Controller/Messages/MessagesViewController.swift+1−1
@@ -70,7 +70,7 @@ class MessagesViewController: UITableViewController {
7070
7171 case .groupChat(let group):
7272 cell.textLabel?.text = group.group.name
73− cell.detailTextLabel?.text = group.lastMessage.body.markdown
73+ cell.detailTextLabel?.text = group.lastMessage!.body.markdown
7474 case .userChat(let userChat):
7575 cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())"
7676 cell.detailTextLabel?.text = userChat.lastMessage.body.markdown
GDproject/Controller/Profile/ProfileViewController.swift+28−28
@@ -38,7 +38,8 @@ class ProfileViewController: UIViewController
3838
3939 var protoDictionary: [Int: UIImage] = [9: #imageLiteral(resourceName: "9"), 5051: #imageLiteral(resourceName: "5051"), 69: #imageLiteral(resourceName: "69"), 42: #imageLiteral(resourceName: "42")]
4040
41− func fill(with user: Model.Users){
41+ func fill(with user: Model.Users)
42+ {
4243 self.facultyLabel.text = "Студент: Факультет Компьютерных Наук"
4344 self.nameLabel.text = "\(user.firstName) \(user.middleName)"
4445 self.surnameLabel.text = "\(user.lastName)"
@@ -54,36 +55,38 @@ class ProfileViewController: UIViewController
5455 var user: Model.Users? {
5556 didSet {
5657 self.fill(with: user!)
57− Model.getPostsForUser(with: user!.id) { [weak self] (posts) in
58− self?.dataSourse = posts
59− }
6058 navigationItem.title = "\(user!.firstName) \(user!.lastName)"
6159 }
6260 }
6361
64− var basicInfo = BasicInfoController()
65− var posts = NewsVC()
62+ var channel: Model.Channels? {
63+ didSet {
64+ self.update()
65+ }
66+ }
6667
67− var dataSourse: [Model.Posts]?{
68− didSet{
69−
70− var newPosts: [Model.Posts] = []
71−
72− dataSourse?.forEach({ (post) in
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()
68+ func update()
69+ {
70+ Model.getAnonymousChannel(by: channel!) { [unowned self] in
71+ self.posts.dataSourse = $0.posts
72+ self.posts.dictionary = $0.users
73+ self.user = $0.users[self.idProfile!]
7874 }
7975 }
8076
77+ var basicInfo = BasicInfoController()
78+ var posts = NewsVC()
79+
8180 override func viewDidLoad()
8281 {
8382 super.viewDidLoad()
84− print("hell")
83+ if idProfile == nil {
84+ idProfile = DataStorage.standard.getUserId()
85+ }
86+
8587 posts.viewController = self
8688 posts.type = .NONE
89+ posts.currChannel = channel
8790
8891 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
8992
@@ -100,23 +103,20 @@ class ProfileViewController: UIViewController
100103 tableView.reloadData()
101104 }
102105
103− var idProfile: Int?
106+ var idProfile: Int? {
107+ didSet {
108+ channel = Model.Channels(people: [idProfile!], name: "", id: 0, tags: [])
109+ }
110+ }
104111
105112 override func viewWillAppear(_ animated: Bool) {
106113
107114 if idProfile == nil {
108115 idProfile = DataStorage.standard.getUserId()
109116 }
117+ user = Model.Channels.fullPeopleDict[idProfile!]
110118
111− if let id = idProfile {
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− }
119+ update()
120120
121121 setUpNavigarionBar()
122122 }
GDproject/Extentions.swift+17
@@ -60,3 +60,20 @@ extension UIStoryboard {
6060 return UIStoryboard.userEdit.instantiateViewController(withIdentifier: logInController) as! LogInViewController
6161 }
6262}
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{
611611
612612 struct GroupChat: Codable {
613613 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+ }
615621 }
616622
617623 struct UserChat: Codable {