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
@@ -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 Combine
import DesignKit
import Foundation
import UIKit
/// Provides a simple api to retrieve and cache avatar images
protocol AvatarServiceProtocol {
func avatarImage(mxContentUri: String, avatarSize: AvatarSize) -> Future<UIImage, Error>
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,13 +14,12 @@
// limitations under the License.
//
import Foundation
import Combine
import DesignKit
import Foundation
/// Simple ViewModel that supports loading an avatar image
class AvatarViewModel: InjectableObject, ObservableObject {
@Inject var avatarService: AvatarServiceProtocol
@Published private(set) var viewState = AvatarViewState.empty
@@ -34,24 +33,22 @@ class AvatarViewModel: InjectableObject, ObservableObject {
/// - displayName: Display name of the avatar.
/// - colorCount: The count of total avatar colors used to generate the stable color index.
/// - avatarSize: The size of the avatar to fetch (as defined within DesignKit).
func loadAvatar(
mxContentUri: String?,
matrixItemId: String,
displayName: String?,
colorCount: Int,
avatarSize: AvatarSize) {
func loadAvatar(mxContentUri: String?,
matrixItemId: String,
displayName: String?,
colorCount: Int,
avatarSize: AvatarSize) {
let placeholderViewModel = PlaceholderAvatarViewModel(displayName: displayName,
matrixItemId: matrixItemId,
colorCount: colorCount)
self.viewState = .placeholder(placeholderViewModel.firstCharacterCapitalized, placeholderViewModel.stableColorIndex)
viewState = .placeholder(placeholderViewModel.firstCharacterCapitalized, placeholderViewModel.stableColorIndex)
guard let mxContentUri = mxContentUri, mxContentUri.count > 0 else {
return
}
avatarService.avatarImage(mxContentUri: mxContentUri, avatarSize: avatarSize)
avatarService.avatarImage(mxContentUri: mxContentUri, avatarSize: avatarSize)
.sink { completion in
guard case let .failure(error) = completion else { return }
UILog.error("[AvatarService] Failed to retrieve avatar", context: error)
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,7 @@ struct PlaceholderAvatarViewModel {
/// Get the first character of the display name capitalized or else a space character.
var firstCharacterCapitalized: Character {
return displayName?.capitalized.first ?? " "
displayName?.capitalized.first ?? " "
}
/// Provides the same color each time for a specified matrixId
@@ -39,7 +39,7 @@ struct PlaceholderAvatarViewModel {
var stableColorIndex: Int {
// Sum all characters
let sum = matrixItemId.utf8
.map({ UInt($0) })
.map { UInt($0) }
.reduce(0, +)
// modulo the color count
return Int(sum) % colorCount