mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-03 14:46:56 +02:00
#4090 - Update after review
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -133,6 +144,7 @@ public class VoiceMessageController: NSObject, VoiceMessageToolbarViewDelegate,
|
||||
// MARK: - AudioRecorderDelegate
|
||||
|
||||
func audioRecorderDidStartRecording(_ audioRecorder: VoiceMessageAudioRecorder) {
|
||||
notifiedRemainingTime = false
|
||||
updateUI()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user