diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index e4b2d4433..0068213ca 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -6179,9 +6179,7 @@ const NSTimeInterval kResizeComposerAnimationDuration = .05; - (void)voiceMessageControllerDidRequestMicrophonePermission:(VoiceMessageController *)voiceMessageController { NSString *appDisplayName = [[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"]; - - // FIXME: fix permission message - NSString * message = [NSString stringWithFormat:[NSBundle mxk_localizedStringForKey:@"microphone_access_not_granted_for_call"], appDisplayName]; + NSString * message = [NSString stringWithFormat:[NSBundle mxk_localizedStringForKey:@"microphone_access_not_granted_for_voice_message"], appDisplayName]; [MXKTools checkAccessForMediaType:AVMediaTypeAudio manualChangeMessage: message diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift b/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift index 640d54e5e..804afbfe7 100644 --- a/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift +++ b/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift @@ -99,11 +99,8 @@ class VoiceMessageAudioPlayer: NSObject { func play() { isStopped = false - let audioSession = AVAudioSession.sharedInstance() - do { - try audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: .default, options: .defaultToSpeaker) - try audioSession.setActive(true, options: .notifyOthersOnDeactivation) + try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback) } catch { MXLog.error("Could not redirect audio playback to speakers.") } diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift b/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift index 7d3acc049..941a99d3a 100644 --- a/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift +++ b/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift @@ -45,7 +45,8 @@ class VoiceMessagePlaybackView: UIView, VoiceMessageAudioPlayerDelegate { var attachment: MXKAttachment? { didSet { - if oldValue?.contentURL == attachment?.contentURL { + if oldValue?.contentURL == attachment?.contentURL && + oldValue?.eventSentState == attachment?.eventSentState { return } @@ -104,6 +105,10 @@ class VoiceMessagePlaybackView: UIView, VoiceMessageAudioPlayerDelegate { // MARK: - VoiceMessageAudioPlayerDelegate + func audioPlayerDidFinishLoading(_ audioPlayer: VoiceMessageAudioPlayer) { + updateUI() + } + func audioPlayerDidStartPlaying(_ audioPlayer: VoiceMessageAudioPlayer) { state = .playing } @@ -143,7 +148,7 @@ class VoiceMessagePlaybackView: UIView, VoiceMessageAudioPlayerDelegate { switch state { case .stopped: - elapsedTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSinceReferenceDate: 0.0)) + elapsedTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSinceReferenceDate: audioPlayer.duration)) waveformView.progress = 0.0 default: elapsedTimeLabel.text = timeFormatter.string(from: Date(timeIntervalSinceReferenceDate: audioPlayer.currentTime)) diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.swift b/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.swift index 5d7c567be..8f7b664f9 100644 --- a/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.swift +++ b/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.swift @@ -35,6 +35,7 @@ class VoiceMessageToolbarView: PassthroughView, Themable, UIGestureRecognizerDel @IBOutlet private var secondaryRecordButton: UIButton! @IBOutlet private var recordingChromeContainerView: UIView! + @IBOutlet private var recordingIndicatorView: UIView! @IBOutlet private var slideToCancelContainerView: UIView! @IBOutlet private var slideToCancelLabel: UILabel! @@ -59,6 +60,7 @@ class VoiceMessageToolbarView: PassthroughView, Themable, UIGestureRecognizerDel case .recording: let convertedFrame = self.convert(slideToCancelLabel.frame, from: slideToCancelContainerView) cancelLabelToRecordButtonDistance = recordButtonsContainerView.frame.minX - convertedFrame.maxX + startAnimatingRecordingIndicator() case .idle: cancelDrag() } @@ -132,10 +134,10 @@ class VoiceMessageToolbarView: PassthroughView, Themable, UIGestureRecognizerDel let translation = gestureRecognizer.translation(in: self) - recordButtonsContainerView.transform = CGAffineTransform(translationX: min(translation.x, 0.0), y: 0.0) + secondaryRecordButton.transform = CGAffineTransform(translationX: min(translation.x, 0.0), y: 0.0) slideToCancelContainerView.transform = CGAffineTransform(translationX: min(translation.x + cancelLabelToRecordButtonDistance, 0.0), y: 0.0) - if abs(translation.x) > self.bounds.width / 2.0 { + if abs(translation.x - recordButtonsContainerView.frame.width / 2.0) > self.bounds.width / 2.0 { cancelDrag() } } @@ -155,8 +157,6 @@ class VoiceMessageToolbarView: PassthroughView, Themable, UIGestureRecognizerDel self.primaryRecordButton.alpha = 1.0 self.secondaryRecordButton.alpha = 0.0 self.recordingChromeContainerView.alpha = 0.0 - self.recordButtonsContainerView.transform = .identity - self.slideToCancelContainerView.transform = .identity case .recording: self.backgroundView.alpha = 1.0 self.primaryRecordButton.alpha = 0.0 @@ -171,10 +171,35 @@ class VoiceMessageToolbarView: PassthroughView, Themable, UIGestureRecognizerDel self.backgroundView.backgroundColor = theme.backgroundColor self.slideToCancelGradient.tintColor = theme.backgroundColor - self.primaryRecordButton.tintColor = theme.textSecondaryColor + self.primaryRecordButton.tintColor = theme.textTertiaryColor self.slideToCancelLabel.textColor = theme.textSecondaryColor self.slideToCancelChevron.tintColor = theme.textSecondaryColor self.elapsedTimeLabel.textColor = theme.textSecondaryColor + } completion: { _ in + switch self.state { + case .idle: + self.secondaryRecordButton.transform = .identity + self.slideToCancelContainerView.transform = .identity + default: + break + } } } + + private func startAnimatingRecordingIndicator() { + if self.state != .recording { + return + } + + UIView.animate(withDuration: 0.5) { + if self.recordingIndicatorView.alpha > 0.0 { + self.recordingIndicatorView.alpha = 0.0 + } else { + self.recordingIndicatorView.alpha = 1.0 + } + } completion: { [weak self] _ in + self?.startAnimatingRecordingIndicator() + } + + } } diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.xib b/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.xib index 55946887d..6218ad96a 100644 --- a/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.xib +++ b/Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.xib @@ -113,6 +113,7 @@ +