pr suggestions

This commit is contained in:
Mauro Romito
2026-02-19 22:03:23 +01:00
committed by Mauro
parent 43fa220b42
commit d6eccd3a64
6 changed files with 54 additions and 41 deletions
@@ -362,8 +362,8 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.optimizeMediaUploads, defaultValue: true, storageType: .userDefaults(store))
var optimizeMediaUploads
@UserPreference(key: UserDefaultsKeys.voiceMessagePlaybackSpeed, defaultValue: VoiceMessagePlaybackSpeed.default, storageType: .userDefaults(store))
var voiceMessagePlaybackSpeed: VoiceMessagePlaybackSpeed
@UserPreference(key: UserDefaultsKeys.voiceMessagePlaybackSpeed, defaultValue: AudioPlaybackSpeed.default, storageType: .userDefaults(store))
var voiceMessagePlaybackSpeed: AudioPlaybackSpeed
/// Whether or not to show a warning on the media caption composer so the user knows
/// that captions might not be visible to users who are using other Matrix clients.
@@ -452,23 +452,3 @@ final class AppSettings {
}
extension AppSettings: CommonSettingsProtocol { }
enum VoiceMessagePlaybackSpeed: Float, CaseIterable, Codable {
case `default` = 1.0
case fast = 1.5
case fastest = 2.0
case slow = 0.5
var label: String {
switch self {
case .default, .fastest:
rawValue.formatted(.number.precision(.fractionLength(0))) + "×"
case .fast, .slow:
rawValue.formatted(.number.precision(.fractionLength(1))) + "×"
}
}
var placeholder: String {
0.0.formatted(.number.precision(.fractionLength(1))) + "×"
}
}
@@ -0,0 +1,33 @@
//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
enum AudioPlaybackSpeed: Float, CaseIterable, Codable {
case `default` = 1.0
case fast = 1.5
case fastest = 2.0
case slow = 0.5
var label: String {
switch self {
case .default, .fastest:
rawValue.formatted(.number.precision(.fractionLength(0))) + "×"
case .fast, .slow:
rawValue.formatted(.number.precision(.fractionLength(1))) + "×"
}
}
var placeholder: String {
0.0.formatted(.number.precision(.fractionLength(1))) + "×"
}
var next: Self {
guard let index = Self.allCases.firstIndex(of: self) else {
return .default
}
return Self.allCases[(index + 1) % Self.allCases.count]
}
}
@@ -8,7 +8,7 @@
import SwiftUI
struct PlaybackSpeedButton: View {
let speed: VoiceMessagePlaybackSpeed
let speed: AudioPlaybackSpeed
let onTap: () -> Void
var body: some View {
@@ -35,7 +35,7 @@ struct PlaybackSpeedButton: View {
struct PlaybackSpeedButton_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
HStack(spacing: 8) {
ForEach(VoiceMessagePlaybackSpeed.allCases, id: \.self) { speed in
ForEach(AudioPlaybackSpeed.allCases, id: \.self) { speed in
PlaybackSpeedButton(speed: speed) { }
}
}
@@ -419,15 +419,7 @@ class TimelineInteractionHandler {
// MARK: Audio Playback
func changePlaybackSpeed(for itemID: TimelineItemIdentifier) {
let availableSpeeds = VoiceMessagePlaybackSpeed.allCases
guard let currentIndex = availableSpeeds.firstIndex(of: appSettings.voiceMessagePlaybackSpeed) else {
appSettings.voiceMessagePlaybackSpeed = .default
audioPlayerState(for: itemID)?.setPlaybackSpeed(VoiceMessagePlaybackSpeed.default)
return
}
let nextIndex = (currentIndex + 1) % availableSpeeds.count
let nextSpeed = availableSpeeds[nextIndex]
let nextSpeed = appSettings.voiceMessagePlaybackSpeed.next
appSettings.voiceMessagePlaybackSpeed = nextSpeed
audioPlayerState(for: itemID)?.setPlaybackSpeed(nextSpeed)
}
@@ -36,7 +36,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
/// It's similar to `playbackState`, with the a difference: `.loading`
/// updates are delayed by a fixed amount of time
@Published private(set) var playerButtonPlaybackState: AudioPlayerPlaybackState
@Published private(set) var playbackSpeed: VoiceMessagePlaybackSpeed
@Published private(set) var playbackSpeed: AudioPlaybackSpeed
private weak var audioPlayer: AudioPlayerProtocol?
private var audioPlayerSubscription: AnyCancellable?
@@ -63,8 +63,8 @@ class AudioPlayerState: ObservableObject, Identifiable {
duration: Double,
waveform: EstimatedWaveform? = nil,
progress: Double = 0.0,
playbackSpeed: VoiceMessagePlaybackSpeed = .default,
playbackSpeedPublisher: AnyPublisher<VoiceMessagePlaybackSpeed, Never>? = nil) {
playbackSpeed: AudioPlaybackSpeed = .default,
playbackSpeedPublisher: AnyPublisher<AudioPlaybackSpeed, Never>? = nil) {
self.id = id
self.title = title
self.duration = duration
@@ -120,7 +120,7 @@ class AudioPlayerState: ObservableObject, Identifiable {
playbackState = .error
}
func setPlaybackSpeed(_ speed: VoiceMessagePlaybackSpeed) {
func setPlaybackSpeed(_ speed: AudioPlaybackSpeed) {
playbackSpeed = speed
audioPlayer?.setPlaybackSpeed(speed.rawValue)
}