Skip to content

Commit

Permalink
#4090 - Update after review
Browse files Browse the repository at this point in the history
  • Loading branch information
gileluard committed Jul 9, 2021
1 parent e492d2b commit 65415c4
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
2 changes: 1 addition & 1 deletion Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,6 @@ Tap the + to start adding people.";

// Mark: - Voice Messages

"voice_message_release_to_send" = "Release to send";
"voice_message_release_to_send" = "Hold to record, release to send";
"voice_message_remaining_recording_time" = "%@s left";
"voice_message_stop_locked_mode_recording" = "Tap on the wavelength to stop and playback";
2 changes: 1 addition & 1 deletion Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4838,7 +4838,7 @@ internal enum VectorL10n {
internal static var voice: String {
return VectorL10n.tr("Vector", "voice")
}
/// Release to send
/// Hold to record, release to send
internal static var voiceMessageReleaseToSend: String {
return VectorL10n.tr("Vector", "voice_message_release_to_send")
}
Expand Down
24 changes: 22 additions & 2 deletions Riot/Modules/Room/VoiceMessages/VoiceMessageController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class VoiceMessageController: NSObject, VoiceMessageToolbarViewDelegate,

private var audioSamples: [Float] = []
private var isInLockedMode: Bool = false
private var notifiedRemainingTime = false

@objc public weak var delegate: VoiceMessageControllerDelegate?

Expand Down Expand Up @@ -82,7 +83,17 @@ public class VoiceMessageController: NSObject, VoiceMessageToolbarViewDelegate,
delegate?.voiceMessageControllerDidRequestMicrophonePermission(self)
return
}


// Haptic are not played during record on iOS by default. This fix works
// only since iOS 13. A workaround for iOS 12 and earlier would be to
// dispatch after at least 100ms recordWithOuputURL call
if #available(iOS 13.0, *) {
try? AVAudioSession.sharedInstance().setCategory(.playAndRecord)
try? AVAudioSession.sharedInstance().setAllowHapticsAndSystemSoundsDuringRecording(true)
}

UIImpactFeedbackGenerator(style: .medium).impactOccurred()

let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let temporaryFileURL = temporaryDirectoryURL.appendingPathComponent(ProcessInfo().globallyUniqueString).appendingPathExtension("m4a")

Expand Down Expand Up @@ -133,6 +144,7 @@ public class VoiceMessageController: NSObject, VoiceMessageToolbarViewDelegate,
// MARK: - AudioRecorderDelegate

func audioRecorderDidStartRecording(_ audioRecorder: VoiceMessageAudioRecorder) {
notifiedRemainingTime = false
updateUI()
}

Expand Down Expand Up @@ -277,7 +289,15 @@ public class VoiceMessageController: NSObject, VoiceMessageToolbarViewDelegate,

if isRecording {
if currentTime >= Constants.maximumAudioRecordingDuration - Constants.maximumAudioRecordingLengthReachedThreshold {
details.toastMessage = VectorL10n.voiceMessageRemainingRecordingTime(String(Constants.maximumAudioRecordingLengthReachedThreshold))

if !self.notifiedRemainingTime {
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
}

notifiedRemainingTime = true

let remainingTime = ceil(Constants.maximumAudioRecordingDuration - currentTime)
details.toastMessage = VectorL10n.voiceMessageRemainingRecordingTime(String(remainingTime))
} else {
details.toastMessage = (isInLockedMode ? VectorL10n.voiceMessageStopLockedModeRecording : VectorL10n.voiceMessageReleaseToSend)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class VoiceMessagePlaybackView: UIView, NibLoadable, Themable {
}

self.backgroundColor = theme.colors.background
playButton.backgroundColor = theme.colors.separator
playButton.backgroundColor = theme.colors.background
playButton.tintColor = theme.colors.secondaryContent
backgroundView.backgroundColor = theme.colors.quinaryContent
_waveformView.primarylineColor = theme.colors.quarterlyContent
_waveformView.secondaryLineColor = theme.colors.secondaryContent
Expand Down
32 changes: 31 additions & 1 deletion Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class VoiceMessageToolbarView: PassthroughView, NibLoadable, Themable, UIGesture
static let lockModeTransitionAnimationDuration: TimeInterval = 0.5
static let panDirectionChangeThreshold: CGFloat = 20.0
static let toastContainerCornerRadii: CGFloat = 8.0
static let toastDisplayTimeout: TimeInterval = 5.0
}

@IBOutlet private var backgroundView: UIView!
Expand Down Expand Up @@ -309,15 +310,44 @@ class VoiceMessageToolbarView: PassthroughView, NibLoadable, Themable, UIGesture
}
}

private var toastIdleTimer: Timer?
private var lastUIState: VoiceMessageToolbarViewUIState = .idle

private func updateToastNotificationsWithDetails(_ details: VoiceMessageToolbarViewDetails, animated: Bool = true) {

guard self.toastNotificationLabel.text != details.toastMessage || lastUIState != details.state else {
return
}

lastUIState = details.state

let shouldShowNotification = details.state != .idle && details.toastMessage != nil
let requiredAlpha: CGFloat = shouldShowNotification ? 1.0 : 0.0

toastIdleTimer?.invalidate()
toastIdleTimer = nil

if shouldShowNotification {
self.toastNotificationLabel.text = details.toastMessage
}

UIView.animate(withDuration: (animated ? Constants.animationDuration : 0.0)) {
self.toastNotificationContainerView.alpha = (shouldShowNotification ? 1.0 : 0.0)
self.toastNotificationContainerView.alpha = requiredAlpha
}

if shouldShowNotification {
toastIdleTimer = Timer.scheduledTimer(withTimeInterval: Constants.toastDisplayTimeout, repeats: false) { [weak self] timer in
guard let self = self else {
return
}

self.toastIdleTimer?.invalidate()
self.toastIdleTimer = nil

UIView.animate(withDuration: Constants.animationDuration) {
self.toastNotificationContainerView.alpha = 0
}
}
}
}

Expand Down

0 comments on commit 65415c4

Please sign in to comment.