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
@@ -15,8 +15,8 @@
//
import Foundation
import UIKit
import SwiftUI
import UIKit
internal protocol MatrixItemChooserCoordinatorViewProvider {
func view(with viewModel: MatrixItemChooserViewModelType.Context) -> AnyView
@@ -49,7 +49,6 @@ struct MatrixItemChooserCoordinatorParameters {
}
final class MatrixItemChooserCoordinator: Coordinator, Presentable {
// MARK: - Properties
// MARK: Private
@@ -94,6 +93,6 @@ final class MatrixItemChooserCoordinator: Coordinator, Presentable {
// MARK: - Presentable
func toPresentable() -> UIViewController {
return self.matrixItemChooserHostingController
matrixItemChooserHostingController
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -58,7 +58,7 @@ struct MatrixListItemSectionData {
}
}
extension MatrixListItemSectionData: Identifiable, Equatable {}
extension MatrixListItemSectionData: Identifiable, Equatable { }
struct MatrixListItemData {
let id: String
@@ -68,7 +68,7 @@ struct MatrixListItemData {
let detailText: String?
}
extension MatrixListItemData: Identifiable, Equatable {}
extension MatrixListItemData: Identifiable, Equatable { }
struct MatrixItemChooserSelectionHeader {
var title: String
@@ -14,21 +14,20 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias MatrixItemChooserViewModelType = StateStoreViewModel<MatrixItemChooserViewState,
Never,
MatrixItemChooserViewAction>
Never,
MatrixItemChooserViewAction>
class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChooserViewModelProtocol {
// MARK: - Properties
// MARK: Private
private var matrixItemChooserService: MatrixItemChooserServiceProtocol
private var isLoading: Bool = false {
private var isLoading = false {
didSet {
state.loading = isLoading
if isLoading {
@@ -44,7 +43,7 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
// MARK: - Setup
static func makeMatrixItemChooserViewModel(matrixItemChooserService: MatrixItemChooserServiceProtocol, title: String?, detail: String?, selectionHeader: MatrixItemChooserSelectionHeader?) -> MatrixItemChooserViewModelProtocol {
return MatrixItemChooserViewModel(matrixItemChooserService: matrixItemChooserService, title: title, detail: detail, selectionHeader: selectionHeader)
MatrixItemChooserViewModel(matrixItemChooserService: matrixItemChooserService, title: title, detail: detail, selectionHeader: selectionHeader)
}
private init(matrixItemChooserService: MatrixItemChooserServiceProtocol, title: String?, detail: String?, selectionHeader: MatrixItemChooserSelectionHeader?) {
@@ -98,13 +97,13 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
}
}
case .searchTextChanged(let searchText):
self.matrixItemChooserService.searchText = searchText
matrixItemChooserService.searchText = searchText
case .itemTapped(let itemId):
self.matrixItemChooserService.reverseSelectionForItem(withId: itemId)
matrixItemChooserService.reverseSelectionForItem(withId: itemId)
case .selectAll:
self.matrixItemChooserService.selectAllItems()
matrixItemChooserService.selectAllItems()
case .selectNone:
self.matrixItemChooserService.deselectAllItems()
matrixItemChooserService.deselectAllItems()
}
}
@@ -119,5 +118,4 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
private func back() {
completion?(.back)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import Foundation
protocol MatrixItemChooserViewModelProtocol {
var completion: ((MatrixItemChooserViewModelResult) -> Void)? { get set }
static func makeMatrixItemChooserViewModel(matrixItemChooserService: MatrixItemChooserServiceProtocol, title: String?, detail: String?, selectionHeader: MatrixItemChooserSelectionHeader?) -> MatrixItemChooserViewModelProtocol
var context: MatrixItemChooserViewModelType.Context { get }
@@ -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,8 +14,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
protocol MatrixItemChooserServiceProtocol {
var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never> { get }
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import Foundation
class MatrixItemChooserDirectChildrenDataSource: MatrixItemChooserDataSource {
// MARK: - Private
private let parentId: String
@@ -34,13 +33,13 @@ class MatrixItemChooserDirectChildrenDataSource: MatrixItemChooserDataSource {
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
let space = session.spaceService.getSpace(withId: parentId)
let children: [MatrixListItemData] = space?.childRoomIds.compactMap({ roomId in
let children: [MatrixListItemData] = space?.childRoomIds.compactMap { roomId in
guard let room = session.room(withRoomId: roomId), !room.isDirect else {
return nil
}
return MatrixListItemData(mxRoom: room, spaceService: session.spaceService)
}) ?? []
} ?? []
completion(Result(catching: {
[
MatrixListItemSectionData(items: children)
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +28,7 @@ class MatrixItemChooserRoomAncestorsDataSource: MatrixItemChooserDataSource {
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
let ancestorsIds = session.spaceService.ancestorsPerRoomId[roomId] ?? []
completion(Result(catching: {
return [
[
MatrixListItemSectionData(title: VectorL10n.roomAccessSpaceChooserKnownSpacesSection(session.room(withRoomId: roomId)?.displayName ?? ""), items: ancestorsIds.compactMap { spaceId in
guard let space = session.spaceService.getSpace(withId: spaceId) else {
return nil
@@ -22,7 +22,6 @@ enum MatrixItemChooserRoomDirectParentsDataSourcePreselectionMode {
}
class MatrixItemChooserRoomDirectParentsDataSource: MatrixItemChooserDataSource {
private let roomId: String
private let preselectionMode: MatrixItemChooserRoomDirectParentsDataSourcePreselectionMode
@@ -44,7 +43,7 @@ class MatrixItemChooserRoomDirectParentsDataSource: MatrixItemChooserDataSource
}
completion(Result(catching: {
return [
[
MatrixListItemSectionData(title: VectorL10n.roomAccessSpaceChooserKnownSpacesSection(session.room(withRoomId: roomId)?.displayName ?? ""), items: ancestorsIds.compactMap { spaceId in
guard let space = session.spaceService.getSpace(withId: spaceId) else {
return nil
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,7 +34,7 @@ class MatrixItemChooserRoomRestrictedAllowedParentsDataSource: MatrixItemChooser
}
room.state { [weak self] state in
guard let self = self else { return }
guard let self = self else { return }
let joinRuleEvent = state?.stateEvents(with: .roomJoinRules)?.last
let allowContent: [[String: String]] = joinRuleEvent?.wireContent[kMXJoinRulesContentKeyAllow] as? [[String: String]] ?? []
@@ -74,19 +74,20 @@ class MatrixItemChooserRoomRestrictedAllowedParentsDataSource: MatrixItemChooser
sections.append(MatrixListItemSectionData(
title: VectorL10n.roomAccessSpaceChooserOtherSpacesSection,
infoText: VectorL10n.roomAccessSpaceChooserOtherSpacesSectionInfo(room.displayName ?? ""),
items: unknownParents.compactMap({ roomId in
items: unknownParents.compactMap { roomId in
MatrixListItemData(
id: roomId,
type: .space,
avatar: AvatarInput(mxContentUri: roomId, matrixItemId: roomId, displayName: roomId),
displayName: roomId,
detailText: nil)
})
detailText: nil
)
}
))
}
completion(Result(catching: {
return sections
sections
}))
}
}
@@ -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,8 +14,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
protocol MatrixItemChooserDataSource {
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void)
@@ -25,12 +25,11 @@ protocol MatrixItemChooserDataSource {
protocol MatrixItemChooserProcessorProtocol {
var loadingText: String? { get }
var dataSource: MatrixItemChooserDataSource { get }
func computeSelection(withIds itemsIds:[String], completion: @escaping (Result<Void, Error>) -> Void)
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool
func computeSelection(withIds itemsIds: [String], completion: @escaping (Result<Void, Error>) -> Void)
func isItemIncluded(_ item: MatrixListItemData) -> Bool
}
class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
// MARK: - Properties
// MARK: Private
@@ -45,6 +44,7 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
sectionsSubject.send(filteredSections)
}
}
private var selectedItemIds: Set<String>
private let itemsProcessor: MatrixItemChooserProcessorProtocol
@@ -52,14 +52,16 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
private(set) var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never>
private(set) var selectedItemIdsSubject: CurrentValueSubject<Set<String>, Never>
var searchText: String = "" {
var searchText = "" {
didSet {
refresh()
}
}
var loadingText: String? {
itemsProcessor.loadingText
}
var itemCount: Int {
var itemCount = 0
for section in sections {
@@ -72,10 +74,10 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
init(session: MXSession, selectedItemIds: [String], itemsProcessor: MatrixItemChooserProcessorProtocol) {
self.session = session
self.sectionsSubject = CurrentValueSubject(self.sections)
sectionsSubject = CurrentValueSubject(sections)
self.selectedItemIds = Set(selectedItemIds)
self.selectedItemIdsSubject = CurrentValueSubject(self.selectedItemIds)
selectedItemIdsSubject = CurrentValueSubject(self.selectedItemIds)
self.itemsProcessor = itemsProcessor
itemsProcessor.dataSource.sections(with: session) { [weak self] result in
@@ -115,7 +117,7 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
}
func refresh() {
self.processingQueue.async { [weak self] in
processingQueue.async { [weak self] in
guard let self = self else { return }
let filteredSections = self.filter(sections: self.sections)
@@ -132,12 +134,12 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
newSelection.insert(item.id)
}
}
self.selectedItemIds = newSelection
selectedItemIds = newSelection
selectedItemIdsSubject.send(selectedItemIds)
}
func deselectAllItems() {
self.selectedItemIds = Set()
selectedItemIds = Set()
selectedItemIdsSubject.send(selectedItemIds)
}
@@ -153,7 +155,7 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
itemsProcessor.isItemIncluded($0)
}
} else {
let lowercasedSearchText = self.searchText.lowercased()
let lowercasedSearchText = searchText.lowercased()
items = section.items.filter {
itemsProcessor.isItemIncluded($0) && ($0.id.lowercased().contains(lowercasedSearchText) || ($0.displayName ?? "").lowercased().contains(lowercasedSearchText))
}
@@ -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");
@@ -17,7 +17,6 @@
import Foundation
extension MatrixListItemData {
init(mxUser: MXUser) {
self.init(id: mxUser.userId, type: .user, avatar: mxUser.avatarData, displayName: mxUser.displayname, detailText: mxUser.userId)
}
@@ -54,5 +53,4 @@ extension MatrixListItemData {
}
self.init(id: mxRoom.roomId, type: type, avatar: mxRoom.avatarData, displayName: mxRoom.summary.displayname, detailText: detailText)
}
}
@@ -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 MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
static let mockSections = [
MatrixListItemSectionData(title: "Section 1", infoText: "This is the first section with a very long description in order to check multi line description", items: [
MatrixListItemData(id: "!aaabaa:matrix.org", type: .room, avatar: MockAvatarInput.example, displayName: "Item #1 section #1", detailText: "Descripton of this room"),
@@ -33,11 +32,12 @@ class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
]
var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never>
var selectedItemIdsSubject: CurrentValueSubject<Set<String>, Never>
var searchText: String = ""
var searchText = ""
var selectedItemIds: Set<String> = Set()
var loadingText: String? {
nil
}
var itemCount: Int {
var itemCount = 0
for section in sectionsSubject.value {
@@ -82,9 +82,7 @@ class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
completion(Result.success(()))
}
func refresh() {
}
func refresh() { }
func selectAllItems() {
var newSelection: Set<String> = Set()
@@ -93,12 +91,12 @@ class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
newSelection.insert(item.id)
}
}
self.selectedItemIds = newSelection
selectedItemIds = newSelection
selectedItemIdsSubject.send(selectedItemIds)
}
func deselectAllItems() {
self.selectedItemIds = Set()
selectedItemIds = Set()
selectedItemIdsSubject.send(selectedItemIds)
}
}
@@ -14,8 +14,8 @@
// limitations under the License.
//
import XCTest
import RiotSwiftUI
import XCTest
class MatrixItemChooserUITests: MockScreenTestCase {
func testEmptyScreen() {
@@ -42,5 +42,4 @@ class MatrixItemChooserUITests: MockScreenTestCase {
XCTAssertEqual(app.staticTexts["messageText"].label, VectorL10n.spacesCreationAddRoomsMessage)
XCTAssertEqual(app.staticTexts["emptyListMessage"].exists, false)
}
}
@@ -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 XCTest
import Combine
import XCTest
@testable import RiotSwiftUI
@@ -19,12 +19,11 @@
import SwiftUI
struct MatrixItemChooser: View {
// MARK: Properties
@ObservedObject var viewModel: MatrixItemChooserViewModel.Context
let listBottomPadding: CGFloat?
@State var searchText: String = ""
@State var searchText = ""
// MARK: Private
@@ -113,7 +112,7 @@ struct MatrixItemChooser: View {
}
Spacer().frame(height: spacerHeight)
SearchBar(placeholder: VectorL10n.searchDefaultPlaceholder, text: $searchText)
.onChange(of: searchText) { value in
.onChange(of: searchText) { _ in
viewModel.send(viewAction: .searchTextChanged(searchText))
}
if let selectionHeader = viewModel.viewState.selectionHeader, searchText.isEmpty {
@@ -124,7 +123,7 @@ struct MatrixItemChooser: View {
}
private func itemSelectionHeader(with selectionHeader: MatrixItemChooserSelectionHeader) -> some View {
VStack(alignment:.leading) {
VStack(alignment: .leading) {
HStack {
Text(selectionHeader.title)
.font(theme.fonts.calloutSB)
@@ -151,7 +150,6 @@ struct MatrixItemChooser: View {
// MARK: - Previews
struct MatrixItemChooser_Previews: PreviewProvider {
static let stateRenderer = MockMatrixItemChooserScreenState.stateRenderer
static var previews: some View {
stateRenderer.screenGroup(addNavigation: false)
@@ -17,7 +17,6 @@
import SwiftUI
struct MatrixItemChooserListRow: View {
// MARK: - Properties
// MARK: Private
@@ -34,7 +33,7 @@ struct MatrixItemChooserListRow: View {
@ViewBuilder
var body: some View {
HStack{
HStack {
if type == .space {
SpaceAvatarImage(avatarData: avatar, size: .small)
} else {
@@ -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 MatrixItemChooserSectionHeader: View {
// MARK: - Properties
// MARK: Private