Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nixzhu committed Apr 27, 2016
2 parents e4de7fc + d916797 commit 0df314d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 201 deletions.
55 changes: 2 additions & 53 deletions Yep/Base.lproj/Intro.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Alignment constraints with different attributes" minToolsVersion="5.1"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -375,79 +374,31 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="i4k-kS-w32" userLabel="Cemera Roll Button">
<rect key="frame" x="170" y="499" width="60" height="66"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<inset key="contentEdgeInsets" minX="10" minY="13" maxX="10" maxY="13"/>
<state key="normal" image="button_camera_roll">
<color key="titleColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="tryOpenCameraRoll:" destination="9hR-GW-qJG" eventType="touchUpInside" id="AfG-fG-cV8"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="uke-GF-N1u" userLabel="Capture Button">
<rect key="frame" x="265" y="484" width="70" height="96"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<inset key="contentEdgeInsets" minX="0.0" minY="13" maxX="0.0" maxY="13"/>
<state key="normal" image="button_capture">
<color key="titleColor" red="0.0" green="0.50196081400000003" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="captureOrFinish:" destination="9hR-GW-qJG" eventType="touchUpInside" id="Fcd-a5-K2s"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="2pw-VA-qDr" userLabel="Retake Button">
<rect key="frame" x="364.5" y="510" width="71" height="44"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<inset key="contentEdgeInsets" minX="10" minY="13" maxX="10" maxY="13"/>
<state key="normal" title="Retake">
<color key="titleColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="retake:" destination="9hR-GW-qJG" eventType="touchUpInside" id="PW8-Gc-beC"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nqi-d1-G0k" userLabel="Open Camera Button" customClass="BorderButton" customModule="Yep" customModuleProvider="target">
<rect key="frame" x="200" y="510" width="200" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="4w5-n3-nzB"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<inset key="contentEdgeInsets" minX="0.0" minY="13" maxX="0.0" maxY="13"/>
<state key="normal" title="Pick Your Avatar">
<state key="normal" title="Choose from Library">
<color key="titleColor" red="0.0" green="0.50196081399917603" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="tryOpenCamera:" destination="9hR-GW-qJG" eventType="touchUpInside" id="ja0-Ec-QgR"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.80000001192092896" green="0.80000001192092896" blue="0.80000001192092896" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="nqi-d1-G0k" firstAttribute="centerY" secondItem="2pw-VA-qDr" secondAttribute="centerY" id="3j4-0d-fOt"/>
<constraint firstItem="uke-GF-N1u" firstAttribute="centerX" secondItem="nqi-d1-G0k" secondAttribute="centerX" id="OAz-6g-WOE"/>
<constraint firstItem="e0h-Ho-j4F" firstAttribute="top" secondItem="Z4g-rM-AaZ" secondAttribute="bottom" constant="50" id="Okw-OW-FJ5"/>
<constraint firstItem="nqi-d1-G0k" firstAttribute="trailing" secondItem="2pw-VA-qDr" secondAttribute="centerX" id="QZC-jz-2kN"/>
<constraint firstItem="uke-GF-N1u" firstAttribute="centerY" secondItem="nqi-d1-G0k" secondAttribute="centerY" id="XBn-S4-NUo"/>
<constraint firstItem="EWy-zw-rkQ" firstAttribute="top" secondItem="nqi-d1-G0k" secondAttribute="bottom" constant="46" id="cg0-cY-cQy"/>
<constraint firstItem="i4k-kS-w32" firstAttribute="centerY" secondItem="nqi-d1-G0k" secondAttribute="centerY" id="eU5-vt-1GK"/>
<constraint firstItem="i4k-kS-w32" firstAttribute="centerX" secondItem="nqi-d1-G0k" secondAttribute="leading" id="gFr-ZO-ZID"/>
<constraint firstAttribute="centerX" secondItem="nqi-d1-G0k" secondAttribute="centerX" id="twB-hI-yMg"/>
<constraint firstAttribute="centerX" secondItem="e0h-Ho-j4F" secondAttribute="centerX" id="vzQ-Z9-TSa"/>
</constraints>
</view>
<connections>
<outlet property="avatarImageView" destination="qI7-tW-94Q" id="Psb-GV-kDf"/>
<outlet property="cameraPreviewView" destination="AEj-wj-Yl6" id="6jR-bI-rj7"/>
<outlet property="cameraRollButton" destination="i4k-kS-w32" id="TKM-OM-Ldx"/>
<outlet property="captureButton" destination="uke-GF-N1u" id="OSq-84-bd2"/>
<outlet property="openCameraButton" destination="nqi-d1-G0k" id="GhI-uW-eZW"/>
<outlet property="retakeButton" destination="2pw-VA-qDr" id="Ilk-KJ-atU"/>
<outlet property="openCameraButton" destination="nqi-d1-G0k" id="1P2-jZ-ekU"/>
<segue destination="OBL-Og-6Ae" kind="show" identifier="showRegisterPickSkills" id="fwO-Qy-gTW"/>
</connections>
</viewController>
Expand Down Expand Up @@ -820,8 +771,6 @@
</scene>
</scenes>
<resources>
<image name="button_camera_roll" width="40" height="40"/>
<image name="button_capture" width="70" height="70"/>
<image name="default_avatar" width="100" height="100"/>
<image name="flat_arrow_down" width="14" height="5"/>
<image name="flat_arrow_left" width="6" height="15"/>
Expand Down
153 changes: 7 additions & 146 deletions Yep/ViewControllers/Register/RegisterPickAvatarViewController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//

// RegisterPickAvatarViewController.swift
// Yep
//
Expand All @@ -16,16 +16,11 @@ class RegisterPickAvatarViewController: SegueViewController {
@IBOutlet private weak var avatarImageView: UIImageView!
@IBOutlet private weak var cameraPreviewView: CameraPreviewView!

@IBOutlet private weak var takePicturePromptLabel: UILabel!

@IBOutlet private weak var openCameraButton: BorderButton!

@IBOutlet private weak var cameraRollButton: UIButton!
@IBOutlet private weak var captureButton: UIButton!
@IBOutlet private weak var retakeButton: UIButton!

private lazy var nextButton: UIBarButtonItem = {
let button = UIBarButtonItem(title: NSLocalizedString("Next", comment: ""), style: .Plain, target: self, action: #selector(RegisterPickAvatarViewController.next(_:)))
button.enabled = false
return button
}()

Expand All @@ -37,53 +32,23 @@ class RegisterPickAvatarViewController: SegueViewController {

private enum PickAvatarState {
case Default
case CameraOpen
case Captured
}

private var pickAvatarState: PickAvatarState = .Default {
willSet {
switch newValue {
case .Default:
openCameraButton.hidden = false

cameraRollButton.hidden = true
captureButton.hidden = true
retakeButton.hidden = true

cameraPreviewView.hidden = true
avatarImageView.hidden = false

avatarImageView.image = UIImage(named: "default_avatar")

nextButton.enabled = false

case .CameraOpen:
openCameraButton.hidden = true

cameraRollButton.hidden = false
captureButton.hidden = false
retakeButton.hidden = true

cameraPreviewView.hidden = false
avatarImageView.hidden = false

captureButton.setImage(UIImage(named: "button_capture"), forState: .Normal)

nextButton.enabled = false


case .Captured:
openCameraButton.hidden = true

cameraRollButton.hidden = false
captureButton.hidden = false
retakeButton.hidden = false

cameraPreviewView.hidden = true
avatarImageView.hidden = false

captureButton.setImage(UIImage(named: "button_capture_ok"), forState: .Normal)

nextButton.enabled = true
}
}
Expand Down Expand Up @@ -119,7 +84,7 @@ class RegisterPickAvatarViewController: SegueViewController {

view.backgroundColor = UIColor.yepViewBackgroundColor()

navigationItem.titleView = NavigationTitleLabel(title: NSLocalizedString("Avatar", comment: ""))
navigationItem.titleView = NavigationTitleLabel(title: NSLocalizedString("Sign Up", comment: ""))

navigationItem.rightBarButtonItem = nextButton

Expand All @@ -129,29 +94,15 @@ class RegisterPickAvatarViewController: SegueViewController {

pickAvatarState = .Default

takePicturePromptLabel.textColor = UIColor.blackColor()
takePicturePromptLabel.text = NSLocalizedString("Set an avatar", comment: "")

openCameraButton.setTitle(NSLocalizedString("Open Camera", comment: ""), forState: .Normal)
openCameraButton.setTitle(NSLocalizedString("Choose from Library", comment: ""), forState: .Normal)
openCameraButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
openCameraButton.backgroundColor = UIColor.yepTintColor()

cameraRollButton.tintColor = UIColor.yepTintColor()
captureButton.tintColor = UIColor.yepTintColor()
retakeButton.setTitleColor(UIColor.yepTintColor(), forState: .Normal)
openCameraButton.addTarget(self, action: #selector(RegisterPickAvatarViewController.openPhotoLibraryPicker), forControlEvents: .TouchUpInside)

nextButton.enabled = false

let tap = UITapGestureRecognizer(target: self, action: #selector(RegisterPickAvatarViewController.openPhotoLibrary(_:)))
avatarImageView.addGestureRecognizer(tap)
avatarImageView.userInteractionEnabled = true

}

// MARK: Helpers



private func deviceWithMediaType(mediaType: String, preferringPosition position: AVCaptureDevicePosition) -> AVCaptureDevice? {
let devices = AVCaptureDevice.devicesWithMediaType(mediaType)
var captureDevice = devices.first as? AVCaptureDevice
Expand All @@ -171,55 +122,7 @@ class RegisterPickAvatarViewController: SegueViewController {
uploadAvatarAndGotoPickSkills()
}

@IBAction private func tryOpenCamera(sender: UIButton) {
proposeToAccess(.Camera, agreed: {
self.openCamera()

}, rejected: {
self.alertCanNotOpenCamera()
})
}

private func openCamera() {

dispatch_async(dispatch_get_main_queue()) {
self.pickAvatarState = .CameraOpen
}

dispatch_async(sessionQueue) {

if self.session.canAddInput(self.videoDeviceInput) {
self.session.addInput(self.videoDeviceInput)

dispatch_async(dispatch_get_main_queue()) {

self.cameraPreviewView.session = self.session
let orientation = AVCaptureVideoOrientation(rawValue: UIInterfaceOrientation.Portrait.rawValue)!
(self.cameraPreviewView.layer as! AVCaptureVideoPreviewLayer).connection.videoOrientation = orientation
}
}

if self.session.canAddOutput(self.stillImageOutput){
self.session.addOutput(self.stillImageOutput)
}

dispatch_async(dispatch_get_main_queue()) {
self.session.startRunning()
}
}
}

@IBAction private func tryOpenCameraRoll(sender: UIButton) {

openPhotoLibraryPicker()
}

@objc private func openPhotoLibrary(sender: UITapGestureRecognizer) {

openPhotoLibraryPicker()
}

private func openPhotoLibraryPicker() {
@objc private func openPhotoLibraryPicker() {

let openCameraRoll: ProposerAction = { [weak self] in

Expand Down Expand Up @@ -270,48 +173,6 @@ class RegisterPickAvatarViewController: SegueViewController {
}
}

@IBAction private func captureOrFinish(sender: UIButton) {
if pickAvatarState == .Captured {
uploadAvatarAndGotoPickSkills()

} else {
dispatch_async(sessionQueue) { [weak self] in
guard let strongSelf = self else {
return
}

guard let captureConnection = strongSelf.stillImageOutput.connectionWithMediaType(strongSelf.mediaType) else {
return
}

strongSelf.stillImageOutput.captureStillImageAsynchronouslyFromConnection(captureConnection, completionHandler: { imageDataSampleBuffer, error in
if error == nil {
let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
var image = UIImage(data: data)!

if let CGImage = image.CGImage {
image = UIImage(CGImage: CGImage, scale: image.scale, orientation: .LeftMirrored)
}

image = image.fixRotation().navi_centerCropWithSize(YepConfig.avatarMaxSize())!

dispatch_async(dispatch_get_main_queue()) { [weak self] in
guard let strongSelf = self else {
return
}

strongSelf.avatar = image
strongSelf.pickAvatarState = .Captured
}
}
})
}
}
}

@IBAction private func retake(sender: UIButton) {
pickAvatarState = .CameraOpen
}
}

// MARK: UIImagePicker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RegisterVerifyMobileViewController: SegueViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.yepViewBackgroundColor()
view.backgroundColor = UIColor.yepViewBackgroundColor()

navigationItem.titleView = NavigationTitleLabel(title: NSLocalizedString("Sign up", comment: ""))

Expand Down Expand Up @@ -89,7 +89,7 @@ class RegisterVerifyMobileViewController: SegueViewController {

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

verifyCodeTextField.becomeFirstResponder()

callMeTimer.fire()
Expand Down
3 changes: 3 additions & 0 deletions Yep/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
/* No comment provided by engineer. */
"Choose Photo" = "Choose Photo";

/* No comment provided by engineer. */
"Choose from Library" = "Choose from Library";

/* No comment provided by engineer. */
"Choose photo" = "Choose photo";

Expand Down
3 changes: 3 additions & 0 deletions Yep/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
/* No comment provided by engineer. */
"Choose photo" = "选择照片";

/* No comment provided by engineer. */
"Choose from Library" = "从相册选取";

/* No comment provided by engineer. */
"Clear history" = "清除历史记录";

Expand Down

0 comments on commit 0df314d

Please sign in to comment.