From fd7eb796505f16bf0c114b93f7e96c2bd617f3a9 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 12:20:17 +0800 Subject: [PATCH 1/8] add UserSkillCategory; UserSkill add category & coverURLString; first Migration --- Yep/AppDelegate.swift | 10 ++++++++++ Yep/Realm/Models.swift | 16 +++++++++++++++- Yep/Services/YepService.swift | 2 +- Yep/Services/YepServiceSync.swift | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Yep/AppDelegate.swift b/Yep/AppDelegate.swift index 9c7efbcc..95b8168c 100644 --- a/Yep/AppDelegate.swift +++ b/Yep/AppDelegate.swift @@ -9,6 +9,7 @@ import UIKit import Crashlytics import AVFoundation +import Realm @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -22,6 +23,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + RLMRealm.setSchemaVersion(1, forRealmAtPath: RLMRealm.defaultRealmPath(), withMigrationBlock: { migration, oldSchemaVersion in + // We haven’t migrated anything yet, so oldSchemaVersion == 0 + if oldSchemaVersion < 1 { + // Nothing to do! + // Realm will automatically detect new properties and removed properties + // And will update the schema on disk automatically + } + }) + Crashlytics.startWithAPIKey("3030ba006e21bcf8eb4a2127b6a7931ea6667486") AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.DefaultToSpeaker, error: nil) diff --git a/Yep/Realm/Models.swift b/Yep/Realm/Models.swift index 8b38d84e..fdfa39df 100644 --- a/Yep/Realm/Models.swift +++ b/Yep/Realm/Models.swift @@ -34,11 +34,25 @@ class Avatar: RLMObject { } } -class UserSkill: RLMObject { +class UserSkillCategory: RLMObject { dynamic var skillID: String = "" dynamic var name: String = "" dynamic var localName: String = "" + var skills: [UserSkill] { + return linkingObjectsOfClass("UserSkill", forProperty: "category") as! [UserSkill] + } +} + +class UserSkill: RLMObject { + + dynamic var category: UserSkillCategory? + + dynamic var skillID: String = "" + dynamic var name: String = "" + dynamic var localName: String = "" + dynamic var coverURLString: String = "" + var learningUsers: [User] { return linkingObjectsOfClass("User", forProperty: "learningSkills") as! [User] } diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index d94696a2..ad7184a5 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -522,7 +522,7 @@ func discoverUsers(#masterSkills: [String], #learningSkills: [String], #discover let parse: JSONDictionary -> [DiscoveredUser]? = { data in -// println("discoverUsers: \(data)") + println("discoverUsers: \(data)") if let usersData = data["users"] as? [JSONDictionary] { diff --git a/Yep/Services/YepServiceSync.swift b/Yep/Services/YepServiceSync.swift index e3884405..4bacb103 100644 --- a/Yep/Services/YepServiceSync.swift +++ b/Yep/Services/YepServiceSync.swift @@ -124,7 +124,7 @@ func userSkillsFromSkillsData(skillsData: [JSONDictionary], inRealm realm: RLMRe func syncFriendshipsAndDoFurtherAction(furtherAction: () -> Void) { friendships { allFriendships in - //println("\n allFriendships: \(allFriendships)") + println("\n allFriendships: \(allFriendships)") // 先整理出所有的 friend 的 userID var remoteUerIDSet = Set() @@ -241,7 +241,7 @@ func syncFriendshipsAndDoFurtherAction(furtherAction: () -> Void) { func syncGroupsAndDoFurtherAction(furtherAction: () -> Void) { groups { allGroups in - //println("allGroups: \(allGroups)") + println("allGroups: \(allGroups)") // 先整理出所有的 group 的 groupID var remoteGroupIDSet = Set() From c7f41478eb10c8abe14ec0de3ae5bd1b30273593 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 12:41:05 +0800 Subject: [PATCH 2/8] sync userSkillCategory --- Yep/Realm/Models.swift | 7 ++++++- Yep/Services/YepServiceSync.swift | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Yep/Realm/Models.swift b/Yep/Realm/Models.swift index fdfa39df..38efd539 100644 --- a/Yep/Realm/Models.swift +++ b/Yep/Realm/Models.swift @@ -35,7 +35,7 @@ class Avatar: RLMObject { } class UserSkillCategory: RLMObject { - dynamic var skillID: String = "" + dynamic var skillCategoryID: String = "" dynamic var name: String = "" dynamic var localName: String = "" @@ -237,6 +237,11 @@ func userSkillWithSkillID(skillID: String) -> UserSkill? { return UserSkill.objectsWithPredicate(predicate).firstObject() as? UserSkill } +func userSkillCategoryWithSkillCategoryID(skillCategoryID: String) -> UserSkillCategory? { + let predicate = NSPredicate(format: "skillCategoryID = %@", skillCategoryID) + return UserSkillCategory.objectsWithPredicate(predicate).firstObject() as? UserSkillCategory +} + func userWithUserID(userID: String) -> User? { let predicate = NSPredicate(format: "userID = %@", userID) return User.objectsWithPredicate(predicate).firstObject() as? User diff --git a/Yep/Services/YepServiceSync.swift b/Yep/Services/YepServiceSync.swift index 4bacb103..0e58c723 100644 --- a/Yep/Services/YepServiceSync.swift +++ b/Yep/Services/YepServiceSync.swift @@ -96,6 +96,7 @@ func userSkillsFromSkillsData(skillsData: [JSONDictionary], inRealm realm: RLMRe for skillInfo in skillsData { if + let categoryData = skillInfo["category"] as? JSONDictionary, let skillID = skillInfo["id"] as? String, let skillName = skillInfo["name"] as? String, let skillLocalName = skillInfo["name_string"] as? String { @@ -108,12 +109,40 @@ func userSkillsFromSkillsData(skillsData: [JSONDictionary], inRealm realm: RLMRe newUserSkill.name = skillID newUserSkill.localName = skillLocalName + if let coverURLString = skillInfo["cover_url"] as? String { + newUserSkill.coverURLString = coverURLString + } + realm.addObject(newUserSkill) userSkill = newUserSkill } if let userSkill = userSkill { + + if let + skillCategoryID = categoryData["id"] as? String, + skillCategoryName = categoryData["name"] as? String, + skillCategoryLocalName = categoryData["name_string"] as? String { + + var userSkillCategory = userSkillCategoryWithSkillCategoryID(skillCategoryID) + + if userSkillCategory == nil { + let newUserSkillCategory = UserSkillCategory() + newUserSkillCategory.skillCategoryID = skillCategoryID + newUserSkillCategory.name = skillCategoryName + newUserSkillCategory.localName = skillCategoryLocalName + + realm.addObject(newUserSkillCategory) + + userSkillCategory = newUserSkillCategory + } + + if let userSkillCategory = userSkillCategory { + userSkill.category = userSkillCategory + } + } + userSkills.append(userSkill) } } From 830d1730d6de77c7b0c6fcf69c286ba3f74298c3 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 12:56:40 +0800 Subject: [PATCH 3/8] sync group members' skills info --- Yep/Services/YepServiceSync.swift | 73 ++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/Yep/Services/YepServiceSync.swift b/Yep/Services/YepServiceSync.swift index 0e58c723..1c8b9b56 100644 --- a/Yep/Services/YepServiceSync.swift +++ b/Yep/Services/YepServiceSync.swift @@ -362,14 +362,6 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL newUser.userID = ownerID - if let nickname = ownerInfo["nickname"] as? String { - newUser.nickname = nickname - } - - if let avatarURLString = ownerInfo["avatar_url"] as? String { - newUser.avatarURLString = avatarURLString - } - if let myUserID = YepUserDefaults.userID.value { if myUserID == ownerID { newUser.friendState = UserFriendState.Me.rawValue @@ -389,7 +381,33 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL if let owner = owner { realm.beginWriteTransaction() + + // 更新个人信息 + + if let nickname = ownerInfo["nickname"] as? String { + owner.nickname = nickname + } + + if let avatarURLString = ownerInfo["avatar_url"] as? String { + owner.avatarURLString = avatarURLString + } + + // 更新技能 + + if let learningSkillsData = ownerInfo["learning_skills"] as? [JSONDictionary] { + owner.learningSkills.removeAllObjects() + let userSkills = userSkillsFromSkillsData(learningSkillsData, inRealm: owner.realm) + owner.learningSkills.addObjects(userSkills) + } + + if let masterSkillsData = ownerInfo["master_skills"] as? [JSONDictionary] { + owner.masterSkills.removeAllObjects() + let userSkills = userSkillsFromSkillsData(masterSkillsData, inRealm: owner.realm) + owner.masterSkills.addObjects(userSkills) + } + group.owner = owner + realm.commitWriteTransaction() } } @@ -428,14 +446,6 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL newMember.userID = memberID - if let nickname = memberInfo["nickname"] as? String { - newMember.nickname = nickname - } - - if let avatarURLString = memberInfo["avatar_url"] as? String { - newMember.avatarURLString = avatarURLString - } - if let myUserID = YepUserDefaults.userID.value { if myUserID == memberID { newMember.friendState = UserFriendState.Me.rawValue @@ -454,6 +464,37 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL realm.commitWriteTransaction() } + + if let member = member { + + realm.beginWriteTransaction() + + // 更新个人信息 + + if let nickname = memberInfo["nickname"] as? String { + member.nickname = nickname + } + + if let avatarURLString = memberInfo["avatar_url"] as? String { + member.avatarURLString = avatarURLString + } + + // 更新技能 + + if let learningSkillsData = memberInfo["learning_skills"] as? [JSONDictionary] { + member.learningSkills.removeAllObjects() + let userSkills = userSkillsFromSkillsData(learningSkillsData, inRealm: member.realm) + member.learningSkills.addObjects(userSkills) + } + + if let masterSkillsData = memberInfo["master_skills"] as? [JSONDictionary] { + member.masterSkills.removeAllObjects() + let userSkills = userSkillsFromSkillsData(masterSkillsData, inRealm: member.realm) + member.masterSkills.addObjects(userSkills) + } + + realm.commitWriteTransaction() + } } } From ef1575fde0135f6406cabd5a0987afd268721b6a Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 13:11:27 +0800 Subject: [PATCH 4/8] sync lastSignInAt --- Yep/Services/YepServiceSync.swift | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Yep/Services/YepServiceSync.swift b/Yep/Services/YepServiceSync.swift index 1c8b9b56..32965aed 100644 --- a/Yep/Services/YepServiceSync.swift +++ b/Yep/Services/YepServiceSync.swift @@ -206,7 +206,9 @@ func syncFriendshipsAndDoFurtherAction(furtherAction: () -> Void) { let newUser = User() newUser.userID = userID - //newUser.createdAt = NSDate.dateWithISO08601String(<#dateString: String?#>) + if let createdAtString = friendInfo["created_at"] as? String { + newUser.createdAt = NSDate.dateWithISO08601String(createdAtString) + } realm.beginWriteTransaction() realm.addObject(newUser) @@ -218,6 +220,12 @@ func syncFriendshipsAndDoFurtherAction(furtherAction: () -> Void) { if let user = user { realm.beginWriteTransaction() + // 更新用户信息 + + if let lastSignInAtString = friendInfo["last_sign_in_at"] as? String { + user.lastSignInAt = NSDate.dateWithISO08601String(lastSignInAtString) + } + if let nickname = friendInfo["nickname"] as? String { user.nickname = nickname } @@ -362,6 +370,10 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL newUser.userID = ownerID + if let createdAtString = ownerInfo["created_at"] as? String { + newUser.createdAt = NSDate.dateWithISO08601String(createdAtString) + } + if let myUserID = YepUserDefaults.userID.value { if myUserID == ownerID { newUser.friendState = UserFriendState.Me.rawValue @@ -384,6 +396,10 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL // 更新个人信息 + if let lastSignInAtString = ownerInfo["last_sign_in_at"] as? String { + owner.lastSignInAt = NSDate.dateWithISO08601String(lastSignInAtString) + } + if let nickname = ownerInfo["nickname"] as? String { owner.nickname = nickname } @@ -446,6 +462,10 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL newMember.userID = memberID + if let createdAtString = memberInfo["created_at"] as? String { + newMember.createdAt = NSDate.dateWithISO08601String(createdAtString) + } + if let myUserID = YepUserDefaults.userID.value { if myUserID == memberID { newMember.friendState = UserFriendState.Me.rawValue @@ -471,6 +491,10 @@ private func syncGroupWithGroupInfo(groupInfo: JSONDictionary, inRealm realm: RL // 更新个人信息 + if let lastSignInAtString = memberInfo["last_sign_in_at"] as? String { + member.lastSignInAt = NSDate.dateWithISO08601String(lastSignInAtString) + } + if let nickname = memberInfo["nickname"] as? String { member.nickname = nickname } From a9faed05348fbf41fdd966ab55971567edf4d321 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 13:27:54 +0800 Subject: [PATCH 5/8] fill skillCategory & cover for DiscoveredUser's skills --- Yep/Services/YepService.swift | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index ad7184a5..c299d4f9 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -145,11 +145,23 @@ func verifyMobile(mobile: String, withAreaCode areaCode: String, #verifyCode: St // MARK: Skills -struct Skill: Hashable { +struct SkillCategory { let id: String let name: String let localName: String + let skills: [Skill] +} + +struct Skill: Hashable { + + let category: SkillCategory? + + let id: String + let name: String + let localName: String + let coverURLString: String? + var hashValue: Int { return id.hashValue } @@ -159,14 +171,6 @@ func ==(lhs: Skill, rhs: Skill) -> Bool { return lhs.id == rhs.id } -struct SkillCategory { - let id: String - let name: String - let localName: String - - let skills: [Skill] -} - /* func skillsInSkillCategory(skillCategoryID: String, #failureHandler: ((Reason, String?) -> Void)?, #completion: [Skill] -> Void) { let parse: JSONDictionary -> [Skill]? = { data in @@ -206,10 +210,23 @@ func skillsFromSkillsData(skillsData: [JSONDictionary]) -> [Skill] { for skillInfo in skillsData { if + let skillCategoryData = skillInfo["category"] as? JSONDictionary, let skillID = skillInfo["id"] as? String, let skillName = skillInfo["name"] as? String, let skillLocalName = skillInfo["name_string"] as? String { - let skill = Skill(id: skillID, name: skillName, localName: skillName) + + var skillCategory: SkillCategory? + if + let categoryID = skillCategoryData["id"] as? String, + let categoryName = skillCategoryData["name"] as? String, + let categoryLocalName = skillCategoryData["name_string"] as? String { + skillCategory = SkillCategory(id: categoryID, name: categoryName, localName: categoryLocalName, skills: []) + } + + let coverURLString = skillInfo["cover_url"] as? String + + let skill = Skill(category: skillCategory, id: skillID, name: skillName, localName: skillName, coverURLString: coverURLString) + skills.append(skill) } } From f09b9936aba0be4f80161db44525d7e4312fb09d Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 13:32:47 +0800 Subject: [PATCH 6/8] fix skillsFromSkillsData for allSkillCategories in register --- Yep/Services/YepService.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yep/Services/YepService.swift b/Yep/Services/YepService.swift index c299d4f9..f6145bce 100644 --- a/Yep/Services/YepService.swift +++ b/Yep/Services/YepService.swift @@ -210,13 +210,13 @@ func skillsFromSkillsData(skillsData: [JSONDictionary]) -> [Skill] { for skillInfo in skillsData { if - let skillCategoryData = skillInfo["category"] as? JSONDictionary, let skillID = skillInfo["id"] as? String, let skillName = skillInfo["name"] as? String, let skillLocalName = skillInfo["name_string"] as? String { var skillCategory: SkillCategory? if + let skillCategoryData = skillInfo["category"] as? JSONDictionary, let categoryID = skillCategoryData["id"] as? String, let categoryName = skillCategoryData["name"] as? String, let categoryLocalName = skillCategoryData["name_string"] as? String { From d1dbbaa789dff0d04fc1e2a9208b75d276b1fb69 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 13:37:44 +0800 Subject: [PATCH 7/8] SkillHome isFirstAppear --- Yep.xcodeproj/project.pbxproj | 6 +++--- .../SkillHome/SkillHomeViewController.swift | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index ede48a49..b5537424 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -372,12 +372,12 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 0A1CAC6C1AFA3D8C00826B45 /* SkillPage */ = { + 0A1CAC6C1AFA3D8C00826B45 /* SkillHome */ = { isa = PBXGroup; children = ( 0A1CAC6D1AFA42D400826B45 /* SkillHomeViewController.swift */, ); - name = SkillPage; + name = SkillHome; sourceTree = ""; }; 0A1CAC711AFA481900826B45 /* SkillHomeHeaderView */ = { @@ -516,7 +516,7 @@ 0A5D83951AC5D3CD000045BF /* TabBar */, 50894CF21AEA472B000981AF /* Settings */, 50894CFF1AEA5A7E000981AF /* EditProfile */, - 0A1CAC6C1AFA3D8C00826B45 /* SkillPage */, + 0A1CAC6C1AFA3D8C00826B45 /* SkillHome */, ); name = ViewControllers; sourceTree = ""; diff --git a/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift b/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift index 062a8c3b..fcbbe031 100644 --- a/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift +++ b/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift @@ -50,7 +50,7 @@ class SkillHomeViewController: UIViewController { } } - var isStateFirstInit = false + var isFirstAppear = true var state: SkillHomeState = .Master { willSet { @@ -134,11 +134,11 @@ class SkillHomeViewController: UIViewController { super.viewDidAppear(animated) - if !isStateFirstInit { + if isFirstAppear { + isFirstAppear = false + state = .Master - isStateFirstInit = true } - } func changeToMaster() { From 5a619dd0cb5de578c6ef1883b6bb66b5f5ee0ff4 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Fri, 8 May 2015 13:48:57 +0800 Subject: [PATCH 8/8] add CustomNavigationBarViewController; fix NavigationBar Style when push/pop multil times --- Yep.xcodeproj/project.pbxproj | 12 +++++ .../CustomNavigationBarViewController.swift | 53 +++++++++++++++++++ .../Profile/ProfileViewController.swift | 49 +---------------- .../SkillHome/SkillHomeViewController.swift | 6 +-- 4 files changed, 68 insertions(+), 52 deletions(-) create mode 100644 Yep/ViewControllers/CustomNavigationBar/CustomNavigationBarViewController.swift diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index b5537424..a1ea9ebb 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -107,6 +107,7 @@ 506EC20A1AC95BFC00CE42B3 /* UIFont+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 506EC2091AC95BFC00CE42B3 /* UIFont+Yep.swift */; }; 5076C56A1AC46B9F00B22952 /* FayeService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5076C5691AC46B9F00B22952 /* FayeService.swift */; }; 5076FC5A1AF9DF6B00D7381A /* ConversationMessagePreviewTransitionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5076FC591AF9DF6B00D7381A /* ConversationMessagePreviewTransitionManager.swift */; }; + 507CF1681AFC84A500E261B4 /* CustomNavigationBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507CF1671AFC84A500E261B4 /* CustomNavigationBarViewController.swift */; }; 50894CF11AEA4726000981AF /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF01AEA4726000981AF /* SettingsViewController.swift */; }; 50894CF51AEA4A01000981AF /* SettingsUserCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */; }; 50894CF61AEA4A01000981AF /* SettingsUserCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50894CF41AEA4A01000981AF /* SettingsUserCell.xib */; }; @@ -282,6 +283,7 @@ 506EC2091AC95BFC00CE42B3 /* UIFont+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIFont+Yep.swift"; path = "Extensions/UIFont+Yep.swift"; sourceTree = ""; }; 5076C5691AC46B9F00B22952 /* FayeService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FayeService.swift; path = Services/FayeService.swift; sourceTree = ""; }; 5076FC591AF9DF6B00D7381A /* ConversationMessagePreviewTransitionManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConversationMessagePreviewTransitionManager.swift; path = ViewControllers/Conversation/ConversationMessagePreviewTransitionManager.swift; sourceTree = ""; }; + 507CF1671AFC84A500E261B4 /* CustomNavigationBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CustomNavigationBarViewController.swift; path = ViewControllers/CustomNavigationBar/CustomNavigationBarViewController.swift; sourceTree = ""; }; 50894CF01AEA4726000981AF /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsViewController.swift; path = ViewControllers/Settings/SettingsViewController.swift; sourceTree = ""; }; 50894CF31AEA4A01000981AF /* SettingsUserCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SettingsUserCell.swift; path = Views/Cells/SettingsUser/SettingsUserCell.swift; sourceTree = ""; }; 50894CF41AEA4A01000981AF /* SettingsUserCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = SettingsUserCell.xib; path = Views/Cells/SettingsUser/SettingsUserCell.xib; sourceTree = ""; }; @@ -517,6 +519,7 @@ 50894CF21AEA472B000981AF /* Settings */, 50894CFF1AEA5A7E000981AF /* EditProfile */, 0A1CAC6C1AFA3D8C00826B45 /* SkillHome */, + 507CF1691AFC84AA00E261B4 /* CustomNavigationBar */, ); name = ViewControllers; sourceTree = ""; @@ -892,6 +895,14 @@ name = SkillAnnotationHeader; sourceTree = ""; }; + 507CF1691AFC84AA00E261B4 /* CustomNavigationBar */ = { + isa = PBXGroup; + children = ( + 507CF1671AFC84A500E261B4 /* CustomNavigationBarViewController.swift */, + ); + name = CustomNavigationBar; + sourceTree = ""; + }; 50894CF21AEA472B000981AF /* Settings */ = { isa = PBXGroup; children = ( @@ -1432,6 +1443,7 @@ 506BB7F91AE5069500C1A2A0 /* RegisterPickSkillsSelectSkillsTransitionManager.swift in Sources */, 502AE52B1AB819AF005BD199 /* YepConfig.swift in Sources */, 0A271FD71ACA055400822DFC /* YepAudioService.swift in Sources */, + 507CF1681AFC84A500E261B4 /* CustomNavigationBarViewController.swift in Sources */, 0A3E60601ACCA9C0003DC853 /* String+Yep.swift in Sources */, 504F41571AD4D35400FBB19A /* ProfileLayout.swift in Sources */, 503315A01AC126100008A209 /* MessageToolbar.swift in Sources */, diff --git a/Yep/ViewControllers/CustomNavigationBar/CustomNavigationBarViewController.swift b/Yep/ViewControllers/CustomNavigationBar/CustomNavigationBarViewController.swift new file mode 100644 index 00000000..e935c47d --- /dev/null +++ b/Yep/ViewControllers/CustomNavigationBar/CustomNavigationBarViewController.swift @@ -0,0 +1,53 @@ +// +// CustomNavigationBarViewController.swift +// Yep +// +// Created by NIX on 15/5/8. +// Copyright (c) 2015年 Catch Inc. All rights reserved. +// + +import UIKit + +class CustomNavigationBarViewController: UIViewController { + + override func viewWillAppear(animated: Bool) { + super.viewWillAppear(animated) + + if let navigationController = navigationController { + navigationController.navigationBar.backgroundColor = UIColor.clearColor() + navigationController.navigationBar.translucent = true + navigationController.navigationBar.shadowImage = UIImage() + navigationController.navigationBar.barStyle = UIBarStyle.BlackTranslucent + navigationController.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default) + + let textAttributes = [ + NSForegroundColorAttributeName: UIColor.whiteColor(), + NSFontAttributeName: UIFont.navigationBarTitleFont() + ] + + navigationController.navigationBar.titleTextAttributes = textAttributes + navigationController.navigationBar.tintColor = UIColor.whiteColor() + } + } + + override func viewWillDisappear(animated: Bool) { + super.viewWillDisappear(animated) + + if let navigationController = navigationController { + + navigationController.navigationBar.backgroundColor = nil + navigationController.navigationBar.translucent = true + navigationController.navigationBar.shadowImage = nil + navigationController.navigationBar.barStyle = UIBarStyle.Default + navigationController.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default) + + let textAttributes = [ + NSForegroundColorAttributeName: UIColor.yepTintColor(), + NSFontAttributeName: UIFont.navigationBarTitleFont() + ] + + navigationController.navigationBar.titleTextAttributes = textAttributes + navigationController.navigationBar.tintColor = nil + } + } +} diff --git a/Yep/ViewControllers/Profile/ProfileViewController.swift b/Yep/ViewControllers/Profile/ProfileViewController.swift index ba3e6cc1..986f6eb5 100644 --- a/Yep/ViewControllers/Profile/ProfileViewController.swift +++ b/Yep/ViewControllers/Profile/ProfileViewController.swift @@ -16,7 +16,7 @@ enum ProfileUser { case UserType(User) } -class ProfileViewController: UIViewController { +class ProfileViewController: CustomNavigationBarViewController { var profileUser: ProfileUser? @@ -26,7 +26,6 @@ class ProfileViewController: UIViewController { @IBOutlet weak var sayHiView: UIView! @IBOutlet weak var sayHiButton: UIButton! - var shouldBackToDefaultNavgationbar = true let skillCellIdentifier = "SkillCell" let headerCellIdentifier = "ProfileHeaderCell" @@ -118,51 +117,9 @@ class ProfileViewController: UIViewController { override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) - if let navigationController = navigationController { - navigationController.navigationBar.backgroundColor = UIColor.clearColor() - navigationController.navigationBar.translucent = true - navigationController.navigationBar.shadowImage = UIImage() - navigationController.navigationBar.barStyle = UIBarStyle.BlackTranslucent - navigationController.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default) - - let textAttributes = [ - NSForegroundColorAttributeName: UIColor.whiteColor(), - NSFontAttributeName: UIFont.navigationBarTitleFont() - ] - - navigationController.navigationBar.titleTextAttributes = textAttributes - navigationController.navigationBar.tintColor = UIColor.whiteColor() - } - self.setNeedsStatusBarAppearanceUpdate() } - override func viewWillDisappear(animated: Bool) { - super.viewWillDisappear(animated) - - if let navigationController = navigationController { - - if !shouldBackToDefaultNavgationbar { - return - } - - navigationController.navigationBar.backgroundColor = nil - navigationController.navigationBar.translucent = true - navigationController.navigationBar.shadowImage = nil - navigationController.navigationBar.barStyle = UIBarStyle.Default - navigationController.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default) - - let textAttributes = [ - NSForegroundColorAttributeName: UIColor.yepTintColor(), - NSFontAttributeName: UIFont.navigationBarTitleFont() - ] - - navigationController.navigationBar.titleTextAttributes = textAttributes - navigationController.navigationBar.tintColor = nil - } - - } - override func preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent } @@ -171,8 +128,6 @@ class ProfileViewController: UIViewController { override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - shouldBackToDefaultNavgationbar = true - if segue.identifier == "showConversation" { let vc = segue.destinationViewController as! ConversationViewController @@ -185,8 +140,6 @@ class ProfileViewController: UIViewController { let vc = segue.destinationViewController as! SkillHomeViewController vc.hidesBottomBarWhenPushed = true vc.skillName = cell.skillLabel.text - shouldBackToDefaultNavgationbar = false - } } } diff --git a/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift b/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift index fcbbe031..1cb7a98e 100644 --- a/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift +++ b/Yep/ViewControllers/SkillHome/SkillHomeViewController.swift @@ -22,7 +22,7 @@ enum SkillHomeState: Printable { } } -class SkillHomeViewController: UIViewController { +class SkillHomeViewController: CustomNavigationBarViewController { let cellIdentifier = "ContactsCell" @@ -237,9 +237,7 @@ class SkillHomeViewController: UIViewController { let discoveredUser = getDiscoveredUserWithState(state.hashValue)[indexPath.row] let vc = segue.destinationViewController as! ProfileViewController - - vc.shouldBackToDefaultNavgationbar = false - + vc.profileUser = ProfileUser.DiscoveredUserType(discoveredUser) vc.hidesBottomBarWhenPushed = true