Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Jun 5, 2022
1 parent e79f6fd commit 333d723
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Tinodios/MessageCell+VLCMediaPlayerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ extension MessageCell: VLCMediaPlayerDelegate {
try session.setActive(true)
try session.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
} catch let error as NSError {
print("audioSession error: \(error.localizedDescription)")
Cache.log.error("Failed to enable speakerphone: %@", error.localizedDescription)
}
} else {
do {
try session.setActive(false)
} catch let error as NSError {
print("audioSession error: \(error.localizedDescription)")
Cache.log.error("Failed to disable audio session: %@", error.localizedDescription)
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions Tinodios/MessageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ class MessageViewController: UIViewController {
guard case let ImagePreviewContent.ImageContent.uiimage(image) = content.imgContent else { return }

guard let data = image.pixelData(forMimeType: content.contentType) else { return }
print("image size: \(data.count), max inband size: \(maxInbandSize)")
if data.count > maxInbandSize {
self.interactor?.uploadImage(UploadDef(caption: content.caption, filename: content.fileName, mimeType: content.contentType, image: image, data: data, width: image.size.width * image.scale, height: image.size.height * image.scale))
} else {
Expand Down Expand Up @@ -462,9 +461,7 @@ class MessageViewController: UIViewController {
if data.count > maxInbandSize {
self.interactor?.uploadAudio(UploadDef(mimeType: mime, data: data, duration: duration, preview: preview))
} else {
print("Sending short audio of size \(data.count), duration=\(duration)")
if let drafty = try? Drafty(plainText: " ").insertAudio(at: 0, mime: mime, bits: data, preview: preview, duration: duration, fname: nil, refurl: nil, size: data.count) {
print("Drafty: \(drafty)")
_ = interactor?.sendMessage(content: drafty)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tinodios/RecordedMediaPlayback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RecordedMediaPlayback: NSObject {
audioPlayer.numberOfLoops = 0
audioPlayer.play()
} catch {
print("Unable to start playback: %@", error.localizedDescription)
Cache.log.error("Unable to start playback: %@", error.localizedDescription)
}
}

Expand Down
8 changes: 1 addition & 7 deletions Tinodios/UiUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1022,27 +1022,21 @@ extension UIView {
/// - dimension: width and height of the square view to make visible.
/// - width: width of the view to make visible
/// - height: height of the view to make visible.
func show(_ show: Bool, dimension: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil, debug: Bool = false) {
func show(_ show: Bool, dimension: CGFloat? = nil, width: CGFloat? = nil, height: CGFloat? = nil) {
for constraint in self.constraints {
self.isHidden = !show
if constraint.firstAttribute == .width {
if !show {
constraint.constant = .leastNonzeroMagnitude
} else if let width = width ?? dimension {
constraint.constant = width
if debug {
print("width = \(constraint.constant)")
}
}
self.setNeedsLayout()
} else if constraint.firstAttribute == .height {
if !show {
constraint.constant = .leastNonzeroMagnitude
} else if let height = height ?? dimension {
constraint.constant = height
if debug {
print("height = \(constraint.constant)")
}
}
self.setNeedsLayout()
}
Expand Down
82 changes: 42 additions & 40 deletions Tinodios/widgets/SendMessageBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,29 @@ class SendMessageBar: UIView {
case hidden
}

private static let kSendButtonPointsNormal: CGFloat = 26
private static let kSendButtonPointsPressed: CGFloat = 40
private static let kSendButtonSizeNormal: CGFloat = 32
private static let kSendButtonSizePressed: CGFloat = 48
private static let kSendButtonImageWave = UIImage(systemName: "waveform.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: SendMessageBar.kSendButtonPointsNormal))!
private static let kSendButtonImageWavePressed = UIImage(systemName: "waveform.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: SendMessageBar.kSendButtonPointsPressed))!
private static let kSendButtonImageArrow = UIImage(systemName: "arrow.up.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: SendMessageBar.kSendButtonPointsNormal))!
private static let kWaveInsetsShort = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 88)
private static let kWaveInsetsLong = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 52)
// Initial input text weight.
private static let kInitialInputFieldHeight: CGFloat = 40
// MARK: - Constants

private enum Constants {
static let maxLines: CGFloat = 4
static let inputFieldInsetLeading: CGFloat = 4
static let inputFieldInsetTrailing: CGFloat = 40
static let peerMessagingDisabledHeight: CGFloat = 30
static let kPreviewCancelButtonMaxWidth: CGFloat = 36

static let kSendButtonPointsNormal: CGFloat = 26
static let kSendButtonPointsPressed: CGFloat = 40
static let kButtonSizeNormal: CGFloat = 32
static let kSendButtonSizePressed: CGFloat = 48

// Initial input text weight.
static let kInitialInputFieldHeight: CGFloat = 40

static let kSendButtonImageWave = UIImage(systemName: "waveform.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: Constants.kSendButtonPointsNormal))!
static let kSendButtonImageWavePressed = UIImage(systemName: "waveform.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: Constants.kSendButtonPointsPressed))!
static let kSendButtonImageArrow = UIImage(systemName: "arrow.up.circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: Constants.kSendButtonPointsNormal))!
static let kWaveInsetsShort = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 88)
static let kWaveInsetsLong = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 52)
}

// MARK: Action delegate

Expand Down Expand Up @@ -174,8 +186,8 @@ class SendMessageBar: UIView {
DispatchQueue.main.async {
UIView.animate(withDuration: 0.2, delay: 0, options: UIView.AnimationOptions.curveEaseIn, animations: {
self.showAudioBar(.short)
self.sendButtonSize.constant = SendMessageBar.kSendButtonSizePressed
self.sendButton.setImage(SendMessageBar.kSendButtonImageWavePressed, for: .normal)
self.sendButtonSize.constant = Constants.kSendButtonSizePressed
self.sendButton.setImage(Constants.kSendButtonImageWavePressed, for: .normal)
self.verticalSliderView.isHidden = false
self.horizontalSliderView.isHidden = false
self.layoutIfNeeded()
Expand Down Expand Up @@ -234,16 +246,6 @@ class SendMessageBar: UIView {
self.delegate?.dismissPendingMessagePreview()
}

// MARK: - Constants

private enum Constants {
static let maxLines: CGFloat = 4
static let inputFieldInsetLeading: CGFloat = 4
static let inputFieldInsetTrailing: CGFloat = 40
static let peerMessagingDisabledHeight: CGFloat = 30
static let kPreviewCancelButtonMaxWidth: CGFloat = 36
}

// MARK: - Private properties

private var inputFieldMaxHeight: CGFloat = 120
Expand Down Expand Up @@ -345,18 +347,18 @@ class SendMessageBar: UIView {
stopAudioRecordingButton.show(false)
} else {
// Long bar
deleteAudioButton.show(true, dimension: 32)
deleteAudioButton.show(true, dimension: Constants.kButtonSizeNormal)
switch state {
case .longInitial:
playAudioButton.show(false)
pauseAudioButton.show(false)
stopAudioRecordingButton.show(true, dimension: 32)
stopAudioRecordingButton.show(true, dimension: Constants.kButtonSizeNormal)
case .longPlayback:
playAudioButton.show(false)
pauseAudioButton.show(true, dimension: 32)
pauseAudioButton.show(true, dimension: Constants.kButtonSizeNormal)
stopAudioRecordingButton.show(false)
case .longPaused:
playAudioButton.show(true, dimension: 32)
playAudioButton.show(true, dimension: Constants.kButtonSizeNormal)
pauseAudioButton.show(false)
stopAudioRecordingButton.show(false)
default:
Expand All @@ -366,15 +368,15 @@ class SendMessageBar: UIView {

if state == .hidden {
// Bar hidden.
inputField.show(true, height: SendMessageBar.kInitialInputFieldHeight)
inputField.show(true, height: Constants.kInitialInputFieldHeight)
attachButton.isHidden = false
// audioDurationLabel.show(false)
audioDurationLabel.isHidden = true
wavePreviewImageView.isHidden = true
wavePreviewImageView.reset()
audioViewHeight.constant = CGFloat.leastNonzeroMagnitude
audioView.isHidden = true
sendButton.setImage(SendMessageBar.kSendButtonImageWave, for: .normal)
sendButton.setImage(Constants.kSendButtonImageWave, for: .normal)
} else {
// Long or short bar visible.
inputField.resignFirstResponder() // Otherwise it does not hide
Expand All @@ -388,10 +390,10 @@ class SendMessageBar: UIView {
wavePreviewImageView.isHidden = false
if state == .short {
wavePreviewLeading.constant = 8
wavePreviewImageView.waveInsets = SendMessageBar.kWaveInsetsShort
wavePreviewImageView.waveInsets = Constants.kWaveInsetsShort
} else {
wavePreviewLeading.constant = 40
wavePreviewImageView.waveInsets = SendMessageBar.kWaveInsetsLong
wavePreviewImageView.waveInsets = Constants.kWaveInsetsLong
}
}

Expand All @@ -405,12 +407,12 @@ class SendMessageBar: UIView {
self.verticalSliderView.isHidden = true
self.horizontalSliderView.isHidden = true
if state == .lock {
self.sendButtonSize.constant = SendMessageBar.kSendButtonSizeNormal
self.sendButtonSize.constant = Constants.kButtonSizeNormal
self.sendButton.setImage(SendMessageBar.kSendButtonImageArrow, for: .normal)
self.showAudioBar(.longInitial)
} else {
self.sendButtonSize.constant = SendMessageBar.kSendButtonSizeNormal
self.sendButton.setImage(SendMessageBar.kSendButtonImageWave, for: .normal)
self.sendButtonSize.constant = Constants.kButtonSizeNormal
self.sendButton.setImage(Constants.kSendButtonImageWave, for: .normal)
self.showAudioBar(.hidden)
}
self.layoutIfNeeded()
Expand All @@ -429,15 +431,15 @@ class SendMessageBar: UIView {
switch state {
case .playbackStart:
playAudioButton.show(false)
pauseAudioButton.show(true, dimension: 32)
pauseAudioButton.show(true, dimension: Constants.kButtonSizeNormal)
wavePreviewImageView.play()
case .playbackReset:
wavePreviewImageView.reset()
playAudioButton.show(true, dimension: 32)
playAudioButton.show(true, dimension: Constants.kButtonSizeNormal)
pauseAudioButton.show(false)
case .playbackPause:
wavePreviewImageView.pause(rewind: false)
playAudioButton.show(true, dimension: 32)
playAudioButton.show(true, dimension: Constants.kButtonSizeNormal)
pauseAudioButton.show(false)
default:
break
Expand All @@ -450,17 +452,17 @@ extension SendMessageBar: UITextViewDelegate {
delegate?.sendMessageBar(textChangedTo: textView.text)

if inputField.actualText.isEmpty {
inputFieldHeight.constant = SendMessageBar.kInitialInputFieldHeight
inputFieldHeight.constant = Constants.kInitialInputFieldHeight

self.sendButton.setImage(SendMessageBar.kSendButtonImageWave, for: .normal)
self.sendButton.setImage(Constants.kSendButtonImageWave, for: .normal)
} else {
let size = CGSize(width: frame.width - Constants.inputFieldInsetLeading - Constants.inputFieldInsetTrailing, height: .greatestFiniteMagnitude)
let fittingSize = inputField.sizeThatFits(size)
if fittingSize.height <= inputFieldMaxHeight {
inputFieldHeight.constant = fittingSize.height + 2 // Not sure why but it seems to be off by 2
}

self.sendButton.setImage(SendMessageBar.kSendButtonImageArrow, for: .normal)
self.sendButton.setImage(Constants.kSendButtonImageArrow, for: .normal)
}
}
}

0 comments on commit 333d723

Please sign in to comment.