mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Replace the player timeline
This commit is contained in:
+39
-5
@@ -58,6 +58,21 @@ class VoiceBroadcastPlaybackViewModel: VoiceBroadcastPlaybackViewModelType, Voic
|
||||
|
||||
private static let defaultBackwardForwardValue: Float = 30000.0 // 30sec in ms
|
||||
|
||||
private var fullDateFormatter: DateComponentsFormatter {
|
||||
let formatter = DateComponentsFormatter()
|
||||
formatter.unitsStyle = .positional
|
||||
formatter.allowedUnits = [.hour, .minute, .second]
|
||||
return formatter
|
||||
}
|
||||
|
||||
private var shortDateFormatter: DateComponentsFormatter {
|
||||
let formatter = DateComponentsFormatter()
|
||||
formatter.unitsStyle = .positional
|
||||
formatter.zeroFormattingBehavior = .pad
|
||||
formatter.allowedUnits = [.minute, .second]
|
||||
return formatter
|
||||
}
|
||||
|
||||
// MARK: Public
|
||||
|
||||
// MARK: - Setup
|
||||
@@ -330,12 +345,16 @@ class VoiceBroadcastPlaybackViewModel: VoiceBroadcastPlaybackViewModelType, Voic
|
||||
|
||||
private func updateDuration() {
|
||||
let duration = voiceBroadcastAggregator.voiceBroadcast.duration
|
||||
let time = TimeInterval(duration / 1000)
|
||||
let formatter = DateComponentsFormatter()
|
||||
formatter.unitsStyle = .abbreviated
|
||||
|
||||
state.playingState.duration = Float(duration)
|
||||
state.playingState.durationLabel = formatter.string(from: time)
|
||||
updateUI()
|
||||
}
|
||||
|
||||
private func dateFormatter(for time: TimeInterval) -> DateComponentsFormatter {
|
||||
if time >= 3600 {
|
||||
return self.fullDateFormatter
|
||||
} else {
|
||||
return self.shortDateFormatter
|
||||
}
|
||||
}
|
||||
|
||||
private func didSliderChanged(_ didChange: Bool) {
|
||||
@@ -368,6 +387,21 @@ class VoiceBroadcastPlaybackViewModel: VoiceBroadcastPlaybackViewModelType, Voic
|
||||
}
|
||||
|
||||
private func updateUI() {
|
||||
let time = TimeInterval(state.playingState.duration / 1000)
|
||||
let formatter = dateFormatter(for: time)
|
||||
|
||||
let currentProgress = TimeInterval(state.bindings.progress / 1000)
|
||||
state.playingState.elapsedTimeLabel = formatter.string(from: currentProgress)
|
||||
if let remainingTimeString = formatter.string(from: time-currentProgress) {
|
||||
if time-currentProgress < 1.0 {
|
||||
state.playingState.remainingTimeLabel = remainingTimeString
|
||||
} else {
|
||||
state.playingState.remainingTimeLabel = "-" + remainingTimeString
|
||||
}
|
||||
} else {
|
||||
state.playingState.remainingTimeLabel = ""
|
||||
}
|
||||
|
||||
state.playingState.canMoveBackward = state.bindings.progress > 0
|
||||
state.playingState.canMoveForward = state.bindings.progress < state.playingState.duration
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user