git.iko.soy/dashared/GDproject
on master help sign in
resolved issues with header height. improved user experience. minor changes in posts and profile
commitb504119a9073cb7a092061b6037daea9fb95702b authorDarya Rednikina <rednikina.com@yandex.ru> dateThu 28 Feb 2019, 22:10 (8 years ago) parentcc07d12
11 files changed+56−44
GDproject/Controller/ News and channels/ChannelListController.swift+1−1 GDproject/Controller/ News and channels/FullPostController.swift+2−1 GDproject/Controller/ News and channels/NewsController.swift+1−1 GDproject/Controller/ News and channels/NewsVC.swift+11−4 GDproject/Controller/ News and channels/PostViewCell.swift+9−6 GDproject/Controller/Coordinator tab bar?/TabbarCoordinator.swift+3−14 GDproject/Controller/Log In/LogInCoordinator.swift+9−6 GDproject/Controller/Log In/LogInViewController.swift+4−4 GDproject/Controller/Profile/ProfileViewController.swift+9−2 GDproject/DataStorage.swift+5−3 GDproject/Simple model/Model.swift+2−2
GDproject/Controller/ News and channels/ChannelListController.swift+1−1
@@ -60,7 +60,7 @@ class ChannelListController: UITableViewController, DataDelegate {
6060 }
6161
6262 func setUpNavigationBar(){
63− navigationController?.navigationItem.largeTitleDisplayMode = .always
63+ navigationItem.largeTitleDisplayMode = .always
6464 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addChannel))]
6565 }
6666
GDproject/Controller/ News and channels/FullPostController.swift+2−1
@@ -23,7 +23,7 @@ class FullPostController: UITableViewController {
2323 }
2424
2525 func setUpNavigationBar(){
26− navigationController?.navigationBar.prefersLargeTitles = false
26+ navigationItem.largeTitleDisplayMode = .never
2727 navigationItem.title = "\(post?.authorId ?? 0)"
2828 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.options))]
2929 }
@@ -93,6 +93,7 @@ class FullPostController: UITableViewController {
9393
9494 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
9595
96+
9697 cell.fill(with: post!.body, true, post: post!)
9798 cell.selectionStyle = .none
9899 return cell
GDproject/Controller/ News and channels/NewsController.swift+1−1
@@ -83,7 +83,7 @@ class NewsController: UITableViewController, UISearchControllerDelegate, NewPost
8383 setUpSearchContr()
8484
8585 news.viewController = self
86− news.type = .NONE
86+ news.type = .NEWS
8787
8888 setUpNavigationItemsforPosts()
8989
GDproject/Controller/ News and channels/NewsVC.swift+11−4
@@ -39,10 +39,17 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
3939
4040 cell.fill(with: dataSourse[indexPath.row].body, false, post: dataSourse[indexPath.row])
4141
42− cell.onUserDisplay = { [weak self] (id) in
43− let vc = self?.viewController!.storyboard!.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
44− vc.idProfile = id
45− self?.viewController!.navigationController!.pushViewController(vc, animated: true)
42+ switch type {
43+ case .NEWS:
44+ cell.onUserDisplay = { [weak self] (id) in
45+ let vc = self?.viewController!.storyboard!.instantiateViewController(withIdentifier: profileViewController) as! ProfileViewController
46+ vc.idProfile = id
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+ }
4653 }
4754
4855 cell.selectionStyle = .none
GDproject/Controller/ News and channels/PostViewCell.swift+9−6
@@ -53,19 +53,22 @@ class PostViewCell: UITableViewCell
5353 fatalError("init(coder:) has not been implemented")
5454 }
5555
56− func createTextView(with text: String) -> UITextView
56+ func createTextView(with text: String, _ isSelectable: Bool) -> UITextView
5757 {
5858 let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 16))
5959 let markdown = text
6060 markdownParser.enabledElements = .disabledAutomaticLink
61− markdownParser.header.fontIncrease = 16
6261 markdownParser.code.textBackgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
6362
6463 let textView = UITextView()
6564 textView.isScrollEnabled = false
6665 textView.isEditable = false
67− //textView.isUserInteractionEnabled = false
68− textView.isSelectable = true
66+ if isSelectable {
67+ //textView.isUserInteractionEnabled = false
68+ textView.isSelectable = true
69+ } else {
70+ textView.isUserInteractionEnabled = false
71+ }
6972 textView.attributedText = markdownParser.parse(markdown)
7073 return textView
7174 }
@@ -82,7 +85,7 @@ class PostViewCell: UITableViewCell
8285 views = []
8386 for attachment in info
8487 {
85− views.append(createTextView(with: attachment.markdown))
88+ views.append(createTextView(with: attachment.markdown, isFullVersoin))
8689 }
8790
8891 nameLabel.setTitle("\(post.user?.firstName ?? "") \(post.user?.secondName ?? "")", for: .normal)
@@ -91,7 +94,7 @@ class PostViewCell: UITableViewCell
9194 setUpInStackView(isFullVersoin)
9295 }
9396
94− let hashtags = ["Kek", "Lol"]
97+ let hashtags = ["Программная инженерия", "ПИ", "НИУ ВШЭ", "Наука"]
9598 func setUpInStackView(_ full : Bool){
9699 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
97100 nameStackView.axis = .vertical
GDproject/Controller/Coordinator tab bar?/TabbarCoordinator.swift+3−14
@@ -2,24 +2,13 @@ import UIKit
22
33class TabbarCoordinator{
44 var window: UIWindow!
5− static let tabBar: UITabBarController = UIStoryboard.tabBarController()
6−
7− // MARK: - Properties
8− //private var user: Model.Users { didSet { updateInterfaces() } }
9−
5+
106 func start(){
11− window.rootViewController = TabbarCoordinator.tabBar
12− TabbarCoordinator.tabBar.selectedIndex = 0
7+ let tabbar = UIStoryboard.tabBarController()
8+ window.rootViewController = tabbar
139 }
1410
1511 init(window: UIWindow) {
1612 self.window = window
1713 }
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−// }
2514}
GDproject/Controller/Log In/LogInCoordinator.swift+9−6
@@ -23,18 +23,21 @@ class LogInCoordinator{
2323 }
2424
2525 // MARK: - Private implementation
26− private func showStatusPage(){
27− let controller = TabbarCoordinator(window: window)
28− controller.start()
29− }
26+// private func showStatusPage(){
27+// let controller = TabbarCoordinator(window: window)
28+// controller.start()
29+// }
3030
3131 private func showLogInPage(){
3232 let controller = UIStoryboard.makeLogIn()
33+
3334 controller.onLogIn = {
34− (id) in
35− Model.authenticate(with: id) {
35+ (id) in Model.authenticate(with: id) {
3636 (res) in
37+
3738 if (res) { DataStorage.standard.setUserKey(with: id) }
39+ else { DataStorage.standard.setUserKey(with: 0) }
40+
3841 controller.authenticateSucceeded = res
3942 }
4043 }
GDproject/Controller/Log In/LogInViewController.swift+4−4
@@ -53,14 +53,10 @@ class LogInViewController: UIViewController {
5353
5454 override func viewWillAppear(_ animated: Bool) {
5555 super.viewWillAppear(animated)
56− // MARK:- uncomment when mail registration will be availiable
57− //self.navigationController?.setNavigationBarHidden(true, animated: animated)
5856 }
5957
6058 override func viewWillDisappear(_ animated: Bool) {
6159 super.viewWillDisappear(animated)
62− // MARK:- uncomment when mail registration will be availiable
63− //self.navigationController?.setNavigationBarHidden(false, animated: animated)
6460 }
6561
6662 private func configureTapgesture(){
@@ -97,6 +93,10 @@ class LogInViewController: UIViewController {
9793
9894 setUpBarComponents()
9995
96+ configureKeyboardBehavior()
97+ }
98+
99+ func configureKeyboardBehavior(){
100100 bottomConstraint = NSLayoutConstraint(item: keyboardBar, attribute: .bottom, relatedBy: .equal, toItem: view.safeAreaLayoutGuide, attribute: .bottom, multiplier: 1, constant: 0)
101101 view.addConstraint(bottomConstraint!)
102102
GDproject/Controller/Profile/ProfileViewController.swift+9−2
@@ -51,7 +51,14 @@ class ProfileViewController: UIViewController
5151
5252 var dataSourse: [Model.Posts]?{
5353 didSet{
54− self.posts.dataSourse = dataSourse!
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+
61+ self.posts.dataSourse = newPosts
5562 tableView.reloadData()
5663 }
5764 }
@@ -136,7 +143,7 @@ class ProfileViewController: UIViewController
136143 let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
137144 {
138145 (_) in
139− DataStorage.standard.setIsLoggedIn(value: false)
146+ DataStorage.standard.setIsLoggedIn(value: false, with: 0)
140147 }
141148
142149 optionMenu.addAction(editAction)
GDproject/DataStorage.swift+5−3
@@ -23,8 +23,9 @@ class DataStorage{
2323 /**
2424 Function for setting log in status of user
2525 */
26− func setIsLoggedIn(value: Bool){
26+ func setIsLoggedIn(value: Bool, with id: Int){
2727 UserDefaults.standard.set(value, forKey: UserDefaultsKeys.loggedIn.rawValue)
28+ setUserKey(with: id)
2829 isLoggedIn = UserDefaults.standard.bool(forKey: UserDefaultsKeys.loggedIn.rawValue)
2930 }
3031
@@ -32,15 +33,16 @@ class DataStorage{
3233 UserDefaults.standard.set(id, forKey: UserDefaultsKeys.id.rawValue)
3334 }
3435
35− func getUserId() -> Int?{
36+ func getUserId() -> Int {
3637 return UserDefaults.standard.integer(forKey: UserDefaultsKeys.id.rawValue)
3738 }
39+
3840 /**
3941 Function to determine is user logged in already or not
4042 */
4143 var isLoggedIn: Bool = UserDefaults.standard.bool(forKey: UserDefaultsKeys.loggedIn.rawValue) {
4244 didSet{
43− if isLoggedIn {
45+ if isLoggedIn && getUserId() != 0 {
4446 (UIApplication.shared.delegate as? AppDelegate)?.tabCoordinator.start()
4547 } else {
4648 (UIApplication.shared.delegate as? AppDelegate)?.logInAgain()
GDproject/Simple model/Model.swift+2−2
@@ -85,14 +85,14 @@ class Model{
8585
8686 HTTPCookieStorage.shared.setCookie(cookies[0])
8787
88− DataStorage.standard.setIsLoggedIn(value: true)
88+ DataStorage.standard.setIsLoggedIn(value: true, with: id)
8989 completion(true)
9090 }
9191 }
9292
9393
9494 static func getLast(completion: @escaping ((Channel)->())){
95− let jsonString = "100"
95+ let jsonString = "30"
9696 var request = URLRequest(url: url1)
9797
9898 request.httpMethod = "POST"