From dbc2f577ae4b2150fed61e837be280a94a64695d Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Sep 2015 18:07:00 +0800 Subject: [PATCH 01/19] fix retain cycle in notifyTypingAction --- .../Conversation/ConversationViewController.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 456a12bd..e5d860cc 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -190,6 +190,8 @@ class ConversationViewController: BaseViewController { NSNotificationCenter.defaultCenter().removeObserver(self) YepUserDefaults.avatarURLString.removeListenerWithName(Listener.Avatar) + + println("deinit ConversationViewController") } override func viewWillAppear(animated: Bool) { @@ -379,9 +381,9 @@ class ConversationViewController: BaseViewController { checkTypingStatusTimer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("checkTypingStatus"), userInfo: nil, repeats: true) - messageToolbar.notifyTypingAction = { + messageToolbar.notifyTypingAction = { [weak self] in - if let withFriend = self.conversation.withFriend { + if let withFriend = self?.conversation.withFriend { let typingMessage: JSONDictionary = ["state": FayeService.InstantStateType.Text.rawValue] @@ -804,7 +806,7 @@ class ConversationViewController: BaseViewController { FayeService.sharedManager.delegate = nil checkTypingStatusTimer?.invalidate() - self.waverView.removeFromSuperview() + waverView.removeFromSuperview() } override func viewDidLayoutSubviews() { From b11acc3a4edb95c2b8a2400e418c128c578b58a9 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Sep 2015 18:11:26 +0800 Subject: [PATCH 02/19] better checkTypingStatusTimer create & destroy logic --- .../Conversation/ConversationViewController.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index e5d860cc..813d91c7 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -371,16 +371,19 @@ class ConversationViewController: BaseViewController { } }).map({ self.markMessageAsReaded($0) }) + // MARK: Notify Typing + + // 为 nil 时才新建 + if checkTypingStatusTimer == nil { + checkTypingStatusTimer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("checkTypingStatus"), userInfo: nil, repeats: true) + } + // 尽量晚的设置一些属性和闭包 if isFirstAppear { isFirstAppear = false - // MARK: Notify Typing - - checkTypingStatusTimer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("checkTypingStatus"), userInfo: nil, repeats: true) - messageToolbar.notifyTypingAction = { [weak self] in if let withFriend = self?.conversation.withFriend { @@ -805,6 +808,7 @@ class ConversationViewController: BaseViewController { FayeService.sharedManager.delegate = nil checkTypingStatusTimer?.invalidate() + checkTypingStatusTimer = nil // 及时释放 waverView.removeFromSuperview() } From f977c2029eec3d3d53664b6e06713ddee1bd91a1 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Wed, 16 Sep 2015 19:01:02 +0800 Subject: [PATCH 03/19] fix pop ConversationViewController may crash (force conversationCollectionView.delegate = nil) --- .../Conversation/ConversationViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 813d91c7..f56cc9f7 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -191,6 +191,8 @@ class ConversationViewController: BaseViewController { YepUserDefaults.avatarURLString.removeListenerWithName(Listener.Avatar) + conversationCollectionView.delegate = nil + println("deinit ConversationViewController") } From 23c1c28b13593ad7a8a29020dfb4ae7f7f4a0361 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 11:25:58 +0800 Subject: [PATCH 04/19] tryRecoverMessageToolBar in willAppear --- .../ConversationViewController.swift | 220 +++++++++--------- 1 file changed, 112 insertions(+), 108 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index f56cc9f7..5dd57421 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -195,15 +195,6 @@ class ConversationViewController: BaseViewController { println("deinit ConversationViewController") } - - override func viewWillAppear(animated: Bool) { - super.viewWillAppear(animated) - - // 尝试恢复原始的 NavigationControllerDelegate,如果自定义 push 了才需要 - if let delegate = originalNavigationControllerDelegate { - navigationController?.delegate = delegate - } - } override func viewDidLoad() { super.viewDidLoad() @@ -329,27 +320,121 @@ class ConversationViewController: BaseViewController { } } } - - func tryRecoverMessageToolBar() { - if let - draft = conversation.draft, - state = MessageToolbarState(rawValue: draft.messageToolbarState) { - - if state == .TextInputing || state == .Default { - messageToolbar.messageTextView.text = draft.text - } - // 恢复时特别注意:因为键盘改由用户触发,因此 - if state == .TextInputing || state == .BeginTextInput { - // 这两种状态时不恢复 messageToolbar.state - return + + override func viewWillAppear(animated: Bool) { + super.viewWillAppear(animated) + + // 尝试恢复原始的 NavigationControllerDelegate,如果自定义 push 了才需要 + if let delegate = originalNavigationControllerDelegate { + navigationController?.delegate = delegate + } + + if isFirstAppear { + + // MARK: MessageToolbar State Transitions + + messageToolbar.stateTransitionAction = { [weak self] (messageToolbar, previousState, currentState) in + + if let strongSelf = self { + + switch (previousState, currentState) { + + case (.MoreMessages, .Default): fallthrough + case (.MoreMessages, .VoiceRecord): + + dispatch_async(dispatch_get_main_queue()) { [weak self] in + + UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseInOut, animations: { _ in + + strongSelf.conversationCollectionView.contentOffset.y -= strongSelf.moreMessageTypesViewDefaultHeight + strongSelf.conversationCollectionView.contentInset.bottom = strongSelf.messageToolbar.frame.height + + strongSelf.messageToolbarBottomConstraint.constant = 0 + strongSelf.view.layoutIfNeeded() + + }, completion: { finished in + }) + } + + default: + + if currentState == .MoreMessages { + + if previousState != .BeginTextInput && previousState != .TextInputing { + + dispatch_async(dispatch_get_main_queue()) { [weak self] in + + UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseInOut, animations: { _ in + + strongSelf.conversationCollectionView.contentOffset.y += strongSelf.moreMessageTypesViewDefaultHeight + strongSelf.conversationCollectionView.contentInset.bottom = strongSelf.messageToolbar.frame.height + strongSelf.moreMessageTypesViewDefaultHeight + + strongSelf.messageToolbarBottomConstraint.constant = strongSelf.moreMessageTypesViewDefaultHeight + strongSelf.view.layoutIfNeeded() + + }, completion: { finished in + }) + } + } + + // touch to create (if need) for faster appear + delay(0.2) { + self?.imagePicker.hidesBarsOnTap = false + } + } + } + + // 尝试保留草稿 + + let realm = Realm() + + if let draft = strongSelf.conversation.draft { + realm.write { + draft.messageToolbarState = currentState.rawValue + + if currentState == .BeginTextInput || currentState == .TextInputing { + draft.text = messageToolbar.messageTextView.text + } + } + + } else { + let draft = Draft() + draft.messageToolbarState = currentState.rawValue + + realm.write { + strongSelf.conversation.draft = draft + } + } } - - // 这句要放在最后,因为它会触发 stateTransitionAction - // 只恢复不改变高度的状态 - if state == .VoiceRecord { - messageToolbar.state = state + } + + // 在这里才尝试恢复 messageToolbar 的状态,因为依赖 stateTransitionAction + + func tryRecoverMessageToolBar() { + if let + draft = conversation.draft, + state = MessageToolbarState(rawValue: draft.messageToolbarState) { + + if state == .TextInputing || state == .Default { + messageToolbar.messageTextView.text = draft.text + } + + // 恢复时特别注意:因为键盘改由用户触发,因此 + if state == .TextInputing || state == .BeginTextInput { + // 这两种状态时不恢复 messageToolbar.state + return + } + + // 这句要放在最后,因为它会触发 stateTransitionAction + // 只恢复不改变高度的状态 + if state == .VoiceRecord { + messageToolbar.state = state + } } + } + + tryRecoverMessageToolBar() } } @@ -651,87 +736,6 @@ class ConversationViewController: BaseViewController { self?.swipeUpPromptLabel.text = text } - // MARK: MessageToolbar State Transitions - - messageToolbar.stateTransitionAction = { [weak self] (messageToolbar, previousState, currentState) in - - if let strongSelf = self { - - switch (previousState, currentState) { - - case (.MoreMessages, .Default): fallthrough - case (.MoreMessages, .VoiceRecord): - - dispatch_async(dispatch_get_main_queue()) { [weak self] in - - UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseInOut, animations: { _ in - - strongSelf.conversationCollectionView.contentOffset.y -= strongSelf.moreMessageTypesViewDefaultHeight - strongSelf.conversationCollectionView.contentInset.bottom = strongSelf.messageToolbar.frame.height - - strongSelf.messageToolbarBottomConstraint.constant = 0 - strongSelf.view.layoutIfNeeded() - - }, completion: { finished in - }) - } - - default: - - if currentState == .MoreMessages { - - if previousState != .BeginTextInput && previousState != .TextInputing { - - dispatch_async(dispatch_get_main_queue()) { [weak self] in - - UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseInOut, animations: { _ in - - strongSelf.conversationCollectionView.contentOffset.y += strongSelf.moreMessageTypesViewDefaultHeight - strongSelf.conversationCollectionView.contentInset.bottom = strongSelf.messageToolbar.frame.height + strongSelf.moreMessageTypesViewDefaultHeight - - strongSelf.messageToolbarBottomConstraint.constant = strongSelf.moreMessageTypesViewDefaultHeight - strongSelf.view.layoutIfNeeded() - - }, completion: { finished in - }) - } - } - - // touch to create (if need) for faster appear - delay(0.2) { - self?.imagePicker.hidesBarsOnTap = false - } - } - } - - // 尝试保留草稿 - - let realm = Realm() - - if let draft = strongSelf.conversation.draft { - realm.write { - draft.messageToolbarState = currentState.rawValue - - if currentState == .BeginTextInput || currentState == .TextInputing { - draft.text = messageToolbar.messageTextView.text - } - } - - } else { - let draft = Draft() - draft.messageToolbarState = currentState.rawValue - - realm.write { - strongSelf.conversation.draft = draft - } - } - } - } - - // 在这里才尝试恢复 messageToolbar 的状态,因为依赖 stateTransitionAction - - tryRecoverMessageToolBar() - // MARK: More Message Types choosePhotoButton.title = NSLocalizedString("Choose photo", comment: "") From 612710076be4c3477ceb9f82a42a25d7c88c7d73 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 11:29:32 +0800 Subject: [PATCH 05/19] fix MessageToolbar's change corner animation --- Yep/Views/MessageToolbar/MessageToolbar.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Yep/Views/MessageToolbar/MessageToolbar.swift b/Yep/Views/MessageToolbar/MessageToolbar.swift index ebda9dde..e851313d 100644 --- a/Yep/Views/MessageToolbar/MessageToolbar.swift +++ b/Yep/Views/MessageToolbar/MessageToolbar.swift @@ -272,8 +272,8 @@ class MessageToolbar: UIToolbar { func showVoiceButtonAnimation() { let animation = CABasicAnimation(keyPath: "cornerRadius") - animation.fromValue = voiceRecordButton.layer.cornerRadius - let newCornerRadius = CGRectGetHeight(voiceRecordButton.bounds) * 0.5 + animation.fromValue = normalCornerRadius + let newCornerRadius: CGFloat = 17 animation.toValue = newCornerRadius animation.timingFunction = CAMediaTimingFunction(name: "easeInEaseOut") animation.repeatCount = 0 @@ -281,7 +281,7 @@ class MessageToolbar: UIToolbar { voiceRecordButton.layer.addAnimation(animation, forKey: "cornerRadius") voiceRecordButton.layer.cornerRadius = newCornerRadius - messageTextView.layer.cornerRadius = CGRectGetHeight(messageTextView.bounds) * 0.5 + messageTextView.layer.cornerRadius = newCornerRadius } func hideVoiceButtonAnimation() { From e9d86b4acae9c544b161427df71103df98815db1 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 11:38:18 +0800 Subject: [PATCH 06/19] remove text when change to VoiceRecord --- Yep/Views/MessageToolbar/MessageToolbar.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Yep/Views/MessageToolbar/MessageToolbar.swift b/Yep/Views/MessageToolbar/MessageToolbar.swift index e851313d..9d58e8d3 100644 --- a/Yep/Views/MessageToolbar/MessageToolbar.swift +++ b/Yep/Views/MessageToolbar/MessageToolbar.swift @@ -84,6 +84,8 @@ class MessageToolbar: UIToolbar { messageTextView.hidden = true voiceRecordButton.hidden = false + messageTextView.text = nil + micButton.setImage(UIImage(named: "icon_keyboard"), forState: .Normal) micButton.tintColor = UIColor.messageToolBarNormalColor() From 45342804566aa37ebe65623e3d23a2182cab2292 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 12:06:19 +0800 Subject: [PATCH 07/19] move updateDraft to MessageToolbar (now only save once when user leave ConversationViewController) --- .../ConversationViewController.swift | 12 ++++++ Yep/Views/MessageToolbar/MessageToolbar.swift | 43 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 5dd57421..609f8b15 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -332,6 +332,10 @@ class ConversationViewController: BaseViewController { if isFirstAppear { + // 为记录草稿准备 + + messageToolbar.conversation = conversation + // MARK: MessageToolbar State Transitions messageToolbar.stateTransitionAction = { [weak self] (messageToolbar, previousState, currentState) in @@ -385,6 +389,7 @@ class ConversationViewController: BaseViewController { } } + /* // 尝试保留草稿 let realm = Realm() @@ -406,6 +411,7 @@ class ConversationViewController: BaseViewController { strongSelf.conversation.draft = draft } } + */ } } @@ -809,6 +815,12 @@ class ConversationViewController: BaseViewController { } } + override func viewWillDisappear(animated: Bool) { + super.viewWillDisappear(animated) + + NSNotificationCenter.defaultCenter().postNotificationName(MessageToolbar.Notification.updateDraft, object: nil) + } + override func viewDidDisappear(animated: Bool) { super.viewDidDisappear(animated) diff --git a/Yep/Views/MessageToolbar/MessageToolbar.swift b/Yep/Views/MessageToolbar/MessageToolbar.swift index 9d58e8d3..93b97608 100644 --- a/Yep/Views/MessageToolbar/MessageToolbar.swift +++ b/Yep/Views/MessageToolbar/MessageToolbar.swift @@ -38,6 +38,22 @@ class MessageToolbar: UIToolbar { let messageTextAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(15)] + deinit { + NSNotificationCenter.defaultCenter().removeObserver(self) + } + + struct Notification { + static let updateDraft = "UpdateDraftOfConversation" + } + + var conversation: Conversation? { + willSet { + if let conversation = newValue { + NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateDraft:", name: Notification.updateDraft, object: nil) + } + } + } + var stateTransitionAction: ((messageToolbar: MessageToolbar, previousState: MessageToolbarState, currentState: MessageToolbarState) -> Void)? var previousState: MessageToolbarState = .Default @@ -322,6 +338,33 @@ class MessageToolbar: UIToolbar { // MARK: Actions + func updateDraft(notification: NSNotification) { + + if let conversation = conversation, realm = conversation.realm { + + if let draft = conversation.draft { + + realm.write { [weak self] in + if let strongSelf = self { + draft.messageToolbarState = strongSelf.state.rawValue + + if strongSelf.state == .BeginTextInput || strongSelf.state == .TextInputing { + draft.text = strongSelf.messageTextView.text + } + } + } + + } else { + let draft = Draft() + draft.messageToolbarState = state.rawValue + + realm.write { + conversation.draft = draft + } + } + } + } + func trySendTextMessage() { if let textSendAction = textSendAction { textSendAction(messageToolBar: self) From a3eea4bfd5ab930ef6c7819acf3f0bd67368fcaa Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 12:07:35 +0800 Subject: [PATCH 08/19] clean code; when applicationDidEnterBackground updateDraft --- Yep/AppDelegate.swift | 2 ++ .../ConversationViewController.swift | 24 ------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index 6db7ac2c..59b52c2d 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -142,6 +142,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + + NSNotificationCenter.defaultCenter().postNotificationName(MessageToolbar.Notification.updateDraft, object: nil) } func applicationWillEnterForeground(application: UIApplication) { diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 609f8b15..040fced5 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -388,30 +388,6 @@ class ConversationViewController: BaseViewController { } } } - - /* - // 尝试保留草稿 - - let realm = Realm() - - if let draft = strongSelf.conversation.draft { - realm.write { - draft.messageToolbarState = currentState.rawValue - - if currentState == .BeginTextInput || currentState == .TextInputing { - draft.text = messageToolbar.messageTextView.text - } - } - - } else { - let draft = Draft() - draft.messageToolbarState = currentState.rawValue - - realm.write { - strongSelf.conversation.draft = draft - } - } - */ } } From 7f4c290fa19695a20bfbcd497c1047d1000c7266 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 13:07:51 +0800 Subject: [PATCH 09/19] add shareOthersProfileButton if can --- .../Profile/ProfileViewController.swift | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index b1ba4c96..5a39ecd8 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -454,11 +454,28 @@ class ProfileViewController: UIViewController { } } - // share button + // share my profile button if customNavigationItem.leftBarButtonItem == nil { - let shareButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "tryShareProfile") - customNavigationItem.leftBarButtonItem = shareButton + let shareMyProfileButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "tryShareMyProfile") + customNavigationItem.leftBarButtonItem = shareMyProfileButton + } + + } else { + // share others' profile button + + var username = "" + + switch profileUser { + case .DiscoveredUserType(let discoveredUser): + username = discoveredUser.username ?? "" + case .UserType(let user): + username = user.username + } + + if !username.isEmpty { + let shareOthersProfileButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "shareOthersProfile") + customNavigationItem.rightBarButtonItem = shareOthersProfileButton } } } @@ -491,7 +508,7 @@ class ProfileViewController: UIViewController { // MARK: Actions - func tryShareProfile() { + func tryShareMyProfile() { if let myUserID = YepUserDefaults.userID.value, @@ -590,6 +607,10 @@ class ProfileViewController: UIViewController { } } + func shareOthersProfile() { + println("shareOthersProfile") + } + func pickSkills() { let storyboard = UIStoryboard(name: "Intro", bundle: nil) From 574a2da319b13be1b7748fa99c91b20e15b94528 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 13:33:27 +0800 Subject: [PATCH 10/19] logic of shareOthersProfile --- .../Profile/ProfileViewController.swift | 102 ++++++++++++++++-- 1 file changed, 92 insertions(+), 10 deletions(-) diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index 5a39ecd8..9a7673bb 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -78,6 +78,42 @@ enum ProfileUser { case DiscoveredUserType(DiscoveredUser) case UserType(User) + var username: String? { + + var username: String? = nil + + switch self { + + case .DiscoveredUserType(let discoveredUser): + username = discoveredUser.username + + case .UserType(let user): + if !user.username.isEmpty { + username = user.username + } + } + + return username + } + + var avatarURLString: String? { + + var avatarURLString: String? = nil + + switch self { + + case .DiscoveredUserType(let discoveredUser): + avatarURLString = discoveredUser.avatarURLString + + case .UserType(let user): + if !user.avatarURLString.isEmpty { + avatarURLString = user.avatarURLString + } + } + + return avatarURLString + } + var isMe: Bool { let userID: String @@ -464,16 +500,7 @@ class ProfileViewController: UIViewController { } else { // share others' profile button - var username = "" - - switch profileUser { - case .DiscoveredUserType(let discoveredUser): - username = discoveredUser.username ?? "" - case .UserType(let user): - username = user.username - } - - if !username.isEmpty { + if let _ = profileUser.username { let shareOthersProfileButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "shareOthersProfile") customNavigationItem.rightBarButtonItem = shareOthersProfileButton } @@ -609,6 +636,61 @@ class ProfileViewController: UIViewController { func shareOthersProfile() { println("shareOthersProfile") + + if let username = profileUser?.username { + if let profileURL = NSURL(string: "http://soyep.com/\(username)") { + + MonkeyKing.registerAccount(.WeChat(appID: YepConfig.ChinaSocialNetwork.WeChat.appID)) + + var thumbnail: UIImage? + + if let + avatarURLString = profileUser?.avatarURLString, + avatar = avatarWithAvatarURLString(avatarURLString, inRealm: Realm()) { + if let + avatarFileURL = NSFileManager.yepAvatarURLWithName(avatar.avatarFileName), + avatarFilePath = avatarFileURL.path, + image = UIImage(contentsOfFile: avatarFilePath) { + thumbnail = image.roundImageOfRadius(50) + } + } + + let info = MonkeyKing.Message.WeChatSubtype.Info( + title: NSLocalizedString("Match me if you can", comment: ""), + description: NSLocalizedString("From Yep with Skills", comment: ""), + thumbnail: thumbnail, + media: .URL(profileURL) + ) + + let sessionMessage = MonkeyKing.Message.WeChat(.Session(info)) + + let weChatSessionActivity = WeChatActivity( + type: .Session, + canPerform: sessionMessage.canBeDelivered, + perform: { + MonkeyKing.shareMessage(sessionMessage) { success in + println("share Profile to WeChat Session success: \(success)") + } + } + ) + + let timelineMessage = MonkeyKing.Message.WeChat(.Timeline(info)) + + let weChatTimelineActivity = WeChatActivity( + type: .Timeline, + canPerform: timelineMessage.canBeDelivered, + perform: { + MonkeyKing.shareMessage(timelineMessage) { success in + println("share Profile to WeChat Timeline success: \(success)") + } + } + ) + + let activityViewController = UIActivityViewController(activityItems: [profileURL], applicationActivities: [weChatSessionActivity, weChatTimelineActivity]) + + self.presentViewController(activityViewController, animated: true, completion: nil) + } + } } func pickSkills() { From 262d95b24ad1cc471e6a74a2a7eb655f2b356af5 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 13:47:57 +0800 Subject: [PATCH 11/19] refactor shareProfile --- .../Profile/ProfileViewController.swift | 150 +++++++++++------- 1 file changed, 93 insertions(+), 57 deletions(-) diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index 9a7673bb..3b1ce90a 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -535,8 +535,98 @@ class ProfileViewController: UIViewController { // MARK: Actions + private func shareProfile() { + + if let username = profileUser?.username, profileURL = NSURL(string: "http://soyep.com/\(username)") { + + MonkeyKing.registerAccount(.WeChat(appID: YepConfig.ChinaSocialNetwork.WeChat.appID)) + + var thumbnail: UIImage? + + if let + avatarURLString = profileUser?.avatarURLString, + avatar = avatarWithAvatarURLString(avatarURLString, inRealm: Realm()) { + if let + avatarFileURL = NSFileManager.yepAvatarURLWithName(avatar.avatarFileName), + avatarFilePath = avatarFileURL.path, + image = UIImage(contentsOfFile: avatarFilePath) { + thumbnail = image.roundImageOfRadius(50) + } + } + + let info = MonkeyKing.Message.WeChatSubtype.Info( + title: NSLocalizedString("Match me if you can", comment: ""), + description: NSLocalizedString("From Yep with Skills", comment: ""), + thumbnail: thumbnail, + media: .URL(profileURL) + ) + + let sessionMessage = MonkeyKing.Message.WeChat(.Session(info)) + + let weChatSessionActivity = WeChatActivity( + type: .Session, + canPerform: sessionMessage.canBeDelivered, + perform: { + MonkeyKing.shareMessage(sessionMessage) { success in + println("share Profile to WeChat Session success: \(success)") + } + } + ) + + let timelineMessage = MonkeyKing.Message.WeChat(.Timeline(info)) + + let weChatTimelineActivity = WeChatActivity( + type: .Timeline, + canPerform: timelineMessage.canBeDelivered, + perform: { + MonkeyKing.shareMessage(timelineMessage) { success in + println("share Profile to WeChat Timeline success: \(success)") + } + } + ) + + let activityViewController = UIActivityViewController(activityItems: [profileURL], applicationActivities: [weChatSessionActivity, weChatTimelineActivity]) + + self.presentViewController(activityViewController, animated: true, completion: nil) + } + } + func tryShareMyProfile() { + if let _ = profileUser?.username { + shareProfile() + + } else { + + YepAlert.textInput(title: NSLocalizedString("Create a username", comment: ""), message: NSLocalizedString("In order to share your profile, create a unique username first.", comment: ""), placeholder: NSLocalizedString("use letters, numbers, and underscore", comment: ""), oldText: nil, confirmTitle: NSLocalizedString("Create", comment: ""), cancelTitle: NSLocalizedString("Cancel", comment: ""), inViewController: self, withConfirmAction: { text in + + let newUsername = text + + updateMyselfWithInfo(["username": newUsername], failureHandler: { [weak self] reason, errorMessage in + defaultFailureHandler(reason, errorMessage) + + YepAlert.alertSorry(message: errorMessage ?? NSLocalizedString("Create username failed!", comment: ""), inViewController: self) + + }, completion: { success in + dispatch_async(dispatch_get_main_queue()) { [weak self] in + let realm = Realm() + if let + myUserID = YepUserDefaults.userID.value, + me = userWithUserID(myUserID, inRealm: realm) { + realm.write { + me.username = newUsername + } + } + + self?.shareProfile() + } + }) + + }, cancelAction: { + }) + } + + /* if let myUserID = YepUserDefaults.userID.value, me = userWithUserID(myUserID, inRealm: Realm()) { @@ -632,66 +722,12 @@ class ProfileViewController: UIViewController { shareProfileWithUsername(username) } } + */ } func shareOthersProfile() { - println("shareOthersProfile") - - if let username = profileUser?.username { - if let profileURL = NSURL(string: "http://soyep.com/\(username)") { - - MonkeyKing.registerAccount(.WeChat(appID: YepConfig.ChinaSocialNetwork.WeChat.appID)) - - var thumbnail: UIImage? - - if let - avatarURLString = profileUser?.avatarURLString, - avatar = avatarWithAvatarURLString(avatarURLString, inRealm: Realm()) { - if let - avatarFileURL = NSFileManager.yepAvatarURLWithName(avatar.avatarFileName), - avatarFilePath = avatarFileURL.path, - image = UIImage(contentsOfFile: avatarFilePath) { - thumbnail = image.roundImageOfRadius(50) - } - } - - let info = MonkeyKing.Message.WeChatSubtype.Info( - title: NSLocalizedString("Match me if you can", comment: ""), - description: NSLocalizedString("From Yep with Skills", comment: ""), - thumbnail: thumbnail, - media: .URL(profileURL) - ) - - let sessionMessage = MonkeyKing.Message.WeChat(.Session(info)) - - let weChatSessionActivity = WeChatActivity( - type: .Session, - canPerform: sessionMessage.canBeDelivered, - perform: { - MonkeyKing.shareMessage(sessionMessage) { success in - println("share Profile to WeChat Session success: \(success)") - } - } - ) - - let timelineMessage = MonkeyKing.Message.WeChat(.Timeline(info)) - - let weChatTimelineActivity = WeChatActivity( - type: .Timeline, - canPerform: timelineMessage.canBeDelivered, - perform: { - MonkeyKing.shareMessage(timelineMessage) { success in - println("share Profile to WeChat Timeline success: \(success)") - } - } - ) - - let activityViewController = UIActivityViewController(activityItems: [profileURL], applicationActivities: [weChatSessionActivity, weChatTimelineActivity]) - - self.presentViewController(activityViewController, animated: true, completion: nil) - } - } - } + shareProfile() + } func pickSkills() { From 6cf35f217a069acc2c15d83c90bffdaa02f49c58 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 13:57:41 +0800 Subject: [PATCH 12/19] clean code; refactor userID of ProfileUser --- .../Profile/ProfileViewController.swift | 118 ++---------------- 1 file changed, 12 insertions(+), 106 deletions(-) diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index 3b1ce90a..430e896f 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -78,6 +78,16 @@ enum ProfileUser { case DiscoveredUserType(DiscoveredUser) case UserType(User) + var userID: String { + switch self { + case .DiscoveredUserType(let discoveredUser): + return discoveredUser.id + + case .UserType(let user): + return user.userID + } + } + var username: String? { var username: String? = nil @@ -436,20 +446,12 @@ class ProfileViewController: UIViewController { if let profileUser = profileUser { - let userID: String - switch profileUser { case .DiscoveredUserType(let discoveredUser): - - userID = discoveredUser.id - customNavigationItem.title = discoveredUser.nickname case .UserType(let user): - - userID = user.userID - customNavigationItem.title = user.nickname if user.friendState == UserFriendState.Me.rawValue { @@ -463,6 +465,8 @@ class ProfileViewController: UIViewController { if !profileUserIsMe { + let userID = profileUser.userID + userInfoOfUserWithUserID(userID, failureHandler: nil, completion: { [weak self] userInfo in //println("userInfoOfUserWithUserID \(userInfo)") @@ -625,104 +629,6 @@ class ProfileViewController: UIViewController { }, cancelAction: { }) } - - /* - if let - myUserID = YepUserDefaults.userID.value, - me = userWithUserID(myUserID, inRealm: Realm()) { - - let username = me.username - - let shareProfileWithUsername: String -> Void = { [weak self] username in - - if let profileURL = NSURL(string: "http://soyep.com/\(username)") { - - MonkeyKing.registerAccount(.WeChat(appID: YepConfig.ChinaSocialNetwork.WeChat.appID)) - - var thumbnail: UIImage? - - if let - avatarURLString = YepUserDefaults.avatarURLString.value, - avatar = avatarWithAvatarURLString(avatarURLString, inRealm: Realm()) { - if let - avatarFileURL = NSFileManager.yepAvatarURLWithName(avatar.avatarFileName), - avatarFilePath = avatarFileURL.path, - image = UIImage(contentsOfFile: avatarFilePath) { - thumbnail = image.roundImageOfRadius(50) - } - } - - let info = MonkeyKing.Message.WeChatSubtype.Info( - title: NSLocalizedString("Match me if you can", comment: ""), - description: NSLocalizedString("From Yep with Skills", comment: ""), - thumbnail: thumbnail, - media: .URL(profileURL) - ) - - let sessionMessage = MonkeyKing.Message.WeChat(.Session(info)) - - let weChatSessionActivity = WeChatActivity( - type: .Session, - canPerform: sessionMessage.canBeDelivered, - perform: { - MonkeyKing.shareMessage(sessionMessage) { success in - println("share Profile to WeChat Session success: \(success)") - } - } - ) - - let timelineMessage = MonkeyKing.Message.WeChat(.Timeline(info)) - - let weChatTimelineActivity = WeChatActivity( - type: .Timeline, - canPerform: timelineMessage.canBeDelivered, - perform: { - MonkeyKing.shareMessage(timelineMessage) { success in - println("share Profile to WeChat Timeline success: \(success)") - } - } - ) - - let activityViewController = UIActivityViewController(activityItems: [profileURL], applicationActivities: [weChatSessionActivity, weChatTimelineActivity]) - - self?.presentViewController(activityViewController, animated: true, completion: nil) - } - } - - if username.isEmpty { - - YepAlert.textInput(title: NSLocalizedString("Create a username", comment: ""), message: NSLocalizedString("In order to share your profile, create a unique username first.", comment: ""), placeholder: NSLocalizedString("use letters, numbers, and underscore", comment: ""), oldText: nil, confirmTitle: NSLocalizedString("Create", comment: ""), cancelTitle: NSLocalizedString("Cancel", comment: ""), inViewController: self, withConfirmAction: { text in - - let newUsername = text - - updateMyselfWithInfo(["username": newUsername], failureHandler: { [weak self] reason, errorMessage in - defaultFailureHandler(reason, errorMessage) - - YepAlert.alertSorry(message: errorMessage ?? NSLocalizedString("Create username failed!", comment: ""), inViewController: self) - - }, completion: { success in - dispatch_async(dispatch_get_main_queue()) { - let realm = Realm() - if let - myUserID = YepUserDefaults.userID.value, - me = userWithUserID(myUserID, inRealm: realm) { - realm.write { - me.username = newUsername - } - } - - shareProfileWithUsername(newUsername) - } - }) - - }, cancelAction: { - }) - - } else { - shareProfileWithUsername(username) - } - } - */ } func shareOthersProfile() { From 4c9161b872db5999f0ae31f0fb7e22e55b2bd8a9 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 14:01:20 +0800 Subject: [PATCH 13/19] indent --- Yep/ViewControllers/Profile/ProfileViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index 430e896f..fd2ee588 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -633,7 +633,7 @@ class ProfileViewController: UIViewController { func shareOthersProfile() { shareProfile() - } + } func pickSkills() { From 6529b3f7b8a7bfbea30e465dc3581574187b5fbc Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 14:21:50 +0800 Subject: [PATCH 14/19] new NSLocationWhenInUseUsageDescription with trans --- Yep.xcodeproj/project.pbxproj | 14 ++++++++++++++ Yep/Info.plist | 2 +- Yep/en.lproj/InfoPlist.strings | 9 +++++++++ Yep/zh-Hans.lproj/InfoPlist.strings | 9 +++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Yep/en.lproj/InfoPlist.strings create mode 100644 Yep/zh-Hans.lproj/InfoPlist.strings diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index a0742b12..66143f75 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -124,6 +124,7 @@ 5056AD6E1B05CB92003F9359 /* ProfileSocialAccountImagesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5056AD6C1B05CB92003F9359 /* ProfileSocialAccountImagesCell.swift */; }; 5056AD6F1B05CB92003F9359 /* ProfileSocialAccountImagesCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5056AD6D1B05CB92003F9359 /* ProfileSocialAccountImagesCell.xib */; }; 505A48401B4E70CB00C3A301 /* RegisterSelectSkillsLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505A483F1B4E70CB00C3A301 /* RegisterSelectSkillsLayout.swift */; }; + 505C338B1BAA92CA00E044E2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 505C338D1BAA92CA00E044E2 /* InfoPlist.strings */; }; 505EC8131ADE607D001D27E0 /* SkillCategoryButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505EC8121ADE607D001D27E0 /* SkillCategoryButton.swift */; }; 505EC8171ADF8151001D27E0 /* SkillCategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505EC8151ADF8151001D27E0 /* SkillCategoryCell.swift */; }; 505EC8181ADF8151001D27E0 /* SkillCategoryCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 505EC8161ADF8151001D27E0 /* SkillCategoryCell.xib */; }; @@ -386,6 +387,8 @@ 5056AD6C1B05CB92003F9359 /* ProfileSocialAccountImagesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProfileSocialAccountImagesCell.swift; path = Views/Cells/ProfileSocialAccount/ProfileSocialAccountImagesCell.swift; sourceTree = ""; }; 5056AD6D1B05CB92003F9359 /* ProfileSocialAccountImagesCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ProfileSocialAccountImagesCell.xib; path = Views/Cells/ProfileSocialAccount/ProfileSocialAccountImagesCell.xib; sourceTree = ""; }; 505A483F1B4E70CB00C3A301 /* RegisterSelectSkillsLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RegisterSelectSkillsLayout.swift; path = ViewControllers/Register/RegisterSelectSkillsLayout.swift; sourceTree = ""; }; + 505C338C1BAA92CA00E044E2 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 505C338E1BAA92CD00E044E2 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = ""; }; 505EC8121ADE607D001D27E0 /* SkillCategoryButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SkillCategoryButton.swift; path = Views/Buttons/SkillCategoryButton.swift; sourceTree = ""; }; 505EC8151ADF8151001D27E0 /* SkillCategoryCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SkillCategoryCell.swift; path = Views/Cells/SkillCategory/SkillCategoryCell.swift; sourceTree = ""; }; 505EC8161ADF8151001D27E0 /* SkillCategoryCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = SkillCategoryCell.xib; path = Views/Cells/SkillCategory/SkillCategoryCell.xib; sourceTree = ""; }; @@ -632,6 +635,7 @@ 0A8F54B91AB67D11004AD60E /* LaunchScreen.xib */, 0A8F54AE1AB67D11004AD60E /* Supporting Files */, 5008A1951B8DB8B500E94274 /* Localizable.strings */, + 505C338D1BAA92CA00E044E2 /* InfoPlist.strings */, ); path = Yep; sourceTree = ""; @@ -1809,6 +1813,7 @@ buildActionMask = 2147483647; files = ( 5023DE381AB6979600B3EE96 /* ConversationCell.xib in Resources */, + 505C338B1BAA92CA00E044E2 /* InfoPlist.strings in Resources */, 50C090A11ADE391600CC6389 /* AddSkillsReusableView.xib in Resources */, 504F415B1AD5028200FBB19A /* SkillCell.xib in Resources */, 50E348931B9063A700A8E699 /* AboutCell.xib in Resources */, @@ -2164,6 +2169,15 @@ name = Intro.storyboard; sourceTree = ""; }; + 505C338D1BAA92CA00E044E2 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 505C338C1BAA92CA00E044E2 /* en */, + 505C338E1BAA92CD00E044E2 /* zh-Hans */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ diff --git a/Yep/Info.plist b/Yep/Info.plist index 79d0c13d..bba8aacb 100644 --- a/Yep/Info.plist +++ b/Yep/Info.plist @@ -55,7 +55,7 @@ LSRequiresIPhoneOS NSLocationWhenInUseUsageDescription - Find pepole around you + Meeting with near genius UIBackgroundModes fetch diff --git a/Yep/en.lproj/InfoPlist.strings b/Yep/en.lproj/InfoPlist.strings new file mode 100644 index 00000000..ba5be173 --- /dev/null +++ b/Yep/en.lproj/InfoPlist.strings @@ -0,0 +1,9 @@ +/* + InfoPlist.strings + Yep + + Created by nixzhu on 15/9/17. + Copyright (c) 2015年 Catch Inc. All rights reserved. +*/ + +"NSLocationWhenInUseUsageDescription" = "Meeting with near genius"; \ No newline at end of file diff --git a/Yep/zh-Hans.lproj/InfoPlist.strings b/Yep/zh-Hans.lproj/InfoPlist.strings new file mode 100644 index 00000000..d65d5d52 --- /dev/null +++ b/Yep/zh-Hans.lproj/InfoPlist.strings @@ -0,0 +1,9 @@ +/* + InfoPlist.strings + Yep + + Created by nixzhu on 15/9/17. + Copyright (c) 2015年 Catch Inc. All rights reserved. +*/ + +"NSLocationWhenInUseUsageDescription" = "与附近的天才相遇"; \ No newline at end of file From 7b4a0891fae01285be49fc8150563e7638a076c8 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 14:57:20 +0800 Subject: [PATCH 15/19] refactor parseDiscoveredUser --- Yep/Services/YepService.swift | 41 +++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index 2110f36d..7ce16637 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -1118,30 +1118,33 @@ let parseDiscoveredUser: JSONDictionary -> DiscoveredUser? = { userInfo in createdUnixTime = userInfo["created_at"] as? NSTimeInterval, lastSignInUnixTime = userInfo["last_sign_in_at"] as? NSTimeInterval, longitude = userInfo["longitude"] as? Double, - latitude = userInfo["latitude"] as? Double, - //distance = userInfo["distance"] as? Double, - masterSkillsData = userInfo["master_skills"] as? [JSONDictionary], - learningSkillsData = userInfo["learning_skills"] as? [JSONDictionary], - socialAccountProvidersInfo = userInfo["providers"] as? [String: Bool] { + latitude = userInfo["latitude"] as? Double { let username = userInfo["username"] as? String - - let masterSkills = skillsFromSkillsData(masterSkillsData) - let learningSkills = skillsFromSkillsData(learningSkillsData) - - var socialAccountProviders = Array() - - for (name, enabled) in socialAccountProvidersInfo { - let provider = DiscoveredUser.SocialAccountProvider(name: name, enabled: enabled) - - socialAccountProviders.append(provider) - } - let introduction = userInfo["introduction"] as? String let badge = userInfo["badge"] as? String - let distance = userInfo["distance"] as? Double + var masterSkills: [Skill] = [] + if let masterSkillsData = userInfo["master_skills"] as? [JSONDictionary] { + masterSkills = skillsFromSkillsData(masterSkillsData) + } + + var learningSkills: [Skill] = [] + if let learningSkillsData = userInfo["learning_skills"] as? [JSONDictionary] { + + learningSkills = skillsFromSkillsData(learningSkillsData) + } + + var socialAccountProviders = Array() + if let socialAccountProvidersInfo = userInfo["providers"] as? [String: Bool] { + for (name, enabled) in socialAccountProvidersInfo { + let provider = DiscoveredUser.SocialAccountProvider(name: name, enabled: enabled) + + socialAccountProviders.append(provider) + } + } + let discoverUser = DiscoveredUser(id: id, username: username, nickname: nickname, introduction: introduction, avatarURLString: avatarURLString, badge: badge, createdUnixTime: createdUnixTime, lastSignInUnixTime: lastSignInUnixTime, longitude: longitude, latitude: latitude, distance: distance, masterSkills: masterSkills, learningSkills: learningSkills, socialAccountProviders: socialAccountProviders) return discoverUser @@ -1152,7 +1155,7 @@ let parseDiscoveredUser: JSONDictionary -> DiscoveredUser? = { userInfo in let parseDiscoveredUsers: JSONDictionary -> [DiscoveredUser]? = { data in - //println("discoverUsers: \(data)") + println("discoverUsers: \(data)") if let usersData = data["users"] as? [JSONDictionary] { From 77671ab6ee41bb595a90f4c9ab27acd7c1f3ed0c Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 15:07:12 +0800 Subject: [PATCH 16/19] refresh discoveredUser for profileUser in Profile --- Yep/ViewControllers/Profile/ProfileViewController.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index fd2ee588..0838fad3 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -474,6 +474,15 @@ class ProfileViewController: UIViewController { updateUserWithUserID(userID, useUserInfo: userInfo) + if let discoveredUser = parseDiscoveredUser(userInfo) { + switch profileUser { + case .DiscoveredUserType: + self?.profileUser = ProfileUser.DiscoveredUserType(discoveredUser) + default: + break + } + } + self?.updateProfileCollectionView() }) } From 5d04eb249a4b9714ece17d2f12f7686714604f16 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 15:13:10 +0800 Subject: [PATCH 17/19] do not show wait alert for audio, image, video --- .../Conversation/ConversationViewController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Yep/ViewControllers/Conversation/ConversationViewController.swift b/Yep/ViewControllers/Conversation/ConversationViewController.swift index 040fced5..14cf4937 100644 --- a/Yep/ViewControllers/Conversation/ConversationViewController.swift +++ b/Yep/ViewControllers/Conversation/ConversationViewController.swift @@ -2087,7 +2087,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi self?.performSegueWithIdentifier("showMessageMedia", sender: message) } else { - YepAlert.alertSorry(message: NSLocalizedString("Please wait while the image is not ready!", comment: ""), inViewController: self) + //YepAlert.alertSorry(message: NSLocalizedString("Please wait while the image is not ready!", comment: ""), inViewController: self) } }, collectionView: collectionView, indexPath: indexPath) @@ -2105,7 +2105,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi self?.playMessageAudioWithMessage(message) } else { - YepAlert.alertSorry(message: NSLocalizedString("Please wait while the audio is not ready!", comment: ""), inViewController: self) + //YepAlert.alertSorry(message: NSLocalizedString("Please wait while the audio is not ready!", comment: ""), inViewController: self) } }, collectionView: collectionView, indexPath: indexPath) @@ -2129,7 +2129,7 @@ extension ConversationViewController: UICollectionViewDataSource, UICollectionVi self?.performSegueWithIdentifier("showMessageMedia", sender: message) } else { - YepAlert.alertSorry(message: NSLocalizedString("Please wait while the video is not ready!", comment: ""), inViewController: self) + //YepAlert.alertSorry(message: NSLocalizedString("Please wait while the video is not ready!", comment: ""), inViewController: self) } }, collectionView: collectionView, indexPath: indexPath) From 76cbac83d15aef8ece2b16a6e8c5679b85d72521 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 15:14:08 +0800 Subject: [PATCH 18/19] reset Realm version 0, all test app must deleted and reinstall for test --- Yep/AppDelegate.swift | 52 +------------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index 59b52c2d..20ceb12f 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -32,57 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(YepConfig.appGroupID)! let realmPath = directory.path!.stringByAppendingPathComponent("db.realm") - return Realm.Configuration(path: realmPath, schemaVersion: 17, migrationBlock: { migration, oldSchemaVersion in - - if oldSchemaVersion < 9 { - migration.enumerate(Message.className()) { oldObject, newObject in - let createdAt = oldObject!["createdAt"] as! NSDate - let updatedAt = oldObject!["updatedAt"] as! NSDate - - newObject!["createdUnixTime"] = createdAt.timeIntervalSince1970 - newObject!["updatedUnixTime"] = updatedAt.timeIntervalSince1970 - } - - migration.enumerate(Conversation.className()) { oldObject, newObject in - let updatedAt = oldObject!["updatedAt"] as! NSDate - - newObject!["updatedUnixTime"] = updatedAt.timeIntervalSince1970 - } - } - - if oldSchemaVersion < 10 { - migration.enumerate(User.className()) { oldObject, newObject in - let createdAt = oldObject!["createdAt"] as! NSDate - let lastSignInAt = oldObject!["lastSignInAt"] as! NSDate - - newObject!["createdUnixTime"] = createdAt.timeIntervalSince1970 - newObject!["lastSignInUnixTime"] = lastSignInAt.timeIntervalSince1970 - } - - migration.enumerate(Group.className()) { oldObject, newObject in - let createdAt = oldObject!["createdAt"] as! NSDate - - newObject!["createdUnixTime"] = createdAt.timeIntervalSince1970 - } - } - - if oldSchemaVersion < 14 { - migration.enumerate(Message.className()) { oldObject, newObject in - let metaDataString = oldObject!["metaData"] as! String - - if !metaDataString.isEmpty { - if let data = metaDataString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) { - let mediaMetaData = MediaMetaData() - mediaMetaData.data = data - - newObject!["mediaMetaData"] = mediaMetaData - } - } - } - } - - if oldSchemaVersion < 17 { - } + return Realm.Configuration(path: realmPath, schemaVersion: 0, migrationBlock: { migration, oldSchemaVersion in }) } From 568d69417a5af9a707afa5b6b6cf220fd4398af2 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Thu, 17 Sep 2015 15:14:32 +0800 Subject: [PATCH 19/19] update version 1.0 (89) --- Yep/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yep/Info.plist b/Yep/Info.plist index bba8aacb..27bae6fa 100644 --- a/Yep/Info.plist +++ b/Yep/Info.plist @@ -32,7 +32,7 @@ CFBundleVersion - 88 + 89 Fabric APIKey