Configured and applied SwiftFormat

This commit is contained in:
Stefan Ceriu
2022-09-27 10:17:22 +03:00
committed by Stefan Ceriu
parent ff2e6ddfa7
commit 43c28d23b7
663 changed files with 2329 additions and 2840 deletions
@@ -25,7 +25,6 @@ import Foundation
/// Each bridge should be removed once the underlying Coordinator has been integrated by another Coordinator.
@objcMembers
final class NotificationSettingsCoordinatorBridgePresenter: NSObject {
// MARK: - Properties
// MARK: Private
@@ -48,7 +47,6 @@ final class NotificationSettingsCoordinatorBridgePresenter: NSObject {
// MARK: - Public
func push(from navigationController: UINavigationController, animated: Bool, screen: NotificationSettingsScreen, popCompletion: (() -> Void)?) {
let router = NavigationRouterStore.shared.navigationRouter(for: navigationController)
let notificationSettingsCoordinator = NotificationSettingsCoordinator(session: session, screen: screen)
@@ -61,12 +59,12 @@ final class NotificationSettingsCoordinatorBridgePresenter: NSObject {
notificationSettingsCoordinator.start()
self.coordinator = notificationSettingsCoordinator
coordinator = notificationSettingsCoordinator
self.router = router
}
func dismiss(animated: Bool, completion: (() -> Void)?) {
guard let coordinator = self.coordinator else {
guard let coordinator = coordinator else {
return
}
coordinator.toPresentable().dismiss(animated: animated) {
@@ -80,18 +78,17 @@ final class NotificationSettingsCoordinatorBridgePresenter: NSObject {
}
// MARK: - NotificationSettingsCoordinatorDelegate
extension NotificationSettingsCoordinatorBridgePresenter: NotificationSettingsCoordinatorDelegate {
func notificationSettingsCoordinatorDidComplete(_ coordinator: NotificationSettingsCoordinatorType) {
self.delegate?.notificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
delegate?.notificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
}
}
// MARK: - UIAdaptivePresentationControllerDelegate
extension NotificationSettingsCoordinatorBridgePresenter: UIAdaptivePresentationControllerDelegate {
func notificationSettingsCoordinatorDidComplete(_ presentationController: UIPresentationController) {
self.delegate?.notificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
delegate?.notificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
}
}
@@ -18,7 +18,6 @@ import Foundation
import SwiftUI
final class NotificationSettingsCoordinator: NotificationSettingsCoordinatorType {
// MARK: - Properties
// MARK: Private
@@ -49,24 +48,25 @@ final class NotificationSettingsCoordinator: NotificationSettingsCoordinatorType
case .other:
viewController = VectorHostingController(rootView: OtherNotificationSettings(viewModel: viewModel))
}
self.notificationSettingsViewModel = viewModel
self.notificationSettingsViewController = viewController
notificationSettingsViewModel = viewModel
notificationSettingsViewController = viewController
}
// MARK: - Public methods
func start() {
self.notificationSettingsViewModel.coordinatorDelegate = self
func start() {
notificationSettingsViewModel.coordinatorDelegate = self
}
func toPresentable() -> UIViewController {
return self.notificationSettingsViewController
notificationSettingsViewController
}
}
// MARK: - NotificationSettingsViewModelCoordinatorDelegate
extension NotificationSettingsCoordinator: NotificationSettingsViewModelCoordinatorDelegate {
func notificationSettingsViewModelDidComplete(_ viewModel: NotificationSettingsViewModelType) {
self.delegate?.notificationSettingsCoordinatorDidComplete(self)
delegate?.notificationSettingsCoordinatorDidComplete(self)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,12 +14,11 @@
// limitations under the License.
//
import Foundation
import DesignKit
import Foundation
// Conformance of MXPushRule to the abstraction `NotificationPushRule` for use in `NotificationSettingsViewModel`.
extension MXPushRule: NotificationPushRuleType {
/// Given a rule, check it match the actions in the static definition.
/// - Parameter standardActions: The standard actions to match against.
/// - Returns: Wether `this` rule matches the standard actions.
@@ -27,7 +26,7 @@ extension MXPushRule: NotificationPushRuleType {
guard let standardActions = standardActions else {
return false
}
if !enabled && standardActions == .disabled {
if !enabled, standardActions == .disabled {
return true
}
@@ -75,10 +74,10 @@ extension MXPushRule: NotificationPushRuleType {
}
var notify: Bool {
return getAction(actionType: MXPushRuleActionTypeNotify) != nil
getAction(actionType: MXPushRuleActionTypeNotify) != nil
}
var dontNotify: Bool {
return getAction(actionType: MXPushRuleActionTypeDontNotify) != nil
getAction(actionType: MXPushRuleActionTypeDontNotify) != nil
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,6 +20,6 @@ struct MockNotificationPushRule: NotificationPushRuleType {
var ruleId: String!
var enabled: Bool
func matches(standardActions: NotificationStandardActions?) -> Bool {
return false
false
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,11 +33,11 @@ extension NotificationIndex {
/// - Parameter enabled: Enabled/Disabled state.
/// - Returns: The associated NotificationIndex
static func index(when enabled: Bool) -> NotificationIndex {
return enabled ? .noisy : .off
enabled ? .noisy : .off
}
/// Used to map from the checked state back to the index.
var enabled: Bool {
return self != .off
self != .off
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,6 @@
import Foundation
extension NotificationPushRuleId {
/// A static definition of the push rule actions.
///
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,7 +32,6 @@ enum NotificationPushRuleId: String {
case keywords = "_keywords"
}
extension NotificationPushRuleId: Identifiable {
var id: String {
rawValue
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,7 @@ import Foundation
extension NotificationSettingsScreen: CaseIterable { }
extension NotificationSettingsScreen: Identifiable {
var id: Int { self.rawValue }
var id: Int { rawValue }
}
extension NotificationSettingsScreen {
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,11 +14,10 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
class MXNotificationSettingsService: NotificationSettingsServiceType {
private let session: MXSession
private var cancellables = Set<AnyCancellable>()
@@ -26,11 +25,11 @@ class MXNotificationSettingsService: NotificationSettingsServiceType {
@Published private var rules = [MXPushRule]()
var rulesPublisher: AnyPublisher<[NotificationPushRuleType], Never> {
$rules.map({ $0.map({ $0 as NotificationPushRuleType }) }).eraseToAnyPublisher()
$rules.map { $0.map { $0 as NotificationPushRuleType } }.eraseToAnyPublisher()
}
var contentRulesPublisher: AnyPublisher<[NotificationPushRuleType], Never> {
$contentRules.map({ $0.map({ $0 as NotificationPushRuleType }) }).eraseToAnyPublisher()
$contentRules.map { $0.map { $0 as NotificationPushRuleType } }.eraseToAnyPublisher()
}
init(session: MXSession) {
@@ -45,7 +44,7 @@ class MXNotificationSettingsService: NotificationSettingsServiceType {
// Observe future updates to content rules
rulesUpdated
.compactMap({ _ in self.session.notificationCenter.rules.global.content as? [MXPushRule] })
.compactMap { _ in self.session.notificationCenter.rules.global.content as? [MXPushRule] }
.assign(to: &$contentRules)
// Set initial value of rules
@@ -54,7 +53,7 @@ class MXNotificationSettingsService: NotificationSettingsServiceType {
}
// Observe future updates to rules
rulesUpdated
.compactMap({ _ in self.session.notificationCenter.flatRules as? [MXPushRule] })
.compactMap { _ in self.session.notificationCenter.flatRules as? [MXPushRule] }
.assign(to: &$rules)
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +14,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
class MockNotificationSettingsService: NotificationSettingsServiceType, ObservableObject {
static let example = MockNotificationSettingsService()
@@ -44,7 +44,5 @@ class MockNotificationSettingsService: NotificationSettingsServiceType, Observab
keywords.remove(keyword)
}
func updatePushRuleActions(for ruleId: String, enabled: Bool, actions: NotificationActions?) {
}
func updatePushRuleActions(for ruleId: String, enabled: Bool, actions: NotificationActions?) { }
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +14,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
/// A service for changing notification settings and keywords
protocol NotificationSettingsServiceType {
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,10 +16,8 @@
import SwiftUI
/// A single rounded rect chip to be rendered within `Chips` collection
struct Chip: View {
@Environment(\.isEnabled) var isEnabled
@Environment(\.theme) var theme: ThemeSwiftUI
@@ -57,7 +55,6 @@ struct Chip: View {
.background(backgroundColor)
.foregroundColor(foregroundColor)
.cornerRadius(20)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,8 +18,7 @@ import SwiftUI
/// Renders multiple chips in a flow layout.
struct Chips: View {
@State private var frame: CGRect = CGRect.zero
@State private var frame = CGRect.zero
let titles: [String]
let didDeleteChip: (String) -> Void
@@ -56,7 +55,7 @@ struct Chips: View {
}
return result
}
.alignmentGuide(.top) { dimension in
.alignmentGuide(.top) { _ in
// Use next y value and reset if its the last.
let result = y
if chip == titles.last {
@@ -82,6 +81,5 @@ struct Chips_Previews: PreviewProvider {
Chips(titles: chips, didDeleteChip: { _ in })
.theme(.dark)
}
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,17 +18,15 @@ import SwiftUI
/// Renders an input field and a collection of chips.
struct ChipsInput: View {
@Environment(\.theme) var theme: ThemeSwiftUI
@Environment(\.isEnabled) var isEnabled
@State private var chipText: String = ""
@State private var chipText = ""
let titles: [String]
let didAddChip: (String) -> Void
let didDeleteChip: (String) -> Void
var placeholder: String = ""
var placeholder = ""
var body: some View {
VStack(spacing: 16) {
@@ -55,6 +53,5 @@ struct ChipsInput_Previews: PreviewProvider {
chips.remove(chip)
}
.disabled(true)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct DefaultNotificationSettings: View {
@ObservedObject var viewModel: NotificationSettingsViewModel
var body: some View {
@@ -38,6 +37,5 @@ struct DefaultNotifications_Previews: PreviewProvider {
)
.navigationBarTitleDisplayMode(.inline)
}
}
}
@@ -19,7 +19,6 @@ import SwiftUI
/// An input field style for forms.
struct FormInputFieldStyle: TextFieldStyle {
@Environment(\.theme) var theme: ThemeSwiftUI
@Environment(\.isEnabled) var isEnabled
@@ -31,7 +30,7 @@ struct FormInputFieldStyle: TextFieldStyle {
}
private var backgroundColor: Color {
if !isEnabled && theme.identifier == .dark {
if !isEnabled, theme.identifier == .dark {
return theme.colors.quinaryContent
}
return theme.colors.background
@@ -47,7 +46,6 @@ struct FormInputFieldStyle: TextFieldStyle {
}
}
struct FormInputFieldStyle_Previews: PreviewProvider {
static var previews: some View {
Group {
@@ -59,7 +57,6 @@ struct FormInputFieldStyle_Previews: PreviewProvider {
TextField("Placeholder", text: .constant("Web"))
.textFieldStyle(FormInputFieldStyle())
.disabled(true)
}
.padding()
VectorForm {
@@ -70,11 +67,9 @@ struct FormInputFieldStyle_Previews: PreviewProvider {
TextField("Placeholder", text: .constant("Web"))
.textFieldStyle(FormInputFieldStyle())
.disabled(true)
}
.padding()
.theme(ThemeIdentifier.dark)
}
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct MentionsAndKeywordNotificationSettings: View {
@ObservedObject var viewModel: NotificationSettingsViewModel
var keywordSection: some View {
@@ -28,6 +27,7 @@ struct MentionsAndKeywordNotificationSettings: View {
NotificationSettingsKeywords(viewModel: viewModel)
}
}
var body: some View {
NotificationSettings(
viewModel: viewModel,
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,6 @@ import SwiftUI
/// Also renders an optional bottom section.
/// Used in the case of keywords, for the keyword chips and input.
struct NotificationSettings<BottomSection: View>: View {
@ObservedObject var viewModel: NotificationSettingsViewModel
var bottomSection: BottomSection?
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,6 @@ struct NotificationSettingsKeywords: View {
placeholder: VectorL10n.settingsNewKeyword
)
.disabled(!(viewModel.viewState.selectionState[.keywords] ?? false))
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,12 +16,11 @@
limitations under the License.
*/
import Foundation
import Combine
import Foundation
import SwiftUI
final class NotificationSettingsViewModel: NotificationSettingsViewModelType, ObservableObject {
// MARK: - Properties
// MARK: Private
@@ -46,7 +45,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
init(notificationSettingsService: NotificationSettingsServiceType, ruleIds: [NotificationPushRuleId], initialState: NotificationSettingsViewState) {
self.notificationSettingsService = notificationSettingsService
self.ruleIds = ruleIds
self.viewState = initialState
viewState = initialState
// Observe when the rules are updated, to subsequently update the state of the settings.
notificationSettingsService.rulesPublisher
@@ -57,11 +56,11 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
if ruleIds.contains(.keywords) {
// Publisher of all the keyword push rules (keyword rules do not start with '.')
let keywordsRules = notificationSettingsService.contentRulesPublisher
.map { $0.filter { !$0.ruleId.starts(with: ".")} }
.map { $0.filter { !$0.ruleId.starts(with: ".") } }
// Map to just the keyword strings
let keywords = keywordsRules
.map { Set($0.compactMap { $0.ruleId }) }
.map { Set($0.compactMap(\.ruleId)) }
// Update the keyword set
keywords
@@ -100,7 +99,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
}
convenience init(notificationSettingsService: NotificationSettingsServiceType, ruleIds: [NotificationPushRuleId]) {
let ruleState = Dictionary(uniqueKeysWithValues: ruleIds.map({ ($0, selected: true) }))
let ruleState = Dictionary(uniqueKeysWithValues: ruleIds.map { ($0, selected: true) })
self.init(notificationSettingsService: notificationSettingsService, ruleIds: ruleIds, initialState: NotificationSettingsViewState(saving: false, ruleIds: ruleIds, selectionState: ruleState))
}
@@ -125,7 +124,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
private func updateKeywords(isChecked: Bool) {
guard !keywordsOrdered.isEmpty else {
self.viewState.selectionState[.keywords]?.toggle()
viewState.selectionState[.keywords]?.toggle()
return
}
// Get the static definition and update the actions and enabled state for every keyword.
@@ -149,22 +148,23 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
}
func remove(keyword: String) {
keywordsOrdered = keywordsOrdered.filter({ $0 != keyword })
keywordsOrdered = keywordsOrdered.filter { $0 != keyword }
notificationSettingsService.remove(keyword: keyword)
}
// MARK: - Private
private func rulesUpdated(newRules: [NotificationPushRuleType]) {
for rule in newRules {
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId),
ruleIds.contains(ruleId) else { continue }
self.viewState.selectionState[ruleId] = self.isChecked(rule: rule)
viewState.selectionState[ruleId] = isChecked(rule: rule)
}
}
private func keywordRuleUpdated(anyEnabled: Bool) {
if !keywordsOrdered.isEmpty {
self.viewState.selectionState[.keywords] = anyEnabled
viewState.selectionState[.keywords] = anyEnabled
}
}
@@ -178,7 +178,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId) else { return false }
let firstIndex = NotificationIndex.allCases.first { nextIndex in
return rule.matches(standardActions: ruleId.standardActions(for: nextIndex))
rule.matches(standardActions: ruleId.standardActions(for: nextIndex))
}
guard let index = firstIndex else {
@@ -187,5 +187,4 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
return index.enabled
}
}