From 636d73db86a8691489ba76f2ab339d6012773a20 Mon Sep 17 00:00:00 2001 From: Tor is Here Date: Tue, 23 Jun 2015 08:45:16 +0900 Subject: [PATCH 1/6] Profile placement --- adam.xcodeproj/project.pbxproj | 16 +- benri/Base.lproj/Main.storyboard | 234 ++++++++++++++++++++++---- benri/PageContentViewController.swift | 8 +- benri/ProfileViewController.swift | 74 +++++++- benri/TutorialViewController.swift | 5 +- benri/User.swift | 50 ++++++ 6 files changed, 349 insertions(+), 38 deletions(-) create mode 100644 benri/User.swift diff --git a/adam.xcodeproj/project.pbxproj b/adam.xcodeproj/project.pbxproj index bf931e2..872e594 100644 --- a/adam.xcodeproj/project.pbxproj +++ b/adam.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 9656ADAB1AECC62800933A8E /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9656ADA91AECC62800933A8E /* LaunchScreen.xib */; }; 9656ADB71AECC62900933A8E /* benriTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9656ADB61AECC62900933A8E /* benriTests.swift */; }; 967867701B2C9A7F0047C7BB /* SearchCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9678676F1B2C9A7F0047C7BB /* SearchCell.swift */; }; + 969AB5B21B36FC9100E92A9F /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 969AB5B11B36FC9100E92A9F /* User.swift */; }; 969FB14E1B1AB32300439BDC /* FBSDKLoginKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 969FB14D1B1AB32300439BDC /* FBSDKLoginKit.framework */; }; 969FB1501B1AB35700439BDC /* FBSDKCoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 969FB14F1B1AB35700439BDC /* FBSDKCoreKit.framework */; }; 96C24E901B244527006C5806 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C24E8F1B244527006C5806 /* SearchViewController.swift */; }; @@ -81,6 +82,7 @@ 9656ADB51AECC62900933A8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9656ADB61AECC62900933A8E /* benriTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = benriTests.swift; sourceTree = ""; }; 9678676F1B2C9A7F0047C7BB /* SearchCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchCell.swift; sourceTree = ""; }; + 969AB5B11B36FC9100E92A9F /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 969FB14D1B1AB32300439BDC /* FBSDKLoginKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FBSDKLoginKit.framework; sourceTree = ""; }; 969FB14F1B1AB35700439BDC /* FBSDKCoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FBSDKCoreKit.framework; sourceTree = ""; }; 96C24E8F1B244527006C5806 /* SearchViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = ""; }; @@ -175,13 +177,12 @@ 96E3771B1B359C1F00229684 /* Tutorial */, 96DA5A131AF284A80003E506 /* Menu */, 96DA5A0A1AF2744F0003E506 /* Lib */, + 969AB5B01B36F52700E92A9F /* Profile */, 9656AD9E1AECC62800933A8E /* AppDelegate.swift */, - 964690851B3308D800DB187D /* TutorialViewController.swift */, 9656ADA01AECC62800933A8E /* FirstViewController.swift */, 96C24E8F1B244527006C5806 /* SearchViewController.swift */, 9616799A1B2C72BA00A43AD3 /* LocationSearchViewController.swift */, 9656ADA21AECC62800933A8E /* SecondViewController.swift */, - 2150F5001B0EFEE200AFDF5E /* ProfileViewController.swift */, 21D7412B1B21AD36008A8EB5 /* DiscoverViewController.swift */, 21D741291B21AA4B008A8EB5 /* DiscoverView.swift */, 9678676F1B2C9A7F0047C7BB /* SearchCell.swift */, @@ -220,6 +221,15 @@ name = "Supporting Files"; sourceTree = ""; }; + 969AB5B01B36F52700E92A9F /* Profile */ = { + isa = PBXGroup; + children = ( + 2150F5001B0EFEE200AFDF5E /* ProfileViewController.swift */, + 969AB5B11B36FC9100E92A9F /* User.swift */, + ); + name = Profile; + sourceTree = ""; + }; 96DA5A0A1AF2744F0003E506 /* Lib */ = { isa = PBXGroup; children = ( @@ -258,6 +268,7 @@ isa = PBXGroup; children = ( 964690891B3392F600DB187D /* PageContentViewController.swift */, + 964690851B3308D800DB187D /* TutorialViewController.swift */, ); name = Tutorial; sourceTree = ""; @@ -438,6 +449,7 @@ 21577E061B2E875000D4218F /* CurrencyConverter.swift in Sources */, 96DA5A121AF274670003E506 /* ImageCache.swift in Sources */, 96C24E901B244527006C5806 /* SearchViewController.swift in Sources */, + 969AB5B21B36FC9100E92A9F /* User.swift in Sources */, 2150F5011B0EFEE200AFDF5E /* ProfileViewController.swift in Sources */, 21AF14871B05FA0B00108190 /* RestaurantServerAPI.swift in Sources */, 9656ADA11AECC62800933A8E /* FirstViewController.swift in Sources */, diff --git a/benri/Base.lproj/Main.storyboard b/benri/Base.lproj/Main.storyboard index e0aa771..720a965 100644 --- a/benri/Base.lproj/Main.storyboard +++ b/benri/Base.lproj/Main.storyboard @@ -621,7 +621,7 @@ @@ -822,27 +819,18 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/benri/PageContentViewController.swift b/benri/PageContentViewController.swift index 01211c3..3177e1e 100644 --- a/benri/PageContentViewController.swift +++ b/benri/PageContentViewController.swift @@ -41,8 +41,9 @@ class PageContentViewController: UIViewController, FBSDKLoginButtonDelegate { if self.pageIndex == 5 { self.textView.hidden = true self.loginTextView.text = NSLocalizedString(detailText, comment: "Tutorial text") + let facebookLoginButton: FBSDKLoginButton = FBSDKLoginButton() - self.loginButton = FBSDKLoginButton() + self.loginButton = facebookLoginButton self.loginButton.readPermissions = ["public_profile", "email", "user_friends"] self.loginButton.delegate = self @@ -111,6 +112,7 @@ class PageContentViewController: UIViewController, FBSDKLoginButtonDelegate { var email:String! var fbID:String! var userName:String! + var profileImgURL:NSURL! if ((error) != nil) { // Process error @@ -121,8 +123,10 @@ class PageContentViewController: UIViewController, FBSDKLoginButtonDelegate { email = result.valueForKey("email") as! String token = FBSDKAccessToken.currentAccessToken().tokenString userName = result.valueForKey("name") as! String + profileImgURL = NSURL(fileURLWithPath: String(format: "https://graph.facebook.com/%@/picture?type=large", fbID)) } - self.delegate.didLoginFacebook(email, token:token, id: fbID, userName: userName) + println(profileImgURL) + self.delegate.didLoginFacebook(email, token:token, profileImgURL: profileImgURL, userName: userName) }) } } diff --git a/benri/ProfileViewController.swift b/benri/ProfileViewController.swift index 0581d78..dd74cf7 100644 --- a/benri/ProfileViewController.swift +++ b/benri/ProfileViewController.swift @@ -9,13 +9,35 @@ import Foundation import UIKit -class ProfileViewController: UIViewController { +class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. - //var facebookButton:FBSDKLoginButton = FBSDKLoginButton() - //self.view.addSubview(facebookButton) + if (FBSDKAccessToken.currentAccessToken() != nil) + { + self.returnUserData() + + // User is already logged in, do work such as go to next view controller. + + // Or Show Logout Button + /* + let loginView : FBSDKLoginButton = FBSDKLoginButton() + self.view.addSubview(loginView) + loginView.center = self.view.center + loginView.readPermissions = ["public_profile", "email", "user_friends"] + loginView.delegate = self + self.returnUserData() + */ + } + else + { + let loginView : FBSDKLoginButton = FBSDKLoginButton() + self.view.addSubview(loginView) + loginView.center = self.view.center + loginView.readPermissions = ["public_profile", "email", "user_friends"] + loginView.delegate = self + } } override func didReceiveMemoryWarning() { @@ -23,5 +45,51 @@ class ProfileViewController: UIViewController { // Dispose of any resources that can be recreated. } + // Facebook Delegate Methods + func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { + if ((error) != nil){ + + } + else if result.isCancelled { + + } + else { + // If you ask for multiple permissions at once, you + // should check if specific permissions missing + if result.grantedPermissions.contains("email") + { + // Do work + } + self.returnUserData() + } + } + + func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) { + println("User Logged Out") + } + + func returnUserData() { + let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil) + graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in + + if ((error) != nil) + { + // Process error + println("Error: \(error)") + } + else + { + println("fetched user: \(result)") + let userName : NSString = result.valueForKey("name") as! NSString + println("User Name is: \(userName)") + let userEmail : NSString = result.valueForKey("email") as! NSString + println("User Email is: \(userEmail)") + + if FBSDKAccessToken.currentAccessToken() != nil { + println(FBSDKAccessToken.currentAccessToken().tokenString) + } + } + }) + } } \ No newline at end of file diff --git a/benri/TutorialViewController.swift b/benri/TutorialViewController.swift index 28bc412..852b8b2 100644 --- a/benri/TutorialViewController.swift +++ b/benri/TutorialViewController.swift @@ -9,7 +9,7 @@ import UIKit protocol TutorialDelegate { - func didLoginFacebook(email:String?, token:String?, id:String?, userName:String?) + func didLoginFacebook(email:String?, token:String?, profileImgURL:NSURL?, userName:String?) func didSkipSignIn() } @@ -132,10 +132,11 @@ class TutorialViewController:UIViewController, UIPageViewControllerDataSource, U } // MARK: - Tutorial Delegate - func didLoginFacebook(email:String?,token: String?, id: String?, userName:String?) { + func didLoginFacebook(email:String?, token: String?, profileImgURL:NSURL?, userName:String?) { userDefault.setBool(true, forKey: "didFinishedTutorial") userDefault.setObject(email, forKey: "email") userDefault.setObject(userName, forKey: "userName") + userDefault.setObject(profileImgURL, forKey: "profileImgURL") userDefault.synchronize() self.performSegueWithIdentifier("tutorialSegueUnwind", sender: self) } diff --git a/benri/User.swift b/benri/User.swift new file mode 100644 index 0000000..0c3e582 --- /dev/null +++ b/benri/User.swift @@ -0,0 +1,50 @@ +// +// User.swift +// adam +// +// Created by Kittikorn Ariyasuk on 6/21/15. +// Copyright (c) 2015 gobbl. All rights reserved. +// + +import Foundation + +class User:NSObject { + + private var email: String! + private var facebookID: String! + private var fullName: String! + private var profileImageURL: String! + private var isUserSet:Bool! + + override init() { + self.isUserSet = false + } + + func setUpUserData(email:String, facebookID:String, fullName:String, profileImageURL:String) { + self.email = email + self.facebookID = facebookID + self.fullName = fullName + self.profileImageURL = profileImageURL + self.isUserSet = true + } + + func clearData() { + self.email = nil + self.facebookID = nil + self.fullName = nil + self.profileImageURL = nil + self.isUserSet = false + } + + class var sharedInstance : User { + struct Static { + static var onceToken : dispatch_once_t = 0 + static var instance : User? = nil + } + dispatch_once(&Static.onceToken) { + Static.instance = User() + } + return Static.instance! + } + +} \ No newline at end of file From 08fe2db4028993e9cca310a944e3dba6e46d3fe7 Mon Sep 17 00:00:00 2001 From: Tor is Here Date: Thu, 25 Jun 2015 01:38:27 +0900 Subject: [PATCH 2/6] Asset profile page --- benri/Base.lproj/Main.storyboard | 277 ++++++++++++++++--------------- 1 file changed, 144 insertions(+), 133 deletions(-) diff --git a/benri/Base.lproj/Main.storyboard b/benri/Base.lproj/Main.storyboard index 720a965..fe975a1 100644 --- a/benri/Base.lproj/Main.storyboard +++ b/benri/Base.lproj/Main.storyboard @@ -623,9 +623,6 @@ - - - @@ -997,208 +994,222 @@ - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - + - - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - + + + + - - - + + + - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + From 6be3c2eba899e2f31b7a4c3af6f13b978a406e9f Mon Sep 17 00:00:00 2001 From: Tor is Here Date: Thu, 25 Jun 2015 01:39:01 +0900 Subject: [PATCH 3/6] Profile page: set image name and email + placement for detail setting --- benri/ProfileViewController.swift | 133 ++++++++++++++++++++++++++---- 1 file changed, 117 insertions(+), 16 deletions(-) diff --git a/benri/ProfileViewController.swift b/benri/ProfileViewController.swift index dd74cf7..73bafce 100644 --- a/benri/ProfileViewController.swift +++ b/benri/ProfileViewController.swift @@ -8,35 +8,65 @@ import Foundation import UIKit +import Alamofire class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { + @IBOutlet weak var imageView: UIImageView! + @IBOutlet weak var nameLabel: UILabel! + @IBOutlet weak var emailLabel: UILabel! + + @IBOutlet weak var logOutButton: UIButton! + @IBOutlet weak var upperView: UIView! + @IBOutlet weak var detailTable: UITableView! + + var loginView:FBSDKLoginButton! + + var userDefault:NSUserDefaults! + var imageCache:ImageCache! + var request: Alamofire.Request? + + var fullName:String! + var email:String! + var profileImageURLString:String! + + + @IBAction func logOut(sender: AnyObject) { + let loginManager = FBSDKLoginManager() + loginManager.logOut() + print("log out") + self.loginView.hidden = false + self.hideProfilePage() + self.view.setNeedsDisplay() + } + override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. - if (FBSDKAccessToken.currentAccessToken() != nil) - { - self.returnUserData() - + + self.userDefault = NSUserDefaults.standardUserDefaults() + self.imageCache = ImageCache.sharedInstance + + if (FBSDKAccessToken.currentAccessToken() != nil) { // User is already logged in, do work such as go to next view controller. // Or Show Logout Button - /* - let loginView : FBSDKLoginButton = FBSDKLoginButton() + self.loginView = FBSDKLoginButton() self.view.addSubview(loginView) - loginView.center = self.view.center - loginView.readPermissions = ["public_profile", "email", "user_friends"] - loginView.delegate = self + self.loginView.center = self.view.center + self.loginView.readPermissions = ["public_profile", "email", "user_friends"] + self.loginView.delegate = self + self.loginView.hidden = true self.returnUserData() - */ + } - else - { - let loginView : FBSDKLoginButton = FBSDKLoginButton() + else { + self.loginView = FBSDKLoginButton() self.view.addSubview(loginView) - loginView.center = self.view.center - loginView.readPermissions = ["public_profile", "email", "user_friends"] - loginView.delegate = self + self.loginView.center = self.view.center + self.loginView.readPermissions = ["public_profile", "email", "user_friends"] + self.loginView.delegate = self + self.hideProfilePage() } } @@ -62,6 +92,7 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { // Do work } self.returnUserData() + self.loginView.hidden = true } } @@ -80,6 +111,60 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { } else { + self.userDefault = NSUserDefaults.standardUserDefaults() + + // Email + if let myEmail = self.userDefault.objectForKey("email") as? String { + self.emailLabel.text = myEmail + } else { + let myEmail = result.valueForKey("email") as! String + self.userDefault.setObject(myEmail, forKey: "email") + } + + // Name + if let myName = self.userDefault.objectForKey("userName") as? String { + self.nameLabel.text = myName + } else { + let myName = result.valueForKey("name") as! String + self.userDefault.setObject(myName, forKey: "userName") + } + + + // Profile Image + self.request?.cancel() + if let imageURL = self.userDefault.objectForKey("profileImgURL") as? NSURL { + if let profileImage = self.imageCache.loadImage(imageURL) { + self.imageView.image = profileImage + } else { + + self.request = Alamofire.request(.GET, imageURL.absoluteString!).validate(contentType: ["image/*"]).responseImage() { + (request, _, image, error) in + if error == nil && image != nil { + self.imageCache.cacheImage(request.URL, image: image!) + self.imageView.image = image + } + } + } + } else { + let fbID = result.valueForKey("id") as! String + let profileImgURL = String(format: "https://graph.facebook.com/%@/picture?type=large", fbID) + self.userDefault.setObject(profileImgURL, forKey: "profileImgURL") + + self.request = Alamofire.request(.GET, profileImgURL).validate(contentType: ["image/*"]).responseImage() { + (request, _, image, error) in + if error == nil && image != nil { + self.imageCache.cacheImage(request.URL, image: image!) + self.imageView.image = image + + self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2 + self.imageView.clipsToBounds = true + } + } + } + self.showProfilePage() + self.view.setNeedsDisplay() + self.userDefault.synchronize() + println("fetched user: \(result)") let userName : NSString = result.valueForKey("name") as! NSString println("User Name is: \(userName)") @@ -92,4 +177,20 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { } }) } + + private func showLoginButton() { + + } + + private func showProfilePage() { + self.upperView.hidden = false + self.detailTable.hidden = false + self.logOutButton.hidden = false + } + + private func hideProfilePage() { + self.upperView.hidden = true + self.detailTable.hidden = true + self.logOutButton.hidden = true + } } \ No newline at end of file From 87f2398e84c942af4b14ccbbce10f9103dcadc30 Mon Sep 17 00:00:00 2001 From: Tor is Here Date: Sun, 28 Jun 2015 00:44:55 +0900 Subject: [PATCH 4/6] profile page log out confirm popup --- benri/Base.lproj/Main.storyboard | 58 +++++++------- benri/ProfileViewController.swift | 129 ++++++++++++++++++------------ 2 files changed, 106 insertions(+), 81 deletions(-) diff --git a/benri/Base.lproj/Main.storyboard b/benri/Base.lproj/Main.storyboard index fe975a1..ed7f172 100644 --- a/benri/Base.lproj/Main.storyboard +++ b/benri/Base.lproj/Main.storyboard @@ -623,6 +623,9 @@ + + + @@ -1013,7 +1016,7 @@ @@ -1097,14 +1097,14 @@ - - - - - + + + + + @@ -1115,14 +1115,14 @@ - - - - - + + + + + @@ -1162,19 +1162,19 @@ + + + + - - - - - - - + + + @@ -1185,19 +1185,19 @@ + + + + - - - - - - - + + + diff --git a/benri/ProfileViewController.swift b/benri/ProfileViewController.swift index 73bafce..1599dca 100644 --- a/benri/ProfileViewController.swift +++ b/benri/ProfileViewController.swift @@ -10,7 +10,14 @@ import Foundation import UIKit import Alamofire -class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { +extension UIImageView { + func setRoundImage() { + self.layer.cornerRadius = self.frame.size.width / 2 + self.clipsToBounds = true + } +} + +class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate, UIAlertViewDelegate { @IBOutlet weak var imageView: UIImageView! @IBOutlet weak var nameLabel: UILabel! @@ -32,12 +39,8 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { @IBAction func logOut(sender: AnyObject) { - let loginManager = FBSDKLoginManager() - loginManager.logOut() - print("log out") - self.loginView.hidden = false - self.hideProfilePage() - self.view.setNeedsDisplay() + var alert:UIAlertView = UIAlertView(title: "Confirm log out", message: "Are you sure you want to log out?", delegate: self, cancelButtonTitle: "cancel", otherButtonTitles: "yes") + alert.show() } override func viewDidLoad() { @@ -114,56 +117,22 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { self.userDefault = NSUserDefaults.standardUserDefaults() // Email - if let myEmail = self.userDefault.objectForKey("email") as? String { - self.emailLabel.text = myEmail - } else { - let myEmail = result.valueForKey("email") as! String - self.userDefault.setObject(myEmail, forKey: "email") - } + let myEmail = result.valueForKey("email") as! String + self.userDefault.setObject(myEmail, forKey: "email") - // Name - if let myName = self.userDefault.objectForKey("userName") as? String { - self.nameLabel.text = myName - } else { - let myName = result.valueForKey("name") as! String - self.userDefault.setObject(myName, forKey: "userName") - } + // Name + let myName = result.valueForKey("name") as! String + self.userDefault.setObject(myName, forKey: "userName") // Profile Image - self.request?.cancel() - if let imageURL = self.userDefault.objectForKey("profileImgURL") as? NSURL { - if let profileImage = self.imageCache.loadImage(imageURL) { - self.imageView.image = profileImage - } else { - - self.request = Alamofire.request(.GET, imageURL.absoluteString!).validate(contentType: ["image/*"]).responseImage() { - (request, _, image, error) in - if error == nil && image != nil { - self.imageCache.cacheImage(request.URL, image: image!) - self.imageView.image = image - } - } - } - } else { - let fbID = result.valueForKey("id") as! String - let profileImgURL = String(format: "https://graph.facebook.com/%@/picture?type=large", fbID) - self.userDefault.setObject(profileImgURL, forKey: "profileImgURL") + let fbID = result.valueForKey("id") as! String + let profileImgURL = String(format: "https://graph.facebook.com/%@/picture?type=large", fbID) + self.userDefault.setObject(profileImgURL, forKey: "profileImgURL") + self.userDefault.synchronize() - self.request = Alamofire.request(.GET, profileImgURL).validate(contentType: ["image/*"]).responseImage() { - (request, _, image, error) in - if error == nil && image != nil { - self.imageCache.cacheImage(request.URL, image: image!) - self.imageView.image = image - - self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2 - self.imageView.clipsToBounds = true - } - } - } - self.showProfilePage() + self.setupProfileView() self.view.setNeedsDisplay() - self.userDefault.synchronize() println("fetched user: \(result)") let userName : NSString = result.valueForKey("name") as! NSString @@ -182,9 +151,48 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { } + private func setupProfileView() { + // Hide detail for now + self.detailTable.hidden = true + + self.userDefault = NSUserDefaults.standardUserDefaults() + + // Email + if let myEmail = self.userDefault.objectForKey("email") as? String { + self.emailLabel.text = myEmail + } + + // Name + if let myName = self.userDefault.objectForKey("userName") as? String { + self.nameLabel.text = myName + } + + self.request?.cancel() + // Profile Image + if let imageURL = self.userDefault.objectForKey("profileImgURL") as? String { + if let profileImage = self.imageCache.loadImage(NSURL(string: imageURL)!) { + self.imageView.image = profileImage + self.imageView.setRoundImage() + } else { + + self.request = Alamofire.request(.GET, imageURL).validate(contentType: ["image/*"]).responseImage() { + (request, _, image, error) in + if error == nil && image != nil { + self.imageCache.cacheImage(request.URL, image: image!) + self.imageView.image = image + self.imageView.setRoundImage() + + } + } + } + } + + self.showProfilePage() + } + private func showProfilePage() { self.upperView.hidden = false - self.detailTable.hidden = false + //self.detailTable.hidden = false self.logOutButton.hidden = false } @@ -193,4 +201,21 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate { self.detailTable.hidden = true self.logOutButton.hidden = true } + // MARK: Alertview delegate + + func alertView(alertView: UIAlertView, didDismissWithButtonIndex buttonIndex: Int) { + if (buttonIndex == 0) { + + } + else if (buttonIndex == 1) { + let loginManager = FBSDKLoginManager() + loginManager.logOut() + + self.loginView.hidden = false + self.hideProfilePage() + self.view.setNeedsDisplay() + + } + + } } \ No newline at end of file From 2a6b581bd17aa7a5713893958cf9ad065fa9e794 Mon Sep 17 00:00:00 2001 From: Tor is Here Date: Sun, 28 Jun 2015 00:49:36 +0900 Subject: [PATCH 5/6] remove user data after logout --- benri/ProfileViewController.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/benri/ProfileViewController.swift b/benri/ProfileViewController.swift index 1599dca..db5755d 100644 --- a/benri/ProfileViewController.swift +++ b/benri/ProfileViewController.swift @@ -135,10 +135,6 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate, UIAlert self.view.setNeedsDisplay() println("fetched user: \(result)") - let userName : NSString = result.valueForKey("name") as! NSString - println("User Name is: \(userName)") - let userEmail : NSString = result.valueForKey("email") as! NSString - println("User Email is: \(userEmail)") if FBSDKAccessToken.currentAccessToken() != nil { println(FBSDKAccessToken.currentAccessToken().tokenString) @@ -211,10 +207,16 @@ class ProfileViewController: UIViewController, FBSDKLoginButtonDelegate, UIAlert let loginManager = FBSDKLoginManager() loginManager.logOut() + self.userDefault = NSUserDefaults.standardUserDefaults() + + self.userDefault.removeObjectForKey("email") + self.userDefault.removeObjectForKey("userName") + self.userDefault.removeObjectForKey("profileImgURL") + self.userDefault.synchronize() + self.loginView.hidden = false self.hideProfilePage() self.view.setNeedsDisplay() - } } From 755e7add6bfdb6298bad75526f452651a5f77700 Mon Sep 17 00:00:00 2001 From: Tor is Here Date: Sun, 28 Jun 2015 00:59:43 +0900 Subject: [PATCH 6/6] Fix layout warning --- benri/Base.lproj/Main.storyboard | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/benri/Base.lproj/Main.storyboard b/benri/Base.lproj/Main.storyboard index b7a3be3..72424f6 100644 --- a/benri/Base.lproj/Main.storyboard +++ b/benri/Base.lproj/Main.storyboard @@ -79,9 +79,6 @@ - - - @@ -93,8 +90,7 @@ - - + @@ -116,8 +112,7 @@ - - + @@ -128,18 +123,12 @@ - - -