mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Add a MediaUploadQualitySettingsScreen. (#6279)
This commit is contained in:
@@ -97,6 +97,7 @@ enum TestablePreviewsDictionary {
|
||||
"MatrixUserPermalink_Previews" : MatrixUserPermalink_Previews.self,
|
||||
"MediaEventsTimelineScreen_Previews" : MediaEventsTimelineScreen_Previews.self,
|
||||
"MediaUploadPreviewScreen_Previews" : MediaUploadPreviewScreen_Previews.self,
|
||||
"MediaUploadQualitySettingsScreen_Previews" : MediaUploadQualitySettingsScreen_Previews.self,
|
||||
"MentionSuggestionItemView_Previews" : MentionSuggestionItemView_Previews.self,
|
||||
"MessageComposerTextField_Previews" : MessageComposerTextField_Previews.self,
|
||||
"MessageComposer_Previews" : MessageComposer_Previews.self,
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct MediaUploadQualitySettingsScreenCoordinatorParameters {
|
||||
let userSettings: UserSettings
|
||||
let analytics: AnalyticsServiceProtocol
|
||||
}
|
||||
|
||||
final class MediaUploadQualitySettingsScreenCoordinator: CoordinatorProtocol {
|
||||
private var viewModel: MediaUploadQualitySettingsScreenViewModelProtocol
|
||||
|
||||
init(parameters: MediaUploadQualitySettingsScreenCoordinatorParameters) {
|
||||
viewModel = MediaUploadQualitySettingsScreenViewModel(userSettings: parameters.userSettings, analytics: parameters.analytics)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(MediaUploadQualitySettingsScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
struct MediaUploadQualitySettingsScreenViewState: BindableState {
|
||||
var bindings: MediaUploadQualitySettingsScreenViewStateBindings
|
||||
}
|
||||
|
||||
struct MediaUploadQualitySettingsScreenViewStateBindings {
|
||||
private let userSettings: UserSettings
|
||||
|
||||
init(userSettings: UserSettings) {
|
||||
self.userSettings = userSettings
|
||||
}
|
||||
|
||||
var optimizeMediaUploads: Bool {
|
||||
get { userSettings.optimizeMediaUploads }
|
||||
set { userSettings.optimizeMediaUploads = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
enum MediaUploadQualitySettingsScreenViewAction {
|
||||
case optimizeMediaUploadsChanged
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias MediaUploadQualitySettingsScreenViewModelType = StateStoreViewModelV2<MediaUploadQualitySettingsScreenViewState, MediaUploadQualitySettingsScreenViewAction>
|
||||
|
||||
class MediaUploadQualitySettingsScreenViewModel: MediaUploadQualitySettingsScreenViewModelType, MediaUploadQualitySettingsScreenViewModelProtocol {
|
||||
private let analytics: AnalyticsServiceProtocol
|
||||
|
||||
init(userSettings: UserSettings, analytics: AnalyticsServiceProtocol) {
|
||||
self.analytics = analytics
|
||||
|
||||
let state = MediaUploadQualitySettingsScreenViewState(bindings: .init(userSettings: userSettings))
|
||||
super.init(initialViewState: state)
|
||||
}
|
||||
|
||||
override func process(viewAction: MediaUploadQualitySettingsScreenViewAction) {
|
||||
switch viewAction {
|
||||
case .optimizeMediaUploadsChanged:
|
||||
// Note: Using a view action here as sinking the UserSettings publisher tracks the initial value.
|
||||
analytics.trackInteraction(name: state.bindings.optimizeMediaUploads ? .MobileSettingsOptimizeMediaUploadsEnabled : .MobileSettingsOptimizeMediaUploadsDisabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Combine
|
||||
|
||||
protocol MediaUploadQualitySettingsScreenViewModelProtocol {
|
||||
var context: MediaUploadQualitySettingsScreenViewModelType.Context { get }
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct MediaUploadQualitySettingsScreen: View {
|
||||
@Bindable var context: MediaUploadQualitySettingsScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenAdvancedSettingsMediaCompressionTitle,
|
||||
description: L10n.screenAdvancedSettingsMediaCompressionDescription),
|
||||
kind: .toggle($context.optimizeMediaUploads))
|
||||
.onChange(of: context.optimizeMediaUploads) {
|
||||
context.send(viewAction: .optimizeMediaUploadsChanged)
|
||||
}
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(L10n.commonMediaUploadQuality)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct MediaUploadQualitySettingsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = MediaUploadQualitySettingsScreenViewModel(userSettings: .mock(), analytics: AnalyticsServiceMock(.init()))
|
||||
|
||||
static var previews: some View {
|
||||
ElementNavigationStack {
|
||||
MediaUploadQualitySettingsScreen(context: viewModel.context)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user