mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
CoordinatorParamters, Type -> Protocol, remove MX Prefix.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
import Foundation
|
||||
|
||||
/// AvatarViewDataProtocol describe a view data that should be given to an AvatarView sublcass
|
||||
protocol AvatarViewDataProtocol: AvatarType {
|
||||
protocol AvatarViewDataProtocol: AvatarProtocol {
|
||||
/// Matrix item identifier (user id or room id)
|
||||
var matrixItemId: String { get }
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol AvatarInputType: AvatarType {
|
||||
protocol AvatarInputProtocol: AvatarProtocol {
|
||||
var mxContentUri: String? { get }
|
||||
var matrixItemId: String { get }
|
||||
var displayName: String? { get }
|
||||
}
|
||||
|
||||
struct AvatarInput: AvatarInputType {
|
||||
struct AvatarInput: AvatarInputProtocol {
|
||||
let mxContentUri: String?
|
||||
var matrixItemId: String
|
||||
let displayName: String?
|
||||
@@ -16,4 +16,4 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol AvatarType { }
|
||||
protocol AvatarProtocol { }
|
||||
@@ -22,7 +22,7 @@ import Foundation
|
||||
E.g. MXRoom, MxUser cna conform to this making it
|
||||
easy to grab the avatar data for display.
|
||||
*/
|
||||
protocol Avatarable: AvatarInputType { }
|
||||
protocol Avatarable: AvatarInputProtocol { }
|
||||
extension Avatarable {
|
||||
var avatarData: AvatarInput {
|
||||
AvatarInput(
|
||||
|
||||
@@ -19,12 +19,12 @@ import MatrixSDK
|
||||
import Combine
|
||||
import DesignKit
|
||||
|
||||
enum MXAvatarServiceError: Error {
|
||||
enum AvatarServiceError: Error {
|
||||
case pathNotfound
|
||||
case loadingImageFailed(Error?)
|
||||
}
|
||||
|
||||
class MXAvatarService: AvatarServiceType {
|
||||
class AvatarService: AvatarServiceProtocol {
|
||||
|
||||
private enum Constants {
|
||||
static let mimeType = "image/jpeg"
|
||||
@@ -33,8 +33,8 @@ class MXAvatarService: AvatarServiceType {
|
||||
|
||||
private let mediaManager: MXMediaManager
|
||||
|
||||
static func instantiate(mediaManager: MXMediaManager) -> AvatarServiceType {
|
||||
return MXAvatarService(mediaManager: mediaManager)
|
||||
static func instantiate(mediaManager: MXMediaManager) -> AvatarServiceProtocol {
|
||||
return AvatarService(mediaManager: mediaManager)
|
||||
}
|
||||
|
||||
init(mediaManager: MXMediaManager) {
|
||||
@@ -73,18 +73,18 @@ class MXAvatarService: AvatarServiceType {
|
||||
toFitViewSize: avatarSize.size,
|
||||
with: Constants.thumbnailMethod) { path in
|
||||
guard let path = path else {
|
||||
promise(.failure(MXAvatarServiceError.pathNotfound))
|
||||
promise(.failure(AvatarServiceError.pathNotfound))
|
||||
return
|
||||
}
|
||||
|
||||
guard let image = MXMediaManager.loadThroughCache(withFilePath: path),
|
||||
let imageUp = Self.orientImageUp(image: image) else {
|
||||
promise(.failure(MXAvatarServiceError.loadingImageFailed(nil)))
|
||||
promise(.failure(AvatarServiceError.loadingImageFailed(nil)))
|
||||
return
|
||||
}
|
||||
promise(.success(imageUp))
|
||||
} failure: { error in
|
||||
promise(.failure(MXAvatarServiceError.loadingImageFailed(error)))
|
||||
promise(.failure(AvatarServiceError.loadingImageFailed(error)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ import DesignKit
|
||||
import UIKit
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class MockAvatarService: AvatarServiceType {
|
||||
static let example: AvatarServiceType = MockAvatarService()
|
||||
class MockAvatarService: AvatarServiceProtocol {
|
||||
static let example: AvatarServiceProtocol = MockAvatarService()
|
||||
func avatarImage(mxContentUri: String, avatarSize: AvatarSize) -> Future<UIImage, Error> {
|
||||
Future { promise in
|
||||
promise(.success(Asset.Images.appSymbol.image))
|
||||
|
||||
@@ -66,7 +66,7 @@ struct AvatarImage: View {
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
extension AvatarImage {
|
||||
init(avatarData: AvatarInputType, size: AvatarSize) {
|
||||
init(avatarData: AvatarInputProtocol, size: AvatarSize) {
|
||||
self.init(
|
||||
mxContentUri: avatarData.mxContentUri,
|
||||
matrixItemId: avatarData.matrixItemId,
|
||||
|
||||
@@ -22,7 +22,7 @@ import UIKit
|
||||
/**
|
||||
Provides a simple api to retrieve and cache avatar images
|
||||
*/
|
||||
protocol AvatarServiceType {
|
||||
protocol AvatarServiceProtocol {
|
||||
@available(iOS 14.0, *)
|
||||
func avatarImage(mxContentUri: String, avatarSize: AvatarSize) -> Future<UIImage, Error>
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import DesignKit
|
||||
@available(iOS 14.0, *)
|
||||
class AvatarViewModel: InjectableObject, ObservableObject {
|
||||
|
||||
@Inject var avatarService: AvatarServiceType
|
||||
@Inject var avatarService: AvatarServiceProtocol
|
||||
|
||||
@Published private(set) var viewState = AvatarViewState.empty
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ final class RoomNotificationSettingsCoordinator: RoomNotificationSettingsCoordin
|
||||
|
||||
init(room: MXRoom, presentedModally: Bool = true) {
|
||||
let roomNotificationService = MXRoomNotificationSettingsService(room: room)
|
||||
let avatarData: AvatarType?
|
||||
let avatarData: AvatarProtocol?
|
||||
let showAvatar = presentedModally
|
||||
if #available(iOS 14.0.0, *) {
|
||||
avatarData = showAvatar ? AvatarInput(
|
||||
@@ -64,7 +64,7 @@ final class RoomNotificationSettingsCoordinator: RoomNotificationSettingsCoordin
|
||||
avatarData: avatarData,
|
||||
displayName: room.summary.displayname,
|
||||
roomEncrypted: room.summary.isEncrypted)
|
||||
let avatarService: AvatarServiceType = MXAvatarService(mediaManager: room.mxSession.mediaManager)
|
||||
let avatarService: AvatarServiceProtocol = AvatarService(mediaManager: room.mxSession.mediaManager)
|
||||
let view = RoomNotificationSettings(viewModel: swiftUIViewModel, presentedModally: presentedModally)
|
||||
.addDependency(avatarService)
|
||||
let host = VectorHostingController(rootView: view)
|
||||
|
||||
@@ -21,7 +21,7 @@ struct RoomNotificationSettingsViewState: RoomNotificationSettingsViewStateType
|
||||
let roomEncrypted: Bool
|
||||
var saving: Bool
|
||||
var notificationState: RoomNotificationState
|
||||
var avatarData: AvatarType?
|
||||
var avatarData: AvatarProtocol?
|
||||
var displayName: String?
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ protocol RoomNotificationSettingsViewStateType {
|
||||
var roomEncrypted: Bool { get }
|
||||
var notificationOptions: [RoomNotificationState] { get }
|
||||
var notificationState: RoomNotificationState { get }
|
||||
var avatarData: AvatarType? { get }
|
||||
var avatarData: AvatarProtocol? { get }
|
||||
var displayName: String? { get }
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ struct RoomNotificationSettings: View {
|
||||
|
||||
var body: some View {
|
||||
VectorForm {
|
||||
if let avatarData = viewModel.viewState.avatarData as? AvatarInputType {
|
||||
if let avatarData = viewModel.viewState.avatarData as? AvatarInputProtocol {
|
||||
RoomNotificationSettingsHeader(
|
||||
avatarData: avatarData,
|
||||
displayName: viewModel.viewState.displayName
|
||||
|
||||
@@ -20,7 +20,7 @@ import SwiftUI
|
||||
struct RoomNotificationSettingsHeader: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var avatarData: AvatarInputType
|
||||
var avatarData: AvatarInputProtocol
|
||||
var displayName: String?
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -55,7 +55,7 @@ class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModelType {
|
||||
|
||||
convenience init(
|
||||
roomNotificationService: RoomNotificationSettingsServiceType,
|
||||
avatarData: AvatarType?,
|
||||
avatarData: AvatarProtocol?,
|
||||
displayName: String?,
|
||||
roomEncrypted: Bool
|
||||
) {
|
||||
|
||||
@@ -24,7 +24,7 @@ final class TemplateUserProfileCoordinator: Coordinator {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let session: MXSession
|
||||
private let parameters: TemplateUserProfileCoordinatorParameters
|
||||
private let templateUserProfileViewController: UIViewController
|
||||
private var templateUserProfileViewModel: TemplateUserProfileViewModelProtocol
|
||||
|
||||
@@ -37,11 +37,11 @@ final class TemplateUserProfileCoordinator: Coordinator {
|
||||
// MARK: - Setup
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
init(session: MXSession) {
|
||||
self.session = session
|
||||
let viewModel = TemplateUserProfileViewModel(userService: MXTemplateUserProfileService(session: session))
|
||||
init(parameters: TemplateUserProfileCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
let viewModel = TemplateUserProfileViewModel(userService: TemplateUserProfileService(session: parameters.session))
|
||||
let view = TemplateUserProfile(viewModel: viewModel)
|
||||
.addDependency(MXAvatarService.instantiate(mediaManager: session.mediaManager))
|
||||
.addDependency(AvatarService.instantiate(mediaManager: parameters.session.mediaManager))
|
||||
templateUserProfileViewModel = viewModel
|
||||
templateUserProfileViewController = VectorHostingController(rootView: view)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct TemplateUserProfileCoordinatorParameters {
|
||||
let session: MXSession
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
import Foundation
|
||||
|
||||
struct TemplateUserProfileViewState {
|
||||
let avatar: AvatarInputType?
|
||||
let avatar: AvatarInputProtocol?
|
||||
let displayName: String?
|
||||
var presence: TemplateUserProfilePresence
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import Foundation
|
||||
import Combine
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class MXTemplateUserProfileService: TemplateUserProfileServiceProtocol {
|
||||
class TemplateUserProfileService: TemplateUserProfileServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@@ -24,7 +24,7 @@ struct TemplateUserProfileHeader: View {
|
||||
// MARK: Public
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
let avatar: AvatarInputType?
|
||||
let avatar: AvatarInputProtocol?
|
||||
let displayName: String?
|
||||
let presence: TemplateUserProfilePresence
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class RoomNotificationSettingsViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
func setupViewModel(roomEncrypted: Bool, showAvatar: Bool) {
|
||||
let avatarData: AvatarType? = showAvatar ? Constants.avatarData : nil
|
||||
let avatarData: AvatarProtocol? = showAvatar ? Constants.avatarData : nil
|
||||
let viewModel = RoomNotificationSettingsViewModel(roomNotificationService: service, avatarData: avatarData, displayName: Constants.roomDisplayName, roomEncrypted: roomEncrypted)
|
||||
viewModel.viewDelegate = view
|
||||
viewModel.coordinatorDelegate = coordinator
|
||||
|
||||
Reference in New Issue
Block a user