git.iko.soy/dashared/GDproject
on master help sign in
resolved issues with header height. improved user experience. minor changes in posts and profile
b504119Darya Rednikina
GDproject/Controller/ News and channels/ChannelListController.swift+1−1
@@ -60,7 +60,7 @@ class ChannelListController: UITableViewController, DataDelegate {
60 }
60 }
61
61
62 func setUpNavigationBar(){
62 func setUpNavigationBar(){
63− navigationController?.navigationItem.largeTitleDisplayMode = .always
63+ navigationItem.largeTitleDisplayMode = .always
64 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
64 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
65 }
65 }
66
66
GDproject/Controller/ News and channels/FullPostController.swift+2−1
@@ -23,7 +23,7 @@ class FullPostController: UITableViewController {
23 }
23 }
24
24
25 func setUpNavigationBar(){
25 func setUpNavigationBar(){
26− navigationController?.navigationBar.prefersLargeTitles = false
26+ navigationItem.largeTitleDisplayMode = .never
27 navigationItem.title = "\(post?.authorId ?? 0)"
27 navigationItem.title = "\(post?.authorId ?? 0)"
28 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.options))]
28 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.options))]
29 }
29 }
@@ -93,6 +93,7 @@ class FullPostController: UITableViewController {
93
93
94 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
94 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
95
95
96+
96 cell.fill(with: post!.body, true, post: post!)
97 cell.fill(with: post!.body, true, post: post!)
97 cell.selectionStyle = .none
98 cell.selectionStyle = .none
98 return cell
99 return cell
GDproject/Controller/ News and channels/NewsController.swift+1−1
@@ -83,7 +83,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
83 setUpSearchContr()
83 setUpSearchContr()
84
84
85 news.viewController = self
85 news.viewController = self
86− news.type = .NONE
86+ news.type = .NEWS
87
87
88 setUpNavigationItemsforPosts()
88 setUpNavigationItemsforPosts()
89
89
GDproject/Controller/ News and channels/NewsVC.swift+11−4
@@ -39,10 +39,17 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
39
39
40 cell.fill(with: dataSourse[indexPath.row].body, false, post: dataSourse[indexPath.row])
40 cell.fill(with: dataSourse[indexPath.row].body, false, post: dataSourse[indexPath.row])
41
41
42+ switch type {
43+ case .NEWS:
42− cell.onUserDisplay = { [weak self] (id) in
44+ cell.onUserDisplay = { [weak self] (id) in
43− let vc = self?.viewController!.storyboard!.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
45+ let vc = self?.viewController!.storyboard!.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
44− vc.idProfile = id
46+ vc.idProfile = id
45− self?.viewController!.navigationController!.pushViewController(vc, animated: true)
47+ self?.viewController!.navigationController!.pushViewController(vc, animated: true)
48+ }
49+ case .NONE:
50+ cell.onUserDisplay = { (id) in
51+ print("tapped when profile is open already \(id)")
52+ }
46 }
53 }
47
54
48 cell.selectionStyle = .none
55 cell.selectionStyle = .none
GDproject/Controller/ News and channels/PostViewCell.swift+9−6
@@ -53,19 +53,22 @@ 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) -> UITextView
56+ func createTextView(with text: String, _ isSelectable: Bool) -> UITextView
57 {
57 {
58 let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
58 let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
59 let markdown = text
59 let markdown = text
60 markdownParser.enabledElements = .disabledAutomaticLink
60 markdownParser.enabledElements = .disabledAutomaticLink
61− markdownParser.header.fontIncrease = 16
62 markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
61 markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
63
62
64 let textView = UITextView()
63 let textView = UITextView()
65 textView.isScrollEnabled = false
64 textView.isScrollEnabled = false
66 textView.isEditable = false
65 textView.isEditable = false
66+ if isSelectable {
67− //textView.isUserInteractionEnabled = false
67+ //textView.isUserInteractionEnabled = false
68− textView.isSelectable = true
68+ textView.isSelectable = true
69+ } else {
70+ textView.isUserInteractionEnabled = false
71+ }
69 textView.attributedText = markdownParser.parse(markdown)
72 textView.attributedText = markdownParser.parse(markdown)
70 return textView
73 return textView
71 }
74 }
@@ -82,7 +85,7 @@ class PostViewCell: UITableViewCell
82 views = []
85 views = []
83 for attachment in info
86 for attachment in info
84 {
87 {
85− views.append(createTextView(with: attachment.markdown))
88+ views.append(createTextView(with: attachment.markdown, isFullVersoin))
86 }
89 }
87
90
88 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.secondName ?? "")", for: .normal)
91 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.secondName ?? "")", for: .normal)
@@ -91,7 +94,7 @@ class PostViewCell: UITableViewCell
91 setUpInStackView(isFullVersoin)
94 setUpInStackView(isFullVersoin)
92 }
95 }
93
96
94− let hashtags = ["Kek", "Lol"]
97+ let hashtags = ["Программная инженерия", "ПИ", "НИУ ВШЭ", "Наука"]
95 func setUpInStackView(_ full : Bool){
98 func setUpInStackView(_ full : Bool){
96 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
99 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
97 nameStackView.axis = .vertical
100 nameStackView.axis = .vertical
GDproject/Controller/Coordinator tab bar?/TabbarCoordinator.swift+3−14
@@ -2,24 +2,13 @@ import UIKit
2
2
3class TabbarCoordinator{
3class TabbarCoordinator{
4 var window: UIWindow!
4 var window: UIWindow!
5− static let tabBar: UITabBarController = UIStoryboard.tabBarController()
5+
6−
7− // MARK: - Properties
8− //private var user: Model.Users { didSet { updateInterfaces() } }
9−
10 func start(){
6 func start(){
7+ let tabbar = UIStoryboard.tabBarController()
11− window.rootViewController = TabbarCoordinator.tabBar
8+ window.rootViewController = tabbar
12− TabbarCoordinator.tabBar.selectedIndex = 0
13 }
9 }
14
10
15 init(window: UIWindow) {
11 init(window: UIWindow) {
16 self.window = window
12 self.window = window
17 }
13 }
18−
19−// // MARK:- update only viewControllers which are depandable on chosen channel
20−// private func updateInterfaces() {
21−// TabbarCoordinator.tabBar.viewControllers?.forEach({
22−// ($0 as? UpdateableWithUser)?.user = user
23−// })
24−// }
25}
14}
GDproject/Controller/Log In/LogInCoordinator.swift+9−6
@@ -23,18 +23,21 @@ class LogInCoordinator{
23 }
23 }
24
24
25 // MARK: - Private implementation
25 // MARK: - Private implementation
26− private func showStatusPage(){
26+// private func showStatusPage(){
27− let controller = TabbarCoordinator(window: window)
27+// let controller = TabbarCoordinator(window: window)
28− controller.start()
28+// controller.start()
29− }
29+// }
30
30
31 private func showLogInPage(){
31 private func showLogInPage(){
32 let controller = UIStoryboard.makeLogIn()
32 let controller = UIStoryboard.makeLogIn()
33+
33 controller.onLogIn = {
34 controller.onLogIn = {
34− (id) in
35− Model.authenticate(with: id) {
35+ (id) in Model.authenticate(with: id) {
36 (res) in
36 (res) in
37+
37 if (res) { DataStorage.standard.setUserKey(with: id) }
38 if (res) { DataStorage.standard.setUserKey(with: id) }
39+ else { DataStorage.standard.setUserKey(with: 0) }
40+
38 controller.authenticateSucceeded = res
41 controller.authenticateSucceeded = res
39 }
42 }
40 }
43 }
GDproject/Controller/Log In/LogInViewController.swift+4−4
@@ -53,14 +53,10 @@ class LogInViewController: UIViewController {
53
53
54 override func viewWillAppear(_ animated: Bool) {
54 override func viewWillAppear(_ animated: Bool) {
55 super.viewWillAppear(animated)
55 super.viewWillAppear(animated)
56− // MARK:- uncomment when mail registration will be availiable
57− //self.navigationController?.setNavigationBarHidden(true, animated: animated)
58 }
56 }
59
57
60 override func viewWillDisappear(_ animated: Bool) {
58 override func viewWillDisappear(_ animated: Bool) {
61 super.viewWillDisappear(animated)
59 super.viewWillDisappear(animated)
62− // MARK:- uncomment when mail registration will be availiable
63− //self.navigationController?.setNavigationBarHidden(false, animated: animated)
64 }
60 }
65
61
66 private func configureTapgesture(){
62 private func configureTapgesture(){
@@ -97,6 +93,10 @@ class LogInViewController: UIViewController {
97
93
98 setUpBarComponents()
94 setUpBarComponents()
99
95
96+ configureKeyboardBehavior()
97+ }
98+
99+ func configureKeyboardBehavior(){
100 bottomConstraint = NSLayoutConstraint(item: keyboardBar, attribute: .bottom, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0)
100 bottomConstraint = NSLayoutConstraint(item: keyboardBar, attribute: .bottom, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0)
101 view.addConstraint(bottomConstraint!)
101 view.addConstraint(bottomConstraint!)
102
102
GDproject/Controller/Profile/ProfileViewController.swift+9−2
@@ -51,7 +51,14 @@ class ProfileViewController: UIViewController
51
51
52 var dataSourse: [Model.Posts]?{
52 var dataSourse: [Model.Posts]?{
53 didSet{
53 didSet{
54+
55+ var newPosts: [Model.Posts] = []
56+
57+ dataSourse?.forEach({ (post) in
58+ newPosts.append(Model.Posts(body: post.body, authorId: post.authorId, id: post.id, user: user!))
59+ })
60+
54− self.posts.dataSourse = dataSourse!
61+ self.posts.dataSourse = newPosts
55 tableView.reloadData()
62 tableView.reloadData()
56 }
63 }
57 }
64 }
@@ -136,7 +143,7 @@ class ProfileViewController: UIViewController
136 let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
143 let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
137 {
144 {
138 (_) in
145 (_) in
139− DataStorage.standard.setIsLoggedIn(value: false)
146+ DataStorage.standard.setIsLoggedIn(value: false, with: 0)
140 }
147 }
141
148
142 optionMenu.addAction(editAction)
149 optionMenu.addAction(editAction)
GDproject/DataStorage.swift+5−3
@@ -23,8 +23,9 @@ class DataStorage{
23 /**
23 /**
24 Function for setting log in status of user
24 Function for setting log in status of user
25 */
25 */
26− func setIsLoggedIn(value: Bool){
26+ func setIsLoggedIn(value: Bool, with id: Int){
27 UserDefaults.standard.set(value, forKey: UserDefaultsKeys.loggedIn.rawValue)
27 UserDefaults.standard.set(value, forKey: UserDefaultsKeys.loggedIn.rawValue)
28+ setUserKey(with: id)
28 isLoggedIn = UserDefaults.standard.bool(forKey: UserDefaultsKeys.loggedIn.rawValue)
29 isLoggedIn = UserDefaults.standard.bool(forKey: UserDefaultsKeys.loggedIn.rawValue)
29 }
30 }
30
31
@@ -32,15 +33,16 @@ class DataStorage{
32 UserDefaults.standard.set(id, forKey: UserDefaultsKeys.id.rawValue)
33 UserDefaults.standard.set(id, forKey: UserDefaultsKeys.id.rawValue)
33 }
34 }
34
35
35− func getUserId() -> Int?{
36+ func getUserId() -> Int {
36 return UserDefaults.standard.integer(forKey: UserDefaultsKeys.id.rawValue)
37 return UserDefaults.standard.integer(forKey: UserDefaultsKeys.id.rawValue)
37 }
38 }
39+
38 /**
40 /**
39 Function to determine is user logged in already or not
41 Function to determine is user logged in already or not
40 */
42 */
41 var isLoggedIn: Bool = UserDefaults.standard.bool(forKey: UserDefaultsKeys.loggedIn.rawValue) {
43 var isLoggedIn: Bool = UserDefaults.standard.bool(forKey: UserDefaultsKeys.loggedIn.rawValue) {
42 didSet{
44 didSet{
43− if isLoggedIn {
45+ if isLoggedIn && getUserId() != 0 {
44 (UIApplication.shared.delegate as? AppDelegate)?.tabCoordinator.start()
46 (UIApplication.shared.delegate as? AppDelegate)?.tabCoordinator.start()
45 } else {
47 } else {
46 (UIApplication.shared.delegate as? AppDelegate)?.logInAgain()
48 (UIApplication.shared.delegate as? AppDelegate)?.logInAgain()
GDproject/Simple model/Model.swift+2−2
@@ -85,14 +85,14 @@ class Model{
85
85
86 HTTPCookieStorage.shared.setCookie(cookies[0])
86 HTTPCookieStorage.shared.setCookie(cookies[0])
87
87
88− DataStorage.standard.setIsLoggedIn(value: true)
88+ DataStorage.standard.setIsLoggedIn(value: true, with: id)
89 completion(true)
89 completion(true)
90 }
90 }
91 }
91 }
92
92
93
93
94 static func getLast(completion: @escaping ((Channel)->())){
94 static func getLast(completion: @escaping ((Channel)->())){
95− let jsonString = "100"
95+ let jsonString = "30"
96 var request = URLRequest(url: url1)
96 var request = URLRequest(url: url1)
97
97
98 request.httpMethod = "POST"
98 request.httpMethod = "POST"