Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 09c2e27e41
commit ee5682165d

@ -181,6 +181,20 @@ class CallViewController: UIViewController, CallDelegate {
var acceptIncomingButton: UIButton! var acceptIncomingButton: UIButton!
var declineIncomingButton: UIButton! var declineIncomingButton: UIButton!
// MARK: Control Groups
var allControls: [UIView] {
return incomingCallControls + ongoingCallControls
}
var incomingCallControls: [UIView] {
return [ incomingTextMessageButton, acceptIncomingButton, declineIncomingButton ]
}
var ongoingCallControls: [UIView] {
return [ muteButton, speakerPhoneButton, ongoingTextMessageButton, hangUpButton, videoButton ]
}
// MARK: Initializers // MARK: Initializers
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
@ -279,7 +293,7 @@ class CallViewController: UIViewController, CallDelegate {
ongoingCallView = createContainerForCallControls(controlGroups : [ ongoingCallView = createContainerForCallControls(controlGroups : [
[ongoingTextMessageButton, videoButton], [ongoingTextMessageButton, videoButton],
[muteButton, speakerPhoneButton ], [muteButton, speakerPhoneButton ],
[hangUpButton ], [hangUpButton ]
]) ])
} }
@ -297,7 +311,7 @@ class CallViewController: UIViewController, CallDelegate {
incomingCallView = createContainerForCallControls(controlGroups : [ incomingCallView = createContainerForCallControls(controlGroups : [
[incomingTextMessageButton], [incomingTextMessageButton],
[acceptIncomingButton, declineIncomingButton ], [acceptIncomingButton, declineIncomingButton ]
]) ])
} }
@ -310,14 +324,14 @@ class CallViewController: UIViewController, CallDelegate {
fixedHeight:buttonSize())) fixedHeight:buttonSize()))
} }
let rowspacing = ScaleFromIPhone5To7Plus(20, 25) let rowspacing = ScaleFromIPhone5To7Plus(20, 25)
var lastRow: UIView? var prevRow: UIView?
for row in rows { for row in rows {
containerView.addSubview(row) containerView.addSubview(row)
row.autoPinWidthToSuperview() row.autoPinWidthToSuperview()
if lastRow != nil { if prevRow != nil {
row.autoPinEdge(.top, to:.bottom, of:lastRow!, withOffset:rowspacing) row.autoPinEdge(.top, to:.bottom, of:prevRow!, withOffset:rowspacing)
} }
lastRow = row prevRow = row
} }
containerView.setContentHuggingVerticalHigh() containerView.setContentHuggingVerticalHigh()
@ -326,10 +340,8 @@ class CallViewController: UIViewController, CallDelegate {
return containerView return containerView
} }
func createButton(imageName: String!, action: Selector!, buttonSize: CGFloat!) -> UIButton { func createButton(imageName: String, action: Selector, buttonSize: CGFloat) -> UIButton {
let image = UIImage(named:imageName) let image = UIImage(named:imageName)
Logger.error("button \(imageName) \(NSStringFromCGSize(image!.size))")
Logger.flush()
let button = UIButton() let button = UIButton()
button.setImage(image, for:.normal) button.setImage(image, for:.normal)
button.addTarget(self, action:action, for:.touchUpInside) button.addTarget(self, action:action, for:.touchUpInside)
@ -338,14 +350,15 @@ class CallViewController: UIViewController, CallDelegate {
return button return button
} }
// Creates a row view that evenly spaces its subviews horizontally. // Creates a row containing a given set of subviews.
// If there is only a single subview, it is centered.
func rowWithSubviews(subviews: [UIView], fixedHeight: CGFloat) -> UIView { func rowWithSubviews(subviews: [UIView], fixedHeight: CGFloat) -> UIView {
let row = UIView() let row = UIView()
row.setContentHuggingVerticalHigh() row.setContentHuggingVerticalHigh()
row.autoSetDimension(.height, toSize:fixedHeight) row.autoSetDimension(.height, toSize:fixedHeight)
if subviews.count > 1 { if subviews.count > 1 {
// If there's more than one subview in the row,
// space them evenly within the row.
var lastSubview: UIView? var lastSubview: UIView?
var lastSpacer: UIView? var lastSpacer: UIView?
for subview in subviews { for subview in subviews {
@ -362,7 +375,7 @@ class CallViewController: UIViewController, CallDelegate {
spacer.setContentHuggingHorizontalLow() spacer.setContentHuggingHorizontalLow()
spacer.autoVCenterInSuperview() spacer.autoVCenterInSuperview()
if lastSpacer != nil { if lastSpacer != nil {
spacer.autoMatch(_:.width, to:.width, of:lastSpacer!) spacer.autoMatch(.width, to:.width, of:lastSpacer!)
} }
lastSpacer = spacer lastSpacer = spacer
} }
@ -371,10 +384,8 @@ class CallViewController: UIViewController, CallDelegate {
} }
subviews.first!.autoPinEdge(toSuperviewEdge:.left) subviews.first!.autoPinEdge(toSuperviewEdge:.left)
subviews.last!.autoPinEdge(toSuperviewEdge:.right) subviews.last!.autoPinEdge(toSuperviewEdge:.right)
Logger.error("row \(subviews.count) -> \(row.subviews.count)")
} else if subviews.count == 1 { } else if subviews.count == 1 {
// If there's only one subview in this row, center it.
let subview = subviews.first! let subview = subviews.first!
row.addSubview(subview) row.addSubview(subview)
subview.autoCenterInSuperview() subview.autoCenterInSuperview()
@ -476,14 +487,14 @@ class CallViewController: UIViewController, CallDelegate {
// Show Incoming vs. (Outgoing || Accepted) call controls // Show Incoming vs. (Outgoing || Accepted) call controls
let isRinging = callState == .localRinging let isRinging = callState == .localRinging
for subview in allControls() { for subview in allControls {
if isRinging { if isRinging {
// Show incoming controls // Show incoming controls
let isIncomingCallControl = incomingCallControls().contains(subview) let isIncomingCallControl = incomingCallControls.contains(subview)
subview.isHidden = !isIncomingCallControl subview.isHidden = !isIncomingCallControl
} else { } else {
// Show ongoing controls // Show ongoing controls
let isOngoingCallControl = ongoingCallControls().contains(subview) let isOngoingCallControl = ongoingCallControls.contains(subview)
subview.isHidden = !isOngoingCallControl subview.isHidden = !isOngoingCallControl
} }
} }
@ -503,18 +514,6 @@ class CallViewController: UIViewController, CallDelegate {
} }
} }
func allControls() -> [UIView] {
return incomingCallControls() + ongoingCallControls()
}
func incomingCallControls() -> [UIView] {
return [ incomingTextMessageButton, acceptIncomingButton, declineIncomingButton ]
}
func ongoingCallControls() -> [UIView] {
return [ muteButton, speakerPhoneButton, ongoingTextMessageButton, hangUpButton, videoButton ]
}
// MARK: - Actions // MARK: - Actions
/** /**

Loading…
Cancel
Save