diff --git a/project/Streamline.xcodeproj/project.pbxproj b/project/Streamline.xcodeproj/project.pbxproj index 1017b6e..fa36581 100644 --- a/project/Streamline.xcodeproj/project.pbxproj +++ b/project/Streamline.xcodeproj/project.pbxproj @@ -33,6 +33,8 @@ 2DA03D1C1F92A8E900F88C13 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA03D1B1F92A8E900F88C13 /* AppDelegate.swift */; }; 2DA03D311F92A8E900F88C13 /* StreamlineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA03D301F92A8E900F88C13 /* StreamlineTests.swift */; }; 2DA03D3C1F92A8E900F88C13 /* StreamlineUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA03D3B1F92A8E900F88C13 /* StreamlineUITests.swift */; }; + 2DA216BD1FBFA65000074D6C /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA216BC1FBFA65000074D6C /* ProfileViewController.swift */; }; + 2DA216BF1FBFA66200074D6C /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DA216BE1FBFA66200074D6C /* ProfileView.swift */; }; 2DDF1E251F99AA100089489C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2DDF1E241F99AA100089489C /* Images.xcassets */; }; 2DDF1E271F99AB850089489C /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DDF1E261F99AB850089489C /* Constants.swift */; }; 554A7D6E1FBC21BE00A58FA7 /* UsernameInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 554A7D6D1FBC21BE00A58FA7 /* UsernameInputView.swift */; }; @@ -98,6 +100,8 @@ 2DA03D371F92A8E900F88C13 /* StreamlineUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StreamlineUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 2DA03D3B1F92A8E900F88C13 /* StreamlineUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamlineUITests.swift; sourceTree = ""; }; 2DA03D3D1F92A8E900F88C13 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 2DA216BC1FBFA65000074D6C /* ProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewController.swift; sourceTree = ""; }; + 2DA216BE1FBFA66200074D6C /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = ""; }; 2DDF1E241F99AA100089489C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 2DDF1E261F99AB850089489C /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 554A7D6D1FBC21BE00A58FA7 /* UsernameInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UsernameInputView.swift; sourceTree = ""; }; @@ -158,6 +162,7 @@ 2D6B7DD11F92ABAA009DA338 /* View */ = { isa = PBXGroup; children = ( + 2DA216BE1FBFA66200074D6C /* ProfileView.swift */, 554A7D6D1FBC21BE00A58FA7 /* UsernameInputView.swift */, 2D125EB21FA12FB80031A21A /* LoginView.swift */, 2D8314D61FA70862002F6C78 /* FeedView.swift */, @@ -173,6 +178,7 @@ 2D6B7DD21F92ABB0009DA338 /* Controller */ = { isa = PBXGroup; children = ( + 2DA216BC1FBFA65000074D6C /* ProfileViewController.swift */, 2D8BA5411F984D5400D8DBE2 /* LoginViewController.swift */, 2D3F9A561F92E2D100A09DCB /* FeedViewController.swift */, 2D6780151FA5014F00F30971 /* NowPlayingViewController.swift */, @@ -610,6 +616,7 @@ 2D05B9DF1FA55D0900F26A79 /* SearchView.swift in Sources */, 2D8314D71FA70862002F6C78 /* FeedView.swift in Sources */, 554A7D6E1FBC21BE00A58FA7 /* UsernameInputView.swift in Sources */, + 2DA216BF1FBFA66200074D6C /* ProfileView.swift in Sources */, D14C0E7D1FAE6C36000818C5 /* Utils.swift in Sources */, 2D3F9A551F92E18E00A09DCB /* VCExtensions.swift in Sources */, 2D3F9A571F92E2D100A09DCB /* FeedViewController.swift in Sources */, @@ -618,6 +625,7 @@ 2D6780181FA501E700F30971 /* NowPlayingView.swift in Sources */, 2DDF1E271F99AB850089489C /* Constants.swift in Sources */, 2D3F9A5C1F92E52300A09DCB /* PostCollectionViewCell.swift in Sources */, + 2DA216BD1FBFA65000074D6C /* ProfileViewController.swift in Sources */, 2D763B141FA29D6600546166 /* ResultTableViewCell.swift in Sources */, 2D8BA5421F984D5400D8DBE2 /* LoginViewController.swift in Sources */, ); diff --git a/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/UserInterfaceState.xcuserstate b/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/UserInterfaceState.xcuserstate index 5ddd05b..6b3e981 100644 Binary files a/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/UserInterfaceState.xcuserstate and b/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 42d18e4..9eb2bb2 100644 --- a/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/project/Streamline.xcworkspace/xcuserdata/ajay.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -10,7 +10,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Streamline/Model/Post.swift" - timestampString = "532426361.534022" + timestampString = "532810420.656477" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "57" @@ -26,7 +26,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Streamline/Model/Post.swift" - timestampString = "532426361.534625" + timestampString = "532810420.656922" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "61" @@ -42,7 +42,7 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Streamline/Controller/FeedViewController.swift" - timestampString = "532426165.039873" + timestampString = "532657498.09823" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" startingLineNumber = "54" diff --git a/project/Streamline/Controller/FeedViewController.swift b/project/Streamline/Controller/FeedViewController.swift index a4ed23b..90ac5f3 100644 --- a/project/Streamline/Controller/FeedViewController.swift +++ b/project/Streamline/Controller/FeedViewController.swift @@ -293,12 +293,16 @@ extension FeedViewController: NowPlayingProtocol, FeedViewDelegate { } } - //Handles logout - func logoutButtonPressed() { - let userDefaults = UserDefaults.standard - userDefaults.removeObject(forKey: "SpotifySession") - - SpotifyAPI.player.logout() - self.dismiss(animated: true, completion: nil) + @objc + func profileButtonPressed() { + performSegue(withIdentifier: "feedToProfile", sender: self) } + // Handles logout +// func logoutButtonPressed() { +// let userDefaults = UserDefaults.standard +// userDefaults.removeObject(forKey: "SpotifySession") +// +// SpotifyAPI.player.logout() +// self.dismiss(animated: true, completion: nil) +// } } diff --git a/project/Streamline/Controller/ProfileViewController.swift b/project/Streamline/Controller/ProfileViewController.swift new file mode 100644 index 0000000..e141efd --- /dev/null +++ b/project/Streamline/Controller/ProfileViewController.swift @@ -0,0 +1,35 @@ +// +// ProfileViewController.swift +// Streamline +// +// Created by Stephen Jayakar on 11/17/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import UIKit + +class ProfileViewController: UIViewController { + var subView: ProfileView! + + override func viewDidLoad() { + super.viewDidLoad() + subView = ProfileView(frame: view.frame) + subView.delegate = self + view.addSubview(subView) + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } +} + +extension ProfileViewController: ProfileViewDelegate { + func logoutButtonPressed() { + // please logout + } + + func backButtonPressed() { + self.dismiss(animated: true, completion: nil) + } +} diff --git a/project/Streamline/Main.storyboard b/project/Streamline/Main.storyboard index a285fe0..f1c623c 100644 --- a/project/Streamline/Main.storyboard +++ b/project/Streamline/Main.storyboard @@ -26,7 +26,7 @@ - + @@ -40,11 +40,12 @@ + - + @@ -77,7 +78,22 @@ - + + + + + + + + + + + + + + + + diff --git a/project/Streamline/Model/User.swift b/project/Streamline/Model/User.swift index 983e716..a1e8c1a 100644 --- a/project/Streamline/Model/User.swift +++ b/project/Streamline/Model/User.swift @@ -50,12 +50,14 @@ class User { } func getProfileImage(withBlock: @escaping (UIImage) -> ()) { - let url = URL(string: imageUrl) - let cache = Shared.imageCache - if let url = url { - cache.fetch(URL: url).onSuccess({ img in - withBlock(img) - }) + DispatchQueue.main.async { + let url = URL(string: self.imageUrl) + let cache = Shared.imageCache + if let url = url { + cache.fetch(URL: url).onSuccess { img in + withBlock(img) + } + } } } } diff --git a/project/Streamline/View/FeedView.swift b/project/Streamline/View/FeedView.swift index 42ad569..92d797d 100644 --- a/project/Streamline/View/FeedView.swift +++ b/project/Streamline/View/FeedView.swift @@ -12,7 +12,7 @@ class FeedView: UIView { var postCollectionView : UICollectionView! var postButton : UIButton! var postButtonArea : UIButton! - var logoutButton : UIButton! + var profileButton : UIButton! var discoverLabel : UILabel! var nowPlayingButton : UIButton! var nowPlayingLabel : UILabel! @@ -90,12 +90,12 @@ class FeedView: UIView { postButtonArea.addTarget(self, action: #selector(postButtonPressed), for: .touchUpInside) addSubview(postButtonArea) - logoutButton = UIButton(frame: Utils.rRect(rx: 15, ry: 30, rw: 74, rh: 22)) - logoutButton.setTitle("Log Out", for: .normal) - logoutButton.setTitleColor(UIColor(hex: "737171"), for: .normal) - logoutButton.addTarget(self, action: #selector(logoutButtonPressed), for: .touchUpInside) - logoutButton.titleLabel?.adjustsFontSizeToFitWidth = true - addSubview(logoutButton) + profileButton = UIButton(frame: Utils.rRect(rx: 15, ry: 30, rw: 74, rh: 22)) + profileButton.setTitle("Profile", for: .normal) + profileButton.setTitleColor(UIColor(hex: "737171"), for: .normal) + profileButton.addTarget(self, action: #selector(profileButtonPressed), for: .touchUpInside) + profileButton.titleLabel?.adjustsFontSizeToFitWidth = true + addSubview(profileButton) } func setupLabel() { @@ -125,13 +125,13 @@ class FeedView: UIView { self.delegate?.nowPlayingButtonPressed() } - func logoutButtonPressed() { - self.delegate?.logoutButtonPressed() + func profileButtonPressed() { + self.delegate?.profileButtonPressed() } } protocol FeedViewDelegate { func postButtonPressed() func nowPlayingButtonPressed() - func logoutButtonPressed() + func profileButtonPressed() } diff --git a/project/Streamline/View/ProfileView.swift b/project/Streamline/View/ProfileView.swift new file mode 100644 index 0000000..07f1a0f --- /dev/null +++ b/project/Streamline/View/ProfileView.swift @@ -0,0 +1,69 @@ +// +// ProfileView.swift +// Streamline +// +// Created by Stephen Jayakar on 11/17/17. +// Copyright © 2017 Stephen Jayakar. All rights reserved. +// + +import UIKit + +class ProfileView: UIView { + var profileImage: UIImageView! + var name: UILabel! + var logoutButton: UIButton! + var backButton: UIButton! + var delegate: ProfileViewDelegate? + + override init(frame: CGRect) { + super.init(frame: frame) + setupUI() + } + + func setupUI() { + // TODO: This should be a square + profileImage = UIImageView(frame: Utils.rRect(rx: 65, ry: 60, rw: 245, rh: 245)) + profileImage.contentMode = .scaleAspectFill + DB.currentUser.getProfileImage { (img) in + self.profileImage.image = img + } + addSubview(profileImage) + + name = UILabel(frame: Utils.rRect(rx: 0, ry: 348, rw: 375, rh: 30)) + name.text = DB.currentUser.username + name.font = Constants.averageSans?.withSize(30) + name.textColor = UIColor.black + name.adjustsFontSizeToFitWidth = true + addSubview(name) + + logoutButton = UIButton(frame: Utils.rRect(rx: 56, ry: 574, rw: 107, rh: 31)) + logoutButton.backgroundColor = Constants.darkPurple + logoutButton.addTarget(self, action: #selector(logoutButtonPressed), for: .touchUpInside) + addSubview(logoutButton) + + backButton = UIButton(frame: Utils.rRect(rx: 213, ry: 574, rw: 107, rh: 31)) + backButton.backgroundColor = UIColor.black + backButton.addTarget(self, action: #selector(backButtonPressed), for: .touchUpInside) + addSubview(backButton) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // Selectors + @objc + func logoutButtonPressed() { + delegate?.logoutButtonPressed() + } + + @objc + func backButtonPressed() { + delegate?.backButtonPressed() + } +} + +protocol ProfileViewDelegate { + func logoutButtonPressed() + func backButtonPressed() +}