diff --git a/Yep.xcodeproj/project.pbxproj b/Yep.xcodeproj/project.pbxproj index 92b163622..4c0ac399f 100644 --- a/Yep.xcodeproj/project.pbxproj +++ b/Yep.xcodeproj/project.pbxproj @@ -304,6 +304,10 @@ 50A6A7B31D23643100E01190 /* ConversationViewController+YepFayeServiceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A6A7B21D23643100E01190 /* ConversationViewController+YepFayeServiceDelegate.swift */; }; 50A6A7B51D23676300E01190 /* ConversationViewController+SendMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A6A7B41D23676300E01190 /* ConversationViewController+SendMessages.swift */; }; 50A6A7B71D2377E100E01190 /* ConversationViewController+SyncMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A6A7B61D2377E100E01190 /* ConversationViewController+SyncMessages.swift */; }; + 50A6A7BA1D23AD4000E01190 /* MeetGeniusShowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A6A7B91D23AD4000E01190 /* MeetGeniusShowView.swift */; }; + 50A6A7BD1D23BED600E01190 /* GeniusInterviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A6A7BC1D23BED600E01190 /* GeniusInterviewViewController.swift */; }; + 50A6A7BF1D23BEEF00E01190 /* GeniusInterview.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50A6A7BE1D23BEEF00E01190 /* GeniusInterview.storyboard */; }; + 50A6A7C21D23C2D300E01190 /* GeniusInterviewActionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A6A7C11D23C2D300E01190 /* GeniusInterviewActionView.swift */; }; 50A820241B969B0F007CD30E /* NSTimeZone+Yep.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A820231B969B0F007CD30E /* NSTimeZone+Yep.swift */; }; 50A93A9D1BD8C515007005DB /* FeedSkillPickerItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A93A9C1BD8C515007005DB /* FeedSkillPickerItemView.swift */; }; 50A9D4571ACD393A000B2599 /* YepWaverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A9D4541ACD393A000B2599 /* YepWaverView.swift */; }; @@ -1020,6 +1024,10 @@ 50A6A7B21D23643100E01190 /* ConversationViewController+YepFayeServiceDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ConversationViewController+YepFayeServiceDelegate.swift"; path = "ViewControllers/Conversation/ConversationViewController+YepFayeServiceDelegate.swift"; sourceTree = ""; }; 50A6A7B41D23676300E01190 /* ConversationViewController+SendMessages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ConversationViewController+SendMessages.swift"; path = "ViewControllers/Conversation/ConversationViewController+SendMessages.swift"; sourceTree = ""; }; 50A6A7B61D2377E100E01190 /* ConversationViewController+SyncMessages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ConversationViewController+SyncMessages.swift"; path = "ViewControllers/Conversation/ConversationViewController+SyncMessages.swift"; sourceTree = ""; }; + 50A6A7B91D23AD4000E01190 /* MeetGeniusShowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MeetGeniusShowView.swift; path = Views/MeetGeniusShow/MeetGeniusShowView.swift; sourceTree = ""; }; + 50A6A7BC1D23BED600E01190 /* GeniusInterviewViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GeniusInterviewViewController.swift; path = ViewControllers/GeniusInterview/GeniusInterviewViewController.swift; sourceTree = ""; }; + 50A6A7BE1D23BEEF00E01190 /* GeniusInterview.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = GeniusInterview.storyboard; path = ViewControllers/GeniusInterview/GeniusInterview.storyboard; sourceTree = ""; }; + 50A6A7C11D23C2D300E01190 /* GeniusInterviewActionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GeniusInterviewActionView.swift; path = Views/GeniusInterviewAction/GeniusInterviewActionView.swift; sourceTree = ""; }; 50A820231B969B0F007CD30E /* NSTimeZone+Yep.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSTimeZone+Yep.swift"; path = "Extensions/NSTimeZone+Yep.swift"; sourceTree = ""; }; 50A93A9C1BD8C515007005DB /* FeedSkillPickerItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FeedSkillPickerItemView.swift; path = Views/PickerItems/FeedSkill/FeedSkillPickerItemView.swift; sourceTree = ""; }; 50A9D4541ACD393A000B2599 /* YepWaverView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YepWaverView.swift; path = Views/AudioWaves/YepWaverView.swift; sourceTree = ""; }; @@ -1804,6 +1812,7 @@ 502048251B0F1BB8002EBFC7 /* SearchedUsers */, 502280F91B1C3F2F00E984EE /* FriendsInContacts */, 5023DE2E1AB685F100B3EE96 /* Discover */, + 50A6A7BB1D23BE7600E01190 /* GeniusInterview */, 5023DE311AB6861900B3EE96 /* Profile */, 845E1A671B788EFC001E0789 /* EditSkills */, 502AE51C1AB70DE5005BD199 /* Welcome */, @@ -1911,6 +1920,8 @@ 5023DE391AB6979C00B3EE96 /* Views */ = { isa = PBXGroup; children = ( + 50A6A7B81D23AD1600E01190 /* MeetGeniusShow */, + 50A6A7C01D23C28D00E01190 /* GeniusInterviewActionView */, 50B6A03D1CA282B100C460E3 /* ActionSheet */, 50B8E6191B41341000C17EA1 /* ProgressViews */, 504CBA3B1B3D048900663A90 /* TextViews */, @@ -2820,6 +2831,31 @@ name = DoNotDisturbPeriod; sourceTree = ""; }; + 50A6A7B81D23AD1600E01190 /* MeetGeniusShow */ = { + isa = PBXGroup; + children = ( + 50A6A7B91D23AD4000E01190 /* MeetGeniusShowView.swift */, + ); + name = MeetGeniusShow; + sourceTree = ""; + }; + 50A6A7BB1D23BE7600E01190 /* GeniusInterview */ = { + isa = PBXGroup; + children = ( + 50A6A7BC1D23BED600E01190 /* GeniusInterviewViewController.swift */, + 50A6A7BE1D23BEEF00E01190 /* GeniusInterview.storyboard */, + ); + name = GeniusInterview; + sourceTree = ""; + }; + 50A6A7C01D23C28D00E01190 /* GeniusInterviewActionView */ = { + isa = PBXGroup; + children = ( + 50A6A7C11D23C2D300E01190 /* GeniusInterviewActionView.swift */, + ); + name = GeniusInterviewActionView; + sourceTree = ""; + }; 50A93A9E1BD8C51D007005DB /* PickerItems */ = { isa = PBXGroup; children = ( @@ -4130,6 +4166,7 @@ 84385C461B8594E80071130D /* Show.xcassets in Resources */, 50894CFB1AEA54BA000981AF /* SettingsMoreCell.xib in Resources */, 50E1CE8F1BE0BFF00025B933 /* MediaViewCell.xib in Resources */, + 50A6A7BF1D23BEEF00E01190 /* GeniusInterview.storyboard in Resources */, 505EC8181ADF8151001D27E0 /* SkillCategoryCell.xib in Resources */, 6A8215091BCBE8F10011F36C /* DiscoverSkillCell.xib in Resources */, 50DEE0451BEA025100015741 /* About.storyboard in Resources */, @@ -4463,6 +4500,7 @@ 502AE5581AB932D5005BD199 /* ProfileSectionHeaderReusableView.swift in Sources */, 500EED981BF07A3000C6BABC /* ConversationViewController+Feed.swift in Sources */, 508F8FDE1B049ACF00461B0B /* InstagramMediaCell.swift in Sources */, + 50A6A7BA1D23AD4000E01190 /* MeetGeniusShowView.swift in Sources */, 502AE5211AB71C7E005BD199 /* BorderButton.swift in Sources */, 50858EBB1C22487900EDE492 /* FeedBasicCell.swift in Sources */, 84C959891B731FD20017D3ED /* ChatBaseCell.swift in Sources */, @@ -4528,6 +4566,7 @@ 5080EB1C1B93F43A006F3C2D /* PodsHelpYepViewController.swift in Sources */, 0A1CAC731AFA526200826B45 /* SkillHomeSectionButton.swift in Sources */, 50E392BC1C22752C00C0CECB /* FeedNormalImagesCell.swift in Sources */, + 50A6A7BD1D23BED600E01190 /* GeniusInterviewViewController.swift in Sources */, 50E34C261CBB8A37007CAE80 /* SearchFeedsViewController.swift in Sources */, 50B38FCC1B6B37F00064C132 /* FeedbackViewController.swift in Sources */, 50CB05761CC5D0FD0024BE06 /* SearchedFeedBasicCell.swift in Sources */, @@ -4609,6 +4648,7 @@ 338940371CB7C80900B276C1 /* NewFeedPreviewCell.swift in Sources */, 502AE52E1AB83879005BD199 /* UnderLineTextField.swift in Sources */, 5012FDDA1BFABDE400294145 /* ProfileFeedsCell.swift in Sources */, + 50A6A7C21D23C2D300E01190 /* GeniusInterviewActionView.swift in Sources */, 508F8FD71B01EDB400461B0B /* DribbbleShotCell.swift in Sources */, 508DF62B1B9985F300B194A4 /* YepLog.swift in Sources */, 50A6A7AF1D2361A900E01190 /* ConversationViewController+AVAudioPlayerDelegate.swift in Sources */, @@ -5106,7 +5146,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; - OTHER_SWIFT_FLAGS = "-D DEBUG -D STAGING_"; + OTHER_SWIFT_FLAGS = "-D DEBUG -D STAGING"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; diff --git a/Yep/Extensions/UISearchBar+Yep.swift b/Yep/Extensions/UISearchBar+Yep.swift index 141dae973..307012fd9 100644 --- a/Yep/Extensions/UISearchBar+Yep.swift +++ b/Yep/Extensions/UISearchBar+Yep.swift @@ -30,7 +30,7 @@ extension UISearchBar { yep_cancelButton?.enabled = true } - func yep_makeSureCancelButtonAlwaysEnabled() -> ObjectKeypathObserver? { + func yep_makeSureCancelButtonAlwaysEnabled() -> ObjectKeypathObserver? { guard let cancelButton = yep_cancelButton else { println("Not cancelButton in searchBar!") @@ -38,10 +38,9 @@ extension UISearchBar { } return ObjectKeypathObserver(object: cancelButton, keypath: "enabled", afterValueChanged: { object in - if let cancelButton = object as? UIButton { - if !cancelButton.enabled { - cancelButton.enabled = true - } + let cancelButton = object + if !cancelButton.enabled { + cancelButton.enabled = true } }) } diff --git a/Yep/Helpers/KVO/ObjectKeypathObserver.swift b/Yep/Helpers/KVO/ObjectKeypathObserver.swift index c51e472b2..1bb573956 100644 --- a/Yep/Helpers/KVO/ObjectKeypathObserver.swift +++ b/Yep/Helpers/KVO/ObjectKeypathObserver.swift @@ -8,18 +8,18 @@ import UIKit -final class ObjectKeypathObserver: NSObject { +final class ObjectKeypathObserver: NSObject { - weak var object: NSObject? + weak var object: Object? var keypath: String - typealias AfterValueChanged = (object: NSObject) -> Void + typealias AfterValueChanged = (object: Object) -> Void var afterValueChanged: AfterValueChanged? deinit { object?.removeObserver(self, forKeyPath: keypath) } - init(object: NSObject, keypath: String, afterValueChanged: AfterValueChanged) { + init(object: Object, keypath: String, afterValueChanged: AfterValueChanged) { self.object = object self.keypath = keypath @@ -32,7 +32,7 @@ final class ObjectKeypathObserver: NSObject { override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer) { - guard let object = object as? NSObject else { + guard let object = object as? Object else { return } diff --git a/Yep/ViewControllers/Discover/Discover.storyboard b/Yep/ViewControllers/Discover/Discover.storyboard index 345c9b7ca..3552cf191 100644 --- a/Yep/ViewControllers/Discover/Discover.storyboard +++ b/Yep/ViewControllers/Discover/Discover.storyboard @@ -49,7 +49,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -94,7 +94,15 @@ - + + + + + + + + + @@ -111,7 +119,7 @@ - + @@ -150,6 +158,7 @@ + diff --git a/Yep/ViewControllers/Discover/DiscoverContainerViewController.swift b/Yep/ViewControllers/Discover/DiscoverContainerViewController.swift index b16435f28..539a20da1 100644 --- a/Yep/ViewControllers/Discover/DiscoverContainerViewController.swift +++ b/Yep/ViewControllers/Discover/DiscoverContainerViewController.swift @@ -155,6 +155,15 @@ class DiscoverContainerViewController: UIViewController { switch identifier { + case "embedMeetGenius": + let vc = segue.destinationViewController as! MeetGeniusViewController + + vc.showGeniusInterviewAction = { + SafeDispatch.async { [weak self] in + self?.performSegueWithIdentifier("showGeniusInterview", sender: nil) + } + } + case "embedDiscover": let vc = segue.destinationViewController as! DiscoverViewController diff --git a/Yep/ViewControllers/Discover/MeetGeniusViewController.swift b/Yep/ViewControllers/Discover/MeetGeniusViewController.swift index 4215c93aa..68afca946 100644 --- a/Yep/ViewControllers/Discover/MeetGeniusViewController.swift +++ b/Yep/ViewControllers/Discover/MeetGeniusViewController.swift @@ -7,20 +7,32 @@ // import UIKit +import YepKit class MeetGeniusViewController: UIViewController { + var showGeniusInterviewAction: (() -> Void)? + @IBOutlet weak var tableView: UITableView! { didSet { + tableView.tableHeaderView = MeetGeniusShowView(frame: CGRect(x: 0, y: 0, width: 100, height: 180)) + tableView.tableFooterView = UIView() + tableView.rowHeight = 90 - tableView.tableFooterView = InfoView(NSLocalizedString("To be continue.", comment: "")) tableView.registerNibOf(GeniusInterviewCell) + tableView.registerNibOf(LoadMoreTableViewCell) } } + var geniusInterviews: [GeniusInterview] = [] + + private var canLoadMore: Bool = false + override func viewDidLoad() { super.viewDidLoad() + + println("tableView.tableHeaderView: \(tableView.tableHeaderView)") } /* @@ -38,19 +50,102 @@ class MeetGeniusViewController: UIViewController { extension MeetGeniusViewController: UITableViewDataSource, UITableViewDelegate { + private enum Section: Int { + case GeniusInterview + case LoadMore + } + func numberOfSectionsInTableView(tableView: UITableView) -> Int { - return 0 + + return 2 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 15 + + guard let section = Section(rawValue: section) else { + fatalError("Invalid Section") + } + + switch section { + + case .GeniusInterview: + return geniusInterviews.count + + case .LoadMore: + return 1 + } } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell: GeniusInterviewCell = tableView.dequeueReusableCell() - cell.avatarImageView.image = UIImage(named: "yep_icon_solo") - cell.numberLabel.text = String(format: "#%03d", indexPath.row) - return cell + + guard let section = Section(rawValue: indexPath.section) else { + fatalError("Invalid Section") + } + + switch section { + + case .GeniusInterview: + let cell: GeniusInterviewCell = tableView.dequeueReusableCell() + let geniusInterview = geniusInterviews[indexPath.row] + cell.configure(withGeniusInterview: geniusInterview) + return cell + + case .LoadMore: + let cell: LoadMoreTableViewCell = tableView.dequeueReusableCell() + cell.isLoading = true + return cell + } + } + + func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { + + guard let section = Section(rawValue: indexPath.section) else { + fatalError("Invalid Section") + } + + switch section { + + case .GeniusInterview: + break + + case .LoadMore: + guard let cell = cell as? LoadMoreTableViewCell else { + break + } + + guard canLoadMore else { + cell.isLoading = false + break + } + + println("load more feeds") + + if !cell.isLoading { + cell.isLoading = true + } + + // TODO + } + } + + func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + + defer { + tableView.deselectRowAtIndexPath(indexPath, animated: true) + } + + guard let section = Section(rawValue: indexPath.section) else { + fatalError("Invalid Section") + } + + switch section { + + case .GeniusInterview: + showGeniusInterviewAction?() + + case .LoadMore: + break + } } } diff --git a/Yep/ViewControllers/EditProfile/EditProfile.storyboard b/Yep/ViewControllers/EditProfile/EditProfile.storyboard index 83bd0f672..b8a01ef25 100644 --- a/Yep/ViewControllers/EditProfile/EditProfile.storyboard +++ b/Yep/ViewControllers/EditProfile/EditProfile.storyboard @@ -1,5 +1,5 @@ - + diff --git a/Yep/ViewControllers/GeniusInterview/GeniusInterview.storyboard b/Yep/ViewControllers/GeniusInterview/GeniusInterview.storyboard new file mode 100644 index 000000000..3d02e20b8 --- /dev/null +++ b/Yep/ViewControllers/GeniusInterview/GeniusInterview.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Yep/ViewControllers/GeniusInterview/GeniusInterviewViewController.swift b/Yep/ViewControllers/GeniusInterview/GeniusInterviewViewController.swift new file mode 100644 index 000000000..7b5cb7fb4 --- /dev/null +++ b/Yep/ViewControllers/GeniusInterview/GeniusInterviewViewController.swift @@ -0,0 +1,160 @@ +// +// GeniusInterviewViewController.swift +// Yep +// +// Created by NIX on 16/6/29. +// Copyright © 2016年 Catch Inc. All rights reserved. +// + +import UIKit +import WebKit + +class GeniusInterviewViewController: UIViewController { + + lazy var webView: WKWebView = { + + let view = WKWebView() + + view.navigationDelegate = self + + view.scrollView.contentInset.bottom = 50 + view.scrollView.delegate = self + + let request = NSURLRequest(URL: NSURL(string: "https://soyep.com")!) + view.loadRequest(request) + + return view + }() + + lazy var indicatorView: UIActivityIndicatorView = { + + let view = UIActivityIndicatorView(activityIndicatorStyle: .Gray) + view.hidesWhenStopped = true + return view + }() + + private var actionViewTopConstraint: NSLayoutConstraint? + lazy var actionView: GeniusInterviewActionView = { + + let view = GeniusInterviewActionView() + + view.tapAvatarAction = { + println("tapAvatarAction") + } + + view.sayHiAction = { + println("sayHiAction") + } + + view.shareAction = { + println("shareAction") + } + + return view + }() + + deinit { + webView.scrollView.delegate = nil + } + + override func viewDidLoad() { + super.viewDidLoad() + + do { + webView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(webView) + + let leading = webView.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor) + let trailing = webView.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor) + let top = webView.topAnchor.constraintEqualToAnchor(view.topAnchor) + let bottom = webView.bottomAnchor.constraintEqualToAnchor(view.bottomAnchor) + NSLayoutConstraint.activateConstraints([leading, trailing, top, bottom]) + } + + do { + indicatorView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(indicatorView) + + let centerX = indicatorView.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor) + let centerY = indicatorView.centerYAnchor.constraintEqualToAnchor(view.centerYAnchor) + NSLayoutConstraint.activateConstraints([centerX, centerY]) + } + + do { + actionView.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(actionView) + + let leading = actionView.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor) + let trailing = actionView.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor) + let top = actionView.topAnchor.constraintEqualToAnchor(view.bottomAnchor, constant: 0) + self.actionViewTopConstraint = top + let height = actionView.heightAnchor.constraintEqualToConstant(50) + NSLayoutConstraint.activateConstraints([leading, trailing, top, height]) + } + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + // Get the new view controller using segue.destinationViewController. + // Pass the selected object to the new view controller. + } + */ + +} + +// MARK: - WKNavigationDelegate + +extension GeniusInterviewViewController: WKNavigationDelegate { + + func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { + + indicatorView.startAnimating() + } + + func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) { + + indicatorView.stopAnimating() + } +} + +// MARK: - UIScrollViewDelegate + +extension GeniusInterviewViewController: UIScrollViewDelegate { + + func scrollViewDidScroll(scrollView: UIScrollView) { + + let scrollViewContentOffsetY = scrollView.contentOffset.y + guard scrollViewContentOffsetY > 0 else { + return + } + let scrollViewHeight = scrollView.bounds.height + let scrollViewContentSizeHeight = scrollView.contentSize.height + + println("scrollViewContentOffsetY: \(scrollViewContentOffsetY)") + println("scrollViewHeight: \(scrollViewHeight)") + println("scrollViewContentSizeHeight: \(scrollViewContentSizeHeight)") + + let y = (scrollViewContentOffsetY + scrollViewHeight) - scrollViewContentSizeHeight + if y > 0 { + UIView.animateWithDuration(0.25, animations: { [weak self] in + self?.actionViewTopConstraint?.constant = -50 + self?.view.layoutIfNeeded() + }) + } else { + UIView.animateWithDuration(0.25, animations: { [weak self] in + self?.actionViewTopConstraint?.constant = 0 + self?.view.layoutIfNeeded() + }) + } + } +} + diff --git a/Yep/ViewControllers/SearchContacts/SearchContactsViewController.swift b/Yep/ViewControllers/SearchContacts/SearchContactsViewController.swift index 7048ea3c6..d2cd5209d 100644 --- a/Yep/ViewControllers/SearchContacts/SearchContactsViewController.swift +++ b/Yep/ViewControllers/SearchContacts/SearchContactsViewController.swift @@ -15,7 +15,7 @@ final class SearchContactsViewController: SegueViewController { var originalNavigationControllerDelegate: UINavigationControllerDelegate? var searchTransition: SearchTransition? - private var searchBarCancelButtonEnabledObserver: ObjectKeypathObserver? + private var searchBarCancelButtonEnabledObserver: ObjectKeypathObserver? @IBOutlet weak var searchBar: UISearchBar! { didSet { searchBar.placeholder = NSLocalizedString("Search Friend", comment: "") diff --git a/Yep/ViewControllers/SearchConversations/SearchConversationsViewController.swift b/Yep/ViewControllers/SearchConversations/SearchConversationsViewController.swift index f48f6a41f..3d75d940c 100644 --- a/Yep/ViewControllers/SearchConversations/SearchConversationsViewController.swift +++ b/Yep/ViewControllers/SearchConversations/SearchConversationsViewController.swift @@ -15,7 +15,7 @@ final class SearchConversationsViewController: SegueViewController { var originalNavigationControllerDelegate: UINavigationControllerDelegate? var searchTransition: SearchTransition? - private var searchBarCancelButtonEnabledObserver: ObjectKeypathObserver? + private var searchBarCancelButtonEnabledObserver: ObjectKeypathObserver? @IBOutlet weak var searchBar: UISearchBar! { didSet { searchBar.placeholder = NSLocalizedString("Search", comment: "") diff --git a/Yep/ViewControllers/SearchFeeds/SearchFeedsViewController.swift b/Yep/ViewControllers/SearchFeeds/SearchFeedsViewController.swift index f564fc40d..2e19541cf 100644 --- a/Yep/ViewControllers/SearchFeeds/SearchFeedsViewController.swift +++ b/Yep/ViewControllers/SearchFeeds/SearchFeedsViewController.swift @@ -27,7 +27,7 @@ final class SearchFeedsViewController: SegueViewController { var skill: Skill? var profileUser: ProfileUser? - private var searchBarCancelButtonEnabledObserver: ObjectKeypathObserver? + private var searchBarCancelButtonEnabledObserver: ObjectKeypathObserver? @IBOutlet weak var searchBar: UISearchBar! { didSet { searchBar.setSearchFieldBackgroundImage(UIImage(named: "searchbar_textfield_background"), forState: .Normal) diff --git a/Yep/Views/Cells/GeniusInterview/GeniusInterviewCell.swift b/Yep/Views/Cells/GeniusInterview/GeniusInterviewCell.swift index 125010732..a9d8734c9 100644 --- a/Yep/Views/Cells/GeniusInterview/GeniusInterviewCell.swift +++ b/Yep/Views/Cells/GeniusInterview/GeniusInterviewCell.swift @@ -7,6 +7,8 @@ // import UIKit +import YepKit +import Navi class GeniusInterviewCell: UITableViewCell { @@ -27,5 +29,15 @@ class GeniusInterviewCell: UITableViewCell { // Configure the view for the selected state } - + + func configure(withGeniusInterview geniusInterview: GeniusInterview) { + + let avatar = PlainAvatar(avatarURLString: geniusInterview.user.avatarURLString, avatarStyle: miniAvatarStyle) + avatarImageView.navi_setAvatar(avatar, withFadeTransitionDuration: avatarFadeTransitionDuration) + + numberLabel.text = String(format: "#%03d", geniusInterview.number) + titleLabel.text = geniusInterview.title + detailLabel.text = geniusInterview.detail + } } + diff --git a/Yep/Views/GeniusInterviewAction/GeniusInterviewActionView.swift b/Yep/Views/GeniusInterviewAction/GeniusInterviewActionView.swift new file mode 100644 index 000000000..e7482718d --- /dev/null +++ b/Yep/Views/GeniusInterviewAction/GeniusInterviewActionView.swift @@ -0,0 +1,97 @@ +// +// GeniusInterviewActionView.swift +// Yep +// +// Created by NIX on 16/6/29. +// Copyright © 2016年 Catch Inc. All rights reserved. +// + +import UIKit +import Ruler + +class GeniusInterviewActionView: UIView { + + var tapAvatarAction: (() -> Void)? + var sayHiAction: (() -> Void)? + var shareAction: (() -> Void)? + + lazy var toolbar = UIToolbar() + + lazy var avatarImageView: UIImageView = { + + let view = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) + view.backgroundColor = UIColor.redColor() + view.layer.cornerRadius = 15 + + view.userInteractionEnabled = true + let tap = UITapGestureRecognizer(target: self, action: #selector(GeniusInterviewActionView.tapAvatar(_:))) + view.addGestureRecognizer(tap) + + return view + }() + + lazy var sayHiButton: UIButton = { + + let width: CGFloat = Ruler.iPhoneHorizontal(150, 185, 185).value + let button = UIButton(frame: CGRect(x: 0, y: 0, width: width, height: 30)) + button.titleLabel?.font = UIFont.systemFontOfSize(14) + button.setTitle(NSLocalizedString("Say Hi", comment: ""), forState: .Normal) + button.backgroundColor = UIColor.yepTintColor() + button.setTitleColor(UIColor.whiteColor(), forState: .Normal) + button.layer.cornerRadius = 5 + + button.addTarget(self, action: #selector(GeniusInterviewActionView.sayHi(_:)), forControlEvents: UIControlEvents.TouchUpInside) + + return button + }() + + override func didMoveToSuperview() { + super.didMoveToSuperview() + + makeUI() + } + + private func makeUI() { + + do { + toolbar.translatesAutoresizingMaskIntoConstraints = false + addSubview(toolbar) + + let leading = toolbar.leadingAnchor.constraintEqualToAnchor(leadingAnchor) + let trailing = toolbar.trailingAnchor.constraintEqualToAnchor(trailingAnchor) + let top = toolbar.topAnchor.constraintEqualToAnchor(topAnchor) + let bottom = toolbar.bottomAnchor.constraintEqualToAnchor(bottomAnchor) + NSLayoutConstraint.activateConstraints([leading, trailing, top, bottom]) + } + + do { + let avatarItem = UIBarButtonItem(customView: avatarImageView) + + let gap1Item = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil) + + let sayHiItem = UIBarButtonItem(customView: sayHiButton) + + let gap2Item = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil) + + let shareItem = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: #selector(GeniusInterviewActionView.share(_:))) + + toolbar.setItems([avatarItem, gap1Item, sayHiItem, gap2Item, shareItem], animated: false) + } + } + + @objc private func tapAvatar(sender: UITapGestureRecognizer) { + + tapAvatarAction?() + } + + @objc private func sayHi(sender: UIButton) { + + sayHiAction?() + } + + @objc private func share(sender: UIBarButtonItem) { + + shareAction?() + } +} + diff --git a/Yep/Views/MeetGeniusShow/MeetGeniusShowView.swift b/Yep/Views/MeetGeniusShow/MeetGeniusShowView.swift new file mode 100644 index 000000000..3170812ab --- /dev/null +++ b/Yep/Views/MeetGeniusShow/MeetGeniusShowView.swift @@ -0,0 +1,93 @@ +// +// MeetGeniusShowView.swift +// Yep +// +// Created by NIX on 16/6/29. +// Copyright © 2016年 Catch Inc. All rights reserved. +// + +import UIKit + +class MeetGeniusShowView: UIView { + + var tapAction: (() -> Void)? + + lazy var backgroundImageView: UIImageView = { + let view = UIImageView() + view.backgroundColor = UIColor.blueColor() + view.userInteractionEnabled = true + + let tap = UITapGestureRecognizer(target: self, action: #selector(MeetGeniusShowView.didTap(_:))) + view.addGestureRecognizer(tap) + + return view + }() + + lazy var showButton: UIButton = { + let button = UIButton() + button.setTitle("SHOW", forState: .Normal) + button.backgroundColor = UIColor.blueColor() + return button + }() + + lazy var titleLabel: UILabel = { + let label = UILabel() + label.text = "Hello World!" + return label + }() + + override init(frame: CGRect) { + super.init(frame: frame) + + makeUI() + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func makeUI() { + + do { + backgroundImageView.translatesAutoresizingMaskIntoConstraints = false + addSubview(backgroundImageView) + + let views = [ + "backgroundImageView": backgroundImageView, + ] + + let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("H:|[backgroundImageView]|", options: [], metrics: nil, views: views) + let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:|[backgroundImageView]|", options: [], metrics: nil, views: views) + NSLayoutConstraint.activateConstraints(constraintsH) + NSLayoutConstraint.activateConstraints(constraintsV) + } + + /* + do { + showButton.translatesAutoresizingMaskIntoConstraints = false + titleLabel.translatesAutoresizingMaskIntoConstraints = false + + let stackView = UIStackView() + stackView.axis = .Vertical + stackView.spacing = 12 + + stackView.addArrangedSubview(showButton) + stackView.addArrangedSubview(titleLabel) + + stackView.translatesAutoresizingMaskIntoConstraints = false + addSubview(stackView) + + let centerX = stackView.centerXAnchor.constraintEqualToAnchor(centerXAnchor) + let centerY = stackView.centerYAnchor.constraintEqualToAnchor(centerYAnchor) + NSLayoutConstraint.activateConstraints([centerX, centerY]) + } + */ + } + + @objc private func didTap(sender: UITapGestureRecognizer) { + println("tap MeetGeniusShowView") + + tapAction?() + } +} + diff --git a/YepKit/Remote/YepService.swift b/YepKit/Remote/YepService.swift index 78a656ee7..07db5a4c7 100644 --- a/YepKit/Remote/YepService.swift +++ b/YepKit/Remote/YepService.swift @@ -3878,3 +3878,20 @@ public func usersMatchWithUsernamePrefix(usernamePrefix: String, failureHandler: apiRequest({_ in}, baseURL: yepBaseURL, resource: resource, failure: failureHandler, completion: completion) } +// MARK: - GeniusInterview + +public struct GeniusInterview { + + public let user: DiscoveredUser + + public let number: Int + public let title: String + public let detail: String + public let url: NSURL + + public init?(_ info: JSONDictionary) { + return nil + } +} + +