Skip to content

Commit

Permalink
#4096 - Various small UI tweaks and bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Jun 18, 2021
1 parent 41f15f2 commit eb9784c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
4 changes: 1 addition & 3 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6179,9 +6179,7 @@ - (void)removeJitsiWidgetViewDidCompleteSliding:(RemoveJitsiWidgetView *)view
- (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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -104,6 +105,10 @@ class VoiceMessagePlaybackView: UIView, VoiceMessageAudioPlayerDelegate {

// MARK: - VoiceMessageAudioPlayerDelegate

func audioPlayerDidFinishLoading(_ audioPlayer: VoiceMessageAudioPlayer) {
updateUI()
}

func audioPlayerDidStartPlaying(_ audioPlayer: VoiceMessageAudioPlayer) {
state = .playing
}
Expand Down Expand Up @@ -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))
Expand Down
35 changes: 30 additions & 5 deletions Riot/Modules/Room/VoiceMessages/VoiceMessageToolbarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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()
}
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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
Expand All @@ -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()
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<outlet property="primaryRecordButton" destination="BDj-Sw-VQ5" id="dg3-fG-Bym"/>
<outlet property="recordButtonsContainerView" destination="7OQ-1F-5qT" id="HDQ-r9-2Tu"/>
<outlet property="recordingChromeContainerView" destination="dyu-ha-046" id="u7O-Vb-T2W"/>
<outlet property="recordingIndicatorView" destination="miF-pM-B9J" id="zNy-ms-awL"/>
<outlet property="secondaryRecordButton" destination="rel-Fo-ROL" id="KXM-gt-9hS"/>
<outlet property="slideToCancelChevron" destination="82A-vC-KEp" id="Chg-EH-UBv"/>
<outlet property="slideToCancelContainerView" destination="6FH-4Q-Z5e" id="qCc-rl-vQX"/>
Expand Down

0 comments on commit eb9784c

Please sign in to comment.