mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-19 16:13:42 +02:00
#4090 - Various tweaks and fixes following code review. Switched back to DateFormatters for formatting durations, sanitising audio player durations and current times.
This commit is contained in:
@@ -26,6 +26,10 @@ enum VoiceMessagePlaybackControllerState {
|
||||
|
||||
class VoiceMessagePlaybackController: VoiceMessageAudioPlayerDelegate, VoiceMessagePlaybackViewDelegate {
|
||||
|
||||
private enum Constants {
|
||||
static let elapsedTimeFormat = "m:ss"
|
||||
}
|
||||
|
||||
private let mediaServiceProvider: VoiceMessageMediaServiceProvider
|
||||
private let cacheManager: VoiceMessageAttachmentCacheManager
|
||||
|
||||
@@ -43,6 +47,13 @@ class VoiceMessagePlaybackController: VoiceMessageAudioPlayerDelegate, VoiceMess
|
||||
}
|
||||
}
|
||||
|
||||
private static let timeFormatter: DateFormatter = {
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = Constants.elapsedTimeFormat
|
||||
return dateFormatter
|
||||
}()
|
||||
|
||||
|
||||
let playbackView: VoiceMessagePlaybackView
|
||||
|
||||
init(mediaServiceProvider: VoiceMessageMediaServiceProvider,
|
||||
@@ -134,11 +145,11 @@ class VoiceMessagePlaybackController: VoiceMessageAudioPlayerDelegate, VoiceMess
|
||||
|
||||
switch state {
|
||||
case .stopped:
|
||||
details.currentTime = durationStringFromTimeInterval(self.duration)
|
||||
details.currentTime = VoiceMessagePlaybackController.timeFormatter.string(from: Date(timeIntervalSinceReferenceDate: self.duration))
|
||||
details.progress = 0.0
|
||||
default:
|
||||
if let audioPlayer = audioPlayer {
|
||||
details.currentTime = durationStringFromTimeInterval(audioPlayer.currentTime)
|
||||
details.currentTime = VoiceMessagePlaybackController.timeFormatter.string(from: Date(timeIntervalSinceReferenceDate: audioPlayer.currentTime))
|
||||
details.progress = (audioPlayer.duration > 0.0 ? audioPlayer.currentTime / audioPlayer.duration : 0.0)
|
||||
}
|
||||
}
|
||||
@@ -199,18 +210,4 @@ class VoiceMessagePlaybackController: VoiceMessageAudioPlayerDelegate, VoiceMess
|
||||
@objc private func updateTheme() {
|
||||
playbackView.update(theme: ThemeService.shared().theme)
|
||||
}
|
||||
|
||||
private func durationStringFromTimeInterval(_ interval: TimeInterval) -> String {
|
||||
guard interval.isFinite else {
|
||||
return ""
|
||||
}
|
||||
|
||||
var timeInterval = abs(interval)
|
||||
let hours = trunc(timeInterval / 3600.0)
|
||||
timeInterval -= hours * 3600.0
|
||||
let minutes = trunc(timeInterval / 60.0)
|
||||
timeInterval -= minutes * 60.0
|
||||
|
||||
return String(format: "%01.0f:%02.0f", minutes, timeInterval)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user